Replace UnitTest-cpp with Catch

This PR replaces UnitTest-cpp with Catch. Catch is downloaded
using cmake's ExternalProject_Add and installed into the
include directory as it's a header only library.

Signed-off-by: Rian Quinn <“rianquinn@gmail.com”>
This commit is contained in:
Rian Quinn 2017-04-28 06:45:49 -06:00
parent 8b320e3f5d
commit 845a59425c
23 changed files with 4236 additions and 4251 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
CMakeFiles
build
include/catch
tests/CMakeFiles
tests/Debug
*.opensdf

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "tests/unittest-cpp"]
path = tests/unittest-cpp
url = https://github.com/unittest-cpp/unittest-cpp.git

View File

@ -10,7 +10,7 @@ cache:
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.2/install
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.7.1/install
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.8.1/install
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.9.0/install
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.9.1/install
matrix:
include:
@ -61,6 +61,19 @@ matrix:
- env: CLANG_VERSION=3.8 BUILD_TYPE=Release
os: linux
addons: *clang38
- env: CLANG_VERSION=3.9 BUILD_TYPE=Debug
os: linux
addons: &clang39
apt:
packages:
- clang-3.9
- g++-5
sources: &sources
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.9
- env: CLANG_VERSION=3.9 BUILD_TYPE=Release
os: linux
addons: *clang39
- env: GCC_VERSION=5 BUILD_TYPE=Debug
os: linux
addons: &gcc5
@ -110,7 +123,7 @@ install:
if [[ "$CLANG_VERSION" == "3.6" ]]; then LLVM_VERSION="3.6.2"; fi
if [[ "$CLANG_VERSION" == "3.7" ]]; then LLVM_VERSION="3.7.1"; fi
if [[ "$CLANG_VERSION" == "3.8" ]]; then LLVM_VERSION="3.8.1"; fi
if [[ "$CLANG_VERSION" == "3.9" ]]; then LLVM_VERSION="3.9.0"; fi
if [[ "$CLANG_VERSION" == "3.9" ]]; then LLVM_VERSION="3.9.1"; fi
LLVM_ROOT="${DEPS_DIR}/llvm-${LLVM_VERSION}"
LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz"

View File

@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 2.8.7)
project(GSL CXX)
include(ExternalProject)
find_package(Git REQUIRED)
# creates a library GSL which is an interface (header files only)
add_library(GSL INTERFACE)

View File

