|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 // System includes |
|
17 #include <e32base.h> |
|
18 #include <e32test.h> |
|
19 #include <f32file.h> |
|
20 |
|
21 // Literal constants |
|
22 _LIT(KTestTitle, "TBitwiseOps"); |
|
23 |
|
24 // Globals |
|
25 RTest TheTest(KTestTitle); |
|
26 |
|
27 void DoSetAndClearL() |
|
28 { |
|
29 TInt iTestFlags = 0; |
|
30 TInt iFlagIsSet = 0; |
|
31 TInt iFlagIsClear = 0; |
|
32 |
|
33 //set "color" flags |
|
34 iTestFlags |= 0x00000001; //set blue color (0) |
|
35 iTestFlags |= 0x00000002; //set red color (1) |
|
36 iTestFlags |= 0x00000004; //set green color (2) |
|
37 iTestFlags |= 0x00000008; //set yellow color (3) |
|
38 iTestFlags |= 0x00000010; //set purple color (4) |
|
39 iTestFlags |= 0x00000020; //set black color (5) |
|
40 iTestFlags |= 0x00000040; //set white color (6) |
|
41 iTestFlags |= 0x00000080; //set grey color (7) |
|
42 |
|
43 |
|
44 //Is the "color" flag set? |
|
45 //If yes, iFlagIsSet = the actual data value of the color |
|
46 //If not, iFlagIsSet = 0 |
|
47 iFlagIsSet = iTestFlags & 0x00000001; //blue color (0) |
|
48 if (iFlagIsSet != 1) User::Leave(KErrGeneral); |
|
49 TheTest(iFlagIsSet == 1, __LINE__); |
|
50 |
|
51 iFlagIsSet = iTestFlags & 0x00000002; //red color (1) |
|
52 TheTest(iFlagIsSet == 2, __LINE__); |
|
53 |
|
54 iFlagIsSet = iTestFlags & 0x00000004; //green color (2) |
|
55 TheTest(iFlagIsSet == 4, __LINE__); |
|
56 |
|
57 iFlagIsSet = iTestFlags & 0x00000008; //yellow color (3) |
|
58 TheTest(iFlagIsSet == 8, __LINE__); |
|
59 |
|
60 iFlagIsSet = iTestFlags & 0x00000010; //purple color (4) |
|
61 TheTest(iFlagIsSet == 16, __LINE__); |
|
62 |
|
63 iFlagIsSet = iTestFlags & 0x00000020; //black color (5) |
|
64 TheTest(iFlagIsSet == 32, __LINE__); |
|
65 |
|
66 iFlagIsSet = iTestFlags & 0x00000040; //white color (6) |
|
67 TheTest(iFlagIsSet == 64, __LINE__); |
|
68 |
|
69 iFlagIsSet = iTestFlags & 0x00000080; //grey color (7) |
|
70 TheTest(iFlagIsSet == 128, __LINE__); |
|
71 |
|
72 |
|
73 //clear "color" flags |
|
74 iTestFlags &= ~0x00000001; //clear blue color (0) |
|
75 iTestFlags &= ~0x00000002; //clear red color (1) |
|
76 iTestFlags &= ~0x00000004; //clear green color (2) |
|
77 iTestFlags &= ~0x00000008; //clear yellow color (3) |
|
78 iTestFlags &= ~0x00000010; //clear purple color (4) |
|
79 iTestFlags &= ~0x00000020; //clear black color (5) |
|
80 iTestFlags &= ~0x00000040; //clear white color (6) |
|
81 iTestFlags &= ~0x00000080; //clear grey color (7) |
|
82 |
|
83 //Is the "color" flag clear? |
|
84 //If yes, iFlagIsClear = 1 |
|
85 //If not, iFlagIsClear = 0 |
|
86 iFlagIsClear = !(iTestFlags & 0x00000001); //blue color (0) |
|
87 TheTest(iFlagIsClear == 1, __LINE__); |
|
88 |
|
89 iFlagIsClear = !(iTestFlags & 0x00000002); //red color (1) |
|
90 TheTest(iFlagIsClear == 1, __LINE__); |
|
91 |
|
92 iFlagIsClear = !(iTestFlags & 0x00000004); //green color (2) |
|
93 TheTest(iFlagIsClear == 1, __LINE__); |
|
94 |
|
95 iFlagIsClear = !(iTestFlags & 0x00000008); //yellow color (3) |
|
96 TheTest(iFlagIsClear == 1, __LINE__); |
|
97 |
|
98 iFlagIsClear = !(iTestFlags & 0x00000010); //purple color (4) |
|
99 TheTest(iFlagIsClear == 1, __LINE__); |
|
100 |
|
101 iFlagIsClear = !(iTestFlags & 0x00000020); //black color (5) |
|
102 TheTest(iFlagIsClear == 1, __LINE__); |
|
103 |
|
104 iFlagIsClear = !(iTestFlags & 0x00000040); //white color (6) |
|
105 TheTest(iFlagIsClear == 1, __LINE__); |
|
106 |
|
107 iFlagIsClear = !(iTestFlags & 0x00000080); //grey color (7) |
|
108 TheTest(iFlagIsClear == 1, __LINE__); |
|
109 } |
|
110 |
|
111 void DoToggle() |
|
112 { |
|
113 TInt iTestFlags = 0; |
|
114 |
|
115 iTestFlags ^= 0x00000001; // switch on blue color (1) |
|
116 iTestFlags ^= 0x00000001; // switch off blue color |
|
117 iTestFlags ^= 0x00000001; // switch on blue color |
|
118 TheTest(iTestFlags == 1, __LINE__); |
|
119 |
|
120 iTestFlags ^= 0x00000002; // switch on and off red color (2) |
|
121 iTestFlags ^= 0x00000002; |
|
122 iTestFlags ^= 0x00000002; |
|
123 TheTest(iTestFlags == 3, __LINE__); |
|
124 |
|
125 iTestFlags ^= 0x00000004; // switch on and off green color (3) |
|
126 iTestFlags ^= 0x00000004; |
|
127 iTestFlags ^= 0x00000004; |
|
128 TheTest(iTestFlags == 7, __LINE__); |
|
129 |
|
130 iTestFlags ^= 0x00000008; // switch on and off yellow color (4) |
|
131 iTestFlags ^= 0x00000008; |
|
132 iTestFlags ^= 0x00000008; |
|
133 TheTest(iTestFlags == 15, __LINE__); |
|
134 |
|
135 iTestFlags ^= 0x00000010; // switch on and off purple color (5) |
|
136 iTestFlags ^= 0x00000010; |
|
137 iTestFlags ^= 0x00000010; |
|
138 TheTest(iTestFlags == 31, __LINE__); |
|
139 |
|
140 iTestFlags ^= 0x00000020; // switch on and off black color (6) |
|
141 iTestFlags ^= 0x00000020; |
|
142 iTestFlags ^= 0x00000020; |
|
143 TheTest(iTestFlags == 63, __LINE__); |
|
144 |
|
145 iTestFlags ^= 0x00000040; // switch on and off white color (7) |
|
146 iTestFlags ^= 0x00000040; |
|
147 iTestFlags ^= 0x00000040; |
|
148 TheTest(iTestFlags == 127, __LINE__); |
|
149 } |
|
150 |
|
151 void DoOperators() |
|
152 { |
|
153 TInt iTestFlags1 = 0; |
|
154 TInt iTestFlags2 = 0; |
|
155 |
|
156 //test equality sign |
|
157 iTestFlags1 |= 0x00000040; |
|
158 iTestFlags2 |= 0x00000040; |
|
159 TheTest(iTestFlags1 == iTestFlags2, __LINE__); |
|
160 |
|
161 //test assignment sign |
|
162 iTestFlags1 ^= 0x00000040; |
|
163 iTestFlags2 = iTestFlags1; |
|
164 TheTest(iTestFlags1 == iTestFlags2, __LINE__); |
|
165 } |
|
166 |
|
167 void RunTestsL() |
|
168 { |
|
169 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
170 CleanupStack::PushL(scheduler); |
|
171 CActiveScheduler::Install(scheduler); |
|
172 |
|
173 DoSetAndClearL(); |
|
174 DoToggle(); |
|
175 DoOperators(); |
|
176 |
|
177 CleanupStack::PopAndDestroy(scheduler); |
|
178 } |
|
179 |
|
180 /** |
|
181 @SYMTestCaseID PIM-TBITWISEOPS-0001 |
|
182 */ |
|
183 TInt E32Main() |
|
184 { |
|
185 __UHEAP_MARK; |
|
186 // |
|
187 TheTest.Title(); |
|
188 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
189 if (!cleanup) |
|
190 return KErrNoMemory; |
|
191 // |
|
192 TheTest.Start(_L("@SYMTestCaseID PIM-TBITWISEOPS-0001 TBITWISEOPS")); |
|
193 TheTest.Title(); |
|
194 |
|
195 TRAPD(err, RunTestsL()); |
|
196 TheTest(err == KErrNone, __LINE__); |
|
197 |
|
198 delete cleanup; |
|
199 TheTest.End(); |
|
200 TheTest.Close(); |
|
201 |
|
202 __UHEAP_MARKEND; |
|
203 return KErrNone; |
|
204 } |