2017-02-13 15:11:45 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// This code is licensed under the MIT License (MIT).
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
//
|
2015-08-20 21:09:14 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-13 00:44:17 -04:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
// blanket turn off warnings from CppCoreCheck from catch
|
|
|
|
// so people aren't annoyed by them when running the tool.
|
2019-10-02 19:17:46 -04:00
|
|
|
#pragma warning(disable : 26440 26426) // from catch
|
|
|
|
#pragma warning(disable : 4996) // use of function or classes marked [[deprecated]]
|
2019-10-04 15:38:55 -04:00
|
|
|
#endif
|
2019-10-02 19:17:46 -04:00
|
|
|
|
2019-10-04 15:38:55 -04:00
|
|
|
#if __clang__ || __GNUC__
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
2019-12-04 15:30:58 -05:00
|
|
|
|
|
|
|
//disable warnings from gtest
|
2019-12-04 15:48:13 -05:00
|
|
|
#pragma GCC diagnostic ignored "-Wundef"
|
2019-12-19 17:05:02 -05:00
|
|
|
#endif // __clang__ || __GNUC__
|
|
|
|
|
2019-12-06 19:03:47 -05:00
|
|
|
#if __clang__
|
2019-12-04 15:30:58 -05:00
|
|
|
#pragma GCC diagnostic ignored "-Wglobal-constructors"
|
|
|
|
#pragma GCC diagnostic ignored "-Wused-but-marked-unused"
|
|
|
|
#pragma GCC diagnostic ignored "-Wcovered-switch-default"
|
2020-01-08 13:13:00 -05:00
|
|
|
#pragma GCC diagnostic ignored "-Winconsistent-missing-destructor-override"
|
2019-12-19 17:05:02 -05:00
|
|
|
#endif // __clang__
|
2018-08-13 00:44:17 -04:00
|
|
|
|
2019-12-04 15:30:58 -05:00
|
|
|
#include <gtest/gtest.h>
|
2017-04-20 10:51:37 -04:00
|
|
|
|
2017-11-28 10:13:49 -05:00
|
|
|
#include <gsl/multi_span> // for static_bounds, static_bounds_dynamic_range_t
|
2017-04-20 10:51:37 -04:00
|
|
|
|
2017-11-28 10:13:49 -05:00
|
|
|
#include <cstddef> // for ptrdiff_t, size_t
|
|
|
|
|
2015-08-20 21:09:14 -04:00
|
|
|
using namespace std;
|
2016-11-03 21:38:32 -04:00
|
|
|
using namespace gsl;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2017-02-13 15:11:45 -05:00
|
|
|
namespace
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
2017-04-20 10:51:37 -04:00
|
|
|
void use(std::ptrdiff_t&) {}
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
|
|
|
|
2019-12-03 17:32:25 -05:00
|
|
|
TEST(bounds_tests, basic_bounds)
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
2017-07-13 16:53:56 -04:00
|
|
|
for (auto point : static_bounds<dynamic_range, 3, 4>{2}) {
|
|
|
|
for (decltype(point)::size_type j = 0;
|
|
|
|
j < static_cast<decltype(point)::size_type>(decltype(point)::rank); j++)
|
|
|
|
{
|
|
|
|
use(j);
|
|
|
|
use(point[static_cast<std::size_t>(j)]);
|
2017-04-20 10:51:37 -04:00
|
|
|
}
|
|
|
|
}
|
2017-07-13 16:53:56 -04:00
|
|
|
}
|
2017-04-20 10:51:37 -04:00
|
|
|
|
2019-12-03 17:32:25 -05:00
|
|
|
TEST(bounds_tests, bounds_basic)
|
2017-07-13 16:53:56 -04:00
|
|
|
{
|
|
|
|
static_bounds<3, 4, 5> b;
|
|
|
|
const auto a = b.slice();
|
|
|
|
(void) a;
|
|
|
|
static_bounds<4, dynamic_range, 2> x{4};
|
|
|
|
x.slice().slice();
|
|
|
|
}
|
2017-04-20 10:51:37 -04:00
|
|
|
|
2019-12-03 17:32:25 -05:00
|
|
|
TEST(bounds_tests, arrayview_iterator)
|
2017-07-13 16:53:56 -04:00
|
|
|
{
|
|
|
|
static_bounds<4, dynamic_range, 2> bounds{3};
|
2017-04-20 10:51:37 -04:00
|
|
|
|
2017-07-13 16:53:56 -04:00
|
|
|
const auto itr = bounds.begin();
|
|
|
|
(void) itr;
|
2015-08-20 21:09:14 -04:00
|
|
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
2017-07-13 16:53:56 -04:00
|
|
|
multi_span<int, 4, dynamic_range, 2> av(nullptr, bounds);
|
2017-02-13 15:11:45 -05:00
|
|
|
|
2017-07-13 16:53:56 -04:00
|
|
|
auto itr2 = av.cbegin();
|
2017-02-13 15:11:45 -05:00
|
|
|
|
2017-07-13 16:53:56 -04:00
|
|
|
for (auto& v : av) {
|
|
|
|
v = 4;
|
2017-04-20 10:51:37 -04:00
|
|
|
}
|
2017-07-13 16:53:56 -04:00
|
|
|
fill(av.begin(), av.end(), 0);
|
|
|
|
#endif
|
|
|
|
}
|
2017-02-13 15:11:45 -05:00
|
|
|
|
2019-12-03 17:32:25 -05:00
|
|
|
TEST(bounds_tests, bounds_convertible)
|
2017-07-13 16:53:56 -04:00
|
|
|
{
|
|
|
|
static_bounds<7, 4, 2> b1;
|
|
|
|
static_bounds<7, dynamic_range, 2> b2 = b1;
|
|
|
|
(void) b2;
|
2015-08-20 21:09:14 -04:00
|
|
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
2017-07-13 16:53:56 -04:00
|
|
|
static_bounds<7, dynamic_range, 1> b4 = b2;
|
2015-08-20 21:09:14 -04:00
|
|
|
#endif
|
2017-02-13 15:11:45 -05:00
|
|
|
|
2017-07-13 16:53:56 -04:00
|
|
|
static_bounds<dynamic_range, dynamic_range, dynamic_range> b3 = b1;
|
|
|
|
static_bounds<7, 4, 2> b4 = b3;
|
|
|
|
(void) b4;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2017-07-13 16:53:56 -04:00
|
|
|
static_bounds<dynamic_range> b5;
|
|
|
|
static_bounds<34> b6;
|
2017-02-13 15:11:45 -05:00
|
|
|
|
2019-12-12 13:55:26 -05:00
|
|
|
std::set_terminate([] {
|
|
|
|
std::cerr << "Expected Death. bounds_convertible";
|
|
|
|
std::abort();
|
|
|
|
});
|
|
|
|
|
2017-07-13 16:53:56 -04:00
|
|
|
b5 = static_bounds<20>();
|
2019-12-03 17:32:25 -05:00
|
|
|
EXPECT_DEATH(b6 = b5, ".*");
|
2017-07-13 16:53:56 -04:00
|
|
|
b5 = static_bounds<34>();
|
|
|
|
b6 = b5;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2019-12-04 16:46:50 -05:00
|
|
|
EXPECT_TRUE(b5 == b6);
|
|
|
|
EXPECT_TRUE(b5.size() == b6.size());
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
2018-08-13 00:44:17 -04:00
|
|
|
|
|
|
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
|
|
|
copy(src_span_static, dst_span_static);
|
|
|
|
#endif
|
2019-10-04 15:38:55 -04:00
|
|
|
|
|
|
|
#if __clang__ || __GNUC__
|
|
|
|
#pragma GCC diagnostic pop
|
2019-12-19 17:05:02 -05:00
|
|
|
#endif // __clang__ || __GNUC__
|