|
1 // Copyright (c) 1998-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 the License "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 // hal\tsrc\t_newhal.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #define __E32TEST_EXTENSION__ |
|
19 |
|
20 #include <e32test.h> |
|
21 #include <hal.h> |
|
22 |
|
23 RTest test(_L("T_NEWHAL")); |
|
24 |
|
25 const TText* AttributeNames[]= |
|
26 { |
|
27 _S("EManufacturer"), |
|
28 _S("EManufacturerHardwareRev"), |
|
29 _S("EManufacturerSoftwareRev"), |
|
30 _S("EManufacturerSoftwareBuild"), |
|
31 _S("EModel"), |
|
32 _S("EMachineUid"), |
|
33 _S("EDeviceFamily"), |
|
34 _S("EDeviceFamilyRev"), |
|
35 _S("ECPU"), |
|
36 _S("ECPUArch"), |
|
37 _S("ECPUABI"), |
|
38 _S("ECPUSpeed"), |
|
39 _S("ESystemStartupReason"), |
|
40 _S("ESystemException"), |
|
41 _S("ESystemTickPeriod"), |
|
42 _S("EMemoryRAM"), |
|
43 _S("EMemoryRAMFree"), |
|
44 _S("EMemoryROM"), |
|
45 _S("EMemoryPageSize"), |
|
46 _S("EPowerGood"), |
|
47 _S("EPowerBatteryStatus"), |
|
48 _S("EPowerBackup"), |
|
49 _S("EPowerBackupStatus"), |
|
50 _S("EPowerExternal"), |
|
51 _S("EKeyboard"), |
|
52 _S("EKeyboardDeviceKeys"), |
|
53 _S("EKeyboardAppKeys"), |
|
54 _S("EKeyboardClick"), |
|
55 _S("EKeyboardClickState"), |
|
56 _S("EKeyboardClickVolume"), |
|
57 _S("EKeyboardClickVolumeMax"), |
|
58 _S("EDisplayXPixels"), |
|
59 _S("EDisplayYPixels"), |
|
60 _S("EDisplayXTwips"), |
|
61 _S("EDisplayYTwips"), |
|
62 _S("EDisplayColors"), |
|
63 _S("EDisplayState"), |
|
64 _S("EDisplayContrast"), |
|
65 _S("EDisplayContrastMax"), |
|
66 _S("EBacklight"), |
|
67 _S("EBacklightState"), |
|
68 _S("EPen"), |
|
69 _S("EPenX"), |
|
70 _S("EPenY"), |
|
71 _S("EPenDisplayOn"), |
|
72 _S("EPenClick"), |
|
73 _S("EPenClickState"), |
|
74 _S("EPenClickVolume"), |
|
75 _S("EPenClickVolumeMax"), |
|
76 _S("EMouse"), |
|
77 _S("EMouseX"), |
|
78 _S("EMouseY"), |
|
79 _S("EMouseState"), |
|
80 _S("EMouseSpeed"), |
|
81 _S("EMouseAcceleration"), |
|
82 _S("EMouseButtons"), |
|
83 _S("EMouseButtonState"), |
|
84 _S("ECaseState"), |
|
85 _S("ECaseSwitch"), |
|
86 _S("ECaseSwitchDisplayOn"), |
|
87 _S("ECaseSwitchDisplayOff"), |
|
88 _S("ELEDs"), |
|
89 _S("ELEDmask"), |
|
90 _S("EIntegratedPhone"), |
|
91 _S("EDisplayBrightness"), |
|
92 _S("EDisplayBrightnessMax"), |
|
93 _S("EKeyboardBacklightState"), |
|
94 _S("EAccessoryPower"), |
|
95 _S("ELanguageIndex"), |
|
96 _S("EKeyboardIndex"), |
|
97 _S("EMaxRAMDriveSize"), |
|
98 _S("EKeyboardState"), |
|
99 _S("ESystemDrive"), |
|
100 _S("EPenState"), |
|
101 _S("EDisplayIsMono"), |
|
102 _S("EDisplayIsPalettized"), |
|
103 _S("EDisplayBitsPerPixel"), |
|
104 _S("EDisplayNumModes"), |
|
105 _S("EDisplayMemoryAddress"), |
|
106 _S("EDisplayOffsetToFirstPixel"), |
|
107 _S("EDisplayOffsetBetweenLines"), |
|
108 _S("EDisplayPaletteEntry"), |
|
109 _S("EDisplayIsPixelOrderRGB"), |
|
110 _S("EDisplayIsPixelOrderLandscape"), |
|
111 _S("EDisplayMode"), |
|
112 _S("ESwitches"), |
|
113 _S("EDebugPort"), |
|
114 _S("ELocaleLoaded"), |
|
115 _S("EClipboardDrive"), |
|
116 _S("ECustomRestart"), |
|
117 _S("ECustomRestartReason"), |
|
118 _S("EDisplayNumberOfScreens"), |
|
119 _S("ENanoTickPeriod"), |
|
120 _S("EFastCounterFrequency"), |
|
121 _S("EFastCounterCountsUp"), |
|
122 _S("EPointer3D"), |
|
123 _S("EPointer3DMaxProximity"), |
|
124 _S("EPointer3DThetaSupported"), |
|
125 _S("EPointer3DPhiSupported"), |
|
126 _S("EPointer3DRotationSupported"), |
|
127 _S("EPointer3DPressureSupported"), |
|
128 _S("EHardwareFloatingPoint"), |
|
129 _S("ETimeNonSecureOffset"), |
|
130 _S("EPersistStartupModeKernel"), |
|
131 _S("EMaximumCustomRestartReasons"), |
|
132 _S("EMaximumRestartStartupModes"), |
|
133 _S("ECustomResourceDrive"), |
|
134 _S("EPointer3DProximityStep"), |
|
135 _S("EPointerMaxPointers"), |
|
136 _S("EPointerNumberOfPointers"), |
|
137 _S("EPointer3DMaxPressure"), |
|
138 _S("EPointer3DPressureStep"), |
|
139 _S("EPointer3DEnterHighPressureThreshold"), |
|
140 _S("EPointer3DExitHighPressureThreshold"), |
|
141 _S("EPointer3DEnterCloseProximityThreshold"), |
|
142 _S("EPointer3DExitCloseProximityThreshold"), |
|
143 _S("EDisplayMemoryHandle"), |
|
144 _S("ESerialNumber"), |
|
145 _S("ECpuProfilingDefaultInterruptBase"), |
|
146 _S("ENumCpus"), |
|
147 |
|
148 }; |
|
149 |
|
150 TInt MatchAbbrev(const TDesC& anInput, const TText** aList, TInt aListLen) |
|
151 { |
|
152 TInt first_match=KErrNotFound; |
|
153 TInt nmatches=0; |
|
154 TInt i; |
|
155 for (i=0; i<aListLen; i++) |
|
156 { |
|
157 TPtrC list_entry(aList[i]); |
|
158 TInt r=list_entry.FindF(anInput); |
|
159 if (r>=0) |
|
160 { |
|
161 // substring matches |
|
162 if (r==0 && list_entry.Length()==anInput.Length()) |
|
163 { |
|
164 // exact match |
|
165 return i; |
|
166 } |
|
167 if (first_match<0) |
|
168 first_match=i; |
|
169 ++nmatches; |
|
170 } |
|
171 } |
|
172 if (nmatches>1) |
|
173 return KErrGeneral; // ambiguous |
|
174 return first_match; // either KErrNotFound or match index |
|
175 } |
|
176 |
|
177 TInt MatchAttribute(const TDesC& anInput) |
|
178 { |
|
179 return MatchAbbrev(anInput, AttributeNames, sizeof(AttributeNames)/sizeof(TText*)); |
|
180 } |
|
181 |
|
182 void TestGet() |
|
183 { |
|
184 TInt i; |
|
185 TInt n=0; |
|
186 |
|
187 for (i=0; i<HAL::ENumHalAttributes; i++) |
|
188 { |
|
189 TPtrC att_name(AttributeNames[i]); |
|
190 TInt val=-1; |
|
191 TInt r=HAL::Get((HAL::TAttribute)i,val); |
|
192 test.Printf(_L("%S: return %d, value %d(0x%08x)\n"),&att_name,r,val,val); |
|
193 if (++n==16) |
|
194 { |
|
195 n=0; |
|
196 test.Printf(_L("\nPress a key to continue...\n")); |
|
197 test.Getch(); |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 |
|
203 void TestGetAll() |
|
204 { |
|
205 User::Allocator().Check(); |
|
206 HAL::SEntry* pE=NULL; |
|
207 TInt nEntries=0; |
|
208 TInt r=HAL::GetAll(nEntries, pE); |
|
209 test(r==KErrNone); |
|
210 test.Printf(_L("%d attributes defined\n"),nEntries); |
|
211 test(nEntries==HAL::ENumHalAttributes); |
|
212 TInt i; |
|
213 for (i=0; i<nEntries; ++i) |
|
214 { |
|
215 TPtrC att_name(AttributeNames[i]); |
|
216 TInt f=pE[i].iProperties; |
|
217 TInt v=pE[i].iValue; |
|
218 TInt v2=-1; |
|
219 TInt r=HAL::Get((HAL::TAttribute)i,v2); |
|
220 if (f & HAL::EEntryValid) |
|
221 { |
|
222 test(r==KErrNone); |
|
223 if (f & HAL::EEntryDynamic) |
|
224 { |
|
225 test.Printf(_L("Attribute %S dynamic "),&att_name); |
|
226 if (v2!=v) |
|
227 { |
|
228 test.Printf(_L("Values %d(%08x), %d(%08x)"),v,v,v2,v2); |
|
229 } |
|
230 test.Printf(_L("\n")); |
|
231 } |
|
232 else |
|
233 { |
|
234 test(v==v2); // constant attribute |
|
235 } |
|
236 } |
|
237 else |
|
238 { |
|
239 test.Printf(_L("Attribute %S not supported on this platform or requires parameter\n"),&att_name,r); |
|
240 test(r==KErrNotSupported || r==KErrArgument); |
|
241 } |
|
242 } |
|
243 User::Free(pE); |
|
244 User::Allocator().Check(); |
|
245 } |
|
246 |
|
247 void InputLine(const TDesC& aPrompt, TDes& aLine) |
|
248 { |
|
249 test.Printf(_L("%S"),&aPrompt); |
|
250 aLine.SetLength(0); |
|
251 FOREVER |
|
252 { |
|
253 TKeyCode k=test.Getch(); |
|
254 switch (k) |
|
255 { |
|
256 case EKeyEnter: |
|
257 test.Printf(_L("\n")); |
|
258 return; |
|
259 case EKeyEscape: |
|
260 aLine.SetLength(0); |
|
261 test.Printf(_L("\n%S"),&aPrompt); |
|
262 break; |
|
263 case EKeyBackspace: |
|
264 case EKeyDelete: |
|
265 if (aLine.Length()>0) |
|
266 { |
|
267 aLine.SetLength(aLine.Length()-1); |
|
268 test.Printf(_L("\x8")); |
|
269 } |
|
270 break; |
|
271 default: |
|
272 { |
|
273 TChar ch((TUint)k); |
|
274 TBuf<1> b; |
|
275 b.Append(ch); |
|
276 aLine.Append(ch); |
|
277 test.Printf(_L("%S"),&b); |
|
278 break; |
|
279 } |
|
280 } |
|
281 } |
|
282 } |
|
283 |
|
284 void TestSet() |
|
285 { |
|
286 TBuf<256> line; |
|
287 FOREVER |
|
288 { |
|
289 TInt attrib=KErrNotFound; |
|
290 while (attrib<0) |
|
291 { |
|
292 InputLine(_L("Attribute: "),line); |
|
293 if (line.Length()==0) |
|
294 return; |
|
295 attrib=MatchAttribute(line); |
|
296 if (attrib==KErrNotFound) |
|
297 test.Printf(_L("Unrecognised attribute\n")); |
|
298 else if (attrib==KErrGeneral) |
|
299 test.Printf(_L("Ambiguous attribute\n")); |
|
300 } |
|
301 TPtrC attrib_name(AttributeNames[attrib]); |
|
302 test.Printf(_L("Attribute %d (%S) selected\n"),attrib,&attrib_name); |
|
303 TInt value=0; |
|
304 TInt r=KErrGeneral; |
|
305 TBool set=ETrue; |
|
306 while(r!=KErrNone) |
|
307 { |
|
308 InputLine(_L("Value: "),line); |
|
309 line.Trim(); |
|
310 TLex lex(line); |
|
311 if (line.MatchF(_L("r"))>=0) |
|
312 { |
|
313 set=EFalse; |
|
314 r=KErrNone; |
|
315 } |
|
316 else if (line.MatchF(_L("0x"))>=0) |
|
317 { |
|
318 lex.Inc(2); |
|
319 r=lex.Val((TUint&)value,EHex); |
|
320 } |
|
321 else |
|
322 { |
|
323 r=lex.Val(value); |
|
324 } |
|
325 } |
|
326 if (set) |
|
327 { |
|
328 r=HAL::Set((HAL::TAttribute)attrib,value); |
|
329 test.Printf(_L("Set returns %d\n"),r); |
|
330 } |
|
331 TInt v2; |
|
332 r=HAL::Get((HAL::TAttribute)attrib,v2); |
|
333 test.Printf(_L("Get returns %d, value %d(%08x)\n"),r,v2,v2); |
|
334 } |
|
335 } |
|
336 |
|
337 GLDEF_C TInt E32Main() |
|
338 { |
|
339 test.Title(); |
|
340 __UHEAP_MARK; |
|
341 __UHEAP_SETFAIL(RHeap::EDeterministic,1); |
|
342 TInt machine_id; |
|
343 TInt r=HAL::Get(HAL::EMachineUid,machine_id); |
|
344 __UHEAP_RESET; |
|
345 test(r==KErrNone); |
|
346 test.Printf(_L("Machine ID %08x\n"),machine_id); |
|
347 |
|
348 test.Start(_L("Check AttributeNames[] is up-to-date")); |
|
349 test_Equal(HAL::ENumHalAttributes, sizeof(AttributeNames)/sizeof(TText*)); |
|
350 |
|
351 test.Next(_L("Test Get")); |
|
352 TestGet(); |
|
353 |
|
354 test.Next(_L("Test GetAll")); |
|
355 TestGetAll(); |
|
356 |
|
357 test.Next(_L("Test Set")); |
|
358 TestSet(); |
|
359 |
|
360 test.End(); |
|
361 |
|
362 __UHEAP_MARKEND; // problem if HAL uses TLS |
|
363 |
|
364 return KErrNone; |
|
365 } |
|
366 |