3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /// @file testAliHLTTriggerCounters.C
20 /// @author Artur Szostak <artursz@iafrica.com>
22 /// @brief Test program for the AliHLTTriggerCounters class.
25 #if !defined(__CINT__) || defined(__MAKECINT__)
26 #include "AliHLTTriggerCounters.h"
27 #include "TObjArray.h"
29 #include "Riostream.h"
33 * Tests basic functionality of the AliHLTTriggerCounters::AliCounter class.
35 bool CheckCounterItemClass()
37 AliHLTTriggerCounters::AliCounter s1("s1", "counter one", 1, 0.1);
38 AliHLTTriggerCounters::AliCounter s2("s2", "counter two", 2, 0.2);
39 AliHLTTriggerCounters::AliCounter s3("s2", "counter two", 3, 0.2);
40 if (TString(s1.GetName()) != s1.Name())
42 cerr << "ERROR: AliHLTTriggerCounters::AliCounter::GetName() returns a different value than AliHLTTriggerCounters::AliCounter::Name()." << endl;
45 if (TString(s1.GetTitle()) != s1.Description())
47 cerr << "ERROR: AliHLTTriggerCounters::AliCounter::GetTitle() returns a different value than AliHLTTriggerCounters::AliCounter::Description()." << endl;
52 cerr << "ERROR: equals operator for AliHLTTriggerCounters::AliCounter returns the wrong value." << endl;
55 if (! s2.IsEqual(&s3))
57 cerr << "ERROR: AliHLTTriggerCounters::AliCounter::IsEqual returns the wrong value." << endl;
63 cerr << "ERROR: equals operator for AliHLTTriggerCounters::AliCounter returns the wrong value." << endl;
70 if (TString(list.At(0)->GetName()) != "s1")
72 cerr << "ERROR: Sorting objects of type AliHLTTriggerCounters::AliCounter is not working correctly." << endl;
79 * Tests functionality of the AliHLTTriggerCounters class.
81 bool CheckCountersListClass()
83 AliHLTTriggerCounters s;
85 s.Add("b", "two", 2, 5);
86 if (s.NumberOfScalars() != 2)
88 cerr << "ERROR: The number of added counters is wrong for class AliHLTTriggerCounters." << endl;
93 cerr << "ERROR: AliHLTTriggerCounters claims counter 'a' does not exist event though it was added." << endl;
98 cerr << "ERROR: AliHLTTriggerCounters claims counter 'b' does not exist event though it was added." << endl;
104 cerr << "ERROR: AliHLTTriggerCounters claims counter 'a' does not exist event though it was removed." << endl;
107 s.Add("a", "one", 1);
108 const AliHLTTriggerCounters& p = s;
109 if (p.GetCounter("a").Rate() != 1)
111 cerr << "ERROR: Constant version of AliHLTTriggerCounters::GetCounter(\"a\") returns the wrong counter object." << endl;
114 if (TString(p.GetCounter("c").Name()) != "" || TString(p.GetCounter("c").Description()) != "" || p.GetCounter("c").Rate() != 0 || p.GetCounter("c").Counter() != 0)
116 cerr << "ERROR: Constant version of AliHLTTriggerCounters::GetCounter(\"c\") does not return a sentinel object." << endl;
119 if (s.GetCounter("a").Rate() != 1)
121 cerr << "ERROR: AliHLTTriggerCounters::GetCounter(\"a\") returns the wrong counter object." << endl;
124 s.GetCounter("c").Value(3);
125 if (TString(s.GetCounter("c").Name()) != "c" || TString(s.GetCounter("c").Description()) != "")
127 cerr << "ERROR: AliHLTTriggerCounters::GetCounter(\"c\") does not create a new object." << endl;
130 s.Add("c", "three", 33, 7);
131 if (s.GetCounter("c").Rate() != 33 || s.GetCounter("c").Counter() != 7 || TString(s.GetCounter("c").Description()) != "")
133 cerr << "ERROR: AliHLTTriggerCounters::Add did not update an exisiting counter correctly." << endl;
136 if (TString(p.GetCounterN(0).Name()) != "b" || TString(p.GetCounterN(1).Name()) != "a" || TString(p.GetCounterN(2).Name()) != "c")
138 cerr << "ERROR: Constant version of AliHLTTriggerCounters::GetCounterN(0) returns the wrong counter object." << endl;
141 if (TString(s.GetCounterN(0).Name()) != "b" || TString(s.GetCounterN(1).Name()) != "a" || TString(s.GetCounterN(2).Name()) != "c")
143 cerr << "ERROR: AliHLTTriggerCounters::GetCounterN(0) returns the wrong counter object." << endl;
146 if (TString(p.GetCounterN(4).Name()) != "" || TString(p.GetCounterN(4).Description()) != "" || p.GetCounterN(4).Rate() != 0)
148 cerr << "ERROR: Constant version of AliHLTTriggerCounters::GetCounterN(4) returns the wrong counter object." << endl;
151 s.GetCounterN(4).Value(5);
152 if (TString(s.GetCounterN(4).Name()) != "Scalar4" || TString(s.GetCounterN(4).Description()) != "" || s.GetCounterN(4).Rate() != 5)
154 cerr << "ERROR: AliHLTTriggerCounters::GetCounterN(4) does not create a new counter object correctly." << endl;
157 if (TString(p.GetCounterN(3).Name()) != "Scalar3" || TString(p.GetCounterN(3).Description()) != "" || p.GetCounterN(3).Rate() != 0)
159 cerr << "ERROR: AliHLTTriggerCounters::GetCounterN(4) did not initialise the third counter as expected." << endl;
163 // The following is a special check to check for compilation ambiguity
164 // rather than runtime behaviour.
165 if (s[4].Rate() != s["Scalar4"].Rate())
167 cerr << "ERROR: AliHLTTriggerCounters::operator[](UInt_t) did not return the same value as AliHLTTriggerCounters::operator[](const char*)." << endl;
171 // Here we check to see that the AliHLTTriggerCounters::GetCounterN class correctly
172 // checks and finds an unused name.
173 s.Add("Scalar7", "six", 6, 2);
174 s.Add("Scalar7_0", "seven", 7, 3);
175 s.GetCounterN(7).Value(8);
176 if (! s.Exists("Scalar7_1") || s.GetCounterN(7).Rate() != 8 || s.GetCounter("Scalar7_1").Rate() != 8)
178 cerr << "ERROR: AliHLTTriggerCounters::GetCounterN is not creating a counter object with a unique name as expected." << endl;
182 // Check the copying of the object.
183 AliHLTTriggerCounters* c1 = (AliHLTTriggerCounters*) s.Clone();
184 AliHLTTriggerCounters c2;
186 AliHLTTriggerCounters c3;
188 if (! (*c1 == s) || *c1 != s)
190 cerr << "ERROR: The equals operator of AliHLTTriggerCounters is not working as expected." << endl;
195 cerr << "ERROR: The assignment operator of AliHLTTriggerCounters is not working as expected." << endl;
200 cerr << "ERROR: The method AliHLTTriggerCounters::Copy is not working as expected." << endl;
203 c1->UpdateTimeStamp();
206 cerr << "ERROR: Modification of the time stamp for AliHLTTriggerCounters did not work as expected or comparison operator is not working." << endl;
211 // Now check the IsEqual and Reset methods:
212 if (! c2.IsEqual(&c3))
214 cerr << "ERROR: The AliHLTTriggerCounters::IsEqual method is not working as expected." << endl;
219 for (UInt_t i = 0; i < c3.NumberOfScalars(); ++i)
221 if (c3[i].Rate() != 0 || c3[i].Counter() != 0)
223 cerr << "ERROR: AliHLTTriggerCounters::Reset did not reset all counter values to zero." << endl;
226 if (TString(c3[i].Name()) != c2[i].Name())
228 cerr << "ERROR: AliHLTTriggerCounters::Reset modified the name by mistake." << endl;
231 if (TString(c3[i].Description()) != c2[i].Description())
233 cerr << "ERROR: AliHLTTriggerCounters::Reset modified the description by mistake." << endl;
237 if (! c2.IsEqual(&c3))
239 cerr << "ERROR: The AliHLTTriggerCounters::IsEqual method is not working as expected after call to Reset." << endl;
244 cerr << "ERROR: The equals operator for AliHLTTriggerCounters is not working as expected after call to Reset." << endl;
251 cerr << "ERROR: The AliHLTTriggerCounters::IsEqual method is not working as expected after call to Remove." << endl;
256 cerr << "ERROR: The equals operator for AliHLTTriggerCounters is not working as expected after call to Remove." << endl;
264 * Runs the unit test for the AliHLTTriggerCounters class.
265 * \returns true if the class passed the test and false otherwise.
267 bool testAliHLTTriggerCounters()
269 if (! CheckCounterItemClass()) return false;
270 if (! CheckCountersListClass()) return false;
276 int main(int /*argc*/, const char** /*argv*/)
278 bool resultOk = testAliHLTTriggerCounters();
279 if (not resultOk) return 1;
283 #endif // __MAKECINT__