blob: 2564367a8a39d6ff3a9c3cc3c0584d360b4abafb [file] [log] [blame]
onqtam119cfb62017-04-17 10:46:55 +03001#include "doctest.h"
2
onqtamabf39d22017-10-28 21:30:45 +03003DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
onqtam119cfb62017-04-17 10:46:55 +03004#include <vector>
onqtamabf39d22017-10-28 21:30:45 +03005DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
onqtam119cfb62017-04-17 10:46:55 +03006
onqtamd320ac22017-04-17 11:44:32 +03007// =================================================================================================
8// NORMAL TEMPLATED TEST CASES
9// =================================================================================================
10
onqtambe460172018-05-30 18:15:58 +030011TEST_CASE_TEMPLATE("signed integers stuff", T, signed char, short, int) {
onqtamd320ac22017-04-17 11:44:32 +030012 T var = T();
13 --var;
14 CHECK(var == -1);
onqtam119cfb62017-04-17 10:46:55 +030015}
16
onqtamd320ac22017-04-17 11:44:32 +030017// teach the library how to stringify this type - otherwise <> will be used
18TYPE_TO_STRING(std::vector<int>);
onqtam119cfb62017-04-17 10:46:55 +030019
onqtambe460172018-05-30 18:15:58 +030020TEST_CASE_TEMPLATE("vector stuff", T, std::vector<int>) {
onqtamd320ac22017-04-17 11:44:32 +030021 T vec(10);
Viktor Kirilov09f55ca2018-03-05 19:34:25 +070022 CHECK(vec.size() == 20); // will fail
onqtam119cfb62017-04-17 10:46:55 +030023}
24
onqtamd320ac22017-04-17 11:44:32 +030025// =================================================================================================
26// NAMED TEMPLATED TEST CASES WITH DEFERRED INSTANTIATION
27// =================================================================================================
onqtam119cfb62017-04-17 10:46:55 +030028
onqtamd320ac22017-04-17 11:44:32 +030029TEST_CASE_TEMPLATE_DEFINE("default construction", T, test_id) {
30 T var = T();
31 CHECK(doctest::Approx(var) == T());
onqtam119cfb62017-04-17 10:46:55 +030032}
33
onqtambe460172018-05-30 18:15:58 +030034TEST_CASE_TEMPLATE_INSTANTIATE(test_id, signed char, short, int);
35TEST_CASE_TEMPLATE_INSTANTIATE(test_id, double, double); // note that types won't be filtered for uniqueness
onqtam119cfb62017-04-17 10:46:55 +030036
onqtamd320ac22017-04-17 11:44:32 +030037// =================================================================================================
38// MULTIPLE TYPES AS PARAMETERS
39// =================================================================================================
40
41template <typename first, typename second>
42struct TypePair
onqtam119cfb62017-04-17 10:46:55 +030043{
onqtamd320ac22017-04-17 11:44:32 +030044 typedef first A;
45 typedef second B;
onqtam119cfb62017-04-17 10:46:55 +030046};
47
onqtam4317c822018-05-30 19:18:55 +030048TEST_CASE_TEMPLATE("multiple types", T, TypePair<int, char>, TypePair<char, int>, TypePair<bool, int>) {
onqtamd320ac22017-04-17 11:44:32 +030049 typedef typename T::A T1;
50 typedef typename T::B T2;
onqtamf7153252017-04-19 21:41:31 +030051 T1 t1 = T1();
52 T2 t2 = T2();
onqtamd320ac22017-04-17 11:44:32 +030053 // use T1 and T2 types
onqtamc79b7542017-04-19 20:47:13 +030054 CHECK(t1 == T1());
55 CHECK(t2 != T2());
onqtam119cfb62017-04-17 10:46:55 +030056}
onqtam8c311762017-04-17 23:58:56 +030057
onqtam8c311762017-04-17 23:58:56 +030058// currently the string result will be "int_pair" instead of "TypePair<int, int>" because of the way the type stringification works
59typedef TypePair<int, int> int_pair;
60TYPE_TO_STRING(int_pair);
61
onqtambe460172018-05-30 18:15:58 +030062TEST_CASE_TEMPLATE("bad stringification of type pair", T, int_pair) {
onqtam8c311762017-04-17 23:58:56 +030063 typedef typename T::A T1;
64 typedef typename T::B T2;
onqtamf7153252017-04-19 21:41:31 +030065 T1 t1 = T1();
66 T2 t2 = T2();
onqtam8c311762017-04-17 23:58:56 +030067 // use T1 and T2 types
onqtamc79b7542017-04-19 20:47:13 +030068 CHECK(t1 == T1());
69 CHECK(t2 != T2());
onqtam8c311762017-04-17 23:58:56 +030070}