blob: 5c204a59c2061b2cf5ce91033de4245d0e0e644e [file] [log] [blame]
ncihnegnc5458f22019-01-28 05:08:18 -08001#include <doctest/doctest.h>
onqtam119cfb62017-04-17 10:46:55 +03002
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
onqtam88911e32019-03-20 21:00:05 +020034TEST_CASE_TEMPLATE_INVOKE(test_id, signed char, short, int);
35TEST_CASE_TEMPLATE_INVOKE(test_id, double, double); // note that types won't be filtered for uniqueness
onqtam119cfb62017-04-17 10:46:55 +030036
onqtam88911e32019-03-20 21:00:05 +020037TEST_CASE_TEMPLATE_APPLY(test_id, std::tuple<unsigned char, char>);
zhihaoy73ff6122019-03-20 12:37:17 -050038
onqtamd320ac22017-04-17 11:44:32 +030039// =================================================================================================
40// MULTIPLE TYPES AS PARAMETERS
41// =================================================================================================
42
43template <typename first, typename second>
44struct TypePair
onqtam119cfb62017-04-17 10:46:55 +030045{
onqtamd320ac22017-04-17 11:44:32 +030046 typedef first A;
47 typedef second B;
onqtam119cfb62017-04-17 10:46:55 +030048};
49
onqtam4317c822018-05-30 19:18:55 +030050TEST_CASE_TEMPLATE("multiple types", T, TypePair<int, char>, TypePair<char, int>, TypePair<bool, int>) {
onqtamd320ac22017-04-17 11:44:32 +030051 typedef typename T::A T1;
52 typedef typename T::B T2;
onqtamf7153252017-04-19 21:41:31 +030053 T1 t1 = T1();
54 T2 t2 = T2();
onqtamd320ac22017-04-17 11:44:32 +030055 // use T1 and T2 types
onqtamc79b7542017-04-19 20:47:13 +030056 CHECK(t1 == T1());
57 CHECK(t2 != T2());
onqtam119cfb62017-04-17 10:46:55 +030058}
onqtam8c311762017-04-17 23:58:56 +030059
onqtam8c311762017-04-17 23:58:56 +030060// currently the string result will be "int_pair" instead of "TypePair<int, int>" because of the way the type stringification works
61typedef TypePair<int, int> int_pair;
62TYPE_TO_STRING(int_pair);
63
onqtambe460172018-05-30 18:15:58 +030064TEST_CASE_TEMPLATE("bad stringification of type pair", T, int_pair) {
onqtam8c311762017-04-17 23:58:56 +030065 typedef typename T::A T1;
66 typedef typename T::B T2;
onqtamf7153252017-04-19 21:41:31 +030067 T1 t1 = T1();
68 T2 t2 = T2();
onqtam8c311762017-04-17 23:58:56 +030069 // use T1 and T2 types
onqtamc79b7542017-04-19 20:47:13 +030070 CHECK(t1 == T1());
71 CHECK(t2 != T2());
onqtam8c311762017-04-17 23:58:56 +030072}