testCountedObject.cc
Go to the documentation of this file.
1 #include <utl/CountedObject.h>
2 #include <utl/CountedObjectRegistry.h>
3 #include <tst/Verify.h>
4 
5 #include <cppunit/extensions/HelperMacros.h>
6 
7 #include <iostream>
8 
9 using namespace utl;
10 using namespace tst;
11 
12 
13 #define ASSERT_EQUAL(x, y) CPPUNIT_ASSERT(Verify<Equal>(x, y))
14 
15 #define ASSERT_OBJECT_COUNTS(o, c, d, e) \
16  ASSERT_EQUAL(utl::CountedObject<o>::GetObjectsCreated(), (long int)(c)); \
17  ASSERT_EQUAL(utl::CountedObject<o>::GetObjectsDestroyed(), (long int)(d)); \
18  ASSERT_EQUAL(utl::CountedObject<o>::GetObjectsExisting(), (long int)(e))
19 
20 #define ASSERT_EXTENDED_OBJECT_COUNTS(o, c, d, e, cp, a) \
21  ASSERT_OBJECT_COUNTS(o, c, d, e); \
22  ASSERT_EQUAL(utl::CountedObject<o>::GetObjectsCopied(), (long int)(cp)); \
23  ASSERT_EQUAL(utl::CountedObject<o>::GetObjectsAssigned(), (long int)(a))
24 
25 #define PRINT(o) \
26  std::cout << 'c' << utl::CountedObject<o>::GetObjectsCreated() << " " \
27  "d" << utl::CountedObject<o>::GetObjectsDestroyed() << " " \
28  "e" << utl::CountedObject<o>::GetObjectsExisting() << " " \
29  "y" << utl::CountedObject<o>::GetObjectsCopied() << " " \
30  "=" << utl::CountedObject<o>::GetObjectsAssigned() << std::endl
31 
32 
33 class testCountedObject : public CppUnit::TestFixture {
34 
43  CPPUNIT_TEST_SUITE(testCountedObject);
44  CPPUNIT_TEST(testSimpleCount);
45  CPPUNIT_TEST(testCountTwoTypes);
46  CPPUNIT_TEST(testCopyAssign);
47  CPPUNIT_TEST(testPrintStatistics);
48  CPPUNIT_TEST_SUITE_END();
49 
50 public:
51  template<int i>
52  class Object : private CountedObject<Object<i> > {
53  };
54 
55  void setUp() { }
56 
57  void tearDown() { }
58 
59  void
61  {
64  {
65  Object<1> o;
68  }
71  }
72 
73  void
75  {
78  Object<2>* po2 = nullptr;
79  {
80  Object<1> o1;
83  Object<2> o2;
86  po2 = new Object<2>();
87  CPPUNIT_ASSERT(po2);
90  }
93  delete po2;
94  }
95 
96  void
98  {
100  {
101  Object<3> o1;
103  }
105  Object<3> o2 = Object<3>();
107  Object<3> o3 = o2;
109  Object<3> o4;
111  o2 = o4;
113  o2 = o3;
115  }
116 
117  void
119  {
120  std::cerr << std::endl;
122  std::cerr << std::endl;
123  }
124 
125 };
126 
127 
#define ASSERT_OBJECT_COUNTS(o, c, d, e)
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
#define ASSERT_EXTENDED_OBJECT_COUNTS(o, c, d, e, cp, a)
static void PrintStatistics(std::ostream &theStream, const std::string &filter="")
Mix-in class for counting creation and destruction of objects.
Definition: CountedObject.h:30

, generated on Tue Sep 26 2023.