onqtam | 15c5f0f | 2016-08-02 17:31:27 +0300 | [diff] [blame] | 1 | #include "doctest.h" |
onqtam | cc9e865 | 2016-08-02 14:23:38 +0300 | [diff] [blame] | 2 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame^] | 3 | #include "header.h" |
| 4 | |
onqtam | c223b69 | 2016-08-02 17:20:06 +0300 | [diff] [blame] | 5 | #include <ostream> |
onqtam | 12d5598 | 2017-04-16 22:35:27 +0300 | [diff] [blame] | 6 | #include <sstream> |
| 7 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame^] | 8 | /* |
| 9 | |
onqtam | 12d5598 | 2017-04-16 22:35:27 +0300 | [diff] [blame] | 10 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6) |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame^] | 11 | //#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" |
onqtam | 12d5598 | 2017-04-16 22:35:27 +0300 | [diff] [blame] | 12 | #endif // > gcc 4.6 |
| 13 | |
| 14 | #ifndef DOCTEST_CONFIG_DISABLE |
onqtam | d9bb03a | 2016-08-02 15:32:49 +0300 | [diff] [blame] | 15 | |
onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 16 | TEST_CASE("doctest internals") { |
onqtam | 12d5598 | 2017-04-16 22:35:27 +0300 | [diff] [blame] | 17 | using namespace doctest; |
| 18 | |
onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 19 | // 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 |
onqtam | 12d5598 | 2017-04-16 22:35:27 +0300 | [diff] [blame] | 38 | //a += doctest::detail::fileForOutput("c:\\a"); |
| 39 | //a += doctest::detail::fileForOutput("c:/a"); |
| 40 | //a += doctest::detail::fileForOutput("a"); |
onqtam | 98e12af | 2017-04-16 22:11:21 +0300 | [diff] [blame] | 41 | 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); |
onqtam | d9bb03a | 2016-08-02 15:32:49 +0300 | [diff] [blame] | 46 | } |
| 47 | |
onqtam | 658c870 | 2017-03-14 14:08:22 +0200 | [diff] [blame] | 48 | TEST_SUITE_BEGIN("ts1"); |
onqtam | d9bb03a | 2016-08-02 15:32:49 +0300 | [diff] [blame] | 49 | |
onqtam | cc9e865 | 2016-08-02 14:23:38 +0300 | [diff] [blame] | 50 | using doctest::Approx; |
| 51 | |
onqtam | c223b69 | 2016-08-02 17:20:06 +0300 | [diff] [blame] | 52 | struct myType |
onqtam | cc6a6d6 | 2016-09-19 17:30:15 +0300 | [diff] [blame] | 53 | { |
| 54 | myType() {} |
| 55 | |
| 56 | private: |
| 57 | myType(const myType&); // non-copyable |
| 58 | myType& operator=(const myType&); // non-assignable |
| 59 | }; |
onqtam | c223b69 | 2016-08-02 17:20:06 +0300 | [diff] [blame] | 60 | |
| 61 | static std::ostream& operator<<(std::ostream& stream, const myType&) { |
| 62 | stream << "myType!"; |
| 63 | return stream; |
| 64 | } |
| 65 | |
| 66 | static bool operator==(const myType&, const myType&) { return false; } |
onqtam | cc9e865 | 2016-08-02 14:23:38 +0300 | [diff] [blame] | 67 | |
onqtam | cc6a6d6 | 2016-09-19 17:30:15 +0300 | [diff] [blame] | 68 | TEST_CASE("expressions should be evaluated only once") { |
| 69 | int a = 5; |
| 70 | REQUIRE(++a == 6); |
| 71 | REQUIRE_EQ(++a, 7); |
| 72 | } |
| 73 | |
onqtam | 4321fd8 | 2016-08-02 14:59:17 +0300 | [diff] [blame] | 74 | TEST_CASE("assertions") { |
onqtam | 4e68e66 | 2016-08-03 11:37:51 +0300 | [diff] [blame] | 75 | CHECK(true); |
onqtam | 30c5e4b | 2016-08-02 16:10:22 +0300 | [diff] [blame] | 76 | CHECK(1 == 0); |
onqtam | d9bb03a | 2016-08-02 15:32:49 +0300 | [diff] [blame] | 77 | CHECK_FALSE(1); |
onqtam | f4ea19f | 2016-09-20 00:07:56 +0300 | [diff] [blame] | 78 | myType a; |
| 79 | myType b; |
| 80 | CHECK(a == b); |
onqtam | 4321fd8 | 2016-08-02 14:59:17 +0300 | [diff] [blame] | 81 | CHECK(Approx(0.1) == 0.2); |
onqtam | 30c5e4b | 2016-08-02 16:10:22 +0300 | [diff] [blame] | 82 | |
onqtam | 4321fd8 | 2016-08-02 14:59:17 +0300 | [diff] [blame] | 83 | CHECK_THROWS(throws(true)); |
onqtam | d9bb03a | 2016-08-02 15:32:49 +0300 | [diff] [blame] | 84 | CHECK_THROWS(throws(false)); |
onqtam | 4321fd8 | 2016-08-02 14:59:17 +0300 | [diff] [blame] | 85 | CHECK_NOTHROW(throws(false)); |
onqtam | d9bb03a | 2016-08-02 15:32:49 +0300 | [diff] [blame] | 86 | CHECK_NOTHROW(throws(true)); |
onqtam | 4321fd8 | 2016-08-02 14:59:17 +0300 | [diff] [blame] | 87 | CHECK_THROWS_AS(throws(true), bool); |
onqtam | c223b69 | 2016-08-02 17:20:06 +0300 | [diff] [blame] | 88 | REQUIRE_THROWS_AS(throws(false), bool); |
onqtam | 4321fd8 | 2016-08-02 14:59:17 +0300 | [diff] [blame] | 89 | } |
onqtam | cc9e865 | 2016-08-02 14:23:38 +0300 | [diff] [blame] | 90 | |
onqtam | 3ef438f | 2016-09-18 22:31:08 +0300 | [diff] [blame] | 91 | TEST_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); |
onqtam | 8d78e70 | 2016-09-18 22:38:44 +0300 | [diff] [blame] | 154 | FAST_REQUIRE_UNARY_FALSE(1); |
onqtam | 3ef438f | 2016-09-18 22:31:08 +0300 | [diff] [blame] | 155 | } |
| 156 | |
onqtam | d9bb03a | 2016-08-02 15:32:49 +0300 | [diff] [blame] | 157 | TEST_CASE("throws") { throws(true); } |
onqtam | cc9e865 | 2016-08-02 14:23:38 +0300 | [diff] [blame] | 158 | |
| 159 | TEST_SUITE_END(); |
onqtam | 12d5598 | 2017-04-16 22:35:27 +0300 | [diff] [blame] | 160 | |
| 161 | #endif // DOCTEST_CONFIG_DISABLE |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame^] | 162 | |
| 163 | */ |