testDeprecator.cc
Go to the documentation of this file.
1 
11 #include <utl/Deprecator.h>
12 #include <string>
13 
14 #include <tst/Verify.h>
15 #include <cppunit/extensions/HelperMacros.h>
16 
17 using namespace utl;
18 using namespace std;
19 using namespace tst;
20 
21 
26 class testDeprecator : public CppUnit::TestFixture {
27 
28  CPPUNIT_TEST_SUITE(testDeprecator);
29  CPPUNIT_TEST(testDeprecatorEmpty);
30  CPPUNIT_TEST(testFillCount);
31  CPPUNIT_TEST(testUsageReport);
32  CPPUNIT_TEST(testUsageReportLong);
33  CPPUNIT_TEST(testCentralDeprecator);
34  //CPPUNIT_TEST_EXCEPTION(testUseFinalized, Deprecator::WrongStageException);
35  CPPUNIT_TEST_SUITE_END();
36 
38 
39 public:
40 
41  void
43  {
44  fDeprecator = new Deprecator;
45  }
46 
47  void
49  {
50  delete fDeprecator;
51  }
52 
53  void
55  {
56  CPPUNIT_ASSERT(fDeprecator->IsEmpty());
57  CPPUNIT_ASSERT(Verify<Equal>(fDeprecator->GetSize(), size_t(0)));
58  }
59 
60  void
62  {
63  CPPUNIT_ASSERT(fDeprecator->IsEmpty());
64  fDeprecator->Deprecated("DontUse", "v0r1", "Use UseMe now");
65  CPPUNIT_ASSERT(!fDeprecator->IsEmpty());
66  CPPUNIT_ASSERT(Verify<Equal>(fDeprecator->GetSize(), size_t(1)));
67 
68  fDeprecator->Deprecated("DontUse", "v0r1", "Use UseMe now");
69  CPPUNIT_ASSERT(!fDeprecator->IsEmpty());
70  CPPUNIT_ASSERT(Verify<Equal>(fDeprecator->GetSize(), size_t(1)));
71 
72  fDeprecator->Deprecated("DontUseEither", "v0r2", "Use UseThis now");
73  CPPUNIT_ASSERT(!fDeprecator->IsEmpty());
74  CPPUNIT_ASSERT(Verify<Equal>(fDeprecator->GetSize(), size_t(2)));
75  }
76 
77  void
79  {
80  fDeprecator->Deprecated("DontUse", "v0r1", "Use UseMe now");
81  CPPUNIT_ASSERT(Verify<Equal>(fDeprecator->GetReport(),
82  string("Interface|Count|Since|Hint \n"
83  "---------+-----+-----+-------------\n"
84  "DontUse | 1|v0r1 |Use UseMe now")));
85  }
86 
87  void
89  {
90  fDeprecator->Deprecated("DontUse", "v0r1", "Use UseMe now");
91  fDeprecator->Deprecated("DontUseEither", "v0r2", "Use UseThis now");
92  fDeprecator->Deprecated("DontUse", "v0r1", "Use UseMe now");
93  CPPUNIT_ASSERT(Verify<Equal>(fDeprecator->GetReport(),
94  string("Interface |Count|Since|Hint \n"
95  "-------------+-----+-----+---------------\n"
96  "DontUse | 2|v0r1 |Use UseMe now \n"
97  "DontUseEither| 1|v0r2 |Use UseThis now")));
98  }
99 
100  void
102  {
103  Deprecator& d(Deprecator::GetInstance());
104  // this should be the first time it is used
105  CPPUNIT_ASSERT(d.IsEmpty());
106  d.Deprecated("DontUse", "v0r1", "Use UseMe now");
107  CPPUNIT_ASSERT(!d.IsEmpty());
108  CPPUNIT_ASSERT(Verify<Equal>(d.GetSize(), size_t(1)));
109 
110  d.Deprecated("DontUse", "v0r1", "Use UseMe now");
111  CPPUNIT_ASSERT(!d.IsEmpty());
112  CPPUNIT_ASSERT(Verify<Equal>(d.GetSize(), size_t(1)));
113 
114  d.Deprecated("DontUseEither", "v0r2", "Use UseThis now");
115  CPPUNIT_ASSERT(!d.IsEmpty());
116  CPPUNIT_ASSERT(Verify<Equal>(d.GetSize(), size_t(2)));
117 
118  CPPUNIT_ASSERT(Verify<Equal>(d.GetReport(),
119  string("Interface |Count|Since|Hint \n"
120  "-------------+-----+-----+---------------\n"
121  "DontUse | 2|v0r1 |Use UseMe now \n"
122  "DontUseEither| 1|v0r2 |Use UseThis now")));
123  }
124 
125 };
126 
127 
std::string GetReport() const
Get the final report on interface usage problems.
Definition: Deprecator.cc:37
void testCentralDeprecator()
void testDeprecatorEmpty()
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Deprecator * fDeprecator
void testUsageReport()
Class to collect and provide information about deprecated class interfaces.
Definition: Deprecator.h:54
void Deprecated(const std::string &theInterface, const std::string &theVersion, const std::string &theNewUsageHint)
Log the usage of a deprecated interface and emit a warning.
Definition: Deprecator.cc:21
bool IsEmpty() const
Check if empty, i.e., no deprecated usage registered.
Definition: Deprecator.h:75
void testUsageReportLong()
std::size_t GetSize() const
Size, i.e., number of different deprecated interfaces uses.
Definition: Deprecator.h:78

, generated on Tue Sep 26 2023.