]>
Commit | Line | Data |
---|---|---|
9cb24db9 | 1 | // $Id: $ |
2 | ||
3 | /************************************************************************** | |
4 | * This file is property of and copyright by the ALICE HLT Project * | |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
6 | * * | |
7 | * Primary Authors: Artur Szostak <artursz@iafrica.com> * | |
8 | * for The ALICE HLT Project. * | |
9 | * * | |
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 | **************************************************************************/ | |
18 | ||
19 | /// @file testAliHLTScalars.C | |
20 | /// @author Artur Szostak <artursz@iafrica.com> | |
21 | /// @date 27 Oct 2010 | |
22 | /// @brief Test program for the AliHLTScalars class. | |
23 | /// | |
24 | ||
25 | #if !defined(__CINT__) || defined(__MAKECINT__) | |
26 | #include "AliHLTScalars.h" | |
27 | #include "TObjArray.h" | |
28 | #include "TString.h" | |
29 | #include "Riostream.h" | |
30 | #endif | |
31 | ||
32 | /** | |
33 | * Tests basic functionality of the AliHLTScalars::AliScalar class. | |
34 | */ | |
35 | bool CheckScalarItemClass() | |
36 | { | |
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()) | |
41 | { | |
42 | cerr << "ERROR: AliHLTScalars::AliScalar::GetName() returns a different value than AliHLTScalars::AliScalar::Name()." << endl; | |
43 | return false; | |
44 | } | |
45 | if (TString(s1.GetTitle()) != s1.Description()) | |
46 | { | |
47 | cerr << "ERROR: AliHLTScalars::AliScalar::GetTitle() returns a different value than AliHLTScalars::AliScalar::Description()." << endl; | |
48 | return false; | |
49 | } | |
50 | if (s2 == s3) | |
51 | { | |
52 | cerr << "ERROR: equals operator for AliHLTScalars::AliScalar returns the wrong value." << endl; | |
53 | return false; | |
54 | } | |
55 | if (! s2.IsEqual(&s3)) | |
56 | { | |
57 | cerr << "ERROR: AliHLTScalars::AliScalar::IsEqual returns the wrong value." << endl; | |
58 | return false; | |
59 | } | |
60 | s2.Increment(); | |
61 | if (! (s2 == s3)) | |
62 | { | |
63 | cerr << "ERROR: equals operator for AliHLTScalars::AliScalar returns the wrong value." << endl; | |
64 | return false; | |
65 | } | |
66 | TObjArray list; | |
67 | list.Add(&s2); | |
68 | list.Add(&s1); | |
69 | list.Sort(); | |
70 | if (TString(list.At(0)->GetName()) != "s1") | |
71 | { | |
72 | cerr << "ERROR: Sorting objects of type AliHLTScalars::AliScalar is not working correctly." << endl; | |
73 | return false; | |
74 | } | |
75 | return true; | |
76 | } | |
77 | ||
78 | /** | |
79 | * Tests functionality of the AliHLTScalars class. | |
80 | */ | |
81 | bool CheckScalarsListClass() | |
82 | { | |
83 | AliHLTScalars s; | |
84 | s.Add("a", "one", 1); | |
85 | s.Add("b", "two", 2); | |
86 | if (s.NumberOfScalars() != 2) | |
87 | { | |
88 | cerr << "ERROR: The number of added scalars is wrong for class AliHLTScalars." << endl; | |
89 | return false; | |
90 | } | |
91 | if (! s.Exists("a")) | |
92 | { | |
93 | cerr << "ERROR: AliHLTScalars claims scalar 'a' does not exist event though it was added." << endl; | |
94 | return false; | |
95 | } | |
96 | if (! s.Exists("b")) | |
97 | { | |
98 | cerr << "ERROR: AliHLTScalars claims scalar 'b' does not exist event though it was added." << endl; | |
99 | return false; | |
100 | } | |
101 | s.Remove("a"); | |
102 | if (s.Exists("a")) | |
103 | { | |
104 | cerr << "ERROR: AliHLTScalars claims scalar 'a' does not exist event though it was removed." << endl; | |
105 | return false; | |
106 | } | |
107 | s.Add("a", "one", 1); | |
108 | const AliHLTScalars& p = s; | |
109 | if (p.GetScalar("a").Value() != 1) | |
110 | { | |
111 | cerr << "ERROR: Constant version of AliHLTScalars::GetScalar(\"a\") returns the wrong scalar object." << endl; | |
112 | return false; | |
113 | } | |
114 | if (TString(p.GetScalar("c").Name()) != "" || TString(p.GetScalar("c").Description()) != "" || p.GetScalar("c").Value() != 0) | |
115 | { | |
116 | cerr << "ERROR: Constant version of AliHLTScalars::GetScalar(\"c\") does not return a sentinel object." << endl; | |
117 | return false; | |
118 | } | |
119 | if (s.GetScalar("a").Value() != 1) | |
120 | { | |
121 | cerr << "ERROR: AliHLTScalars::GetScalar(\"a\") returns the wrong scalar object." << endl; | |
122 | return false; | |
123 | } | |
124 | s.GetScalar("c").Value(3); | |
125 | if (TString(s.GetScalar("c").Name()) != "c" || TString(s.GetScalar("c").Description()) != "") | |
126 | { | |
127 | cerr << "ERROR: AliHLTScalars::GetScalar(\"c\") does not create a new object." << endl; | |
128 | return false; | |
129 | } | |
130 | s.Add("c", "three", 33); | |
131 | if (s.GetScalar("c").Value() != 33 || TString(s.GetScalar("c").Description()) != "") | |
132 | { | |
a8267917 | 133 | cerr << "ERROR: AliHLTScalars::Add did not update an exisiting scalar correctly." << endl; |
9cb24db9 | 134 | return false; |
135 | } | |
136 | if (TString(p.GetScalarN(0).Name()) != "b" || TString(p.GetScalarN(1).Name()) != "a" || TString(p.GetScalarN(2).Name()) != "c") | |
137 | { | |
138 | cerr << "ERROR: Constant version of AliHLTScalars::GetScalarN(0) returns the wrong scalar object." << endl; | |
139 | return false; | |
140 | } | |
141 | if (TString(s.GetScalarN(0).Name()) != "b" || TString(s.GetScalarN(1).Name()) != "a" || TString(s.GetScalarN(2).Name()) != "c") | |
142 | { | |
143 | cerr << "ERROR: AliHLTScalars::GetScalarN(0) returns the wrong scalar object." << endl; | |
144 | return false; | |
145 | } | |
146 | if (TString(p.GetScalarN(4).Name()) != "" || TString(p.GetScalarN(4).Description()) != "" || p.GetScalarN(4).Value() != 0) | |
147 | { | |
148 | cerr << "ERROR: Constant version of AliHLTScalars::GetScalarN(4) returns the wrong scalar object." << endl; | |
149 | return false; | |
150 | } | |
151 | s.GetScalarN(4).Value(5); | |
152 | if (TString(s.GetScalarN(4).Name()) != "Scalar4" || TString(s.GetScalarN(4).Description()) != "" || s.GetScalarN(4).Value() != 5) | |
153 | { | |
154 | cerr << "ERROR: AliHLTScalars::GetScalarN(4) does not create a new scalar object correctly." << endl; | |
155 | return false; | |
156 | } | |
157 | if (TString(p.GetScalarN(3).Name()) != "Scalar3" || TString(p.GetScalarN(3).Description()) != "" || p.GetScalarN(3).Value() != 0) | |
158 | { | |
159 | cerr << "ERROR: AliHLTScalars::GetScalarN(4) did not initialise the third scalar as expected." << endl; | |
160 | return false; | |
161 | } | |
162 | ||
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()) | |
166 | { | |
167 | cerr << "ERROR: AliHLTScalars::operator[](UInt_t) did not return the same value as AliHLTScalars::operator[](const char*)." << endl; | |
168 | return false; | |
169 | } | |
170 | ||
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) | |
177 | { | |
178 | cerr << "ERROR: AliHLTScalars::GetScalarN is not creating a scalar object with a unique name as expected." << endl; | |
179 | return false; | |
180 | } | |
181 | ||
182 | // Check the copying of the object. | |
183 | AliHLTScalars* c1 = (AliHLTScalars*) s.Clone(); | |
184 | AliHLTScalars c2; | |
185 | c2 = s; | |
186 | AliHLTScalars c3; | |
187 | s.Copy(c3); | |
188 | if (! (*c1 == s) || *c1 != s) | |
189 | { | |
190 | cerr << "ERROR: The equals operator of AliHLTScalars is not working as expected." << endl; | |
191 | return false; | |
192 | } | |
193 | if (c2 != s) | |
194 | { | |
195 | cerr << "ERROR: The assignment operator of AliHLTScalars is not working as expected." << endl; | |
196 | return false; | |
197 | } | |
198 | if (c3 != s) | |
199 | { | |
200 | cerr << "ERROR: The method AliHLTScalars::Copy is not working as expected." << endl; | |
201 | return false; | |
202 | } | |
203 | delete c1; | |
204 | ||
205 | // Now check the IsEqual and Reset methods: | |
206 | if (! c2.IsEqual(&c3)) | |
207 | { | |
208 | cerr << "ERROR: The AliHLTScalars::IsEqual method is not working as expected." << endl; | |
209 | return false; | |
210 | } | |
211 | ||
212 | c3.Reset(); | |
213 | for (UInt_t i = 0; i < c3.NumberOfScalars(); ++i) | |
214 | { | |
215 | if (c3[i].Value() != 0) | |
216 | { | |
217 | cerr << "ERROR: AliHLTScalars::Reset did not reset all scalar values to zero." << endl; | |
218 | return false; | |
219 | } | |
220 | if (TString(c3[i].Name()) != c2[i].Name()) | |
221 | { | |
222 | cerr << "ERROR: AliHLTScalars::Reset modified the name by mistake." << endl; | |
223 | return false; | |
224 | } | |
225 | if (TString(c3[i].Description()) != c2[i].Description()) | |
226 | { | |
227 | cerr << "ERROR: AliHLTScalars::Reset modified the description by mistake." << endl; | |
228 | return false; | |
229 | } | |
230 | } | |
231 | if (! c2.IsEqual(&c3)) | |
232 | { | |
233 | cerr << "ERROR: The AliHLTScalars::IsEqual method is not working as expected after call to Reset." << endl; | |
234 | return false; | |
235 | } | |
236 | if (c2 == c3) | |
237 | { | |
238 | cerr << "ERROR: The equals operator for AliHLTScalars is not working as expected after call to Reset." << endl; | |
239 | return false; | |
240 | } | |
241 | ||
242 | c2.Remove("c"); | |
243 | if (c2.IsEqual(&c3)) | |
244 | { | |
245 | cerr << "ERROR: The AliHLTScalars::IsEqual method is not working as expected after call to Remove." << endl; | |
246 | return false; | |
247 | } | |
248 | if (c2 == c3) | |
249 | { | |
250 | cerr << "ERROR: The equals operator for AliHLTScalars is not working as expected after call to Remove." << endl; | |
251 | return false; | |
252 | } | |
253 | ||
254 | return true; | |
255 | } | |
256 | ||
257 | /** | |
258 | * Runs the unit test for the AliHLTScalars class. | |
259 | * \returns true if the class passed the test and false otherwise. | |
260 | */ | |
261 | bool testAliHLTScalars() | |
262 | { | |
263 | if (! CheckScalarItemClass()) return false; | |
264 | if (! CheckScalarsListClass()) return false; | |
265 | return true; | |
266 | } | |
267 | ||
268 | #ifndef __MAKECINT__ | |
269 | ||
270 | int main(int /*argc*/, const char** /*argv*/) | |
271 | { | |
272 | bool resultOk = testAliHLTScalars(); | |
273 | if (not resultOk) return 1; | |
274 | return 0; | |
275 | } | |
276 | ||
277 | #endif // __MAKECINT__ |