mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-25 01:01:58 -05:00
changing text in notices & readme. adding terminate handler for tests
This commit is contained in:
parent
ec05ecd6b1
commit
4f6f05d463
@ -18,7 +18,7 @@ other platforms. Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more inform
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
||||
# Usage of Third Party Libraries
|
||||
This project makes use of the [Catch](https://github.com/philsquared/catch) testing library. Please see the [ThirdPartyNotices.txt](./ThirdPartyNotices.txt) file for details regarding the licensing of Catch.
|
||||
This project makes use of the [Google Test](https://github.com/google/gooletest) testing library. Please see the [ThirdPartyNotices.txt](./ThirdPartyNotices.txt) file for details regarding the licensing of Google Test.
|
||||
|
||||
# Quick Start
|
||||
## Supported Platforms
|
||||
|
@ -3,8 +3,6 @@ THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
|
||||
Do Not Translate or Localize
|
||||
|
||||
GSL: Guidelines Support Library incorporates third party material from the projects listed below.
|
||||
The original copyright notice and the license under which Microsoft received such third party material are set forth below.
|
||||
Microsoft reserves all other rights not expressly granted, whether by implication, estoppel or otherwise.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Software: Google Test
|
||||
|
@ -188,5 +188,5 @@ function(add_gsl_test_noexcept name)
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "GSL_tests_noexcept")
|
||||
endfunction()
|
||||
|
||||
# add_gsl_test_noexcept(no_exception_throw_tests)
|
||||
# add_gsl_test_noexcept(no_exception_ensure_tests)
|
||||
add_gsl_test_noexcept(no_exception_throw_tests)
|
||||
add_gsl_test_noexcept(no_exception_ensure_tests)
|
||||
|
@ -21,7 +21,7 @@
|
||||
#endif
|
||||
|
||||
#if __clang__ || __GNUC__
|
||||
//disable warnings from gtest
|
||||
// disable warnings from gtest
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wundef"
|
||||
#endif
|
||||
@ -34,11 +34,16 @@
|
||||
|
||||
#include <gsl/gsl_algorithm> // for copy
|
||||
#include <gsl/span> // for span
|
||||
|
||||
#include <array> // for array
|
||||
#include <string_view>
|
||||
#include <cstddef> // for size_t
|
||||
|
||||
namespace gsl {
|
||||
namespace{
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
}
|
||||
|
||||
namespace gsl
|
||||
{
|
||||
struct fail_fast;
|
||||
} // namespace gsl
|
||||
|
||||
@ -58,7 +63,8 @@ TEST(algorithm_tests, same_type)
|
||||
copy(src_span, dst_span);
|
||||
copy(src_span, dst_span.subspan(src_span.size()));
|
||||
|
||||
for (std::size_t i = 0; i < src.size(); ++i) {
|
||||
for (std::size_t i = 0; i < src.size(); ++i)
|
||||
{
|
||||
EXPECT_TRUE(dst[i] == src[i]);
|
||||
EXPECT_TRUE(dst[i + src.size()] == src[i]);
|
||||
}
|
||||
@ -75,7 +81,8 @@ TEST(algorithm_tests, same_type)
|
||||
copy(src_span, dst_span);
|
||||
copy(src_span, dst_span.subspan(src_span.size()));
|
||||
|
||||
for (std::size_t i = 0; i < src.size(); ++i) {
|
||||
for (std::size_t i = 0; i < src.size(); ++i)
|
||||
{
|
||||
EXPECT_TRUE(dst[i] == src[i]);
|
||||
EXPECT_TRUE(dst[i + src.size()] == src[i]);
|
||||
}
|
||||
@ -92,7 +99,8 @@ TEST(algorithm_tests, same_type)
|
||||
copy(src_span, dst_span);
|
||||
copy(src_span, dst_span.subspan(src_span.size()));
|
||||
|
||||
for (std::size_t i = 0; i < src.size(); ++i) {
|
||||
for (std::size_t i = 0; i < src.size(); ++i)
|
||||
{
|
||||
EXPECT_TRUE(dst[i] == src[i]);
|
||||
EXPECT_TRUE(dst[i + src.size()] == src[i]);
|
||||
}
|
||||
@ -109,7 +117,8 @@ TEST(algorithm_tests, same_type)
|
||||
copy(src_span, dst_span);
|
||||
copy(src_span, dst_span.subspan(src_span.size()));
|
||||
|
||||
for (std::size_t i = 0; i < src.size(); ++i) {
|
||||
for (std::size_t i = 0; i < src.size(); ++i)
|
||||
{
|
||||
EXPECT_TRUE(dst[i] == src[i]);
|
||||
EXPECT_TRUE(dst[i + src.size()] == src[i]);
|
||||
}
|
||||
@ -129,7 +138,8 @@ TEST(algorithm_tests, compatible_type)
|
||||
copy(src_span, dst_span);
|
||||
copy(src_span, dst_span.subspan(src_span.size()));
|
||||
|
||||
for (std::size_t i = 0; i < src.size(); ++i) {
|
||||
for (std::size_t i = 0; i < src.size(); ++i)
|
||||
{
|
||||
EXPECT_TRUE(dst[i] == src[i]);
|
||||
EXPECT_TRUE(dst[i + src.size()] == src[i]);
|
||||
}
|
||||
@ -146,7 +156,8 @@ TEST(algorithm_tests, compatible_type)
|
||||
copy(src_span, dst_span);
|
||||
copy(src_span, dst_span.subspan(src_span.size()));
|
||||
|
||||
for (std::size_t i = 0; i < src.size(); ++i) {
|
||||
for (std::size_t i = 0; i < src.size(); ++i)
|
||||
{
|
||||
EXPECT_TRUE(dst[i] == src[i]);
|
||||
EXPECT_TRUE(dst[i + src.size()] == src[i]);
|
||||
}
|
||||
@ -163,7 +174,8 @@ TEST(algorithm_tests, compatible_type)
|
||||
copy(src_span, dst_span);
|
||||
copy(src_span, dst_span.subspan(src_span.size()));
|
||||
|
||||
for (std::size_t i = 0; i < src.size(); ++i) {
|
||||
for (std::size_t i = 0; i < src.size(); ++i)
|
||||
{
|
||||
EXPECT_TRUE(dst[i] == src[i]);
|
||||
EXPECT_TRUE(dst[i + src.size()] == src[i]);
|
||||
}
|
||||
@ -180,7 +192,8 @@ TEST(algorithm_tests, compatible_type)
|
||||
copy(src_span, dst_span);
|
||||
copy(src_span, dst_span.subspan(src_span.size()));
|
||||
|
||||
for (std::size_t i = 0; i < src.size(); ++i) {
|
||||
for (std::size_t i = 0; i < src.size(); ++i)
|
||||
{
|
||||
EXPECT_TRUE(dst[i] == src[i]);
|
||||
EXPECT_TRUE(dst[i + src.size()] == src[i]);
|
||||
}
|
||||
@ -208,6 +221,11 @@ TEST(algorithm_tests, incompatible_type)
|
||||
|
||||
TEST(algorithm_tests, small_destination_span)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. small_destination_span";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
std::array<int, 12> src{1, 2, 3, 4};
|
||||
std::array<int, 4> dst{};
|
||||
|
||||
@ -216,9 +234,9 @@ TEST(algorithm_tests, small_destination_span)
|
||||
const span<int> dst_span_dyn(dst);
|
||||
const span<int, 4> dst_span_static(dst);
|
||||
|
||||
EXPECT_DEATH(copy(src_span_dyn, dst_span_dyn), ".*");
|
||||
EXPECT_DEATH(copy(src_span_dyn, dst_span_static), ".*");
|
||||
EXPECT_DEATH(copy(src_span_static, dst_span_dyn), ".*");
|
||||
EXPECT_DEATH(copy(src_span_dyn, dst_span_dyn), deathstring.data());
|
||||
EXPECT_DEATH(copy(src_span_dyn, dst_span_static), deathstring.data());
|
||||
EXPECT_DEATH(copy(src_span_static, dst_span_dyn), deathstring.data());
|
||||
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
copy(src_span_static, dst_span_static);
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <gsl/gsl_assert> // for fail_fast (ptr only), Ensures, Expects
|
||||
|
||||
#include <string_view>
|
||||
using namespace gsl;
|
||||
|
||||
namespace
|
||||
@ -51,19 +51,31 @@ int g(int i)
|
||||
Ensures(i > 0 && i < 10);
|
||||
return i;
|
||||
}
|
||||
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
} // namespace
|
||||
|
||||
TEST(assertion_tests, expects)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. expects";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
EXPECT_TRUE(f(2) == 2);
|
||||
EXPECT_DEATH(f(10), ".*");
|
||||
EXPECT_DEATH(f(10), deathstring.data());
|
||||
}
|
||||
|
||||
|
||||
TEST(assertion_tests, ensures)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. ensures";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
EXPECT_TRUE(g(2) == 3);
|
||||
EXPECT_DEATH(g(9), ".*");
|
||||
EXPECT_DEATH(g(9), deathstring.data());
|
||||
}
|
||||
|
||||
#if __clang__ || __GNUC__
|
||||
|
@ -40,6 +40,10 @@
|
||||
#include <initializer_list> // for initializer_list
|
||||
#include <vector> // for vector
|
||||
|
||||
namespace{
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
}
|
||||
|
||||
TEST(at_tests, static_array)
|
||||
{
|
||||
int a[4] = {1, 2, 3, 4};
|
||||
@ -50,10 +54,15 @@ TEST(at_tests, static_array)
|
||||
EXPECT_TRUE(&gsl::at(c_a, i) == &a[i]);
|
||||
}
|
||||
|
||||
EXPECT_DEATH(gsl::at(a, -1), ".*");
|
||||
EXPECT_DEATH(gsl::at(a, 4), ".*");
|
||||
EXPECT_DEATH(gsl::at(c_a, -1), ".*");
|
||||
EXPECT_DEATH(gsl::at(c_a, 4), ".*");
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. static_array";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
EXPECT_DEATH(gsl::at(a, -1), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(a, 4), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(c_a, -1), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(c_a, 4), deathstring.data());
|
||||
}
|
||||
|
||||
TEST(at_tests, std_array)
|
||||
@ -66,13 +75,18 @@ TEST(at_tests, std_array)
|
||||
EXPECT_TRUE(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
|
||||
}
|
||||
|
||||
EXPECT_DEATH(gsl::at(a, -1), ".*");
|
||||
EXPECT_DEATH(gsl::at(a, 4), ".*");
|
||||
EXPECT_DEATH(gsl::at(c_a, -1), ".*");
|
||||
EXPECT_DEATH(gsl::at(c_a, 4), ".*");
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. std_array";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
EXPECT_DEATH(gsl::at(a, -1), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(a, 4), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(c_a, -1), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(c_a, 4), deathstring.data());
|
||||
}
|
||||
|
||||
TEST(at_tests, StdVector)
|
||||
TEST(at_tests, std_vector)
|
||||
{
|
||||
std::vector<int> a = {1, 2, 3, 4};
|
||||
const std::vector<int>& c_a = a;
|
||||
@ -82,10 +96,15 @@ TEST(at_tests, StdVector)
|
||||
EXPECT_TRUE(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
|
||||
}
|
||||
|
||||
EXPECT_DEATH(gsl::at(a, -1), ".*");
|
||||
EXPECT_DEATH(gsl::at(a, 4), ".*");
|
||||
EXPECT_DEATH(gsl::at(c_a, -1), ".*");
|
||||
EXPECT_DEATH(gsl::at(c_a, 4), ".*");
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. std_vector";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
EXPECT_DEATH(gsl::at(a, -1), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(a, 4), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(c_a, -1), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(c_a, 4), deathstring.data());
|
||||
}
|
||||
|
||||
TEST(at_tests, InitializerList)
|
||||
@ -97,10 +116,15 @@ TEST(at_tests, InitializerList)
|
||||
EXPECT_TRUE(gsl::at({1, 2, 3, 4}, i) == i + 1);
|
||||
}
|
||||
|
||||
EXPECT_DEATH(gsl::at(a, -1), ".*");
|
||||
EXPECT_DEATH(gsl::at(a, 4), ".*");
|
||||
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, -1), ".*");
|
||||
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, 4), ".*");
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. InitializerList";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
EXPECT_DEATH(gsl::at(a, -1), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at(a, 4), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, -1), deathstring.data());
|
||||
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, 4), deathstring.data());
|
||||
}
|
||||
|
||||
#if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER >= 1910
|
||||
|
@ -107,6 +107,11 @@ TEST(bounds_tests, bounds_convertible)
|
||||
static_bounds<dynamic_range> b5;
|
||||
static_bounds<34> b6;
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. bounds_convertible";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
b5 = static_bounds<20>();
|
||||
EXPECT_DEATH(b6 = b5, ".*");
|
||||
b5 = static_bounds<34>();
|
||||
|
@ -138,6 +138,8 @@ void fn(const Bounds&)
|
||||
{
|
||||
static_assert(Bounds::static_size == 60, "static bounds is wrong size");
|
||||
}
|
||||
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
} // namespace
|
||||
|
||||
TEST(multi_span_test, default_constructor)
|
||||
@ -253,20 +255,25 @@ TEST(multi_span_test, from_nullptr_length_constructor) {
|
||||
EXPECT_TRUE(cs.data() == nullptr);
|
||||
}
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. from_nullptr_length_constructor";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
auto workaround_macro = []() { const multi_span<int> s{nullptr, 1}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
|
||||
auto const_workaround_macro = []() { const multi_span<const int> cs{nullptr, 1}; };
|
||||
EXPECT_DEATH(const_workaround_macro(), ".*");
|
||||
EXPECT_DEATH(const_workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
auto workaround_macro = []() { const multi_span<int, 0> s{nullptr, 1}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
|
||||
auto const_workaround_macro = []() { const multi_span<const int, 0> s{nullptr, 1}; };
|
||||
EXPECT_DEATH(const_workaround_macro(), ".*");
|
||||
EXPECT_DEATH(const_workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -370,10 +377,15 @@ TEST(multi_span_test, from_pointer_length_constructor)
|
||||
EXPECT_TRUE(s.data() == nullptr);
|
||||
}
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. from_pointer_length_constructor";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
int* p = nullptr;
|
||||
auto workaround_macro = [=]() { const multi_span<int> s{p, 2}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -409,27 +421,33 @@ TEST(multi_span_test, from_pointer_pointer_constructor)
|
||||
EXPECT_TRUE(s.data() == &arr[0]);
|
||||
}
|
||||
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. from_pointer_pointer_constructor";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
auto workaround_macro = [&]() { const multi_span<int> s{&arr[1], &arr[0]}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
int* p = nullptr;
|
||||
auto workaround_macro = [&]() { const multi_span<int> s{&arr[0], p}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
int* p = nullptr;
|
||||
auto workaround_macro = [&]() { const multi_span<int> s{p, p}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
int* p = nullptr;
|
||||
auto workaround_macro = [&]() { const multi_span<int> s{&arr[0], p}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -578,11 +596,16 @@ TEST(multi_span_test, from_dynamic_array_constructor)
|
||||
{
|
||||
double(*arr)[3][4] = new double[100][3][4];
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. from_nullptr_length_constructor";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
multi_span<double, dynamic_range, 3, 4> s(arr, 10);
|
||||
EXPECT_TRUE(s.length() == 120);
|
||||
EXPECT_TRUE(s.data() == &arr[0][0][0]);
|
||||
EXPECT_DEATH(s[10][3][4], ".*");
|
||||
EXPECT_DEATH(s[10][3][4], deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -809,8 +832,13 @@ TEST(multi_span_test, from_convertible_span_constructor)
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
multi_span<int, 7, 4, 2> av1(nullptr, b1);
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. from_convertible_span_constructor";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
auto f = [&]() { multi_span<int, 7, 4, 2> av1(nullptr); };
|
||||
EXPECT_DEATH(f(), ".*");
|
||||
EXPECT_DEATH(f(), deathstring.data());
|
||||
#endif
|
||||
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
@ -910,7 +938,13 @@ TEST(multi_span_test, first)
|
||||
EXPECT_TRUE(av.first<6>().length() == 6);
|
||||
EXPECT_TRUE(av.first<-1>().length() == -1);
|
||||
#endif
|
||||
EXPECT_DEATH(av.first(6).length(), ".*");
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. first";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
EXPECT_DEATH(av.first(6).length(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -952,7 +986,13 @@ TEST(multi_span_test, last)
|
||||
EXPECT_TRUE(av.last<6>().bounds() == static_bounds<6>());
|
||||
EXPECT_TRUE(av.last<6>().length() == 6);
|
||||
#endif
|
||||
EXPECT_DEATH(av.last(6).length(), ".*");
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. last";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
EXPECT_DEATH(av.last(6).length(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -982,13 +1022,18 @@ TEST(multi_span_test, subspan)
|
||||
EXPECT_TRUE(av.subspan(0, 0).length() == 0);
|
||||
}
|
||||
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. subspan";
|
||||
std::abort();
|
||||
});
|
||||
{
|
||||
multi_span<int, 5> av = arr;
|
||||
EXPECT_TRUE((av.subspan<0, 5>().bounds()) == static_bounds<5>());
|
||||
EXPECT_TRUE((av.subspan<0, 5>().length()) == 5);
|
||||
EXPECT_TRUE(av.subspan(0, 5).length() == 5);
|
||||
EXPECT_DEATH(av.subspan(0, 6).length(), ".*");
|
||||
EXPECT_DEATH(av.subspan(1, 5).length(), ".*");
|
||||
EXPECT_DEATH(av.subspan(0, 6).length(), deathstring.data());
|
||||
EXPECT_DEATH(av.subspan(1, 5).length(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -996,7 +1041,7 @@ TEST(multi_span_test, subspan)
|
||||
EXPECT_TRUE((av.subspan<5, 0>().bounds()) == static_bounds<0>());
|
||||
EXPECT_TRUE((av.subspan<5, 0>().length()) == 0);
|
||||
EXPECT_TRUE(av.subspan(5, 0).length() == 0);
|
||||
EXPECT_DEATH(av.subspan(6, 0).length(), ".*");
|
||||
EXPECT_DEATH(av.subspan(6, 0).length(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -1004,13 +1049,13 @@ TEST(multi_span_test, subspan)
|
||||
EXPECT_TRUE((av.subspan<0, 0>().bounds()) == static_bounds<0>());
|
||||
EXPECT_TRUE((av.subspan<0, 0>().length()) == 0);
|
||||
EXPECT_TRUE(av.subspan(0, 0).length() == 0);
|
||||
EXPECT_DEATH((av.subspan<1, 0>().length()), ".*");
|
||||
EXPECT_DEATH((av.subspan<1, 0>().length()), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
multi_span<int> av;
|
||||
EXPECT_TRUE(av.subspan(0).length() == 0);
|
||||
EXPECT_DEATH(av.subspan(1).length(), ".*");
|
||||
EXPECT_DEATH(av.subspan(1).length(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -1019,7 +1064,7 @@ TEST(multi_span_test, subspan)
|
||||
EXPECT_TRUE(av.subspan(1).length() == 4);
|
||||
EXPECT_TRUE(av.subspan(4).length() == 1);
|
||||
EXPECT_TRUE(av.subspan(5).length() == 0);
|
||||
EXPECT_DEATH(av.subspan(6).length(), ".*");
|
||||
EXPECT_DEATH(av.subspan(6).length(), deathstring.data());
|
||||
auto av2 = av.subspan(1);
|
||||
for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2);
|
||||
}
|
||||
@ -1030,7 +1075,7 @@ TEST(multi_span_test, subspan)
|
||||
EXPECT_TRUE(av.subspan(1).length() == 4);
|
||||
EXPECT_TRUE(av.subspan(4).length() == 1);
|
||||
EXPECT_TRUE(av.subspan(5).length() == 0);
|
||||
EXPECT_DEATH(av.subspan(6).length(), ".*");
|
||||
EXPECT_DEATH(av.subspan(6).length(), deathstring.data());
|
||||
auto av2 = av.subspan(1);
|
||||
for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2);
|
||||
}
|
||||
@ -1059,11 +1104,16 @@ TEST(multi_span_test, rank)
|
||||
|
||||
TEST(multi_span_test, extent)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. extent";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
multi_span<int> s;
|
||||
EXPECT_TRUE(s.extent() == 0);
|
||||
EXPECT_TRUE(s.extent(0) == 0);
|
||||
EXPECT_DEATH(s.extent(1), ".*");
|
||||
EXPECT_DEATH(s.extent(1), deathstring.data());
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
EXPECT_TRUE(s.extent<1>() == 0);
|
||||
#endif
|
||||
@ -1073,7 +1123,7 @@ TEST(multi_span_test, extent)
|
||||
multi_span<int, 0> s;
|
||||
EXPECT_TRUE(s.extent() == 0);
|
||||
EXPECT_TRUE(s.extent(0) == 0);
|
||||
EXPECT_DEATH(s.extent(1), ".*");
|
||||
EXPECT_DEATH(s.extent(1), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -1085,7 +1135,7 @@ TEST(multi_span_test, extent)
|
||||
EXPECT_TRUE(s.extent<1>() == 2);
|
||||
EXPECT_TRUE(s.extent(0) == 1);
|
||||
EXPECT_TRUE(s.extent(1) == 2);
|
||||
EXPECT_DEATH(s.extent(3), ".*");
|
||||
EXPECT_DEATH(s.extent(3), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -1097,7 +1147,7 @@ TEST(multi_span_test, extent)
|
||||
EXPECT_TRUE(s.extent<1>() == 2);
|
||||
EXPECT_TRUE(s.extent(0) == 0);
|
||||
EXPECT_TRUE(s.extent(1) == 2);
|
||||
EXPECT_DEATH(s.extent(3), ".*");
|
||||
EXPECT_DEATH(s.extent(3), deathstring.data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1105,10 +1155,15 @@ TEST(multi_span_test, operator_function_call)
|
||||
{
|
||||
int arr[4] = {1, 2, 3, 4};
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. operator_function_call";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
multi_span<int> s = arr;
|
||||
EXPECT_TRUE(s(0) == 1);
|
||||
EXPECT_DEATH(s(5), ".*");
|
||||
EXPECT_DEATH(s(5), deathstring.data());
|
||||
}
|
||||
|
||||
int arr2d[2][3] = {1, 2, 3, 4, 5, 6};
|
||||
@ -1261,18 +1316,23 @@ TEST(multi_span_test, bounds_checks)
|
||||
av[2][0] = 1;
|
||||
av[1][1] = 3;
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. bounds_check";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
// out of bounds
|
||||
EXPECT_DEATH(av[1][3] = 3, ".*");
|
||||
EXPECT_DEATH((av[{1, 3}] = 3), ".*");
|
||||
EXPECT_DEATH(av[1][3] = 3, deathstring.data());
|
||||
EXPECT_DEATH((av[{1, 3}] = 3), deathstring.data());
|
||||
|
||||
EXPECT_DEATH(av[10][2], ".*");
|
||||
EXPECT_DEATH((av[{10, 2}]), ".*");
|
||||
EXPECT_DEATH(av[10][2], deathstring.data());
|
||||
EXPECT_DEATH((av[{10, 2}]), deathstring.data());
|
||||
|
||||
EXPECT_DEATH(av[-1][0], ".*");
|
||||
EXPECT_DEATH((av[{-1, 0}]), ".*");
|
||||
EXPECT_DEATH(av[-1][0], deathstring.data());
|
||||
EXPECT_DEATH((av[{-1, 0}]), deathstring.data());
|
||||
|
||||
EXPECT_DEATH(av[0][-1], ".*");
|
||||
EXPECT_DEATH((av[{0, -1}]), ".*");
|
||||
EXPECT_DEATH(av[0][-1], deathstring.data());
|
||||
EXPECT_DEATH((av[{0, -1}]), deathstring.data());
|
||||
}
|
||||
|
||||
TEST(multi_span_test, span_parameter_test)
|
||||
@ -1390,13 +1450,18 @@ TEST(multi_span_test, as_multi_span)
|
||||
|
||||
TEST(multi_span_test, empty_spans)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. empty_spans";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
multi_span<int, 0> empty_av(nullptr);
|
||||
|
||||
EXPECT_TRUE(empty_av.bounds().index_bounds() == multi_span_index<1>{0});
|
||||
EXPECT_DEATH(empty_av[0], ".*");
|
||||
EXPECT_DEATH(empty_av.begin()[0], ".*");
|
||||
EXPECT_DEATH(empty_av.cbegin()[0], ".*");
|
||||
EXPECT_DEATH(empty_av[0], deathstring.data());
|
||||
EXPECT_DEATH(empty_av.begin()[0], deathstring.data());
|
||||
EXPECT_DEATH(empty_av.cbegin()[0], deathstring.data());
|
||||
for (auto& v : empty_av)
|
||||
{
|
||||
(void) v;
|
||||
@ -1407,9 +1472,9 @@ TEST(multi_span_test, empty_spans)
|
||||
{
|
||||
multi_span<int> empty_av = {};
|
||||
EXPECT_TRUE(empty_av.bounds().index_bounds() == multi_span_index<1>{0});
|
||||
EXPECT_DEATH(empty_av[0], ".*");
|
||||
EXPECT_DEATH(empty_av.begin()[0], ".*");
|
||||
EXPECT_DEATH(empty_av.cbegin()[0], ".*");
|
||||
EXPECT_DEATH(empty_av[0], deathstring.data());
|
||||
EXPECT_DEATH(empty_av.begin()[0], deathstring.data());
|
||||
EXPECT_DEATH(empty_av.cbegin()[0], deathstring.data());
|
||||
for (auto& v : empty_av)
|
||||
{
|
||||
(void) v;
|
||||
@ -1639,7 +1704,12 @@ TEST(multi_span_test, span_structure_size)
|
||||
};
|
||||
EXPECT_TRUE(sizeof(av1) == sizeof(EffectiveStructure));
|
||||
|
||||
EXPECT_DEATH(av1[10][3][4], ".*");
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. span_structure_size";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
EXPECT_DEATH(av1[10][3][4], deathstring.data());
|
||||
|
||||
multi_span<const double, dynamic_range, 6, 4> av2 =
|
||||
as_multi_span(av1, dim(5), dim<6>(), dim<4>());
|
||||
@ -1727,12 +1797,18 @@ TEST(multi_span_test, fixed_size_conversions)
|
||||
multi_span<int, 4> av4 = av2;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. fixed_size_conversions";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
auto f = [&]() {
|
||||
const multi_span<int, 4> av9 = {arr2, 2};
|
||||
(void) av9;
|
||||
};
|
||||
EXPECT_DEATH(f(), ".*");
|
||||
EXPECT_DEATH(f(), deathstring.data());
|
||||
}
|
||||
|
||||
// this should fail - we are trying to assign a small dynamic a_v to a fixed_size larger one
|
||||
@ -1741,7 +1817,7 @@ TEST(multi_span_test, fixed_size_conversions)
|
||||
const multi_span<int, 4> av2 = av;
|
||||
(void) av2;
|
||||
};
|
||||
EXPECT_DEATH(f(), ".*");
|
||||
EXPECT_DEATH(f(), deathstring.data());
|
||||
}
|
||||
|
||||
TEST(multi_span_test, as_writeable_bytes)
|
||||
|
@ -52,6 +52,10 @@ struct fail_fast;
|
||||
|
||||
using namespace gsl;
|
||||
|
||||
namespace{
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
}
|
||||
|
||||
struct MyBase
|
||||
{
|
||||
};
|
||||
@ -163,6 +167,10 @@ TEST(notnull_tests, TestNotNullConstructors)
|
||||
#endif
|
||||
}
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. TestNotNullConstructors";
|
||||
std::abort();
|
||||
});
|
||||
{
|
||||
// from shared pointer
|
||||
int i = 12;
|
||||
@ -174,7 +182,7 @@ TEST(notnull_tests, TestNotNullConstructors)
|
||||
std::make_shared<int>(10)); // shared_ptr<int> is nullptr assignable
|
||||
|
||||
int* pi = nullptr;
|
||||
EXPECT_DEATH((not_null<decltype(pi)>(pi)), ".*");
|
||||
EXPECT_DEATH((not_null<decltype(pi)>(pi)), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -231,8 +239,8 @@ TEST(notnull_tests, TestNotNullConstructors)
|
||||
{
|
||||
// from returned pointer
|
||||
|
||||
EXPECT_DEATH(helper(return_pointer()), ".*");
|
||||
EXPECT_DEATH(helper_const(return_pointer()), ".*");
|
||||
EXPECT_DEATH(helper(return_pointer()), deathstring.data());
|
||||
EXPECT_DEATH(helper_const(return_pointer()), deathstring.data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,12 +300,17 @@ TEST(notnull_tests, TestNotNullCasting)
|
||||
|
||||
TEST(notnull_tests, TestNotNullAssignment)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. TestNotNullAssignmentd";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
int i = 12;
|
||||
not_null<int*> p(&i);
|
||||
EXPECT_TRUE(helper(p));
|
||||
|
||||
int* q = nullptr;
|
||||
EXPECT_DEATH(p = not_null<int*>(q), ".*");
|
||||
EXPECT_DEATH(p = not_null<int*>(q), deathstring.data());
|
||||
}
|
||||
|
||||
TEST(notnull_tests, TestNotNullRawPointerComparison)
|
||||
@ -446,12 +459,17 @@ TEST(notnull_tests, TestNotNullConstructorTypeDeduction)
|
||||
EXPECT_TRUE(*x == 42);
|
||||
}
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. TestNotNullConstructorTypeDeduction";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
auto workaround_macro = []() {
|
||||
int* p1 = nullptr;
|
||||
const not_null x{p1};
|
||||
};
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -459,14 +477,14 @@ TEST(notnull_tests, TestNotNullConstructorTypeDeduction)
|
||||
const int* p1 = nullptr;
|
||||
const not_null x{p1};
|
||||
};
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
int* p = nullptr;
|
||||
|
||||
EXPECT_DEATH(helper(not_null{p}), ".*");
|
||||
EXPECT_DEATH(helper_const(not_null{p}), ".*");
|
||||
EXPECT_DEATH(helper(not_null{p}), deathstring.data());
|
||||
EXPECT_DEATH(helper_const(not_null{p}), deathstring.data());
|
||||
}
|
||||
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
@ -502,13 +520,18 @@ TEST(notnull_tests, TestMakeNotNull)
|
||||
EXPECT_TRUE(*x == 42);
|
||||
}
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. TestMakeNotNull";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
const auto workaround_macro = []() {
|
||||
int* p1 = nullptr;
|
||||
const auto x = make_not_null(p1);
|
||||
EXPECT_TRUE(*x == 42);
|
||||
};
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -517,21 +540,21 @@ TEST(notnull_tests, TestMakeNotNull)
|
||||
const auto x = make_not_null(p1);
|
||||
EXPECT_TRUE(*x == 42);
|
||||
};
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
int* p = nullptr;
|
||||
|
||||
EXPECT_DEATH(helper(make_not_null(p)), ".*");
|
||||
EXPECT_DEATH(helper_const(make_not_null(p)), ".*");
|
||||
EXPECT_DEATH(helper(make_not_null(p)), deathstring.data());
|
||||
EXPECT_DEATH(helper_const(make_not_null(p)), deathstring.data());
|
||||
}
|
||||
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
{
|
||||
EXPECT_DEATH(make_not_null(nullptr), ".*");
|
||||
EXPECT_DEATH(helper(make_not_null(nullptr)), ".*");
|
||||
EXPECT_DEATH(helper_const(make_not_null(nullptr)), ".*");
|
||||
EXPECT_DEATH(make_not_null(nullptr), deathstring.data());
|
||||
EXPECT_DEATH(helper(make_not_null(nullptr)), deathstring.data());
|
||||
EXPECT_DEATH(helper_const(make_not_null(nullptr)), deathstring.data());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ struct AddressOverloaded
|
||||
return {};
|
||||
}
|
||||
};
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
} // namespace
|
||||
|
||||
TEST(span_test, constructors)
|
||||
@ -121,6 +122,10 @@ TEST(span_test, size_optimization)
|
||||
|
||||
TEST(span_test, from_nullptr_size_constructor)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. from_nullptr_size_constructor";
|
||||
std::abort();
|
||||
});
|
||||
{
|
||||
span<int> s{nullptr, narrow_cast<span<int>::index_type>(0)};
|
||||
EXPECT_TRUE(s.size() == 0);
|
||||
@ -134,21 +139,21 @@ TEST(span_test, from_nullptr_size_constructor)
|
||||
auto workaround_macro = []() {
|
||||
const span<int, 1> s{nullptr, narrow_cast<span<int>::index_type>(0)};
|
||||
};
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
{
|
||||
auto workaround_macro = []() { const span<int> s{nullptr, 1}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
|
||||
auto const_workaround_macro = []() { const span<const int> s{nullptr, 1}; };
|
||||
EXPECT_DEATH(const_workaround_macro(), ".*");
|
||||
EXPECT_DEATH(const_workaround_macro(), deathstring.data());
|
||||
}
|
||||
{
|
||||
auto workaround_macro = []() { const span<int, 0> s{nullptr, 1}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
|
||||
auto const_workaround_macro = []() { const span<const int, 0> s{nullptr, 1}; };
|
||||
EXPECT_DEATH(const_workaround_macro(), ".*");
|
||||
EXPECT_DEATH(const_workaround_macro(), deathstring.data());
|
||||
}
|
||||
{
|
||||
span<int*> s{nullptr, narrow_cast<span<int>::index_type>(0)};
|
||||
@ -163,6 +168,10 @@ TEST(span_test, from_nullptr_size_constructor)
|
||||
|
||||
TEST(span_test, from_pointer_length_constructor)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. from_pointer_length_constructor";
|
||||
std::abort();
|
||||
});
|
||||
int arr[4] = {1, 2, 3, 4};
|
||||
|
||||
{
|
||||
@ -214,7 +223,7 @@ TEST(span_test, from_pointer_length_constructor)
|
||||
{
|
||||
int* p = nullptr;
|
||||
auto workaround_macro = [=]() { const span<int> s{p, 2}; };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -235,7 +244,7 @@ TEST(span_test, from_pointer_length_constructor)
|
||||
{
|
||||
int* p = nullptr;
|
||||
auto workaround_macro = [=]() { make_span(p, 2); };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,14 +282,14 @@ TEST(span_test, from_pointer_pointer_construction)
|
||||
// this will fail the std::distance() precondition, which asserts on MSVC debug builds
|
||||
//{
|
||||
// auto workaround_macro = [&]() { span<int> s{&arr[1], &arr[0]}; };
|
||||
// EXPECT_DEATH(workaround_macro(), ".*");
|
||||
// EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
//}
|
||||
|
||||
// this will fail the std::distance() precondition, which asserts on MSVC debug builds
|
||||
//{
|
||||
// int* p = nullptr;
|
||||
// auto workaround_macro = [&]() { span<int> s{&arr[0], p}; };
|
||||
// EXPECT_DEATH(workaround_macro(), ".*");
|
||||
// EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
//}
|
||||
|
||||
{
|
||||
@ -301,7 +310,7 @@ TEST(span_test, from_pointer_pointer_construction)
|
||||
//{
|
||||
// int* p = nullptr;
|
||||
// auto workaround_macro = [&]() { span<int> s{&arr[0], p}; };
|
||||
// EXPECT_DEATH(workaround_macro(), ".*");
|
||||
// EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
//}
|
||||
|
||||
{
|
||||
@ -823,6 +832,10 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
TEST(span_test, first)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. first";
|
||||
std::abort();
|
||||
});
|
||||
int arr[5] = {1, 2, 3, 4, 5};
|
||||
|
||||
{
|
||||
@ -849,7 +862,7 @@ TEST(span_test, from_array_constructor)
|
||||
EXPECT_TRUE(av.first<6>().size() == 6);
|
||||
EXPECT_TRUE(av.first<-1>().size() == -1);
|
||||
#endif
|
||||
EXPECT_DEATH(av.first(6).size(), ".*");
|
||||
EXPECT_DEATH(av.first(6).size(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -861,6 +874,10 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
TEST(span_test, last)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. last";
|
||||
std::abort();
|
||||
});
|
||||
int arr[5] = {1, 2, 3, 4, 5};
|
||||
|
||||
{
|
||||
@ -886,7 +903,7 @@ TEST(span_test, from_array_constructor)
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
EXPECT_TRUE(av.last<6>().size() == 6);
|
||||
#endif
|
||||
EXPECT_DEATH(av.last(6).size(), ".*");
|
||||
EXPECT_DEATH(av.last(6).size(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -898,6 +915,10 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
TEST(span_test, subspan)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. subspan";
|
||||
std::abort();
|
||||
});
|
||||
int arr[5] = {1, 2, 3, 4, 5};
|
||||
|
||||
{
|
||||
@ -921,8 +942,8 @@ TEST(span_test, from_array_constructor)
|
||||
EXPECT_TRUE(decltype(av.subspan<0, 5>())::extent == 5);
|
||||
EXPECT_TRUE(av.subspan(0, 5).size() == 5);
|
||||
|
||||
EXPECT_DEATH(av.subspan(0, 6).size(), ".*");
|
||||
EXPECT_DEATH(av.subspan(1, 5).size(), ".*");
|
||||
EXPECT_DEATH(av.subspan(0, 6).size(), deathstring.data());
|
||||
EXPECT_DEATH(av.subspan(1, 5).size(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -931,7 +952,7 @@ TEST(span_test, from_array_constructor)
|
||||
EXPECT_TRUE(decltype(av.subspan<4, 0>())::extent == 0);
|
||||
EXPECT_TRUE(av.subspan(4, 0).size() == 0);
|
||||
EXPECT_TRUE(av.subspan(5, 0).size() == 0);
|
||||
EXPECT_DEATH(av.subspan(6, 0).size(), ".*");
|
||||
EXPECT_DEATH(av.subspan(6, 0).size(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -945,13 +966,13 @@ TEST(span_test, from_array_constructor)
|
||||
EXPECT_TRUE((av.subspan<0, 0>().size()) == 0);
|
||||
EXPECT_TRUE(decltype(av.subspan<0, 0>())::extent == 0);
|
||||
EXPECT_TRUE(av.subspan(0, 0).size() == 0);
|
||||
EXPECT_DEATH((av.subspan<1, 0>().size()), ".*");
|
||||
EXPECT_DEATH((av.subspan<1, 0>().size()), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
span<int> av;
|
||||
EXPECT_TRUE(av.subspan(0).size() == 0);
|
||||
EXPECT_DEATH(av.subspan(1).size(), ".*");
|
||||
EXPECT_DEATH(av.subspan(1).size(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -960,7 +981,7 @@ TEST(span_test, from_array_constructor)
|
||||
EXPECT_TRUE(av.subspan(1).size() == 4);
|
||||
EXPECT_TRUE(av.subspan(4).size() == 1);
|
||||
EXPECT_TRUE(av.subspan(5).size() == 0);
|
||||
EXPECT_DEATH(av.subspan(6).size(), ".*");
|
||||
EXPECT_DEATH(av.subspan(6).size(), deathstring.data());
|
||||
const auto av2 = av.subspan(1);
|
||||
for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2);
|
||||
}
|
||||
@ -971,7 +992,7 @@ TEST(span_test, from_array_constructor)
|
||||
EXPECT_TRUE(av.subspan(1).size() == 4);
|
||||
EXPECT_TRUE(av.subspan(4).size() == 1);
|
||||
EXPECT_TRUE(av.subspan(5).size() == 0);
|
||||
EXPECT_DEATH(av.subspan(6).size(), ".*");
|
||||
EXPECT_DEATH(av.subspan(6).size(), deathstring.data());
|
||||
const auto av2 = av.subspan(1);
|
||||
for (int i = 0; i < 4; ++i) EXPECT_TRUE(av2[i] == i + 2);
|
||||
}
|
||||
@ -979,12 +1000,16 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
TEST(span_test, at_call)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. at_call";
|
||||
std::abort();
|
||||
});
|
||||
int arr[4] = {1, 2, 3, 4};
|
||||
|
||||
{
|
||||
span<int> s = arr;
|
||||
EXPECT_TRUE(s.at(0) == 1);
|
||||
EXPECT_DEATH(s.at(5), ".*");
|
||||
EXPECT_DEATH(s.at(5), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -992,18 +1017,22 @@ TEST(span_test, from_array_constructor)
|
||||
span<int, 2> s = arr2d;
|
||||
EXPECT_TRUE(s.at(0) == 1);
|
||||
EXPECT_TRUE(s.at(1) == 6);
|
||||
EXPECT_DEATH(s.at(2), ".*");
|
||||
EXPECT_DEATH(s.at(2), deathstring.data());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(span_test, operator_function_call)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. operator_function_call";
|
||||
std::abort();
|
||||
});
|
||||
int arr[4] = {1, 2, 3, 4};
|
||||
|
||||
{
|
||||
span<int> s = arr;
|
||||
EXPECT_TRUE(s(0) == 1);
|
||||
EXPECT_DEATH(s(5), ".*");
|
||||
EXPECT_DEATH(s(5), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -1011,7 +1040,7 @@ TEST(span_test, from_array_constructor)
|
||||
span<int, 2> s = arr2d;
|
||||
EXPECT_TRUE(s(0) == 1);
|
||||
EXPECT_TRUE(s(1) == 6);
|
||||
EXPECT_DEATH(s(2), ".*");
|
||||
EXPECT_DEATH(s(2), deathstring.data());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1100,6 +1129,10 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
TEST(span_test, begin_end)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. begin_end";
|
||||
std::abort();
|
||||
});
|
||||
{
|
||||
int a[] = {1, 2, 3, 4};
|
||||
span<int> s = a;
|
||||
@ -1124,7 +1157,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
auto beyond = s.end();
|
||||
EXPECT_TRUE(it != beyond);
|
||||
EXPECT_DEATH(*beyond, ".*");
|
||||
EXPECT_DEATH(*beyond, deathstring.data());
|
||||
|
||||
EXPECT_TRUE(beyond - first == 4);
|
||||
EXPECT_TRUE(first - first == 0);
|
||||
@ -1154,6 +1187,10 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
TEST(span_test, cbegin_cend)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. cbegin_cend";
|
||||
std::abort();
|
||||
});
|
||||
{
|
||||
int a[] = {1, 2, 3, 4};
|
||||
span<int> s = a;
|
||||
@ -1178,7 +1215,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
auto beyond = s.cend();
|
||||
EXPECT_TRUE(it != beyond);
|
||||
EXPECT_DEATH(*beyond, ".*");
|
||||
EXPECT_DEATH(*beyond, deathstring.data());
|
||||
|
||||
EXPECT_TRUE(beyond - first == 4);
|
||||
EXPECT_TRUE(first - first == 0);
|
||||
@ -1207,6 +1244,10 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
TEST(span_test, rbegin_rend)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. rbegin_rend";
|
||||
std::abort();
|
||||
});
|
||||
{
|
||||
int a[] = {1, 2, 3, 4};
|
||||
span<int> s = a;
|
||||
@ -1218,7 +1259,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
auto beyond = s.rend();
|
||||
EXPECT_TRUE(it != beyond);
|
||||
EXPECT_DEATH(auto _ = *beyond , ".*");
|
||||
EXPECT_DEATH(auto _ = *beyond , deathstring.data());
|
||||
|
||||
EXPECT_TRUE(beyond - first == 4);
|
||||
EXPECT_TRUE(first - first == 0);
|
||||
@ -1248,6 +1289,10 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
TEST(span_test, crbegin_crend)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. crbegin_crend";
|
||||
std::abort();
|
||||
});
|
||||
{
|
||||
int a[] = {1, 2, 3, 4};
|
||||
span<int> s = a;
|
||||
@ -1259,7 +1304,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
auto beyond = s.crend();
|
||||
EXPECT_TRUE(it != beyond);
|
||||
EXPECT_DEATH(auto _ = *beyond, ".*");
|
||||
EXPECT_DEATH(auto _ = *beyond, deathstring.data());
|
||||
|
||||
EXPECT_TRUE(beyond - first == 4);
|
||||
EXPECT_TRUE(first - first == 0);
|
||||
@ -1472,6 +1517,10 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
TEST(span_test, fixed_size_conversions)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. fixed_size_conversions";
|
||||
std::abort();
|
||||
});
|
||||
int arr[] = {1, 2, 3, 4};
|
||||
|
||||
// converting to an span from an equal size array is ok
|
||||
@ -1503,7 +1552,7 @@ TEST(span_test, from_array_constructor)
|
||||
const span<int, 2> s2 = s;
|
||||
static_cast<void>(s2);
|
||||
};
|
||||
EXPECT_DEATH(f(), ".*");
|
||||
EXPECT_DEATH(f(), deathstring.data());
|
||||
}
|
||||
|
||||
// but doing so explicitly is ok
|
||||
@ -1542,7 +1591,7 @@ TEST(span_test, from_array_constructor)
|
||||
const span<int, 4> _s4 = {arr2, 2};
|
||||
static_cast<void>(_s4);
|
||||
};
|
||||
EXPECT_DEATH(f(), ".*");
|
||||
EXPECT_DEATH(f(), deathstring.data());
|
||||
}
|
||||
|
||||
// this should fail - we are trying to assign a small dynamic span to a fixed_size larger one
|
||||
@ -1550,7 +1599,7 @@ TEST(span_test, from_array_constructor)
|
||||
const span<int, 4> _s4 = av;
|
||||
static_cast<void>(_s4);
|
||||
};
|
||||
EXPECT_DEATH(f(), ".*");
|
||||
EXPECT_DEATH(f(), deathstring.data());
|
||||
}
|
||||
|
||||
TEST(span_test, interop_with_std_regex)
|
||||
|
@ -42,6 +42,10 @@ namespace gsl
|
||||
struct fail_fast;
|
||||
} // namespace gsl
|
||||
|
||||
namespace{
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
}
|
||||
|
||||
using namespace gsl;
|
||||
|
||||
GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
|
||||
@ -146,6 +150,11 @@ TEST(strict_notnull_tests, TestStrictNotNull)
|
||||
|
||||
TEST(strict_notnull_tests, TestStrictNotNullConstructorTypeDeduction)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. TestStrictNotNullConstructorTypeDeduction";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
int i = 42;
|
||||
|
||||
@ -172,7 +181,7 @@ TEST(strict_notnull_tests, TestStrictNotNullConstructorTypeDeduction)
|
||||
int* p1 = nullptr;
|
||||
const strict_not_null x{p1};
|
||||
};
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -180,14 +189,14 @@ TEST(strict_notnull_tests, TestStrictNotNullConstructorTypeDeduction)
|
||||
const int* p1 = nullptr;
|
||||
const strict_not_null x{p1};
|
||||
};
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
int* p = nullptr;
|
||||
|
||||
EXPECT_DEATH(helper(strict_not_null{p}), ".*");
|
||||
EXPECT_DEATH(helper_const(strict_not_null{p}), ".*");
|
||||
EXPECT_DEATH(helper(strict_not_null{p}), deathstring.data());
|
||||
EXPECT_DEATH(helper_const(strict_not_null{p}), deathstring.data());
|
||||
}
|
||||
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
|
@ -56,6 +56,7 @@ using namespace gsl;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
struct BaseClass
|
||||
{
|
||||
};
|
||||
@ -420,18 +421,23 @@ TEST(strided_span_tests, strided_span_bounds)
|
||||
int arr[] = {0, 1, 2, 3};
|
||||
multi_span<int> av(arr);
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. strided_span_bounds";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
// incorrect sections
|
||||
|
||||
EXPECT_DEATH(av.section(0, 0)[0], ".*");
|
||||
EXPECT_DEATH(av.section(1, 0)[0], ".*");
|
||||
EXPECT_DEATH(av.section(1, 1)[1], ".*");
|
||||
EXPECT_DEATH(av.section(0, 0)[0], deathstring.data());
|
||||
EXPECT_DEATH(av.section(1, 0)[0], deathstring.data());
|
||||
EXPECT_DEATH(av.section(1, 1)[1], deathstring.data());
|
||||
|
||||
EXPECT_DEATH(av.section(2, 5), ".*");
|
||||
EXPECT_DEATH(av.section(5, 2), ".*");
|
||||
EXPECT_DEATH(av.section(5, 0), ".*");
|
||||
EXPECT_DEATH(av.section(0, 5), ".*");
|
||||
EXPECT_DEATH(av.section(5, 5), ".*");
|
||||
EXPECT_DEATH(av.section(2, 5), deathstring.data());
|
||||
EXPECT_DEATH(av.section(5, 2), deathstring.data());
|
||||
EXPECT_DEATH(av.section(5, 0), deathstring.data());
|
||||
EXPECT_DEATH(av.section(0, 5), deathstring.data());
|
||||
EXPECT_DEATH(av.section(5, 5), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -439,19 +445,19 @@ TEST(strided_span_tests, strided_span_bounds)
|
||||
strided_span<int, 1> sav{av, {{4}, {}}};
|
||||
EXPECT_TRUE(sav[0] == 0);
|
||||
EXPECT_TRUE(sav[3] == 0);
|
||||
EXPECT_DEATH(sav[4], ".*");
|
||||
EXPECT_DEATH(sav[4], deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
// zero extent
|
||||
strided_span<int, 1> sav{av, {{}, {1}}};
|
||||
EXPECT_DEATH(sav[0], ".*");
|
||||
EXPECT_DEATH(sav[0], deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
// zero extent and stride
|
||||
strided_span<int, 1> sav{av, {{}, {}}};
|
||||
EXPECT_DEATH(sav[0], ".*");
|
||||
EXPECT_DEATH(sav[0], deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -459,7 +465,7 @@ TEST(strided_span_tests, strided_span_bounds)
|
||||
strided_span<int, 1> sav{arr, {4, 1}};
|
||||
EXPECT_TRUE(sav.bounds().index_bounds() == multi_span_index<1>{4});
|
||||
EXPECT_TRUE(sav[3] == 3);
|
||||
EXPECT_DEATH(sav[4], ".*");
|
||||
EXPECT_DEATH(sav[4], deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -467,7 +473,7 @@ TEST(strided_span_tests, strided_span_bounds)
|
||||
strided_span<int, 1> sav{arr, {2, 1}};
|
||||
EXPECT_TRUE(sav.bounds().index_bounds() == multi_span_index<1>{2});
|
||||
EXPECT_TRUE(sav[1] == 1);
|
||||
EXPECT_DEATH(sav[2], ".*");
|
||||
EXPECT_DEATH(sav[2], deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
@ -476,35 +482,35 @@ TEST(strided_span_tests, strided_span_bounds)
|
||||
EXPECT_TRUE(sav.bounds().index_bounds() == multi_span_index<1>{2});
|
||||
EXPECT_TRUE(sav[0] == 0);
|
||||
EXPECT_TRUE(sav[1] == 3);
|
||||
EXPECT_DEATH(sav[2], ".*");
|
||||
EXPECT_DEATH(sav[2], deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
// bounds cross data boundaries - from static arrays
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {3, 2}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {3, 3}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {4, 5}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {5, 1}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {5, 5}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {3, 2}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {3, 3}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {4, 5}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {5, 1}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{arr, {5, 5}}), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
// bounds cross data boundaries - from array view
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {3, 2}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {3, 3}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {4, 5}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {5, 1}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {5, 5}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {3, 2}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {3, 3}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {4, 5}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {5, 1}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{av, {5, 5}}), deathstring.data());
|
||||
}
|
||||
|
||||
{
|
||||
// bounds cross data boundaries - from dynamic arrays
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {3, 2}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {3, 3}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {4, 5}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {5, 1}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {5, 5}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 2, {2, 2}}), ".*");
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {3, 2}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {3, 3}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {4, 5}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {5, 1}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 4, {5, 5}}), deathstring.data());
|
||||
EXPECT_DEATH((strided_span<int, 1>{av.data(), 2, {2, 2}}), deathstring.data());
|
||||
}
|
||||
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
@ -536,6 +542,11 @@ TEST(strided_span_tests, strided_span_type_conversion)
|
||||
int arr[] = {0, 1, 2, 3};
|
||||
multi_span<int> av(arr);
|
||||
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. strided_span_type_conversion";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
strided_span<int, 1> sav{av.data(), av.size(), {av.size() / 2, 2}};
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
@ -558,8 +569,8 @@ TEST(strided_span_tests, strided_span_type_conversion)
|
||||
strided_span<const int, 2> sav3 = sav2.as_strided_span<const int>();
|
||||
EXPECT_TRUE(sav3[0][0] == 0);
|
||||
EXPECT_TRUE(sav3[1][0] == 2);
|
||||
EXPECT_DEATH(sav3[1][1], ".*");
|
||||
EXPECT_DEATH(sav3[0][1], ".*");
|
||||
EXPECT_DEATH(sav3[1][1], deathstring.data());
|
||||
EXPECT_DEATH(sav3[0][1], deathstring.data());
|
||||
}
|
||||
|
||||
// retype strided array with regular strides - from multi_span
|
||||
@ -571,8 +582,8 @@ TEST(strided_span_tests, strided_span_type_conversion)
|
||||
strided_span<int, 2> sav3 = sav2.as_strided_span<int>();
|
||||
EXPECT_TRUE(sav3[0][0] == 0);
|
||||
EXPECT_TRUE(sav3[1][0] == 2);
|
||||
EXPECT_DEATH(sav3[1][1], ".*");
|
||||
EXPECT_DEATH(sav3[0][1], ".*");
|
||||
EXPECT_DEATH(sav3[1][1], deathstring.data());
|
||||
EXPECT_DEATH(sav3[0][1], deathstring.data());
|
||||
}
|
||||
|
||||
// retype strided array with not enough elements - last dimension of the array is too small
|
||||
@ -581,7 +592,7 @@ TEST(strided_span_tests, strided_span_type_conversion)
|
||||
multi_span<const byte, 2, dynamic_range> bytes2 =
|
||||
as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2));
|
||||
strided_span<const byte, 2> sav2{bytes2, bounds};
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), ".*");
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data());
|
||||
}
|
||||
|
||||
// retype strided array with not enough elements - strides are too small
|
||||
@ -590,7 +601,7 @@ TEST(strided_span_tests, strided_span_type_conversion)
|
||||
multi_span<const byte, 2, dynamic_range> bytes2 =
|
||||
as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2));
|
||||
strided_span<const byte, 2> sav2{bytes2, bounds};
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), ".*");
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data());
|
||||
}
|
||||
|
||||
// retype strided array with not enough elements - last dimension does not divide by the new
|
||||
@ -600,7 +611,7 @@ TEST(strided_span_tests, strided_span_type_conversion)
|
||||
multi_span<const byte, 2, dynamic_range> bytes2 =
|
||||
as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2));
|
||||
strided_span<const byte, 2> sav2{bytes2, bounds};
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), ".*");
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data());
|
||||
}
|
||||
|
||||
// retype strided array with not enough elements - strides does not divide by the new
|
||||
@ -610,35 +621,40 @@ TEST(strided_span_tests, strided_span_type_conversion)
|
||||
multi_span<const byte, 2, dynamic_range> bytes2 =
|
||||
as_multi_span(bytes, dim<2>(), dim(bytes.size() / 2));
|
||||
strided_span<const byte, 2> sav2{bytes2, bounds};
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), ".*");
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data());
|
||||
}
|
||||
|
||||
// retype strided array with irregular strides - from raw data
|
||||
{
|
||||
strided_bounds<1> bounds{bytes.size() / 2, 2};
|
||||
strided_span<const byte, 1> sav2{bytes.data(), bytes.size(), bounds};
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), ".*");
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data());
|
||||
}
|
||||
|
||||
// retype strided array with irregular strides - from multi_span
|
||||
{
|
||||
strided_bounds<1> bounds{bytes.size() / 2, 2};
|
||||
strided_span<const byte, 1> sav2{bytes, bounds};
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), ".*");
|
||||
EXPECT_DEATH(sav2.as_strided_span<int>(), deathstring.data());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(strided_span_tests, empty_strided_spans)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. empty_strided_spans";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
{
|
||||
multi_span<int, 0> empty_av(nullptr);
|
||||
strided_span<int, 1> empty_sav{empty_av, {0, 1}};
|
||||
|
||||
EXPECT_TRUE(empty_sav.bounds().index_bounds() == multi_span_index<1>{0});
|
||||
EXPECT_TRUE(empty_sav.empty());
|
||||
EXPECT_DEATH(empty_sav[0], ".*");
|
||||
EXPECT_DEATH(empty_sav.begin()[0], ".*");
|
||||
EXPECT_DEATH(empty_sav.cbegin()[0], ".*");
|
||||
EXPECT_DEATH(empty_sav[0], deathstring.data());
|
||||
EXPECT_DEATH(empty_sav.begin()[0], deathstring.data());
|
||||
EXPECT_DEATH(empty_sav.cbegin()[0], deathstring.data());
|
||||
|
||||
for (const auto& v : empty_sav) {
|
||||
(void) v;
|
||||
@ -650,9 +666,9 @@ TEST(strided_span_tests, empty_strided_spans)
|
||||
strided_span<int, 1> empty_sav{nullptr, 0, {0, 1}};
|
||||
|
||||
EXPECT_TRUE(empty_sav.bounds().index_bounds() == multi_span_index<1>{0});
|
||||
EXPECT_DEATH(empty_sav[0], ".*");
|
||||
EXPECT_DEATH(empty_sav.begin()[0], ".*");
|
||||
EXPECT_DEATH(empty_sav.cbegin()[0], ".*");
|
||||
EXPECT_DEATH(empty_sav[0], deathstring.data());
|
||||
EXPECT_DEATH(empty_sav.begin()[0], deathstring.data());
|
||||
EXPECT_DEATH(empty_sav.cbegin()[0], deathstring.data());
|
||||
|
||||
for (const auto& v : empty_sav) {
|
||||
(void) v;
|
||||
@ -740,6 +756,11 @@ TEST(strided_span_tests, dynamic_strided_span_section_iteration_3d)
|
||||
|
||||
TEST(strided_span_tests, strided_span_conversion)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. strided_span_conversion";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
// get an multi_span of 'c' values from the list of X's
|
||||
|
||||
struct X
|
||||
@ -783,7 +804,7 @@ TEST(strided_span_tests, strided_span_conversion)
|
||||
strided_span<int, 1> result = transposed[0];
|
||||
|
||||
EXPECT_TRUE(result.bounds().index_bounds()[0] == 4);
|
||||
EXPECT_DEATH(result.bounds().index_bounds()[1], ".*");
|
||||
EXPECT_DEATH(result.bounds().index_bounds()[1], deathstring.data());
|
||||
|
||||
int i = 0;
|
||||
for (auto& num : result) {
|
||||
|
@ -72,6 +72,7 @@ auto strnlen(const CharT* s, std::size_t n)
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
|
||||
template <typename T>
|
||||
T move_wrapper(T&& t)
|
||||
@ -964,6 +965,10 @@ TEST(string_span_tests, Conversion)
|
||||
|
||||
TEST(string_span_tests, zstring)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. zstring";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
// create zspan from zero terminated string
|
||||
{
|
||||
@ -983,7 +988,7 @@ TEST(string_span_tests, zstring)
|
||||
buf[0] = 'a';
|
||||
|
||||
auto workaround_macro = [&]() { const zstring_span<> zspan({buf, 1}); };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
// usage scenario: create zero-terminated temp file name and pass to a legacy API
|
||||
@ -1001,6 +1006,10 @@ TEST(string_span_tests, zstring)
|
||||
|
||||
TEST(string_span_tests, wzstring)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. wzstring";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
// create zspan from zero terminated string
|
||||
{
|
||||
@ -1020,7 +1029,7 @@ TEST(string_span_tests, wzstring)
|
||||
buf[0] = L'a';
|
||||
|
||||
const auto workaround_macro = [&]() { const wzstring_span<> zspan({buf, 1}); };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
// usage scenario: create zero-terminated temp file name and pass to a legacy API
|
||||
@ -1038,6 +1047,10 @@ TEST(string_span_tests, wzstring)
|
||||
|
||||
TEST(string_span_tests, u16zstring)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. u16zstring";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
// create zspan from zero terminated string
|
||||
{
|
||||
@ -1057,7 +1070,7 @@ TEST(string_span_tests, u16zstring)
|
||||
buf[0] = u'a';
|
||||
|
||||
const auto workaround_macro = [&]() { const u16zstring_span<> zspan({buf, 1}); };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
// usage scenario: create zero-terminated temp file name and pass to a legacy API
|
||||
@ -1075,6 +1088,10 @@ TEST(string_span_tests, u16zstring)
|
||||
|
||||
TEST(string_span_tests, u32zstring)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. u31zstring";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
// create zspan from zero terminated string
|
||||
{
|
||||
@ -1094,7 +1111,7 @@ TEST(string_span_tests, u32zstring)
|
||||
buf[0] = u'a';
|
||||
|
||||
const auto workaround_macro = [&]() { const u32zstring_span<> zspan({buf, 1}); };
|
||||
EXPECT_DEATH(workaround_macro(), ".*");
|
||||
EXPECT_DEATH(workaround_macro(), deathstring.data());
|
||||
}
|
||||
|
||||
// usage scenario: create zero-terminated temp file name and pass to a legacy API
|
||||
|
@ -1,26 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
// blanket turn off warnings from CppCoreCheck from catch
|
||||
// so people aren't annoyed by them when running the tool.
|
||||
#include <CodeAnalysis/Warnings.h>
|
||||
#pragma warning(disable : ALL_CODE_ANALYSIS_WARNINGS) // from catch
|
||||
#endif // _MSC_VER
|
||||
|
@ -44,9 +44,13 @@
|
||||
|
||||
using namespace gsl;
|
||||
|
||||
namespace{
|
||||
constexpr std::string_view deathstring("Expected Death");
|
||||
void f(int& i) { i += 1; }
|
||||
static int j = 0;
|
||||
void g() { j += 1; }
|
||||
}
|
||||
|
||||
|
||||
TEST(utils_tests, sanity_check_for_gsl_index_typedef)
|
||||
{
|
||||
@ -116,12 +120,17 @@ TEST(utils_tests, narrow_cast)
|
||||
|
||||
TEST(utils_tests, narrow)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. narrow";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
int n = 120;
|
||||
const char c = narrow<char>(n);
|
||||
EXPECT_TRUE(c == 120);
|
||||
|
||||
n = 300;
|
||||
EXPECT_DEATH(narrow<char>(n), ".*");
|
||||
EXPECT_DEATH(narrow<char>(n), deathstring.data());
|
||||
|
||||
const auto int32_max = std::numeric_limits<int32_t>::max();
|
||||
const auto int32_min = std::numeric_limits<int32_t>::min();
|
||||
@ -130,11 +139,11 @@ TEST(utils_tests, narrow)
|
||||
EXPECT_TRUE(narrow<uint32_t>(int32_t(1)) == 1);
|
||||
EXPECT_TRUE(narrow<uint32_t>(int32_max) == static_cast<uint32_t>(int32_max));
|
||||
|
||||
EXPECT_DEATH(narrow<uint32_t>(int32_t(-1)), ".*");
|
||||
EXPECT_DEATH(narrow<uint32_t>(int32_min), ".*");
|
||||
EXPECT_DEATH(narrow<uint32_t>(int32_t(-1)), deathstring.data());
|
||||
EXPECT_DEATH(narrow<uint32_t>(int32_min), deathstring.data());
|
||||
|
||||
n = -42;
|
||||
EXPECT_DEATH(narrow<unsigned>(n), ".*");
|
||||
EXPECT_DEATH(narrow<unsigned>(n), deathstring.data());
|
||||
|
||||
#if GSL_CONSTEXPR_NARROW
|
||||
static_assert(narrow<char>(120) == 120, "Fix GSL_CONSTEXPR_NARROW");
|
||||
|
Loading…
Reference in New Issue
Block a user