blob: 4e91f06a11a512eefa955c9823dfb2c1db2792f9 [file] [log] [blame]
onqtam15c5f0f2016-08-02 17:31:27 +03001#include "doctest.h"
onqtamcc9e8652016-08-02 14:23:38 +03002
onqtam7cc0e962017-04-17 23:30:36 +03003#include "header.h"
4
onqtamc223b692016-08-02 17:20:06 +03005#include <ostream>
onqtam12d55982017-04-16 22:35:27 +03006#include <sstream>
7
onqtam7cc0e962017-04-17 23:30:36 +03008/*
9
onqtam12d55982017-04-16 22:35:27 +030010#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)
onqtam7cc0e962017-04-17 23:30:36 +030011//#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
onqtam12d55982017-04-16 22:35:27 +030012#endif // > gcc 4.6
13
14#ifndef DOCTEST_CONFIG_DISABLE
onqtamd9bb03a2016-08-02 15:32:49 +030015
onqtam98e12af2017-04-16 22:11:21 +030016TEST_CASE("doctest internals") {
onqtam12d55982017-04-16 22:35:27 +030017 using namespace doctest;
18
onqtam98e12af2017-04-16 22:11:21 +030019 // string stuff
20 doctest::String a(0);
21 const doctest::String const_str("omgomgomg");
22 a = const_str.c_str();
23 CHECK(a.size() == const_str.size());
24 CHECK(a.length() == const_str.length());
25 CHECK(a.compare(const_str, true) == 0);
26 CHECK(a.compare("omgomgomg", false) == 0);
27
28 // toString
29 a += toString("aaa") + toString(0.5f) + toString('c') + toString(true) +
30 toString(static_cast<long double>(0.1)) //
31 + toString(static_cast<unsigned char>(1)) //
32 + toString(static_cast<short>(1)) //
33 + toString(static_cast<long>(1)) //
34 + toString(static_cast<unsigned long>(1)) //
35 + toString(static_cast<unsigned short>(1));
36
37 // others
onqtam12d55982017-04-16 22:35:27 +030038 //a += doctest::detail::fileForOutput("c:\\a");
39 //a += doctest::detail::fileForOutput("c:/a");
40 //a += doctest::detail::fileForOutput("a");
onqtam98e12af2017-04-16 22:11:21 +030041 std::ostringstream oss;
42 oss << a;
43 oss << doctest::detail::getAssertString(static_cast<doctest::detail::assertType::Enum>(3));
44 a += oss.str().c_str();
45 CHECK(doctest::detail::rawMemoryToString(a).length() > 0u);
onqtamd9bb03a2016-08-02 15:32:49 +030046}
47
onqtam658c8702017-03-14 14:08:22 +020048TEST_SUITE_BEGIN("ts1");
onqtamd9bb03a2016-08-02 15:32:49 +030049
onqtamcc9e8652016-08-02 14:23:38 +030050using doctest::Approx;
51
onqtamc223b692016-08-02 17:20:06 +030052struct myType
onqtamcc6a6d62016-09-19 17:30:15 +030053{
54 myType() {}
55
56private:
57 myType(const myType&); // non-copyable
58 myType& operator=(const myType&); // non-assignable
59};
onqtamc223b692016-08-02 17:20:06 +030060
61static std::ostream& operator<<(std::ostream& stream, const myType&) {
62 stream << "myType!";
63 return stream;
64}
65
66static bool operator==(const myType&, const myType&) { return false; }
onqtamcc9e8652016-08-02 14:23:38 +030067
onqtamcc6a6d62016-09-19 17:30:15 +030068TEST_CASE("expressions should be evaluated only once") {
69 int a = 5;
70 REQUIRE(++a == 6);
71 REQUIRE_EQ(++a, 7);
72}
73
onqtam4321fd82016-08-02 14:59:17 +030074TEST_CASE("assertions") {
onqtam4e68e662016-08-03 11:37:51 +030075 CHECK(true);
onqtam30c5e4b2016-08-02 16:10:22 +030076 CHECK(1 == 0);
onqtamd9bb03a2016-08-02 15:32:49 +030077 CHECK_FALSE(1);
onqtamf4ea19f2016-09-20 00:07:56 +030078 myType a;
79 myType b;
80 CHECK(a == b);
onqtam4321fd82016-08-02 14:59:17 +030081 CHECK(Approx(0.1) == 0.2);
onqtam30c5e4b2016-08-02 16:10:22 +030082
onqtam4321fd82016-08-02 14:59:17 +030083 CHECK_THROWS(throws(true));
onqtamd9bb03a2016-08-02 15:32:49 +030084 CHECK_THROWS(throws(false));
onqtam4321fd82016-08-02 14:59:17 +030085 CHECK_NOTHROW(throws(false));
onqtamd9bb03a2016-08-02 15:32:49 +030086 CHECK_NOTHROW(throws(true));
onqtam4321fd82016-08-02 14:59:17 +030087 CHECK_THROWS_AS(throws(true), bool);
onqtamc223b692016-08-02 17:20:06 +030088 REQUIRE_THROWS_AS(throws(false), bool);
onqtam4321fd82016-08-02 14:59:17 +030089}
onqtamcc9e8652016-08-02 14:23:38 +030090
onqtam3ef438f2016-09-18 22:31:08 +030091TEST_CASE("assertions - all of them") {
92 WARN(true);
93 CHECK(true);
94 REQUIRE(true);
95 WARN_FALSE(false);
96 CHECK_FALSE(false);
97 REQUIRE_FALSE(false);
98 WARN_THROWS(throws(true));
99 CHECK_THROWS(throws(true));
100 REQUIRE_THROWS(throws(true));
101 WARN_THROWS_AS(throws(true), bool);
102 CHECK_THROWS_AS(throws(true), bool);
103 REQUIRE_THROWS_AS(throws(true), bool);
104 WARN_NOTHROW(throws(false));
105 CHECK_NOTHROW(throws(false));
106 REQUIRE_NOTHROW(throws(false));
107 WARN_EQ(1, 1);
108 CHECK_EQ(1, 1);
109 REQUIRE_EQ(1, 1);
110 WARN_NE(1, 0);
111 CHECK_NE(1, 0);
112 REQUIRE_NE(1, 0);
113 WARN_GT(1, 0);
114 CHECK_GT(1, 0);
115 REQUIRE_GT(1, 0);
116 WARN_LT(0, 1);
117 CHECK_LT(0, 1);
118 REQUIRE_LT(0, 1);
119 WARN_GE(1, 1);
120 CHECK_GE(1, 1);
121 REQUIRE_GE(1, 1);
122 WARN_LE(1, 1);
123 CHECK_LE(1, 1);
124 REQUIRE_LE(1, 1);
125 WARN_UNARY(1);
126 CHECK_UNARY(1);
127 REQUIRE_UNARY(1);
128 WARN_UNARY_FALSE(0);
129 CHECK_UNARY_FALSE(0);
130 REQUIRE_UNARY_FALSE(0);
131 FAST_WARN_EQ(1, 1);
132 FAST_CHECK_EQ(1, 1);
133 FAST_REQUIRE_EQ(1, 1);
134 FAST_WARN_NE(1, 0);
135 FAST_CHECK_NE(1, 0);
136 FAST_REQUIRE_NE(1, 0);
137 FAST_WARN_GT(1, 0);
138 FAST_CHECK_GT(1, 0);
139 FAST_REQUIRE_GT(1, 0);
140 FAST_WARN_LT(0, 1);
141 FAST_CHECK_LT(0, 1);
142 FAST_REQUIRE_LT(0, 1);
143 FAST_WARN_GE(1, 1);
144 FAST_CHECK_GE(1, 1);
145 FAST_REQUIRE_GE(1, 1);
146 FAST_WARN_LE(1, 1);
147 FAST_CHECK_LE(1, 1);
148 FAST_REQUIRE_LE(1, 1);
149 FAST_WARN_UNARY(1);
150 FAST_CHECK_UNARY(1);
151 FAST_REQUIRE_UNARY(1);
152 FAST_WARN_UNARY_FALSE(0);
153 FAST_CHECK_UNARY_FALSE(0);
onqtam8d78e702016-09-18 22:38:44 +0300154 FAST_REQUIRE_UNARY_FALSE(1);
onqtam3ef438f2016-09-18 22:31:08 +0300155}
156
onqtamd9bb03a2016-08-02 15:32:49 +0300157TEST_CASE("throws") { throws(true); }
onqtamcc9e8652016-08-02 14:23:38 +0300158
159TEST_SUITE_END();
onqtam12d55982017-04-16 22:35:27 +0300160
161#endif // DOCTEST_CONFIG_DISABLE
onqtam7cc0e962017-04-17 23:30:36 +0300162
163*/