testBoolCast.cc
Go to the documentation of this file.
1 
11 #include <utl/SafeBoolCast.h>
12 
13 #include <utl/Test.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 
16 using namespace tst;
17 using namespace utl;
18 
19 
23 class MyTrue : public SafeBoolCast<MyTrue> {
24 public:
25  bool BoolCast() const { return true; }
26 };
27 
28 class MyFalse : public SafeBoolCast<MyFalse> {
29 public:
30  bool BoolCast() const { return false; }
31 };
32 
33 
35 
45 class MyFakeFalse : public MyTrue {
46 public:
47  bool BoolCast() const { return false; }
48 };
49 
50 
51 class MyNegated : public SafeBoolCast<MyNegated> {
52 public:
53  bool BoolCast() const { return !fB; }
54  bool fB;
55 };
56 
57 
58 class MyTrueBase : public SafeBoolCast<> {
59 public:
60  bool BoolCast() const { return true; }
61 };
62 
63 
64 class MyFalseDerived : public SafeBoolCast<> {
65 public:
66  bool BoolCast() const { return false; }
67 };
68 
69 
70 class TestBoolCast : public CppUnit::TestFixture {
71 
72  CPPUNIT_TEST_SUITE(TestBoolCast);
73  CPPUNIT_TEST(TestTrueFalse);
74  CPPUNIT_TEST(TestFakeFalse);
75  CPPUNIT_TEST(TestVirtualTrueFalse);
76  CPPUNIT_TEST(TestNegated);
77  //CPPUNIT_TEST_EXCEPTION(TestThrows, thisException);
78  CPPUNIT_TEST_SUITE_END();
79 
80 public:
81  void setUp() { }
82 
83  void tearDown() { }
84 
85  void
87  {
88  MyTrue t;
89  CPPUNIT_ASSERT(t);
90 
91  MyFalse f;
92  CPPUNIT_ASSERT(!f);
93  }
94 
95  void
97  {
98  MyFakeFalse ff;
99  CPPUNIT_ASSERT(ff); // is true, not false !
100  }
101 
102  void
104  {
105  MyTrueBase t;
106  CPPUNIT_ASSERT(t);
107 
108  MyFalseDerived f;
109  CPPUNIT_ASSERT(!f);
110  }
111 
112  void
114  {
115  MyNegated n;
116  n.fB = true;
117  CPPUNIT_ASSERT(!n);
118 
119  n.fB = false;
120  CPPUNIT_ASSERT(n);
121  }
122 
123 };
124 
125 
127 
128 
129 // Configure (x)emacs for this file ...
130 // Local Variables:
131 // mode: c++
132 // compile-command: "make -C .. -k run-testBoolCast
133 // End:
bool BoolCast() const
Definition: testBoolCast.cc:47
bool BoolCast() const
Definition: testBoolCast.cc:53
bool BoolCast() const
Definition: testBoolCast.cc:60
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
void TestNegated()
Fake false, it is actually True.
Definition: testBoolCast.cc:45
bool BoolCast() const
Definition: testBoolCast.cc:25
void TestTrueFalse()
Definition: testBoolCast.cc:86
void TestFakeFalse()
Definition: testBoolCast.cc:96
bool BoolCast() const
Definition: testBoolCast.cc:30
bool BoolCast() const
Definition: testBoolCast.cc:66
void tearDown()
Definition: testBoolCast.cc:83
void TestVirtualTrueFalse()

, generated on Tue Sep 26 2023.