Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 90 lines (84 sloc) 4.093 kb
24cd580 @tpounds tpunit++:
authored
1 /**
2 * Copyright (c) 2011 Trevor Pounds
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22 #include "tpunit++.hpp"
23
24 /**
25 * Test tpunit++ internal logic, macros and compiler support.
26 */
27 struct TPUnitPPTest : tpunit::TestFixture
28 {
29 TPUnitPPTest() : tpunit::TestFixture
30 (
31 BEFORE_CLASS(TPUnitPPTest::before_class),
32 BEFORE(TPUnitPPTest::before),
33 TEST(TPUnitPPTest::test), TEST(TPUnitPPTest::test),
34 TEST(TPUnitPPTest::test), TEST(TPUnitPPTest::test),
35 TEST(TPUnitPPTest::test), TEST(TPUnitPPTest::test),
36 TEST(TPUnitPPTest::test), TEST(TPUnitPPTest::test),
37 TEST(TPUnitPPTest::test_invocations),
38 TEST(TPUnitPPTest::test_macros),
39 AFTER(TPUnitPPTest::after),
40 AFTER_CLASS(TPUnitPPTest::after_class)
41 )
42 {}
43
44 int __after_num, __after_class_num,
45 __before_num, __before_class_num,
46 __test_num;
47
48 void after() { __after_num++; }
49 void after_class() { __after_class_num++; }
50 void before() { __before_num++; }
51 void before_class() { __before_class_num++; }
52 void test() { __test_num++; }
53
54 void test_invocations()
55 {
56 ASSERT_EQUAL(__after_num, 8);
57 ASSERT_EQUAL(__after_class_num, 0);
58 ASSERT_EQUAL(__before_num, 9);
59 ASSERT_EQUAL(__before_class_num, 1);
60 ASSERT_EQUAL(__test_num, 8);
61 }
62
63 void test_macros()
64 {
65 PASS();
66 ASSERT_TRUE(true); EXPECT_TRUE(true);
67 ASSERT_FALSE(false); EXPECT_FALSE(false);
68 ASSERT_EQUAL(0, 0); EXPECT_EQUAL(0, 0);
69 ASSERT_NOT_EQUAL(true, false); EXPECT_NOT_EQUAL(true, false);
70 ASSERT_GREATER_THAN(1, 0); EXPECT_GREATER_THAN(1, 0);
71 ASSERT_GREATER_THAN_EQUAL(1, 0); EXPECT_GREATER_THAN_EQUAL(1, 0);
72 ASSERT_GREATER_THAN_EQUAL(1, 1); EXPECT_GREATER_THAN_EQUAL(1, 1);
73 ASSERT_LESS_THAN(0, 1); EXPECT_LESS_THAN(0, 1);
74 ASSERT_LESS_THAN_EQUAL(0, 1); EXPECT_LESS_THAN_EQUAL(0, 1);
75 ASSERT_LESS_THAN_EQUAL(1, 1); EXPECT_LESS_THAN_EQUAL(1, 1);
784f355 @tpounds tpunit++: add floating-point assertions
authored
76 ASSERT_FLOAT_EQUAL(3.14159265f, 3.141592650000001f); EXPECT_FLOAT_EQUAL(3.14159265f, 3.141592650001f);
6634bc8 @tpounds Revert to older, more portable ULP code, fixes #2
authored
77 ASSERT_FLOAT_EQUAL(0.0f, -0.0f); EXPECT_FLOAT_EQUAL(0.0f, -0.0f);
784f355 @tpounds tpunit++: add floating-point assertions
authored
78 ASSERT_FLOAT_EQUAL(1.77245385, 1.7724538500000001); EXPECT_FLOAT_EQUAL(1.77245385, 1.7724538500000001);
6634bc8 @tpounds Revert to older, more portable ULP code, fixes #2
authored
79 ASSERT_FLOAT_EQUAL(0.0, -0.0); EXPECT_FLOAT_EQUAL(0.0, -0.0);
784f355 @tpounds tpunit++: add floating-point assertions
authored
80 ASSERT_FLOAT_NEAR(3.14159265f, 3.1400001f, 0.002f); EXPECT_FLOAT_NEAR(3.14159265f, 3.1400001f, 0.002f);
81 ASSERT_FLOAT_NEAR(1.77245385, 1.77240000, 0.0005); EXPECT_FLOAT_NEAR(1.77245385, 1.77240000, 0.0005);
24cd580 @tpounds tpunit++:
authored
82 #if defined(TPUNITPP_HAS_EXCEPTIONS) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)
83 int __dummy = 0;
84 ASSERT_THROW(throw __dummy, int); EXPECT_THROW(throw __dummy, int);
85 ASSERT_NO_THROW(__dummy = 1); EXPECT_NO_THROW(__dummy = 1);
86 ASSERT_ANY_THROW(throw __dummy); EXPECT_ANY_THROW(throw __dummy);
87 #endif
88 }
89 } __TPUnitPPTest;
Something went wrong with that request. Please try again.