@ -40,8 +40,6 @@ contributing any changes that were necessary back to this project to benefit the
To build the tests, you will require the following:
* [CMake](http://cmake.org), version 2.8.7 or later to be installed and in your PATH.
* [UnitTest-cpp](https://github.com/Microsoft/unittest-cpp), to be cloned under the [tests/unittest-cpp](./tests/unittest-cpp) directory
of your GSL source.
These steps assume the source code of this repository has been cloned into a directory named `c:\GSL`.

View File

@ -13,16 +13,15 @@ image:
- Visual Studio 2017
cache:
- C:\cmake-3.7.2-win32-x86
- C:\cmake-3.8.0-win32-x86
install:
- git clone --quiet --depth=1 https://github.com/Microsoft/unittest-cpp.git tests/unittest-cpp
- ps: |
if (![IO.File]::Exists("C:\cmake-3.7.2-win32-x86\bin\cmake.exe")) {
Start-FileDownload 'https://cmake.org/files/v3.7/cmake-3.7.2-win32-x86.zip'
7z x -y cmake-3.7.2-win32-x86.zip -oC:\
if (![IO.File]::Exists("C:\cmake-3.8.0-win32-x86\bin\cmake.exe")) {
Start-FileDownload 'https://cmake.org/files/v3.8/cmake-3.8.0-win32-x86.zip'
7z x -y cmake-3.8.0-win32-x86.zip -oC:\
}
$env:PATH="C:\cmake-3.7.2-win32-x86\bin;$env:PATH"
$env:PATH="C:\cmake-3.8.0-win32-x86\bin;$env:PATH"
before_build:
- ps: |

View File

@ -41,6 +41,7 @@
// turn off some warnings that are noisy about our Expects statements
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4702) // unreachable code
#if _MSC_VER < 1910
#pragma push_macro("constexpr")

View File

@ -37,6 +37,7 @@
// turn off some warnings that are noisy about our Expects statements
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4702) // unreachable code
// blanket turn off warnings from CppCoreCheck for now
// so people aren't annoyed by them when running the tool.

View File

@ -5,15 +5,21 @@ project(GSLTests CXX)
# will make visual studio generated project group files
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest-cpp/CMakeLists.txt)
find_package(Git)
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
list(APPEND CATCH_CMAKE_ARGS
"-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}"
"-DNO_SELFTEST=true"
)
endif()
add_subdirectory(unittest-cpp)
# add catch
ExternalProject_Add(
catch
PREFIX ${CMAKE_BINARY_DIR}/catch
GIT_REPOSITORY https://github.com/philsquared/Catch.git
# GIT_TAG v1.9.4 uncomment once v1.9.4 is available
CMAKE_ARGS ${CATCH_CMAKE_ARGS}
LOG_DOWNLOAD 1
UPDATE_DISCONNECTED 1
)
# this interface adds compile options to how the tests are run
# please try to keep entries ordered =)
@ -42,24 +48,29 @@ target_compile_options(gsl_tests_config INTERFACE
>
)
# set test to include the unittest-cpp headers
# this shiuld be removed when UnitTest++ has the proper headers
target_include_directories(gsl_tests_config INTERFACE
./unittest-cpp
)
# set definitions for tests
target_compile_definitions(gsl_tests_config INTERFACE
GSL_THROW_ON_CONTRACT_VIOLATION
)
function(add_gsl_test name)
add_executable(${name} ${name}.cpp)
target_link_libraries(${name}
UnitTest++
# create the main executable for each test. this reduces the compile time
# of each test by pre-compiling catch.
add_library(test_catch STATIC test.cpp)
target_link_libraries(test_catch
GSL
gsl_tests_config
)
add_dependencies(test_catch catch)
set_property(TARGET test_catch PROPERTY FOLDER "GSL_tests")
function(add_gsl_test name)
add_executable(${name} ${name}.cpp)
target_link_libraries(${name}
GSL
test_catch
gsl_tests_config
)
add_dependencies(${name} catch)
add_test(
${name}
${name}

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/gsl_algorithm>
@ -23,10 +23,7 @@
using namespace std;
using namespace gsl;
SUITE(copy_tests)
{
TEST(same_type)
TEST_CASE("same_type")
{
// dynamic source and destination span
{
@ -97,7 +94,7 @@ SUITE(copy_tests)
}
}
TEST(compatible_type)
TEST_CASE("compatible_type")
{
// dynamic source and destination span
{
@ -169,7 +166,7 @@ SUITE(copy_tests)
}
#ifdef CONFIRM_COMPILATION_ERRORS
TEST(incompatible_type)
TEST_CASE("incompatible_type")
{
std::array<int, 4> src{1, 2, 3, 4};
std::array<int*, 12> dst{};
@ -187,7 +184,7 @@ SUITE(copy_tests)
}
#endif
TEST(small_destination_span)
TEST_CASE("small_destination_span")
{
std::array<int, 12> src{1, 2, 3, 4};
std::array<int, 4> dst{};
@ -197,14 +194,11 @@ SUITE(copy_tests)
span<int> dst_span_dyn(dst);
span<int, 4> dst_span_static(dst);
CHECK_THROW(copy(src_span_dyn, dst_span_dyn), fail_fast);
CHECK_THROW(copy(src_span_dyn, dst_span_static), fail_fast);
CHECK_THROW(copy(src_span_static, dst_span_dyn), fail_fast);
CHECK_THROWS_AS(copy(src_span_dyn, dst_span_dyn), fail_fast);
CHECK_THROWS_AS(copy(src_span_dyn, dst_span_static), fail_fast);
CHECK_THROWS_AS(copy(src_span_static, dst_span_dyn), fail_fast);
#ifdef CONFIRM_COMPILATION_ERRORS
copy(src_span_static, dst_span_static);
#endif
}
}
int main() { return UnitTest::RunAllTests(); }

View File

@ -14,24 +14,22 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/gsl>
using namespace gsl;
SUITE(assertion_tests)
{
int f(int i)
{
Expects(i > 0 && i < 10);
return i;
}
TEST(expects)
TEST_CASE("expects")
{
CHECK(f(2) == 2);
CHECK_THROW(f(10), fail_fast);
CHECK_THROWS_AS(f(10), fail_fast);
}
int g(int i)
@ -41,11 +39,8 @@ SUITE(assertion_tests)
return i;
}
TEST(ensures)
TEST_CASE("ensures")
{
CHECK(g(2) == 3);
CHECK_THROW(g(9), fail_fast);
CHECK_THROWS_AS(g(9), fail_fast);
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/gsl>
@ -23,9 +23,7 @@
using gsl::fail_fast;
SUITE(at_tests)
{
TEST(static_array)
TEST_CASE("static_array")
{
int a[4] = {1, 2, 3, 4};
const int(&c_a)[4] = a;
@ -35,13 +33,13 @@ SUITE(at_tests)
CHECK(&gsl::at(c_a, i) == &a[i]);
}
CHECK_THROW(gsl::at(a, -1), fail_fast);
CHECK_THROW(gsl::at(a, 4), fail_fast);
CHECK_THROW(gsl::at(c_a, -1), fail_fast);
CHECK_THROW(gsl::at(c_a, 4), fail_fast);
CHECK_THROWS_AS(gsl::at(a, -1), fail_fast);
CHECK_THROWS_AS(gsl::at(a, 4), fail_fast);
CHECK_THROWS_AS(gsl::at(c_a, -1), fail_fast);
CHECK_THROWS_AS(gsl::at(c_a, 4), fail_fast);
}
TEST(std_array)
TEST_CASE("std_array")
{
std::array<int, 4> a = {1, 2, 3, 4};
const std::array<int, 4>& c_a = a;
@ -51,13 +49,13 @@ SUITE(at_tests)
CHECK(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
}
CHECK_THROW(gsl::at(a, -1), fail_fast);
CHECK_THROW(gsl::at(a, 4), fail_fast);
CHECK_THROW(gsl::at(c_a, -1), fail_fast);
CHECK_THROW(gsl::at(c_a, 4), fail_fast);
CHECK_THROWS_AS(gsl::at(a, -1), fail_fast);
CHECK_THROWS_AS(gsl::at(a, 4), fail_fast);
CHECK_THROWS_AS(gsl::at(c_a, -1), fail_fast);
CHECK_THROWS_AS(gsl::at(c_a, 4), fail_fast);
}
TEST(StdVector)
TEST_CASE("StdVector")
{
std::vector<int> a = {1, 2, 3, 4};
const std::vector<int>& c_a = a;
@ -67,13 +65,13 @@ SUITE(at_tests)
CHECK(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
}
CHECK_THROW(gsl::at(a, -1), fail_fast);
CHECK_THROW(gsl::at(a, 4), fail_fast);
CHECK_THROW(gsl::at(c_a, -1), fail_fast);
CHECK_THROW(gsl::at(c_a, 4), fail_fast);
CHECK_THROWS_AS(gsl::at(a, -1), fail_fast);
CHECK_THROWS_AS(gsl::at(a, 4), fail_fast);
CHECK_THROWS_AS(gsl::at(c_a, -1), fail_fast);
CHECK_THROWS_AS(gsl::at(c_a, 4), fail_fast);
}
TEST(InitializerList)
TEST_CASE("InitializerList")
{
std::initializer_list<int> a = {1, 2, 3, 4};
@ -82,11 +80,10 @@ SUITE(at_tests)
CHECK(gsl::at({1, 2, 3, 4}, i) == i + 1);
}
CHECK_THROW(gsl::at(a, -1), fail_fast);
CHECK_THROW(gsl::at(a, 4), fail_fast);
CHECK_THROW(gsl::at({1, 2, 3, 4}, -1), fail_fast);
CHECK_THROW(gsl::at({1, 2, 3, 4}, 4), fail_fast);
}
CHECK_THROWS_AS(gsl::at(a, -1), fail_fast);
CHECK_THROWS_AS(gsl::at(a, 4), fail_fast);
CHECK_THROWS_AS(gsl::at({1, 2, 3, 4}, -1), fail_fast);
CHECK_THROWS_AS(gsl::at({1, 2, 3, 4}, 4), fail_fast);
}
#if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER >= 1910
@ -111,5 +108,3 @@ static constexpr bool test_constexpr()
static_assert(test_constexpr(), "FAIL");
#endif
int main() { return UnitTest::RunAllTests(); }

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/multi_span>
@ -28,9 +28,7 @@ namespace
void use(std::ptrdiff_t&) {}
}
SUITE(bounds_test)
{
TEST(basic_bounds)
TEST_CASE("basic_bounds")
{
for (auto point : static_bounds<dynamic_range, 3, 4>{2}) {
for (decltype(point)::size_type j = 0;
@ -42,7 +40,7 @@ SUITE(bounds_test)
}
}
TEST(bounds_basic)
TEST_CASE("bounds_basic")
{
static_bounds<3, 4, 5> b;
const auto a = b.slice();
@ -51,7 +49,7 @@ SUITE(bounds_test)
x.slice().slice();
}
TEST(arrayview_iterator)
TEST_CASE("arrayview_iterator")
{
static_bounds<4, dynamic_range, 2> bounds{3};
@ -69,7 +67,7 @@ SUITE(bounds_test)
#endif
}
TEST(bounds_convertible)
TEST_CASE("bounds_convertible")
{
static_bounds<7, 4, 2> b1;
static_bounds<7, dynamic_range, 2> b2 = b1;
@ -88,13 +86,10 @@ SUITE(bounds_test)
static_bounds<34> b6;
b5 = static_bounds<20>();
CHECK_THROW(b6 = b5, fail_fast);
CHECK_THROWS_AS(b6 = b5, fail_fast);
b5 = static_bounds<34>();
b6 = b5;
CHECK(b5 == b6);
CHECK(b5.size() == b6.size());
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/gsl_byte>
@ -31,9 +31,7 @@ using namespace gsl;
namespace
{
SUITE(byte_tests)
{
TEST(construction)
TEST_CASE("construction")
{
{
const byte b = static_cast<byte>(4);
@ -62,7 +60,7 @@ SUITE(byte_tests)
//}
}
TEST(bitwise_operations)
TEST_CASE("bitwise_operations")
{
const byte b = to_byte<0xFF>();
@ -98,7 +96,7 @@ SUITE(byte_tests)
CHECK(a == to_byte<0x0F>());
}
TEST(to_integer)
TEST_CASE("to_integer")
{
const byte b = to_byte<0x12>();
@ -123,13 +121,11 @@ SUITE(byte_tests)
return i;
}
TEST(aliasing)
TEST_CASE("aliasing")
{
int i{0};
const int res = modify_both(reinterpret_cast<byte&>(i), i);
CHECK(res == i);
}
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }
}

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/multi_span>
@ -38,146 +38,143 @@ struct DerivedClass : BaseClass
};
}
SUITE(multi_span_tests)
{
TEST(default_constructor)
TEST_CASE("default_constructor")
{
{
multi_span<int> s;
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int> cs;
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
{
multi_span<int, 0> s;
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int, 0> cs;
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
{
#ifdef CONFIRM_COMPILATION_ERRORS
multi_span<int, 1> s;
CHECK(s.length() == 1 && s.data() == nullptr); // explains why it can't compile
CHECK((s.length() == 1 && s.data() == nullptr)); // explains why it can't compile
#endif
}
{
multi_span<int> s{};
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int> cs{};
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
}
TEST(from_nullptr_constructor)
TEST_CASE("from_nullptr_constructor")
{
{
multi_span<int> s = nullptr;
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int> cs = nullptr;
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
{
multi_span<int, 0> s = nullptr;
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int, 0> cs = nullptr;
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
{
#ifdef CONFIRM_COMPILATION_ERRORS
multi_span<int, 1> s = nullptr;
CHECK(s.length() == 1 && s.data() == nullptr); // explains why it can't compile
CHECK((s.length() == 1 && s.data() == nullptr)); // explains why it can't compile
#endif
}
{
multi_span<int> s{nullptr};
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int> cs{nullptr};
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
{
multi_span<int*> s{nullptr};
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int*> cs{nullptr};
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
}
TEST(from_nullptr_length_constructor)
TEST_CASE("from_nullptr_length_constructor")
{
{
multi_span<int> s{nullptr, 0};
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int> cs{nullptr, 0};
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
{
multi_span<int, 0> s{nullptr, 0};
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int, 0> cs{nullptr, 0};
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
{
#ifdef CONFIRM_COMPILATION_ERRORS
multi_span<int, 1> s{nullptr, 0};
CHECK(s.length() == 1 && s.data() == nullptr); // explains why it can't compile
CHECK((s.length() == 1 && s.data() == nullptr)); // explains why it can't compile
#endif
}
{
auto workaround_macro = []() { multi_span<int> s{nullptr, 1}; };
CHECK_THROW(workaround_macro(), fail_fast);
CHECK_THROWS_AS(workaround_macro(), fail_fast);
auto const_workaround_macro = []() { multi_span<const int> cs{nullptr, 1}; };
CHECK_THROW(const_workaround_macro(), fail_fast);
CHECK_THROWS_AS(const_workaround_macro(), fail_fast);
}
{
auto workaround_macro = []() { multi_span<int, 0> s{nullptr, 1}; };
CHECK_THROW(workaround_macro(), fail_fast);
CHECK_THROWS_AS(workaround_macro(), fail_fast);
auto const_workaround_macro = []() { multi_span<const int, 0> s{nullptr, 1}; };
CHECK_THROW(const_workaround_macro(), fail_fast);
CHECK_THROWS_AS(const_workaround_macro(), fail_fast);
}
{
multi_span<int*> s{nullptr, 0};
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
multi_span<const int*> cs{nullptr, 0};
CHECK(cs.length() == 0 && cs.data() == nullptr);
CHECK((cs.length() == 0 && cs.data() == nullptr));
}
}
TEST(from_element_constructor)
TEST_CASE("from_element_constructor")
{
int i = 5;
{
multi_span<int> s = i;
CHECK(s.length() == 1 && s.data() == &i);
CHECK((s.length() == 1 && s.data() == &i));
CHECK(s[0] == 5);
multi_span<const int> cs = i;
CHECK(cs.length() == 1 && cs.data() == &i);
CHECK((cs.length() == 1 && cs.data() == &i));
CHECK(cs[0] == 5);
}
@ -191,20 +188,20 @@ SUITE(multi_span_tests)
{
#ifdef CONFIRM_COMPILATION_ERRORS
multi_span<int, 0> s = i;
CHECK(s.length() == 0 && s.data() == &i);
CHECK((s.length() == 0 && s.data() == &i));
#endif
}
{
multi_span<int, 1> s = i;
CHECK(s.length() == 1 && s.data() == &i);
CHECK((s.length() == 1 && s.data() == &i));
CHECK(s[0] == 5);
}
{
#ifdef CONFIRM_COMPILATION_ERRORS
multi_span<int, 2> s = i;
CHECK(s.length() == 2 && s.data() == &i);
CHECK((s.length() == 2 && s.data() == &i));
#endif
}
@ -217,97 +214,97 @@ SUITE(multi_span_tests)
}
}
TEST(from_pointer_length_constructor)
TEST_CASE("from_pointer_length_constructor")
{
int arr[4] = {1, 2, 3, 4};
{
multi_span<int> s{&arr[0], 2};
CHECK(s.length() == 2 && s.data() == &arr[0]);
CHECK(s[0] == 1 && s[1] == 2);
CHECK((s.length() == 2 && s.data() == &arr[0]));
CHECK((s[0] == 1 && s[1] == 2));
}
{
multi_span<int, 2> s{&arr[0], 2};
CHECK(s.length() == 2 && s.data() == &arr[0]);
CHECK(s[0] == 1 && s[1] == 2);
CHECK((s.length() == 2 && s.data() == &arr[0]));
CHECK((s[0] == 1 && s[1] == 2));
}
{
int* p = nullptr;
multi_span<int> s{p, 0};
CHECK(s.length() == 0 && s.data() == nullptr);
CHECK((s.length() == 0 && s.data() == nullptr));
}
{
int* p = nullptr;
auto workaround_macro = [=]() { multi_span<int> s{p, 2}; };
CHECK_THROW(workaround_macro(), fail_fast);
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
}
TEST(from_pointer_pointer_constructor)
TEST_CASE("from_pointer_pointer_constructor")
{
int arr[4] = {1, 2, 3, 4};
{
multi_span<int> s{&arr[0], &arr[2]};
CHECK(s.length() == 2 && s.data() == &arr[0]);
CHECK(s[0] == 1 && s[1] == 2);
CHECK((s.length() == 2 && s.data() == &arr[0]));
CHECK((s[0] == 1 && s[1] == 2));
}
{
multi_span<int, 2> s{&arr[0], &arr[2]};
CHECK(s.length() == 2 && s.data() == &arr[0]);
CHECK(s[0] == 1 && s[1] == 2);
CHECK((s.length() == 2 && s.data() == &arr[0]));
CHECK((s[0] == 1 && s[1] == 2));
}
{
multi_span<int> s{&arr[0], &arr[0]};
CHECK(s.length() == 0 && s.data() == &arr[0]);
CHECK((s.length() == 0 && s.data() == &arr[0]));
}
{
multi_span<int, 0> s{&arr[0], &arr[0]};
CHECK(s.length() == 0 && s.data() == &arr[0]);
CHECK((s.length() == 0 && s.data() == &arr[0]));
}
{
auto workaround_macro = [&]() { multi_span<int> s{&arr[1], &arr[0]}; };
CHECK_THROW(workaround_macro(), fail_fast);
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
{
int* p = nullptr;
auto workaround_macro = [&]() { multi_span<int> s{&arr[0], p}; };
CHECK_THROW(workaround_macro(), fail_fast);
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
{
int* p = nullptr;
auto workaround_macro = [&]() { multi_span<int> s{p, p}; };
CHECK_THROW(workaround_macro(), fail_fast);
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
{
int* p = nullptr;
auto workaround_macro = [&]() { multi_span<int> s{&arr[0], p}; };
CHECK_THROW(workaround_macro(), fail_fast);
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
}
TEST(from_array_constructor)
TEST_CASE("from_array_constructor")
{
int arr[5] = {1, 2, 3, 4, 5};
{
multi_span<int> s{arr};
CHECK(s.length() == 5 && s.data() == &arr[0]);
CHECK((s.length() == 5 && s.data() == &arr[0]));
}
{
multi_span<int, 5> s{arr};
CHECK(s.length() == 5 && s.data() == &arr[0]);
CHECK((s.length() == 5 && s.data() == &arr[0]));
}
{
@ -318,20 +315,20 @@ SUITE(multi_span_tests)
{
multi_span<int, 0> s{arr};
CHECK(s.length() == 0 && s.data() == &arr[0]);
CHECK((s.length() == 0 && s.data() == &arr[0]));
}
int arr2d[2][3] = {1, 2, 3, 4, 5, 6};
{
multi_span<int> s{arr2d};
CHECK(s.length() == 6 && s.data() == &arr2d[0][0]);
CHECK(s[0] == 1 && s[5] == 6);
CHECK((s.length() == 6 && s.data() == &arr2d[0][0]));
CHECK((s[0] == 1 && s[5] == 6));
}
{
multi_span<int, 0> s{arr2d};
CHECK(s.length() == 0 && s.data() == &arr2d[0][0]);
CHECK((s.length() == 0 && s.data() == &arr2d[0][0]));
}
{
@ -342,8 +339,8 @@ SUITE(multi_span_tests)
{
multi_span<int, 6> s{arr2d};
CHECK(s.length() == 6 && s.data() == &arr2d[0][0]);
CHECK(s[0] == 1 && s[5] == 6);
CHECK((s.length() == 6 && s.data() == &arr2d[0][0]));
CHECK((s[0] == 1 && s[5] == 6));
}
{
@ -354,12 +351,12 @@ SUITE(multi_span_tests)
{
multi_span<int[3]> s{arr2d[0]};
CHECK(s.length() == 1 && s.data() == &arr2d[0]);
CHECK((s.length() == 1 && s.data() == &arr2d[0]));
}
{
multi_span<int, 2, 3> s{arr2d};
CHECK(s.length() == 6 && s.data() == &arr2d[0][0]);
CHECK((s.length() == 6 && s.data() == &arr2d[0][0]));
auto workaround_macro = [&]() { return s[{1, 2}] == 6; };
CHECK(workaround_macro());
}
@ -374,13 +371,13 @@ SUITE(multi_span_tests)
{
multi_span<int> s{arr3d};
CHECK(s.length() == 12 && s.data() == &arr3d[0][0][0]);
CHECK(s[0] == 1 && s[11] == 12);
CHECK((s.length() == 12 && s.data() == &arr3d[0][0][0]));
CHECK((s[0] == 1 && s[11] == 12));
}
{
multi_span<int, 0> s{arr3d};
CHECK(s.length() == 0 && s.data() == &arr3d[0][0][0]);
CHECK((s.length() == 0 && s.data() == &arr3d[0][0][0]));
}
{
@ -391,8 +388,8 @@ SUITE(multi_span_tests)
{
multi_span<int, 12> s{arr3d};
CHECK(s.length() == 12 && s.data() == &arr3d[0][0][0]);
CHECK(s[0] == 1 && s[5] == 6);
CHECK((s.length() == 12 && s.data() == &arr3d[0][0][0]));
CHECK((s[0] == 1 && s[5] == 6));
}
{
@ -403,12 +400,12 @@ SUITE(multi_span_tests)
{
multi_span<int[3][2]> s{arr3d[0]};
CHECK(s.length() == 1 && s.data() == &arr3d[0]);
CHECK((s.length() == 1 && s.data() == &arr3d[0]));
}
{
multi_span<int, 3, 2, 2> s{arr3d};
CHECK(s.length() == 12 && s.data() == &arr3d[0][0][0]);
CHECK((s.length() == 12 && s.data() == &arr3d[0][0][0]));
auto workaround_macro = [&]() { return s[{2, 1, 0}] == 11; };
CHECK(workaround_macro());
}
@ -420,68 +417,68 @@ SUITE(multi_span_tests)
}
}
TEST(from_dynamic_array_constructor)
TEST_CASE("from_dynamic_array_constructor")
{
double(*arr)[3][4] = new double[100][3][4];
{
multi_span<double, dynamic_range, 3, 4> s(arr, 10);
CHECK(s.length() == 120 && s.data() == &arr[0][0][0]);
CHECK_THROW(s[10][3][4], fail_fast);
CHECK((s.length() == 120 && s.data() == &arr[0][0][0]));
CHECK_THROWS_AS(s[10][3][4], fail_fast);
}
{
multi_span<double, dynamic_range, 4, 3> s(arr, 10);
CHECK(s.length() == 120 && s.data() == &arr[0][0][0]);
CHECK((s.length() == 120 && s.data() == &arr[0][0][0]));
}
{
multi_span<double> s(arr, 10);
CHECK(s.length() == 120 && s.data() == &arr[0][0][0]);
CHECK((s.length() == 120 && s.data() == &arr[0][0][0]));
}
{
multi_span<double, dynamic_range, 3, 4> s(arr, 0);
CHECK(s.length() == 0 && s.data() == &arr[0][0][0]);
CHECK((s.length() == 0 && s.data() == &arr[0][0][0]));
}
delete[] arr;
}
TEST(from_std_array_constructor)
TEST_CASE("from_std_array_constructor")
{
std::array<int, 4> arr = {1, 2, 3, 4};
{
multi_span<int> s{arr};
CHECK(s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data());
CHECK((s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data()));
multi_span<const int> cs{arr};
CHECK(cs.size() == narrow_cast<ptrdiff_t>(arr.size()) && cs.data() == arr.data());
CHECK((cs.size() == narrow_cast<ptrdiff_t>(arr.size()) && cs.data() == arr.data()));
}
{
multi_span<int, 4> s{arr};
CHECK(s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data());
CHECK((s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data()));
multi_span<const int, 4> cs{arr};
CHECK(cs.size() == narrow_cast<ptrdiff_t>(arr.size()) && cs.data() == arr.data());
CHECK((cs.size() == narrow_cast<ptrdiff_t>(arr.size()) && cs.data() == arr.data()));
}
{
multi_span<int, 2> s{arr};
CHECK(s.size() == 2 && s.data() == arr.data());
CHECK((s.size() == 2 && s.data() == arr.data()));
multi_span<const int, 2> cs{arr};
CHECK(cs.size() == 2 && cs.data() == arr.data());
CHECK((cs.size() == 2 && cs.data() == arr.data()));
}
{
multi_span<int, 0> s{arr};
CHECK(s.size() == 0 && s.data() == arr.data());
CHECK((s.size() == 0 && s.data() == arr.data()));
multi_span<const int, 0> cs{arr};
CHECK(cs.size() == 0 && cs.data() == arr.data());
CHECK((cs.size() == 0 && cs.data() == arr.data()));
}
// TODO This is currently an unsupported scenario. We will come back to it as we revise
@ -507,28 +504,28 @@ SUITE(multi_span_tests)
}
}
TEST(from_const_std_array_constructor)
TEST_CASE("from_const_std_array_constructor")
{
const std::array<int, 4> arr = {1, 2, 3, 4};
{
multi_span<const int> s{arr};
CHECK(s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data());
CHECK((s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data()));
}
{
multi_span<const int, 4> s{arr};
CHECK(s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data());
CHECK((s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data()));
}
{
multi_span<const int, 2> s{arr};
CHECK(s.size() == 2 && s.data() == arr.data());
CHECK((s.size() == 2 && s.data() == arr.data()));
}
{
multi_span<const int, 0> s{arr};
CHECK(s.size() == 0 && s.data() == arr.data());
CHECK((s.size() == 0 && s.data() == arr.data()));
}
// TODO This is currently an unsupported scenario. We will come back to it as we revise
@ -554,17 +551,17 @@ SUITE(multi_span_tests)
}
}
TEST(from_container_constructor)
TEST_CASE("from_container_constructor")
{
std::vector<int> v = {1, 2, 3};
const std::vector<int> cv = v;
{
multi_span<int> s{v};
CHECK(s.size() == narrow_cast<std::ptrdiff_t>(v.size()) && s.data() == v.data());
CHECK((s.size() == narrow_cast<std::ptrdiff_t>(v.size()) && s.data() == v.data()));
multi_span<const int> cs{v};
CHECK(cs.size() == narrow_cast<std::ptrdiff_t>(v.size()) && cs.data() == v.data());
CHECK((cs.size() == narrow_cast<std::ptrdiff_t>(v.size()) && cs.data() == v.data()));
}
std::string str = "hello";
@ -573,10 +570,10 @@ SUITE(multi_span_tests)
{
#ifdef CONFIRM_COMPILATION_ERRORS
multi_span<char> s{str};
CHECK(s.size() == narrow_cast<std::ptrdiff_t>(str.size()) && s.data() == str.data());
CHECK((s.size() == narrow_cast<std::ptrdiff_t>(str.size()) && s.data() == str.data()));
#endif
multi_span<const char> cs{str};
CHECK(cs.size() == narrow_cast<std::ptrdiff_t>(str.size()) && cs.data() == str.data());
CHECK((cs.size() == narrow_cast<std::ptrdiff_t>(str.size()) && cs.data() == str.data()));
}
{
@ -584,8 +581,8 @@ SUITE(multi_span_tests)
multi_span<char> s{cstr};
#endif
multi_span<const char> cs{cstr};
CHECK(cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()) &&
cs.data() == cstr.data());
CHECK((cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()) &&
cs.data() == cstr.data()));
}
{
@ -628,13 +625,13 @@ SUITE(multi_span_tests)
}
}
TEST(from_convertible_span_constructor)
TEST_CASE("from_convertible_span_constructor")
{
#ifdef CONFIRM_COMPILATION_ERRORS
multi_span<int, 7, 4, 2> av1(nullptr, b1);
auto f = [&]() { multi_span<int, 7, 4, 2> av1(nullptr); };
CHECK_THROW(f(), fail_fast);
CHECK_THROWS_AS(f(), fail_fast);
#endif
#ifdef CONFIRM_COMPILATION_ERRORS
@ -655,7 +652,7 @@ SUITE(multi_span_tests)
(void) avcd;
}
TEST(copy_move_and_assignment)
TEST_CASE("copy_move_and_assignment")
{
multi_span<int> s1;
CHECK(s1.empty());
@ -663,19 +660,19 @@ SUITE(multi_span_tests)
int arr[] = {3, 4, 5};
multi_span<const int> s2 = arr;
CHECK(s2.length() == 3 && s2.data() == &arr[0]);
CHECK((s2.length() == 3 && s2.data() == &arr[0]));
s2 = s1;
CHECK(s2.empty());
auto get_temp_span = [&]() -> multi_span<int> { return {&arr[1], 2}; };
auto use_span = [&](multi_span<const int> s) {
CHECK(s.length() == 2 && s.data() == &arr[1]);
CHECK((s.length() == 2 && s.data() == &arr[1]));
};
use_span(get_temp_span());
s1 = get_temp_span();
CHECK(s1.length() == 2 && s1.data() == &arr[1]);
CHECK((s1.length() == 2 && s1.data() == &arr[1]));
}
template <class Bounds>
@ -683,7 +680,7 @@ SUITE(multi_span_tests)
{
static_assert(Bounds::static_size == 60, "static bounds is wrong size");
}
TEST(as_multi_span_reshape)
TEST_CASE("as_multi_span_reshape")
{
int a[3][4][5];
auto av = as_multi_span(a);
@ -706,7 +703,7 @@ SUITE(multi_span_tests)
}
}
TEST(first)
TEST_CASE("first")
{
int arr[5] = {1, 2, 3, 4, 5};
@ -738,7 +735,7 @@ SUITE(multi_span_tests)
CHECK(av.first<6>().length() == 6);
CHECK(av.first<-1>().length() == -1);
#endif
CHECK_THROW(av.first(6).length(), fail_fast);
CHECK_THROWS_AS(av.first(6).length(), fail_fast);
}
{
@ -749,7 +746,7 @@ SUITE(multi_span_tests)
}
}
TEST(last)
TEST_CASE("last")
{
int arr[5] = {1, 2, 3, 4, 5};
@ -780,7 +777,7 @@ SUITE(multi_span_tests)
CHECK((av.last<6>().bounds() == static_bounds<6>()));
CHECK(av.last<6>().length() == 6);
#endif
CHECK_THROW(av.last(6).length(), fail_fast);
CHECK_THROWS_AS(av.last(6).length(), fail_fast);
}
{
@ -791,7 +788,7 @@ SUITE(multi_span_tests)
}
}
TEST(subspan)
TEST_CASE("subspan")
{
int arr[5] = {1, 2, 3, 4, 5};
@ -815,8 +812,8 @@ SUITE(multi_span_tests)
CHECK((av.subspan<0, 5>().bounds() == static_bounds<5>()));
CHECK((av.subspan<0, 5>().length() == 5));
CHECK(av.subspan(0, 5).length() == 5);
CHECK_THROW(av.subspan(0, 6).length(), fail_fast);
CHECK_THROW(av.subspan(1, 5).length(), fail_fast);
CHECK_THROWS_AS(av.subspan(0, 6).length(), fail_fast);
CHECK_THROWS_AS(av.subspan(1, 5).length(), fail_fast);
}
{
@ -824,7 +821,7 @@ SUITE(multi_span_tests)
CHECK((av.subspan<5, 0>().bounds() == static_bounds<0>()));
CHECK((av.subspan<5, 0>().length() == 0));
CHECK(av.subspan(5, 0).length() == 0);
CHECK_THROW(av.subspan(6, 0).length(), fail_fast);
CHECK_THROWS_AS(av.subspan(6, 0).length(), fail_fast);
}
{
@ -832,13 +829,13 @@ SUITE(multi_span_tests)
CHECK((av.subspan<0, 0>().bounds() == static_bounds<0>()));
CHECK((av.subspan<0, 0>().length() == 0));
CHECK(av.subspan(0, 0).length() == 0);
CHECK_THROW((av.subspan<1, 0>().length()), fail_fast);
CHECK_THROWS_AS((av.subspan<1, 0>().length()), fail_fast);
}
{
multi_span<int> av;
CHECK(av.subspan(0).length() == 0);
CHECK_THROW(av.subspan(1).length(), fail_fast);
CHECK_THROWS_AS(av.subspan(1).length(), fail_fast);
}
{
@ -847,7 +844,7 @@ SUITE(multi_span_tests)
CHECK(av.subspan(1).length() == 4);
CHECK(av.subspan(4).length() == 1);
CHECK(av.subspan(5).length() == 0);
CHECK_THROW(av.subspan(6).length(), fail_fast);
CHECK_THROWS_AS(av.subspan(6).length(), fail_fast);
auto av2 = av.subspan(1);
for (int i = 0; i < 4; ++i) CHECK(av2[i] == i + 2);
}
@ -858,13 +855,13 @@ SUITE(multi_span_tests)
CHECK(av.subspan(1).length() == 4);
CHECK(av.subspan(4).length() == 1);
CHECK(av.subspan(5).length() == 0);
CHECK_THROW(av.subspan(6).length(), fail_fast);
CHECK_THROWS_AS(av.subspan(6).length(), fail_fast);
auto av2 = av.subspan(1);
for (int i = 0; i < 4; ++i) CHECK(av2[i] == i + 2);
}
}
TEST(rank)
TEST_CASE("rank")
{
int arr[2] = {1, 2};
@ -885,13 +882,13 @@ SUITE(multi_span_tests)
}
}
TEST(extent)
TEST_CASE("extent")
{
{
multi_span<int> s;
CHECK(s.extent() == 0);
CHECK(s.extent(0) == 0);
CHECK_THROW(s.extent(1), fail_fast);
CHECK_THROWS_AS(s.extent(1), fail_fast);
#ifdef CONFIRM_COMPILATION_ERRORS
CHECK(s.extent<1>() == 0);
#endif
@ -901,7 +898,7 @@ SUITE(multi_span_tests)
multi_span<int, 0> s;
CHECK(s.extent() == 0);
CHECK(s.extent(0) == 0);
CHECK_THROW(s.extent(1), fail_fast);
CHECK_THROWS_AS(s.extent(1), fail_fast);
}
{
@ -913,7 +910,7 @@ SUITE(multi_span_tests)
CHECK(s.extent<1>() == 2);
CHECK(s.extent(0) == 1);
CHECK(s.extent(1) == 2);
CHECK_THROW(s.extent(3), fail_fast);
CHECK_THROWS_AS(s.extent(3), fail_fast);
}
{
@ -925,18 +922,18 @@ SUITE(multi_span_tests)
CHECK(s.extent<1>() == 2);
CHECK(s.extent(0) == 0);
CHECK(s.extent(1) == 2);
CHECK_THROW(s.extent(3), fail_fast);
CHECK_THROWS_AS(s.extent(3), fail_fast);
}
}
TEST(operator_function_call)
TEST_CASE("operator_function_call")
{
int arr[4] = {1, 2, 3, 4};
{
multi_span<int> s = arr;
CHECK(s(0) == 1);
CHECK_THROW(s(5), fail_fast);
CHECK_THROWS_AS(s(5), fail_fast);
}
int arr2d[2][3] = {1, 2, 3, 4, 5, 6};
@ -957,7 +954,7 @@ SUITE(multi_span_tests)
}
}
TEST(comparison_operators)
TEST_CASE("comparison_operators")
{
{
int arr[10][2];
@ -967,7 +964,7 @@ SUITE(multi_span_tests)
CHECK(s1 == s2);
multi_span<int, 20> s3 = as_multi_span(s1, dim(20));
CHECK(s3 == s2 && s3 == s1);
CHECK((s3 == s2 && s3 == s1));
}
{
@ -1069,7 +1066,7 @@ SUITE(multi_span_tests)
}
}
TEST(basics)
TEST_CASE("basics")
{
auto ptr = as_multi_span(new int[10], 10);
fill(ptr.begin(), ptr.end(), 99);
@ -1080,7 +1077,7 @@ SUITE(multi_span_tests)
delete[] ptr.data();
}
TEST(bounds_checks)
TEST_CASE("bounds_checks")
{
int arr[10][2];
auto av = as_multi_span(arr);
@ -1091,17 +1088,17 @@ SUITE(multi_span_tests)
av[1][1] = 3;
// out of bounds
CHECK_THROW(av[1][3] = 3, fail_fast);
CHECK_THROW((av[{1, 3}] = 3), fail_fast);
CHECK_THROWS_AS(av[1][3] = 3, fail_fast);
CHECK_THROWS_AS((av[{1, 3}] = 3), fail_fast);
CHECK_THROW(av[10][2], fail_fast);
CHECK_THROW((av[{10, 2}]), fail_fast);
CHECK_THROWS_AS(av[10][2], fail_fast);
CHECK_THROWS_AS((av[{10, 2}]), fail_fast);
CHECK_THROW(av[-1][0], fail_fast);
CHECK_THROW((av[{-1, 0}]), fail_fast);
CHECK_THROWS_AS(av[-1][0], fail_fast);
CHECK_THROWS_AS((av[{-1, 0}]), fail_fast);
CHECK_THROW(av[0][-1], fail_fast);
CHECK_THROW((av[{0, -1}]), fail_fast);
CHECK_THROWS_AS(av[0][-1], fail_fast);
CHECK_THROWS_AS((av[{0, -1}]), fail_fast);
}
void overloaded_func(multi_span<const int, dynamic_range, 3, 5> exp, int expected_value)
@ -1125,7 +1122,7 @@ SUITE(multi_span_tests)
}
}
TEST(span_parameter_test)
TEST_CASE("span_parameter_test")
{
auto data = new int[4][3][5];
@ -1146,7 +1143,7 @@ SUITE(multi_span_tests)
delete[] data;
}
TEST(md_access)
TEST_CASE("md_access")
{
auto width = 5, height = 20;
@ -1178,7 +1175,7 @@ SUITE(multi_span_tests)
}
}
TEST(as_multi_span)
TEST_CASE("as_multi_span")
{
{
int* arr = new int[150];
@ -1233,15 +1230,15 @@ SUITE(multi_span_tests)
}
}
TEST(empty_spans)
TEST_CASE("empty_spans")
{
{
multi_span<int, 0> empty_av(nullptr);
CHECK(empty_av.bounds().index_bounds() == index<1>{0});
CHECK_THROW(empty_av[0], fail_fast);
CHECK_THROW(empty_av.begin()[0], fail_fast);
CHECK_THROW(empty_av.cbegin()[0], fail_fast);
CHECK_THROWS_AS(empty_av[0], fail_fast);
CHECK_THROWS_AS(empty_av.begin()[0], fail_fast);
CHECK_THROWS_AS(empty_av.cbegin()[0], fail_fast);
for (auto& v : empty_av) {
(void) v;
CHECK(false);
@ -1251,9 +1248,9 @@ SUITE(multi_span_tests)
{
multi_span<int> empty_av = {};
CHECK(empty_av.bounds().index_bounds() == index<1>{0});
CHECK_THROW(empty_av[0], fail_fast);
CHECK_THROW(empty_av.begin()[0], fail_fast);
CHECK_THROW(empty_av.cbegin()[0], fail_fast);
CHECK_THROWS_AS(empty_av[0], fail_fast);
CHECK_THROWS_AS(empty_av.begin()[0], fail_fast);
CHECK_THROWS_AS(empty_av.cbegin()[0], fail_fast);
for (auto& v : empty_av) {
(void) v;
CHECK(false);
@ -1261,7 +1258,7 @@ SUITE(multi_span_tests)
}
}
TEST(index_constructor)
TEST_CASE("index_constructor")
{
auto arr = new int[8];
for (int i = 0; i < 4; ++i) {
@ -1286,7 +1283,10 @@ SUITE(multi_span_tests)
delete[] arr;
}
TEST(index_constructors){{// components of the same type
TEST_CASE("index_constructors")
{
{
// components of the same type
index<3> i1(0, 1, 2);
CHECK(i1[0] == 0);
@ -1355,7 +1355,7 @@ SUITE(multi_span_tests)
#endif
}
TEST(index_operations)
TEST_CASE("index_operations")
{
ptrdiff_t a[3] = {0, 1, 2};
ptrdiff_t b[3] = {3, 4, 5};
@ -1465,7 +1465,7 @@ void iterate_second_column(multi_span<int, dynamic_range, dynamic_range> av)
}
}
TEST(span_section_iteration)
TEST_CASE("span_section_iteration")
{
int arr[4][2] = {{4, 0}, {5, 1}, {6, 2}, {7, 3}};
@ -1491,7 +1491,7 @@ TEST(span_section_iteration)
}
}
TEST(dynamic_span_section_iteration)
TEST_CASE("dynamic_span_section_iteration")
{
auto height = 4, width = 2;
auto size = height * width;
@ -1523,7 +1523,7 @@ TEST(dynamic_span_section_iteration)
delete[] arr;
}
TEST(span_structure_size)
TEST_CASE("span_structure_size")
{
double(*arr)[3][4] = new double[100][3][4];
multi_span<double, dynamic_range, 3, 4> av1(arr, 10);
@ -1535,14 +1535,14 @@ TEST(span_structure_size)
};
CHECK(sizeof(av1) == sizeof(EffectiveStructure));
CHECK_THROW(av1[10][3][4], fail_fast);
CHECK_THROWS_AS(av1[10][3][4], fail_fast);
multi_span<const double, dynamic_range, 6, 4> av2 =
as_multi_span(av1, dim(5), dim<6>(), dim<4>());
(void) av2;
}
TEST(fixed_size_conversions)
TEST_CASE("fixed_size_conversions")
{
int arr[] = {1, 2, 3, 4};
@ -1626,7 +1626,7 @@ TEST(fixed_size_conversions)
multi_span<int, 4> av9 = {arr2, 2};
(void) av9;
};
CHECK_THROW(f(), fail_fast);
CHECK_THROWS_AS(f(), fail_fast);
}
// this should fail - we are trying to assign a small dynamic a_v to a fixed_size larger one
@ -1635,10 +1635,10 @@ TEST(fixed_size_conversions)
multi_span<int, 4> av2 = av;
(void) av2;
};
CHECK_THROW(f(), fail_fast);
CHECK_THROWS_AS(f(), fail_fast);
}
TEST(as_writeable_bytes)
TEST_CASE("as_writeable_bytes")
{
int a[] = {1, 2, 3, 4};
@ -1666,7 +1666,7 @@ TEST(as_writeable_bytes)
}
}
TEST(iterator)
TEST_CASE("iterator")
{
int a[] = {1, 2, 3, 4};
@ -1691,6 +1691,3 @@ TEST(iterator)
}
}
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/gsl>
@ -95,12 +95,9 @@ std::string operator>=(CustomPtr<T> const& lhs, CustomPtr<U> const& rhs)
: "false";
}
SUITE(NotNullTests)
{
bool helper(not_null<int*> p) { return *p == 12; }
TEST(TestNotNullConstructors)
TEST_CASE("TestNotNullConstructors")
{
#ifdef CONFIRM_COMPILATION_ERRORS
not_null<int*> p = nullptr; // yay...does not compile!
@ -123,7 +120,7 @@ SUITE(NotNullTests)
std::make_shared<int>(10)); // shared_ptr<int> is nullptr assignable
}
TEST(TestNotNullCasting)
TEST_CASE("TestNotNullCasting")
{
MyBase base;
MyDerived derived;
@ -146,17 +143,17 @@ SUITE(NotNullTests)
CHECK(reinterpret_cast<void*>(p.get()) == reinterpret_cast<void*>(t.get()));
}
TEST(TestNotNullAssignment)
TEST_CASE("TestNotNullAssignment")
{
int i = 12;
not_null<int*> p = &i;
CHECK(helper(p));
int* q = nullptr;
CHECK_THROW(p = q, fail_fast);
CHECK_THROWS_AS(p = q, fail_fast);
}
TEST(TestNotNullRawPointerComparison)
TEST_CASE("TestNotNullRawPointerComparison")
{
int ints[2] = {42, 43};
int* p1 = &ints[0];
@ -188,7 +185,7 @@ SUITE(NotNullTests)
CHECK((NotNull2(p2) >= NotNull1(p1)) == (p2 >= p1));
}
TEST(TestNotNullSharedPtrComparison)
TEST_CASE("TestNotNullSharedPtrComparison")
{
auto sp1 = std::make_shared<int>(42);
auto sp2 = std::make_shared<const int>(43);
@ -219,7 +216,7 @@ SUITE(NotNullTests)
CHECK((NotNullSp2(sp2) >= NotNullSp1(sp1)) == (sp2 >= sp1));
}
TEST(TestNotNullCustomPtrComparison)
TEST_CASE("TestNotNullCustomPtrComparison")
{
int ints[2] = {42, 43};
CustomPtr<int> p1(&ints[0]);
@ -250,6 +247,3 @@ SUITE(NotNullTests)
CHECK((NotNull1(p1) >= NotNull2(p2)) == (p1 >= p2));
CHECK((NotNull2(p2) >= NotNull1(p1)) == (p2 >= p1));
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/gsl>
@ -22,11 +22,9 @@
using namespace gsl;
SUITE(owner_tests)
{
void f(int* i) { *i += 1; }
TEST(basic_test)
TEST_CASE("basic_test")
{
owner<int*> p = new int(120);
CHECK(*p == 120);
@ -34,6 +32,3 @@ SUITE(owner_tests)
CHECK(*p == 121);
delete p;
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/multi_span>
@ -38,9 +38,7 @@ struct DerivedClass : BaseClass
};
}
SUITE(strided_span_tests)
{
TEST(span_section_test)
TEST_CASE("span_section_test")
{
int a[30][4][5];
@ -50,7 +48,7 @@ SUITE(strided_span_tests)
(void) subsub;
}
TEST(span_section)
TEST_CASE("span_section")
{
std::vector<int> data(5 * 10);
std::iota(begin(data), end(data), 0);
@ -68,7 +66,7 @@ SUITE(strided_span_tests)
CHECK((av_section_2[{1, 0}] == 34));
}
TEST(strided_span_constructors)
TEST_CASE("strided_span_constructors")
{
// Check stride constructor
{
@ -78,12 +76,12 @@ SUITE(strided_span_tests)
strided_span<int, 1> sav1{arr, {{9}, {1}}}; // T -> T
CHECK(sav1.bounds().index_bounds() == index<1>{9});
CHECK(sav1.bounds().stride() == 1);
CHECK(sav1[0] == 1 && sav1[8] == 9);
CHECK((sav1[0] == 1 && sav1[8] == 9));
strided_span<const int, 1> sav2{carr, {{4}, {2}}}; // const T -> const T
CHECK(sav2.bounds().index_bounds() == index<1>{4});
CHECK(sav2.bounds().strides() == index<1>{2});
CHECK(sav2[0] == 1 && sav2[3] == 7);
CHECK((sav2[0] == 1 && sav2[3] == 7));
strided_span<int, 2> sav3{arr, {{2, 2}, {6, 2}}}; // T -> const T
CHECK((sav3.bounds().index_bounds() == index<2>{2, 2}));
@ -268,7 +266,7 @@ SUITE(strided_span_tests)
}
}
TEST(strided_span_slice)
TEST_CASE("strided_span_slice")
{
std::vector<int> data(5 * 10);
std::iota(begin(data), end(data), 0);
@ -294,7 +292,7 @@ SUITE(strided_span_tests)
CHECK(sav[4][9] == 49);
}
TEST(strided_span_column_major)
TEST_CASE("strided_span_column_major")
{
// strided_span may be used to accomodate more peculiar
// use cases, such as column-major multidimensional array
@ -326,7 +324,7 @@ SUITE(strided_span_tests)
CHECK((cm_sec[{2, 1}] == 15));
}
TEST(strided_span_bounds)
TEST_CASE("strided_span_bounds")
{
int arr[] = {0, 1, 2, 3};
multi_span<int> av(arr);
@ -334,15 +332,15 @@ SUITE(strided_span_tests)
{
// incorrect sections
CHECK_THROW(av.section(0, 0)[0], fail_fast);
CHECK_THROW(av.section(1, 0)[0], fail_fast);
CHECK_THROW(av.section(1, 1)[1], fail_fast);
CHECK_THROWS_AS(av.section(0, 0)[0], fail_fast);
CHECK_THROWS_AS(av.section(1, 0)[0], fail_fast);
CHECK_THROWS_AS(av.section(1, 1)[1], fail_fast);
CHECK_THROW(av.section(2, 5), fail_fast);
CHECK_THROW(av.section(5, 2), fail_fast);
CHECK_THROW(av.section(5, 0), fail_fast);
CHECK_THROW(av.section(0, 5), fail_fast);
CHECK_THROW(av.section(5, 5), fail_fast);
CHECK_THROWS_AS(av.section(2, 5), fail_fast);
CHECK_THROWS_AS(av.section(5, 2), fail_fast);
CHECK_THROWS_AS(av.section(5, 0), fail_fast);
CHECK_THROWS_AS(av.section(0, 5), fail_fast);
CHECK_THROWS_AS(av.section(5, 5), fail_fast);
}
{
@ -350,19 +348,19 @@ SUITE(strided_span_tests)
strided_span<int, 1> sav{av, {{4}, {}}};
CHECK(sav[0] == 0);
CHECK(sav[3] == 0);
CHECK_THROW(sav[4], fail_fast);
CHECK_THROWS_AS(sav[4], fail_fast);
}
{
// zero extent
strided_span<int, 1> sav{av, {{}, {1}}};
CHECK_THROW(sav[0], fail_fast);
CHECK_THROWS_AS(sav[0], fail_fast);
}
{
// zero extent and stride
strided_span<int, 1> sav{av, {{}, {}}};
CHECK_THROW(sav[0], fail_fast);
CHECK_THROWS_AS(sav[0], fail_fast);
}
{
@ -370,7 +368,7 @@ SUITE(strided_span_tests)
strided_span<int, 1> sav{arr, {4, 1}};
CHECK(sav.bounds().index_bounds() == index<1>{4});
CHECK(sav[3] == 3);
CHECK_THROW(sav[4], fail_fast);
CHECK_THROWS_AS(sav[4], fail_fast);
}
{
@ -378,7 +376,7 @@ SUITE(strided_span_tests)
strided_span<int, 1> sav{arr, {2, 1}};
CHECK(sav.bounds().index_bounds() == index<1>{2});
CHECK(sav[1] == 1);
CHECK_THROW(sav[2], fail_fast);
CHECK_THROWS_AS(sav[2], fail_fast);
}
{
@ -387,35 +385,35 @@ SUITE(strided_span_tests)
CHECK(sav.bounds().index_bounds() == index<1>{2});
CHECK(sav[0] == 0);
CHECK(sav[1] == 3);
CHECK_THROW(sav[2], fail_fast);
CHECK_THROWS_AS(sav[2], fail_fast);
}
{
// bounds cross data boundaries - from static arrays
CHECK_THROW((strided_span<int, 1>{arr, {3, 2}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{arr, {3, 3}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{arr, {4, 5}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{arr, {5, 1}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{arr, {5, 5}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{arr, {3, 2}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{arr, {3, 3}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{arr, {4, 5}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{arr, {5, 1}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{arr, {5, 5}}), fail_fast);
}
{
// bounds cross data boundaries - from array view
CHECK_THROW((strided_span<int, 1>{av, {3, 2}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{av, {3, 3}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{av, {4, 5}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{av, {5, 1}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{av, {5, 5}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av, {3, 2}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av, {3, 3}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av, {4, 5}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av, {5, 1}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av, {5, 5}}), fail_fast);
}
{
// bounds cross data boundaries - from dynamic arrays
CHECK_THROW((strided_span<int, 1>{av.data(), 4, {3, 2}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{av.data(), 4, {3, 3}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{av.data(), 4, {4, 5}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{av.data(), 4, {5, 1}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{av.data(), 4, {5, 5}}), fail_fast);
CHECK_THROW((strided_span<int, 1>{av.data(), 2, {2, 2}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av.data(), 4, {3, 2}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av.data(), 4, {3, 3}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av.data(), 4, {4, 5}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av.data(), 4, {5, 1}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av.data(), 4, {5, 5}}), fail_fast);
CHECK_THROWS_AS((strided_span<int, 1>{av.data(), 2, {2, 2}}), fail_fast);
}
#ifdef CONFIRM_COMPILATION_ERRORS
@ -442,7 +440,7 @@ SUITE(strided_span_tests)
#endif
}
TEST(strided_span_type_conversion)
TEST_CASE("strided_span_type_conversion")
{
int arr[] = {0, 1, 2, 3};
multi_span<int> av(arr);
@ -469,8 +467,8 @@ SUITE(strided_span_tests)
strided_span<const int, 2> sav3 = sav2.as_strided_span<const int>();
CHECK(sav3[0][0] == 0);
CHECK(sav3[1][0] == 2);
CHECK_THROW(sav3[1][1], fail_fast);
CHECK_THROW(sav3[0][1], fail_fast);
CHECK_THROWS_AS(sav3[1][1], fail_fast);
CHECK_THROWS_AS(sav3[0][1], fail_fast);
}
// retype strided array with regular strides - from multi_span
@ -482,8 +480,8 @@ SUITE(strided_span_tests)
strided_span<int, 2> sav3 = sav2.as_strided_span<int>();
CHECK(sav3[0][0] == 0);
CHECK(sav3[1][0] == 2);
CHECK_THROW(sav3[1][1], fail_fast);
CHECK_THROW(sav3[0][1], fail_fast);
CHECK_THROWS_AS(sav3[1][1], fail_fast);
CHECK_THROWS_AS(sav3[0][1], fail_fast);
}
// retype strided array with not enough elements - last dimension of the array is too small
@ -492,7 +490,7 @@ SUITE(strided_span_tests)
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};
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
CHECK_THROWS_AS(sav2.as_strided_span<int>(), fail_fast);
}
// retype strided array with not enough elements - strides are too small
@ -501,7 +499,7 @@ SUITE(strided_span_tests)
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};
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
CHECK_THROWS_AS(sav2.as_strided_span<int>(), fail_fast);
}
// retype strided array with not enough elements - last dimension does not divide by the new
@ -511,7 +509,7 @@ SUITE(strided_span_tests)
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};
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
CHECK_THROWS_AS(sav2.as_strided_span<int>(), fail_fast);
}
// retype strided array with not enough elements - strides does not divide by the new
@ -521,34 +519,34 @@ SUITE(strided_span_tests)
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};
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
CHECK_THROWS_AS(sav2.as_strided_span<int>(), fail_fast);
}
// 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};
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
CHECK_THROWS_AS(sav2.as_strided_span<int>(), fail_fast);
}
// 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};
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
CHECK_THROWS_AS(sav2.as_strided_span<int>(), fail_fast);
}
}
TEST(empty_strided_spans)
TEST_CASE("empty_strided_spans")
{
{
multi_span<int, 0> empty_av(nullptr);
strided_span<int, 1> empty_sav{empty_av, {0, 1}};
CHECK(empty_sav.bounds().index_bounds() == index<1>{0});
CHECK_THROW(empty_sav[0], fail_fast);
CHECK_THROW(empty_sav.begin()[0], fail_fast);
CHECK_THROW(empty_sav.cbegin()[0], fail_fast);
CHECK_THROWS_AS(empty_sav[0], fail_fast);
CHECK_THROWS_AS(empty_sav.begin()[0], fail_fast);
CHECK_THROWS_AS(empty_sav.cbegin()[0], fail_fast);
for (const auto& v : empty_sav) {
(void) v;
@ -560,9 +558,9 @@ SUITE(strided_span_tests)
strided_span<int, 1> empty_sav{nullptr, 0, {0, 1}};
CHECK(empty_sav.bounds().index_bounds() == index<1>{0});
CHECK_THROW(empty_sav[0], fail_fast);
CHECK_THROW(empty_sav.begin()[0], fail_fast);
CHECK_THROW(empty_sav.cbegin()[0], fail_fast);
CHECK_THROWS_AS(empty_sav[0], fail_fast);
CHECK_THROWS_AS(empty_sav.begin()[0], fail_fast);
CHECK_THROWS_AS(empty_sav.cbegin()[0], fail_fast);
for (const auto& v : empty_sav) {
(void) v;
@ -596,7 +594,7 @@ SUITE(strided_span_tests)
}
}
TEST(strided_span_section_iteration)
TEST_CASE("strided_span_section_iteration")
{
int arr[8] = {4, 0, 5, 1, 6, 2, 7, 3};
@ -613,7 +611,7 @@ SUITE(strided_span_tests)
}
}
TEST(dynamic_strided_span_section_iteration)
TEST_CASE("dynamic_strided_span_section_iteration")
{
auto arr = new int[8];
for (int i = 0; i < 4; ++i) {
@ -653,7 +651,7 @@ SUITE(strided_span_tests)
}
}
TEST(strided_span_section_iteration_3d)
TEST_CASE("strided_span_section_iteration_3d")
{
int arr[3][4][2]{};
for (auto i = 0; i < 3; ++i) {
@ -667,7 +665,7 @@ SUITE(strided_span_tests)
}
}
TEST(dynamic_strided_span_section_iteration_3d)
TEST_CASE("dynamic_strided_span_section_iteration_3d")
{
const auto height = 12, width = 2;
const auto size = height * width;
@ -699,7 +697,7 @@ SUITE(strided_span_tests)
delete[] arr;
}
TEST(strided_span_conversion)
TEST_CASE("strided_span_conversion")
{
// get an multi_span of 'c' values from the list of X's
@ -744,7 +742,7 @@ SUITE(strided_span_tests)
strided_span<int, 1> result = transposed[0];
CHECK(result.bounds().index_bounds()[0] == 4);
CHECK_THROW(result.bounds().index_bounds()[1], fail_fast);
CHECK_THROWS_AS(result.bounds().index_bounds()[1], fail_fast);
int i = 0;
for (auto& num : result) {
@ -752,6 +750,3 @@ SUITE(strided_span_tests)
i++;
}
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/gsl> //owner
#include <gsl/string_span>
@ -26,10 +26,7 @@
using namespace std;
using namespace gsl;
SUITE(string_span_tests)
{
TEST(TestLiteralConstruction)
TEST_CASE("TestLiteralConstruction")
{
cwstring_span<> v = ensure_z(L"Hello");
CHECK(5 == v.length());
@ -39,21 +36,21 @@ SUITE(string_span_tests)
#endif
}
TEST(TestConstructFromStdString)
TEST_CASE("TestConstructFromStdString")
{
std::string s = "Hello there world";
cstring_span<> v = s;
CHECK(v.length() == static_cast<cstring_span<>::index_type>(s.length()));
}
TEST(TestConstructFromStdVector)
TEST_CASE("TestConstructFromStdVector")
{
std::vector<char> vec(5, 'h');
string_span<> v{vec};
CHECK(v.length() == static_cast<string_span<>::index_type>(vec.size()));
}
TEST(TestStackArrayConstruction)
TEST_CASE("TestStackArrayConstruction")
{
wchar_t stack_string[] = L"Hello";
@ -78,14 +75,14 @@ SUITE(string_span_tests)
}
}
TEST(TestConstructFromConstCharPointer)
TEST_CASE("TestConstructFromConstCharPointer")
{
const char* s = "Hello";
cstring_span<> v = ensure_z(s);
CHECK(v.length() == 5);
}
TEST(TestConversionToConst)
TEST_CASE("TestConversionToConst")
{
char stack_string[] = "Hello";
string_span<> v = ensure_z(stack_string);
@ -93,7 +90,7 @@ SUITE(string_span_tests)
CHECK(v.length() == v2.length());
}
TEST(TestConversionFromConst)
TEST_CASE("TestConversionFromConst")
{
char stack_string[] = "Hello";
cstring_span<> v = ensure_z(stack_string);
@ -104,7 +101,7 @@ SUITE(string_span_tests)
#endif
}
TEST(TestToString)
TEST_CASE("TestToString")
{
auto s = gsl::to_string(cstring_span<>{});
CHECK(s.length() == 0);
@ -116,7 +113,7 @@ SUITE(string_span_tests)
CHECK(s2.length() == 5);
}
TEST(TestToBasicString)
TEST_CASE("TestToBasicString")
{
auto s = gsl::to_basic_string<char, std::char_traits<char>, ::std::allocator<char>>(
cstring_span<>{});
@ -129,7 +126,7 @@ SUITE(string_span_tests)
CHECK(s2.length() == 5);
}
TEST(EqualityAndImplicitConstructors)
TEST_CASE("EqualityAndImplicitConstructors")
{
{
cstring_span<> span = "Hello";
@ -355,7 +352,7 @@ SUITE(string_span_tests)
}
}
TEST(ComparisonAndImplicitConstructors)
TEST_CASE("ComparisonAndImplicitConstructors")
{
{
cstring_span<> span = "Hello";
@ -425,7 +422,7 @@ SUITE(string_span_tests)
CHECK(span >= string_span<>(vec));
}
}
TEST(ConstrutorsEnsureZ)
TEST_CASE("ConstrutorsEnsureZ")
{
// remove z from literals
{
@ -455,7 +452,7 @@ SUITE(string_span_tests)
}
}
TEST(Constructors)
TEST_CASE("Constructors")
{
// creating cstring_span
@ -767,7 +764,7 @@ SUITE(string_span_tests)
{
}
TEST(MoveConstructors)
TEST_CASE("MoveConstructors")
{
// move string_span
{
@ -841,7 +838,7 @@ SUITE(string_span_tests)
}
}
TEST(Conversion)
TEST_CASE("Conversion")
{
#ifdef CONFIRM_COMPILATION_ERRORS
cstring_span<> span = "Hello";
@ -867,7 +864,7 @@ SUITE(string_span_tests)
return {ret};
}
TEST(zstring)
TEST_CASE("zstring")
{
// create zspan from zero terminated string
@ -888,7 +885,7 @@ SUITE(string_span_tests)
buf[0] = 'a';
auto workaround_macro = [&]() { zstring_span<> zspan({buf, 1}); };
CHECK_THROW(workaround_macro(), fail_fast);
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
// usage scenario: create zero-terminated temp file name and pass to a legacy API
@ -921,7 +918,7 @@ SUITE(string_span_tests)
return {ret};
}
TEST(wzstring)
TEST_CASE("wzstring")
{
// create zspan from zero terminated string
@ -942,7 +939,7 @@ SUITE(string_span_tests)
buf[0] = L'a';
const auto workaround_macro = [&]() { wzstring_span<> zspan({buf, 1}); };
CHECK_THROW(workaround_macro(), fail_fast);
CHECK_THROWS_AS(workaround_macro(), fail_fast);
}
// usage scenario: create zero-terminated temp file name and pass to a legacy API
@ -958,12 +955,9 @@ SUITE(string_span_tests)
}
}
TEST(Issue305)
TEST_CASE("Issue305")
{
std::map<gsl::cstring_span<>, int> foo = {{"foo", 0}, {"bar", 1}};
CHECK(foo["foo"] == 0);
CHECK(foo["bar"] == 1);
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }

18
tests/test.cpp Normal file
View File

@ -0,0 +1,18 @@
///////////////////////////////////////////////////////////////////////////////
//
// 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
#include <catch/catch.hpp>

@ -1 +0,0 @@
Subproject commit c331bb0deaaf92659a31887c029ee34cac2ab19e

View File

@ -14,7 +14,7 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <catch/catch.hpp>
#include <gsl/gsl>
@ -22,11 +22,9 @@
using namespace gsl;
SUITE(utils_tests)
{
void f(int& i) { i += 1; }
TEST(finally_lambda)
TEST_CASE("finally_lambda")
{
int i = 0;
{
@ -36,7 +34,7 @@ SUITE(utils_tests)
CHECK(i == 1);
}
TEST(finally_lambda_move)
TEST_CASE("finally_lambda_move")
{
int i = 0;
{
@ -55,7 +53,7 @@ SUITE(utils_tests)
CHECK(i == 1);
}
TEST(finally_function_with_bind)
TEST_CASE("finally_function_with_bind")
{
int i = 0;
{
@ -67,7 +65,7 @@ SUITE(utils_tests)
int j = 0;
void g() { j += 1; }
TEST(finally_function_ptr)
TEST_CASE("finally_function_ptr")
{
j = 0;
{
@ -77,7 +75,7 @@ SUITE(utils_tests)
CHECK(j == 1);
}
TEST(narrow_cast)
TEST_CASE("narrow_cast")
{
int n = 120;
char c = narrow_cast<char>(n);
@ -88,14 +86,14 @@ SUITE(utils_tests)
CHECK(uc == 44);
}
TEST(narrow)
TEST_CASE("narrow")
{
int n = 120;
const char c = narrow<char>(n);
CHECK(c == 120);
n = 300;
CHECK_THROW(narrow<char>(n), narrowing_error);
CHECK_THROWS_AS(narrow<char>(n), narrowing_error);
const auto int32_max = std::numeric_limits<int32_t>::max();
const auto int32_min = std::numeric_limits<int32_t>::min();
@ -104,12 +102,9 @@ SUITE(utils_tests)
CHECK(narrow<uint32_t>(int32_t(1)) == 1);
CHECK(narrow<uint32_t>(int32_max) == static_cast<uint32_t>(int32_max));
CHECK_THROW(narrow<uint32_t>(int32_t(-1)), narrowing_error);
CHECK_THROW(narrow<uint32_t>(int32_min), narrowing_error);
CHECK_THROWS_AS(narrow<uint32_t>(int32_t(-1)), narrowing_error);
CHECK_THROWS_AS(narrow<uint32_t>(int32_min), narrowing_error);
n = -42;
CHECK_THROW(narrow<unsigned>(n), narrowing_error);
CHECK_THROWS_AS(narrow<unsigned>(n), narrowing_error);
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }