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 testAliHLTScalars.C
20 /// @author Artur Szostak <artursz@iafrica.com>
22 /// @brief Test program for the AliHLTScalars class.
25 #if !defined(__CINT__) || defined(__MAKECINT__)
26 #include "AliHLTScalars.h"
27 #include "TObjArray.h"
29 #include "Riostream.h"
33 * Tests basic functionality of the AliHLTScalars::AliScalar class.
35 bool CheckScalarItemClass()
37 AliHLTScalars::AliScalar s1("s1", "scalar one", 1);
38 AliHLTScalars::AliScalar s2("s2", "scalar two", 2);
39 AliHLTScalars::AliScalar s3("s2", "scalar two", 3);
40 if (TString(s1.GetName()) != s1.Name())
42 cerr << "ERROR: AliHLTScalars::AliScalar::GetName() returns a different value than AliHLTScalars::AliScalar::Name()." << endl;
45 if (TString(s1.GetTitle()) != s1.Description())
47 cerr << "ERROR: AliHLTScalars::AliScalar::GetTitle() returns a different value than AliHLTScalars::AliScalar::Description()." << endl;
52 cerr << "ERROR: equals operator for AliHLTScalars::AliScalar returns the wrong value." << endl;
55 if (! s2.IsEqual(&s3))
57 cerr << "ERROR: AliHLTScalars::AliScalar::IsEqual returns the wrong value." << endl;
63 cerr << "ERROR: equals operator for AliHLTScalars::AliScalar returns the wrong value." << endl;
70 if (TString(list.At(0)->GetName()) != "s1")
72 cerr << "ERROR: Sorting objects of type AliHLTScalars::AliScalar is not working correctly." << endl;
79 * Tests functionality of the AliHLTScalars class.
81 bool CheckScalarsListClass()
86 if (s.NumberOfScalars() != 2)
88 cerr << "ERROR: The number of added scalars is wrong for class AliHLTScalars." << endl;
93 cerr << "ERROR: AliHLTScalars claims scalar 'a' does not exist event though it was added." << endl;
98 cerr << "ERROR: AliHLTScalars claims scalar 'b' does not exist event though it was added." << endl;
104 cerr << "ERROR: AliHLTScalars claims scalar 'a' does not exist event though it was removed." << endl;
107 s.Add("a", "one", 1);
108 const AliHLTScalars& p = s;
109 if (p.GetScalar("a").Value() != 1)
111 cerr << "ERROR: Constant version of AliHLTScalars::GetScalar(\"a\") returns the wrong scalar object." << endl;
114 if (TString(p.GetScalar("c").Name()) != "" || TString(p.GetScalar("c").Description()) != "" || p.GetScalar("c").Value() != 0)
116 cerr << "ERROR: Constant version of AliHLTScalars::GetScalar(\"c\") does not return a sentinel object." << endl;
119 if (s.GetScalar("a").Value() != 1)
121 cerr << "ERROR: AliHLTScalars::GetScalar(\"a\") returns the wrong scalar object." << endl;
124 s.GetScalar("c").Value(3);
125 if (TString(s.GetScalar("c").Name()) != "c" || TString(s.GetScalar("c").Description()) != "")
127 cerr << "ERROR: AliHLTScalars::GetScalar(\"c\") does not create a new object." << endl;
130 s.Add("c", "three", 33);
131 if (s.GetScalar("c").Value() != 33 || TString(s.GetScalar("c").Description()) != "")
133 cerr << "ERROR: AliHLTScalars::Add did not update an exisiting scalar correctly." << endl;
136 if (TString(p.GetScalarN(0).Name()) != "b" || TString(p.GetScalarN(1).Name()) != "a" || TString(p.GetScalarN(2).Name()) != "c")
138 cerr << "ERROR: Constant version of AliHLTScalars::GetScalarN(0) returns the wrong scalar object." << endl;
141 if (TString(s.GetScalarN(0).Name()) != "b" || TString(s.GetScalarN(1).Name()) != "a" || TString(s.GetScalarN(2).Name()) != "c")
143 cerr << "ERROR: AliHLTScalars::GetScalarN(0) returns the wrong scalar object." << endl;
146 if (TString(p.GetScalarN(4).Name()) != "" || TString(p.GetScalarN(4).Description()) != "" || p.GetScalarN(4).Value() != 0)
148 cerr << "ERROR: Constant version of AliHLTScalars::GetScalarN(4) returns the wrong scalar object." << endl;
151 s.GetScalarN(4).Value(5);
152 if (TString(s.GetScalarN(4).Name()) != "Scalar4" || TString(s.GetScalarN(4).Description()) != "" || s.GetScalarN(4).Value() != 5)
154 cerr << "ERROR: AliHLTScalars::GetScalarN(4) does not create a new scalar object correctly." << endl;
157 if (TString(p.GetScalarN(3).Name()) != "Scalar3" || TString(p.GetScalarN(3).Description()) != "" || p.GetScalarN(3).Value() != 0)
159 cerr << "ERROR: AliHLTScalars::GetScalarN(4) did not initialise the third scalar as expected." << endl;
163 // The following is a special check to check for compilation ambiguity
164 // rather than runtime behaviour.
165 if (s[4].Value() != s["Scalar4"].Value())
167 cerr << "ERROR: AliHLTScalars::operator[](UInt_t) did not return the same value as AliHLTScalars::operator[](const char*)." << endl;
171 // Here we check to see that the AliHLTScalars::GetScalarN class correctly
172 // checks and finds an unused name.
173 s.Add("Scalar7", "six", 6);
174 s.Add("Scalar7_0", "seven", 7);
175 s.GetScalarN(7).Value(8);
176 if (! s.Exists("Scalar7_1") || s.GetScalarN(7).Value() != 8 || s.GetScalar("Scalar7_1").Value() != 8)
178 cerr << "ERROR: AliHLTScalars::GetScalarN is not creating a scalar object with a unique name as expected." << endl;
182 // Check the copying of the object.
183 AliHLTScalars* c1 = (AliHLTScalars*) s.Clone();
188 if (! (*c1 == s) || *c1 != s)
190 cerr << "ERROR: The equals operator of AliHLTScalars is not working as expected." << endl;
195 cerr << "ERROR: The assignment operator of AliHLTScalars is not working as expected." << endl;
200 cerr << "ERROR: The method AliHLTScalars::Copy is not working as expected." << endl;
205 // Now check the IsEqual and Reset methods:
206 if (! c2.IsEqual(&c3))
208 cerr << "ERROR: The AliHLTScalars::IsEqual method is not working as expected." << endl;
213 for (UInt_t i = 0; i < c3.NumberOfScalars(); ++i)
215 if (c3[i].Value() != 0)
217 cerr << "ERROR: AliHLTScalars::Reset did not reset all scalar values to zero." << endl;
220 if (TString(c3[i].Name()) != c2[i].Name())
222 cerr << "ERROR: AliHLTScalars::Reset modified the name by mistake." << endl;
225 if (TString(c3[i].Description()) != c2[i].Description())
227 cerr << "ERROR: AliHLTScalars::Reset modified the description by mistake." << endl;
231 if (! c2.IsEqual(&c3))
233 cerr << "ERROR: The AliHLTScalars::IsEqual method is not working as expected after call to Reset." << endl;
238 cerr << "ERROR: The equals operator for AliHLTScalars is not working as expected after call to Reset." << endl;
245 cerr << "ERROR: The AliHLTScalars::IsEqual method is not working as expected after call to Remove." << endl;
250 cerr << "ERROR: The equals operator for AliHLTScalars is not working as expected after call to Remove." << endl;
258 * Runs the unit test for the AliHLTScalars class.
259 * \returns true if the class passed the test and false otherwise.
261 bool testAliHLTScalars()
263 if (! CheckScalarItemClass()) return false;
264 if (! CheckScalarsListClass()) return false;
270 int main(int /*argc*/, const char** /*argv*/)
272 bool resultOk = testAliHLTScalars();
273 if (not resultOk) return 1;
277 #endif // __MAKECINT__