sl@0
|
1 |
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// TBITFLAGS.CPP
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "T_BitFlags.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
// System includes
|
sl@0
|
21 |
#include <e32test.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
// Literal constants
|
sl@0
|
24 |
_LIT(KTestTitle, "TestBitFlags");
|
sl@0
|
25 |
|
sl@0
|
26 |
RTest TheTest(KTestTitle);
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
void TestBitFlags::TestSetAll()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
iTestFlags.SetAll();
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
void TestBitFlags::TestClearAll()
|
sl@0
|
35 |
{
|
sl@0
|
36 |
iTestFlags.ClearAll();
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
void TestBitFlags::TestSetL(TInt aColor)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
iTestFlags.Set(aColor);
|
sl@0
|
42 |
if (!(iTestFlags.IsSet(aColor)))
|
sl@0
|
43 |
User::Leave(KErrGeneral);
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
void TestBitFlags::TestClearL(TInt aColor)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
iTestFlags.Clear(aColor);
|
sl@0
|
49 |
if (iTestFlags.IsSet(aColor))
|
sl@0
|
50 |
User::Leave(KErrGeneral);
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
void TestBitFlags::TestAssign(TInt aColor, TBool aSetOrClear)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
iTestFlags.Assign(aColor, aSetOrClear);
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
void TestBitFlags::TestToggleL(TInt aColor)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
TBool isSet = iTestFlags.IsSet(aColor);
|
sl@0
|
61 |
iTestFlags.Toggle(aColor);
|
sl@0
|
62 |
if (isSet == iTestFlags.IsSet(aColor))
|
sl@0
|
63 |
User::Leave(KErrGeneral);
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
TBool TestBitFlags::TestOperator1(TInt aColor) //testing operator []
|
sl@0
|
67 |
{
|
sl@0
|
68 |
return iTestFlags.operator[](aColor);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
void TestBitFlags::TestOperator2() // test operator =
|
sl@0
|
72 |
{
|
sl@0
|
73 |
iFlagA.Set(TestBitFlags::EBlue);
|
sl@0
|
74 |
iFlagB = iFlagA;
|
sl@0
|
75 |
TheTest(iFlagB == iFlagA);
|
sl@0
|
76 |
|
sl@0
|
77 |
iFlagB.Set(TestBitFlags::ERed);
|
sl@0
|
78 |
TheTest(!(iFlagB == iFlagA));
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
void TestBitFlags::TestOperator3() //test operator ==
|
sl@0
|
82 |
{
|
sl@0
|
83 |
iFlagA.Set(TestBitFlags::EBlue);
|
sl@0
|
84 |
iFlagB.Set(TestBitFlags::EBlue);
|
sl@0
|
85 |
TheTest(iFlagA == iFlagB);
|
sl@0
|
86 |
|
sl@0
|
87 |
iFlagB.Set(TestBitFlags::ERed);
|
sl@0
|
88 |
TheTest(!(iFlagB == iFlagA));
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
TBool TestBitFlags::TestIsSet(TInt aColor)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
return iTestFlags.IsSet(aColor);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
TBool TestBitFlags::TestIsClear(TInt aColor)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
return iTestFlags.IsClear(aColor);
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
TInt TestBitFlags::TestValue()
|
sl@0
|
102 |
{
|
sl@0
|
103 |
return iTestFlags.Value();
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
/**
|
sl@0
|
107 |
@SYMTestCaseID SYSLIB-BAFL-CT-0468
|
sl@0
|
108 |
@SYMTestCaseDesc Tests the behaviour of bits
|
sl@0
|
109 |
@SYMTestPriority High
|
sl@0
|
110 |
@SYMTestActions Tests for bits by setting and clearing
|
sl@0
|
111 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
112 |
@SYMREQ REQ0000
|
sl@0
|
113 |
*/
|
sl@0
|
114 |
void DoTest1()
|
sl@0
|
115 |
{
|
sl@0
|
116 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0468 Pure Set and Clear and related functions only "));
|
sl@0
|
117 |
TestBitFlags test;
|
sl@0
|
118 |
TBool checkTestFlags;
|
sl@0
|
119 |
TInt checkValue;
|
sl@0
|
120 |
|
sl@0
|
121 |
TRAPD(errCode, test.TestSetL(TestBitFlags::EBlue));
|
sl@0
|
122 |
TheTest(errCode==KErrNone);
|
sl@0
|
123 |
|
sl@0
|
124 |
checkTestFlags = test.TestIsSet(TestBitFlags::EBlue); //expect 1
|
sl@0
|
125 |
checkValue = test.TestValue(); //expect 1 (hex)
|
sl@0
|
126 |
TheTest(checkTestFlags == 1);
|
sl@0
|
127 |
TheTest(checkValue == 1);
|
sl@0
|
128 |
|
sl@0
|
129 |
TRAP(errCode, test.TestSetL(TestBitFlags::EGreen));
|
sl@0
|
130 |
TheTest(errCode==KErrNone);
|
sl@0
|
131 |
checkTestFlags = test.TestIsSet(TestBitFlags::EGreen); //expect 4
|
sl@0
|
132 |
TheTest(checkTestFlags == 4);
|
sl@0
|
133 |
checkTestFlags = test.TestIsClear(TestBitFlags::EGreen); //expect 0 - means it hasnt been cleared
|
sl@0
|
134 |
checkValue = test.TestValue(); //expect 5 (hex)
|
sl@0
|
135 |
TheTest(checkTestFlags == 0);
|
sl@0
|
136 |
TheTest(checkValue == 5);
|
sl@0
|
137 |
|
sl@0
|
138 |
TRAP(errCode, test.TestSetL(TestBitFlags::EYellow));
|
sl@0
|
139 |
TheTest(errCode==KErrNone);
|
sl@0
|
140 |
checkTestFlags = test.TestIsSet(TestBitFlags::EYellow); //expect 8
|
sl@0
|
141 |
checkValue = test.TestValue(); //expect d (hex)
|
sl@0
|
142 |
TheTest(checkTestFlags == 8);
|
sl@0
|
143 |
TheTest(checkValue == 13);
|
sl@0
|
144 |
|
sl@0
|
145 |
test.TestClearL(TestBitFlags::EGreen);
|
sl@0
|
146 |
checkTestFlags = test.TestIsClear(TestBitFlags::EGreen); //expect 1
|
sl@0
|
147 |
checkValue = test.TestValue(); //expect 9 (hex)
|
sl@0
|
148 |
TheTest(checkTestFlags == 1);
|
sl@0
|
149 |
TheTest(checkValue == 9);
|
sl@0
|
150 |
|
sl@0
|
151 |
checkTestFlags = test.TestIsClear(TestBitFlags::ERed); //expect 1 - means it has been cleared
|
sl@0
|
152 |
checkValue = test.TestValue(); //expect 9 (hex)
|
sl@0
|
153 |
TheTest(checkTestFlags == 1);
|
sl@0
|
154 |
TheTest(checkValue == 9);
|
sl@0
|
155 |
|
sl@0
|
156 |
test.TestSetAll();
|
sl@0
|
157 |
checkTestFlags = test.TestIsSet(TestBitFlags::EBlue);
|
sl@0
|
158 |
TheTest(checkTestFlags == 1);
|
sl@0
|
159 |
checkTestFlags = test.TestIsSet(TestBitFlags::ERed);
|
sl@0
|
160 |
TheTest(checkTestFlags == 2);
|
sl@0
|
161 |
checkTestFlags = test.TestIsSet(TestBitFlags::EGreen);
|
sl@0
|
162 |
TheTest(checkTestFlags == 4);
|
sl@0
|
163 |
checkTestFlags = test.TestIsSet(TestBitFlags::EYellow);
|
sl@0
|
164 |
TheTest(checkTestFlags == 8);
|
sl@0
|
165 |
checkTestFlags = test.TestIsSet(TestBitFlags::EPurple);
|
sl@0
|
166 |
TheTest(checkTestFlags == 16);
|
sl@0
|
167 |
checkTestFlags = test.TestIsSet(TestBitFlags::EBlack);
|
sl@0
|
168 |
TheTest(checkTestFlags == 32);
|
sl@0
|
169 |
checkTestFlags = test.TestIsSet(TestBitFlags::EWhite);
|
sl@0
|
170 |
TheTest(checkTestFlags == 64);
|
sl@0
|
171 |
checkTestFlags = test.TestIsSet(TestBitFlags::EGrey);
|
sl@0
|
172 |
TheTest(checkTestFlags == 128);
|
sl@0
|
173 |
checkValue = test.TestValue(); //expect 0xffffffff (hex)
|
sl@0
|
174 |
TheTest(checkValue == -1);
|
sl@0
|
175 |
|
sl@0
|
176 |
|
sl@0
|
177 |
test.TestClearL(TestBitFlags::EBlue);
|
sl@0
|
178 |
checkTestFlags = test.TestIsClear(TestBitFlags::EBlue);
|
sl@0
|
179 |
TheTest(checkTestFlags == 1);
|
sl@0
|
180 |
test.TestClearL(TestBitFlags::ERed);
|
sl@0
|
181 |
checkTestFlags = test.TestIsClear(TestBitFlags::ERed);
|
sl@0
|
182 |
TheTest(checkTestFlags == 1);
|
sl@0
|
183 |
test.TestClearL(TestBitFlags::EGreen);
|
sl@0
|
184 |
checkTestFlags = test.TestIsClear(TestBitFlags::EGreen);
|
sl@0
|
185 |
TheTest(checkTestFlags == 1);
|
sl@0
|
186 |
test.TestClearL(TestBitFlags::EYellow);
|
sl@0
|
187 |
checkTestFlags = test.TestIsClear(TestBitFlags::EYellow);
|
sl@0
|
188 |
TheTest(checkTestFlags == 1);
|
sl@0
|
189 |
test.TestClearL(TestBitFlags::EPurple);
|
sl@0
|
190 |
checkTestFlags = test.TestIsClear(TestBitFlags::EPurple);
|
sl@0
|
191 |
TheTest(checkTestFlags == 1);
|
sl@0
|
192 |
test.TestClearL(TestBitFlags::EBlack);
|
sl@0
|
193 |
checkTestFlags = test.TestIsClear(TestBitFlags::EBlack);
|
sl@0
|
194 |
TheTest(checkTestFlags == 1);
|
sl@0
|
195 |
test.TestClearL(TestBitFlags::EWhite);
|
sl@0
|
196 |
checkTestFlags = test.TestIsClear(TestBitFlags::EWhite);
|
sl@0
|
197 |
TheTest(checkTestFlags == 1);
|
sl@0
|
198 |
test.TestClearL(TestBitFlags::EGrey);
|
sl@0
|
199 |
checkTestFlags = test.TestIsClear(TestBitFlags::EGrey);
|
sl@0
|
200 |
TheTest(checkTestFlags == 1);
|
sl@0
|
201 |
checkValue = test.TestValue(); //expect 0xffffff00
|
sl@0
|
202 |
TheTest(checkValue == -256);
|
sl@0
|
203 |
|
sl@0
|
204 |
test.TestClearAll();
|
sl@0
|
205 |
checkValue = test.TestValue();
|
sl@0
|
206 |
TheTest(checkValue ==0);
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
/**
|
sl@0
|
210 |
@SYMTestCaseID SYSLIB-BAFL-CT-0469
|
sl@0
|
211 |
@SYMTestCaseDesc Tests the behaviour of bits
|
sl@0
|
212 |
@SYMTestPriority High
|
sl@0
|
213 |
@SYMTestActions Tests for bits by reading them back (assign function)
|
sl@0
|
214 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
215 |
@SYMREQ REQ0000
|
sl@0
|
216 |
*/
|
sl@0
|
217 |
void DoTest2()
|
sl@0
|
218 |
{
|
sl@0
|
219 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0469 Assign function "));
|
sl@0
|
220 |
TestBitFlags test;
|
sl@0
|
221 |
TBool checkTestFlags;
|
sl@0
|
222 |
TInt checkValue;
|
sl@0
|
223 |
|
sl@0
|
224 |
test.TestAssign(TestBitFlags::ERed, 1);
|
sl@0
|
225 |
checkTestFlags = test.TestIsSet(TestBitFlags::ERed); //expect 2
|
sl@0
|
226 |
checkValue = test.TestValue(); //expect 2
|
sl@0
|
227 |
TheTest(checkTestFlags == 2);
|
sl@0
|
228 |
TheTest(checkValue == 2);
|
sl@0
|
229 |
|
sl@0
|
230 |
test.TestAssign(TestBitFlags::EWhite, 1);
|
sl@0
|
231 |
checkTestFlags = test.TestIsSet(TestBitFlags::EWhite); //expect 64
|
sl@0
|
232 |
checkValue = test.TestValue(); //expect 66
|
sl@0
|
233 |
TheTest(checkTestFlags == 64);
|
sl@0
|
234 |
TheTest(checkValue == 66);
|
sl@0
|
235 |
|
sl@0
|
236 |
test.TestAssign(TestBitFlags::ERed, 0);
|
sl@0
|
237 |
checkTestFlags = test.TestIsClear(TestBitFlags::ERed); //expect 1
|
sl@0
|
238 |
checkValue = test.TestValue(); //expect 64
|
sl@0
|
239 |
TheTest(checkTestFlags == 1);
|
sl@0
|
240 |
TheTest(checkValue == 64);
|
sl@0
|
241 |
|
sl@0
|
242 |
test.TestAssign(TestBitFlags::ERed, 3); //test anything other than 1 will activate Set function
|
sl@0
|
243 |
checkTestFlags = test.TestIsSet(TestBitFlags::ERed); //expect 2
|
sl@0
|
244 |
checkValue = test.TestValue(); //expect 66
|
sl@0
|
245 |
TheTest(checkTestFlags == 2);
|
sl@0
|
246 |
TheTest(checkValue == 66);
|
sl@0
|
247 |
}
|
sl@0
|
248 |
|
sl@0
|
249 |
/**
|
sl@0
|
250 |
@SYMTestCaseID SYSLIB-BAFL-CT-0470
|
sl@0
|
251 |
@SYMTestCaseDesc Tests the behaviour of bits
|
sl@0
|
252 |
@SYMTestPriority High
|
sl@0
|
253 |
@SYMTestActions Tests for [] operator
|
sl@0
|
254 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
255 |
@SYMREQ REQ0000
|
sl@0
|
256 |
*/
|
sl@0
|
257 |
void DoTest3()
|
sl@0
|
258 |
{
|
sl@0
|
259 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0470 operator [] "));
|
sl@0
|
260 |
|
sl@0
|
261 |
TestBitFlags test;
|
sl@0
|
262 |
TBool checkTestFlags;
|
sl@0
|
263 |
|
sl@0
|
264 |
TRAPD(errCode, test.TestSetL(TestBitFlags::EBlue));
|
sl@0
|
265 |
TheTest(errCode==KErrNone);
|
sl@0
|
266 |
|
sl@0
|
267 |
checkTestFlags = test.TestOperator1(TestBitFlags::ERed); //0
|
sl@0
|
268 |
TheTest(checkTestFlags == 0);
|
sl@0
|
269 |
|
sl@0
|
270 |
TRAP(errCode, test.TestSetL(TestBitFlags::EYellow));
|
sl@0
|
271 |
TheTest(errCode==KErrNone);
|
sl@0
|
272 |
|
sl@0
|
273 |
checkTestFlags = test.TestOperator1(TestBitFlags::EGreen); //0
|
sl@0
|
274 |
TheTest(checkTestFlags == 0);
|
sl@0
|
275 |
|
sl@0
|
276 |
checkTestFlags = test.TestOperator1(TestBitFlags::EBlack); //0
|
sl@0
|
277 |
TheTest(checkTestFlags == 0);
|
sl@0
|
278 |
|
sl@0
|
279 |
checkTestFlags = test.TestOperator1(TestBitFlags::EYellow); //8
|
sl@0
|
280 |
TheTest(checkTestFlags == 8);
|
sl@0
|
281 |
|
sl@0
|
282 |
checkTestFlags = test.TestOperator1(TestBitFlags::EBlue); //1
|
sl@0
|
283 |
TheTest(checkTestFlags == 1);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
/**
|
sl@0
|
287 |
@SYMTestCaseID SYSLIB-BAFL-CT-0471
|
sl@0
|
288 |
@SYMTestCaseDesc Tests the behaviour of bits
|
sl@0
|
289 |
@SYMTestPriority High
|
sl@0
|
290 |
@SYMTestActions Tests for == operator
|
sl@0
|
291 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
292 |
@SYMREQ REQ0000
|
sl@0
|
293 |
*/
|
sl@0
|
294 |
void DoTest4()
|
sl@0
|
295 |
{
|
sl@0
|
296 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0471 Operator== "));
|
sl@0
|
297 |
TestBitFlags test;
|
sl@0
|
298 |
test.TestOperator3();
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
/**
|
sl@0
|
302 |
@SYMTestCaseID SYSLIB-BAFL-CT-0472
|
sl@0
|
303 |
@SYMTestCaseDesc Tests the behaviour of bits
|
sl@0
|
304 |
@SYMTestPriority High
|
sl@0
|
305 |
@SYMTestActions Tests for toggling the value
|
sl@0
|
306 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
307 |
@SYMREQ REQ0000
|
sl@0
|
308 |
*/
|
sl@0
|
309 |
void DoTest5()
|
sl@0
|
310 |
{
|
sl@0
|
311 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0472 Toggle "));
|
sl@0
|
312 |
TestBitFlags test;
|
sl@0
|
313 |
TInt checkTestFlags;
|
sl@0
|
314 |
|
sl@0
|
315 |
test.TestToggleL(TestBitFlags::EBlue);
|
sl@0
|
316 |
checkTestFlags = test.TestValue();
|
sl@0
|
317 |
TheTest(checkTestFlags == 1);
|
sl@0
|
318 |
|
sl@0
|
319 |
test.TestToggleL(TestBitFlags::ERed);
|
sl@0
|
320 |
checkTestFlags = test.TestValue();
|
sl@0
|
321 |
TheTest(checkTestFlags == 3);
|
sl@0
|
322 |
|
sl@0
|
323 |
test.TestToggleL(TestBitFlags::EBlue);
|
sl@0
|
324 |
checkTestFlags = test.TestValue();
|
sl@0
|
325 |
TheTest(checkTestFlags == 2);
|
sl@0
|
326 |
|
sl@0
|
327 |
test.TestToggleL(TestBitFlags::EGreen);
|
sl@0
|
328 |
checkTestFlags = test.TestValue();
|
sl@0
|
329 |
TheTest(checkTestFlags == 6);
|
sl@0
|
330 |
|
sl@0
|
331 |
test.TestToggleL(TestBitFlags::ERed);
|
sl@0
|
332 |
checkTestFlags = test.TestValue();
|
sl@0
|
333 |
TheTest(checkTestFlags == 4);
|
sl@0
|
334 |
|
sl@0
|
335 |
test.TestToggleL(TestBitFlags::EGreen);
|
sl@0
|
336 |
checkTestFlags = test.TestValue();
|
sl@0
|
337 |
TheTest(checkTestFlags == 0);
|
sl@0
|
338 |
|
sl@0
|
339 |
test.TestToggleL(TestBitFlags::EYellow);
|
sl@0
|
340 |
checkTestFlags = test.TestValue();
|
sl@0
|
341 |
TheTest(checkTestFlags == 8);
|
sl@0
|
342 |
}
|
sl@0
|
343 |
|
sl@0
|
344 |
/**
|
sl@0
|
345 |
@SYMTestCaseID SYSLIB-BAFL-CT-0473
|
sl@0
|
346 |
@SYMTestCaseDesc Tests the behaviour of bits
|
sl@0
|
347 |
@SYMTestPriority High
|
sl@0
|
348 |
@SYMTestActions Tests for assignment operator
|
sl@0
|
349 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
350 |
@SYMREQ REQ0000
|
sl@0
|
351 |
*/
|
sl@0
|
352 |
void DoTest6()
|
sl@0
|
353 |
{
|
sl@0
|
354 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0473 Operator= "));
|
sl@0
|
355 |
TestBitFlags test;
|
sl@0
|
356 |
test.TestOperator2();
|
sl@0
|
357 |
}
|
sl@0
|
358 |
|
sl@0
|
359 |
// TestData
|
sl@0
|
360 |
|
sl@0
|
361 |
TTestEnum KEnumArray[] =
|
sl@0
|
362 |
{
|
sl@0
|
363 |
ETest1, ETest2, ETest3, ETest4, ETest5, ETest6, ETest7, ETest8,
|
sl@0
|
364 |
ETest9, ETest10, ETest11, ETest12, ETest13, ETest14, ETest15, ETest16,
|
sl@0
|
365 |
ETest17, ETest18, ETest19, ETest20, ETest21, ETest22, ETest23, ETest24,
|
sl@0
|
366 |
ETest25, ETest26, ETest27, ETest28, ETest29, ETest30, ETest31, ETest32
|
sl@0
|
367 |
};
|
sl@0
|
368 |
|
sl@0
|
369 |
/**
|
sl@0
|
370 |
@SYMTestCaseID SYSLIB-BAFL-CT-3387
|
sl@0
|
371 |
@SYMTestCaseDesc Tests the behaviour of template class when type is an enum.
|
sl@0
|
372 |
@SYMTestPriority High
|
sl@0
|
373 |
@SYMTestActions For each bit test each function in class for when T is an enum.
|
sl@0
|
374 |
It is important that this test includes the MSB bit because enums
|
sl@0
|
375 |
are stored as an unsigned int and the MSB is the signed bit.
|
sl@0
|
376 |
@SYMTestExpectedResults Flags must be set and reset to the expected values
|
sl@0
|
377 |
@SYMDEF DEF102233
|
sl@0
|
378 |
*/
|
sl@0
|
379 |
void DEF102233()
|
sl@0
|
380 |
{
|
sl@0
|
381 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3387 Tests for DEF102233 "));
|
sl@0
|
382 |
|
sl@0
|
383 |
TInt arrayPos;
|
sl@0
|
384 |
TInt bitPos;
|
sl@0
|
385 |
for(TInt x = 0; x <= 31; x++)
|
sl@0
|
386 |
{
|
sl@0
|
387 |
arrayPos = x;
|
sl@0
|
388 |
bitPos = x;
|
sl@0
|
389 |
|
sl@0
|
390 |
// Constructor
|
sl@0
|
391 |
TBitFlagsT<TTestEnum> myBitFlagMSB1(KEnumArray[arrayPos]);
|
sl@0
|
392 |
TheTest(myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
393 |
|
sl@0
|
394 |
// Copy Constructor
|
sl@0
|
395 |
TBitFlagsT<TTestEnum> myBitFlagMSB2(myBitFlagMSB1);
|
sl@0
|
396 |
TheTest(myBitFlagMSB2.IsSet(bitPos));
|
sl@0
|
397 |
|
sl@0
|
398 |
// SetAll
|
sl@0
|
399 |
myBitFlagMSB1.SetAll();
|
sl@0
|
400 |
TheTest(myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
401 |
|
sl@0
|
402 |
// ClearAll
|
sl@0
|
403 |
myBitFlagMSB1.ClearAll();
|
sl@0
|
404 |
TheTest(!myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
405 |
|
sl@0
|
406 |
// Set and Clear
|
sl@0
|
407 |
myBitFlagMSB1.Set(bitPos);
|
sl@0
|
408 |
TheTest(myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
409 |
myBitFlagMSB1.Clear(bitPos);
|
sl@0
|
410 |
TheTest(!myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
411 |
|
sl@0
|
412 |
// Assign
|
sl@0
|
413 |
myBitFlagMSB1.Assign(bitPos, ETrue);
|
sl@0
|
414 |
TheTest(myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
415 |
myBitFlagMSB1.Assign(bitPos, EFalse);
|
sl@0
|
416 |
TheTest(!myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
417 |
|
sl@0
|
418 |
// Toggle
|
sl@0
|
419 |
myBitFlagMSB1.Toggle(bitPos);
|
sl@0
|
420 |
TheTest(myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
421 |
myBitFlagMSB1.Toggle(bitPos);
|
sl@0
|
422 |
TheTest(!myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
423 |
|
sl@0
|
424 |
// operator[]
|
sl@0
|
425 |
TheTest(!myBitFlagMSB1[arrayPos]);
|
sl@0
|
426 |
myBitFlagMSB1.Set(bitPos);
|
sl@0
|
427 |
TheTest(myBitFlagMSB1[arrayPos]);
|
sl@0
|
428 |
|
sl@0
|
429 |
// operator=
|
sl@0
|
430 |
myBitFlagMSB2 = myBitFlagMSB1;
|
sl@0
|
431 |
TheTest(myBitFlagMSB2[arrayPos]);
|
sl@0
|
432 |
myBitFlagMSB1.Toggle(bitPos);
|
sl@0
|
433 |
myBitFlagMSB2 = myBitFlagMSB1;
|
sl@0
|
434 |
TheTest(!myBitFlagMSB2[arrayPos]);
|
sl@0
|
435 |
|
sl@0
|
436 |
// operator==
|
sl@0
|
437 |
TheTest(myBitFlagMSB1 == myBitFlagMSB2);
|
sl@0
|
438 |
myBitFlagMSB1.Toggle(bitPos);
|
sl@0
|
439 |
myBitFlagMSB2.Toggle(bitPos);
|
sl@0
|
440 |
TheTest(myBitFlagMSB1 == myBitFlagMSB2);
|
sl@0
|
441 |
myBitFlagMSB1.Toggle(bitPos);
|
sl@0
|
442 |
TheTest(!(myBitFlagMSB1 == myBitFlagMSB2));
|
sl@0
|
443 |
|
sl@0
|
444 |
// IsSet and IsClear
|
sl@0
|
445 |
TheTest(myBitFlagMSB1.IsClear(bitPos));
|
sl@0
|
446 |
myBitFlagMSB1.Toggle(bitPos);
|
sl@0
|
447 |
TheTest(myBitFlagMSB1.IsSet(bitPos));
|
sl@0
|
448 |
|
sl@0
|
449 |
// Value and SetValue
|
sl@0
|
450 |
myBitFlagMSB1.ClearAll();
|
sl@0
|
451 |
myBitFlagMSB1.SetValue(KEnumArray[arrayPos]);
|
sl@0
|
452 |
TheTest(myBitFlagMSB1.Value() == KEnumArray[arrayPos]);
|
sl@0
|
453 |
|
sl@0
|
454 |
// Value against a signed integer
|
sl@0
|
455 |
TInt signedInteger = KEnumArray[arrayPos];
|
sl@0
|
456 |
TheTest(myBitFlagMSB1.Value() == signedInteger);
|
sl@0
|
457 |
|
sl@0
|
458 |
// Value against an unsigned integer
|
sl@0
|
459 |
TUint unsignedInteger = KEnumArray[arrayPos];
|
sl@0
|
460 |
TheTest(myBitFlagMSB1.Value() == unsignedInteger);
|
sl@0
|
461 |
|
sl@0
|
462 |
// iFlags
|
sl@0
|
463 |
myBitFlagMSB1.ClearAll();
|
sl@0
|
464 |
myBitFlagMSB1.iFlags = KEnumArray[arrayPos];
|
sl@0
|
465 |
TheTest(myBitFlagMSB1.Value() == KEnumArray[arrayPos]);
|
sl@0
|
466 |
}
|
sl@0
|
467 |
// check MSB was tested
|
sl@0
|
468 |
TheTest(KEnumArray[arrayPos] == ETest32);
|
sl@0
|
469 |
TheTest(bitPos == 31);
|
sl@0
|
470 |
}
|
sl@0
|
471 |
|
sl@0
|
472 |
/**
|
sl@0
|
473 |
@SYMTestCaseID BASESRVCS-BAFL-CT-4078
|
sl@0
|
474 |
@SYMTestCaseDesc tests the IsSet API for out of bounds index values.
|
sl@0
|
475 |
@SYMTestPriority High
|
sl@0
|
476 |
@SYMTestActions query flag state statinig an index that is out of bound
|
sl@0
|
477 |
@SYMTestExpectedResults should return EFalse for out of bound values
|
sl@0
|
478 |
@SYMDEF DEF130663
|
sl@0
|
479 |
*/
|
sl@0
|
480 |
void DEF130663()
|
sl@0
|
481 |
{
|
sl@0
|
482 |
// type is considered as an enum here
|
sl@0
|
483 |
TheTest.Next(_L(" @SYMTestCaseID:BASESRVCS-BAFL-CT-4078 Tests for DEF130663 "));
|
sl@0
|
484 |
|
sl@0
|
485 |
TInt arrayPos;
|
sl@0
|
486 |
TInt bitPos;
|
sl@0
|
487 |
for(TInt x = 0; x <= 31; x++)
|
sl@0
|
488 |
{
|
sl@0
|
489 |
arrayPos = x;
|
sl@0
|
490 |
bitPos = x;
|
sl@0
|
491 |
|
sl@0
|
492 |
// Constructor
|
sl@0
|
493 |
TBitFlagsT<TTestEnum> myBitFlag(KEnumArray[arrayPos]);
|
sl@0
|
494 |
TheTest(myBitFlag.IsSet(bitPos));
|
sl@0
|
495 |
|
sl@0
|
496 |
//clear all and set one paricular bit
|
sl@0
|
497 |
myBitFlag.ClearAll();
|
sl@0
|
498 |
myBitFlag.Set(bitPos);
|
sl@0
|
499 |
|
sl@0
|
500 |
// check "out of bounds" values as well
|
sl@0
|
501 |
// expected behavior is that for all out of bound values the
|
sl@0
|
502 |
// result should be EFalse for IsSet("out of bounds") call.
|
sl@0
|
503 |
// IsSet and all the functions directly calling IsSet are being tested here
|
sl@0
|
504 |
// this test in conjuction with the other cts listed here
|
sl@0
|
505 |
// should be sufficient to validate the fix
|
sl@0
|
506 |
for(TInt i = 0; i < 64; i++)
|
sl@0
|
507 |
{
|
sl@0
|
508 |
if(i==x)
|
sl@0
|
509 |
{
|
sl@0
|
510 |
TheTest(myBitFlag.IsSet(i));
|
sl@0
|
511 |
TheTest(!myBitFlag.IsClear(i));
|
sl@0
|
512 |
TheTest(myBitFlag[i]);
|
sl@0
|
513 |
}
|
sl@0
|
514 |
else
|
sl@0
|
515 |
{
|
sl@0
|
516 |
TheTest(!myBitFlag.IsSet(i));
|
sl@0
|
517 |
TheTest(myBitFlag.IsClear(i));
|
sl@0
|
518 |
TheTest(!myBitFlag[i]);
|
sl@0
|
519 |
}
|
sl@0
|
520 |
}
|
sl@0
|
521 |
}
|
sl@0
|
522 |
// check MSB was tested
|
sl@0
|
523 |
TheTest(KEnumArray[arrayPos] == ETest32);
|
sl@0
|
524 |
TheTest(bitPos == 31);
|
sl@0
|
525 |
}
|
sl@0
|
526 |
|
sl@0
|
527 |
void RunTestsL()
|
sl@0
|
528 |
{
|
sl@0
|
529 |
DoTest1();
|
sl@0
|
530 |
DoTest2();
|
sl@0
|
531 |
DoTest3();
|
sl@0
|
532 |
DoTest4();
|
sl@0
|
533 |
DoTest5();
|
sl@0
|
534 |
DoTest6();
|
sl@0
|
535 |
DEF102233();
|
sl@0
|
536 |
DEF130663();
|
sl@0
|
537 |
}
|
sl@0
|
538 |
|
sl@0
|
539 |
TInt E32Main()
|
sl@0
|
540 |
{
|
sl@0
|
541 |
__UHEAP_MARK;
|
sl@0
|
542 |
|
sl@0
|
543 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
544 |
if (!cleanup)
|
sl@0
|
545 |
return KErrNoMemory;
|
sl@0
|
546 |
|
sl@0
|
547 |
TheTest.Start(_L("TBITFLAGS "));
|
sl@0
|
548 |
TheTest.Title();
|
sl@0
|
549 |
|
sl@0
|
550 |
TRAPD(err, RunTestsL());
|
sl@0
|
551 |
TheTest(err == KErrNone);
|
sl@0
|
552 |
|
sl@0
|
553 |
delete cleanup;
|
sl@0
|
554 |
TheTest.End();
|
sl@0
|
555 |
TheTest.Close();
|
sl@0
|
556 |
|
sl@0
|
557 |
__UHEAP_MARKEND;
|
sl@0
|
558 |
return KErrNone;
|
sl@0
|
559 |
}
|