testTypeLabeledContainer.cc
Go to the documentation of this file.
1 
11 #include <iostream>
12 
13 #include <utl/TypeLabeledContainer.h>
14 
15 #include <tst/Verify.h>
16 #include <cppunit/extensions/HelperMacros.h>
17 
18 using namespace utl;
19 using namespace tst;
20 using namespace std;
21 
22 
23 #define ASSERT_EQUAL(x, y) CPPUNIT_ASSERT(Verify<Equal>(x, y))
24 
25 
26 struct Base {
27  Base() { fLabel = 0; }
28  virtual ~Base() { }
29  int fLabel;
30 };
31 
32 struct Foo : public Base {
33  Foo() { fLabel = 10; }
34 };
35 
36 struct Bar : public Base {
37  Bar() { fLabel = 20; }
38 };
39 
40 struct Baz : public Bar {
41  Baz() { fLabel = 320; }
42 };
43 
44 
45 class TestTypeLabeledContainer : public CppUnit::TestFixture {
46 
47  CPPUNIT_TEST_SUITE(TestTypeLabeledContainer);
48  CPPUNIT_TEST(TestInsert);
49  CPPUNIT_TEST_SUITE_END();
50 
51 public:
52  void setUp() { cerr << "\nTestTypeLabeledContainer: Start\n"; }
53 
54  void tearDown() { cerr << "TestTypeLabeledContainer: Stop" << endl; }
55 
56  template<class Cast, class T>
57  void
58  TestIterator(T& c, const int label, const int count)
59  {
60  int i = 0;
61  for (typename T::template Iterator<Cast> it = c.template Begin<Cast>();
62  it != c.template End<Cast>(); ++it) {
63  ASSERT_EQUAL(it->fLabel, label);
64  ++i;
65  }
66  ASSERT_EQUAL(count, i);
67  }
68 
69  template<class Cast, class T>
70  void
71  TestConstIterator(T& c, const int label, const int count)
72  {
73  int i = 0;
74  for (typename T::template ConstIterator<Cast> it = c.template Begin<Cast>();
75  it != c.template End<Cast>(); ++it) {
76  ASSERT_EQUAL(it->fLabel, label);
77  ++i;
78  }
79  ASSERT_EQUAL(count, i);
80  }
81 
82  void
84  {
85  Base* const b = new Base;
86  Foo* const fb= new Foo;
87  Bar* const bb[] = { new Bar, new Bar };
88  Baz* const bbb[] = { new Baz, new Baz, new Baz };
89  typedef TypeLabeledContainer<Base> MyContainer;
90  MyContainer c;
91  c.Insert(b);
92  c.Insert(fb);
93  c.Insert(bb[0]);
94  c.Insert(bb[1]);
95  c.Insert(bbb[0]);
96  c.Insert(bbb[1]);
97  c.Insert(bbb[2]);
98  const MyContainer& d = c;
99 
100  TestIterator<Base>(c, 0, 1);
101  TestConstIterator<Base>(d, 0, 1);
102 
103  TestIterator<Foo>(c, 10, 1);
104  TestConstIterator<Foo>(d, 10, 1);
105 
106  TestIterator<Bar>(c, 20, 2);
107  TestConstIterator<Bar>(d, 20, 2);
108 
109  TestIterator<Baz>(c, 320, 3);
110  TestConstIterator<Baz>(d, 320, 3);
111  }
112 
113 };
114 
115 
117 
118 
119 // Configure (x)emacs for this file ...
120 // Local Variables:
121 // mode: c++
122 // End:
void TestConstIterator(T &c, const int label, const int count)
container of classes with common base, labeled by concrete type
void TestIterator(T &c, const int label, const int count)
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
#define ASSERT_EQUAL(x, y)

, generated on Tue Sep 26 2023.