#include DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN #include DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END // ================================================================================================= // NORMAL TEMPLATED TEST CASES // ================================================================================================= TYPE_TO_STRING_AS("SHORT!!!", short); TEST_CASE_TEMPLATE("signed integers stuff", T, signed char, short, int) { T var = T(); --var; CHECK(var == -1); } // teach the library how to stringify this type - otherwise <> will be used TYPE_TO_STRING(std::vector); TEST_CASE_TEMPLATE("vector stuff", T, std::vector) { T vec(10); CHECK(vec.size() == 20); // will fail } // ================================================================================================= // NAMED TEMPLATED TEST CASES WITH DEFERRED INSTANTIATION // ================================================================================================= TEST_CASE_TEMPLATE_DEFINE("default construction", T, test_id) { T var = T(); CHECK(doctest::Approx(var) == T()); } TEST_CASE_TEMPLATE_INVOKE(test_id, signed char, short, int); TEST_CASE_TEMPLATE_INVOKE(test_id, double, double); // note that types won't be filtered for uniqueness TEST_CASE_TEMPLATE_APPLY(test_id, std::tuple); // ================================================================================================= // MULTIPLE TYPES AS PARAMETERS // ================================================================================================= template struct TypePair { typedef first A; typedef second B; }; TYPE_TO_STRING_AS("Custom name test", TypePair); TYPE_TO_STRING_AS("Other custom name", TypePair); TYPE_TO_STRING(TypePair); TEST_CASE_TEMPLATE("multiple types", T, TypePair, TypePair, TypePair) { typedef typename T::A T1; typedef typename T::B T2; T1 t1 = T1(); T2 t2 = T2(); // use T1 and T2 types CHECK(t1 == T1()); CHECK(t2 != T2()); } // currently the string result will be "int_pair" instead of "TypePair" because of the way the type stringification works typedef TypePair int_pair; TYPE_TO_STRING(int_pair); TEST_CASE_TEMPLATE("bad stringification of type pair", T, int_pair) { typedef typename T::A T1; typedef typename T::B T2; T1 t1 = T1(); T2 t2 = T2(); // use T1 and T2 types CHECK(t1 == T1()); CHECK(t2 != T2()); }