blob: 7dc501e12daef761006e8436defd858ead20e557 [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
onqtambe460172018-05-30 18:15:58 +030048#define pairs \
49 TypePair<int, char>, \
50 TypePair<char, int>, \
onqtamd320ac22017-04-17 11:44:32 +030051 TypePair<bool, int>
onqtam119cfb62017-04-17 10:46:55 +030052
onqtamd320ac22017-04-17 11:44:32 +030053TEST_CASE_TEMPLATE("multiple types", T, pairs) {
54 typedef typename T::A T1;
55 typedef typename T::B T2;
onqtamf7153252017-04-19 21:41:31 +030056 T1 t1 = T1();
57 T2 t2 = T2();
onqtamd320ac22017-04-17 11:44:32 +030058 // use T1 and T2 types
onqtamc79b7542017-04-19 20:47:13 +030059 CHECK(t1 == T1());
60 CHECK(t2 != T2());
onqtam119cfb62017-04-17 10:46:55 +030061}
onqtam8c311762017-04-17 23:58:56 +030062
onqtam8c311762017-04-17 23:58:56 +030063// currently the string result will be "int_pair" instead of "TypePair<int, int>" because of the way the type stringification works
64typedef TypePair<int, int> int_pair;
65TYPE_TO_STRING(int_pair);
66
onqtambe460172018-05-30 18:15:58 +030067TEST_CASE_TEMPLATE("bad stringification of type pair", T, int_pair) {
onqtam8c311762017-04-17 23:58:56 +030068 typedef typename T::A T1;
69 typedef typename T::B T2;
onqtamf7153252017-04-19 21:41:31 +030070 T1 t1 = T1();
71 T2 t2 = T2();
onqtam8c311762017-04-17 23:58:56 +030072 // use T1 and T2 types
onqtamc79b7542017-04-19 20:47:13 +030073 CHECK(t1 == T1());
74 CHECK(t2 != T2());
onqtam8c311762017-04-17 23:58:56 +030075}