author | John Imhofe |
Tue, 06 Jul 2010 11:40:58 +0100 | |
branch | RCL_3 |
changeset 38 | 83c58605f049 |
parent 36 | bbf8bed59bcb |
permissions | -rw-r--r-- |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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"), |
|
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
147 |
_S("EDigitiserOrientation") |
0 | 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 |
|
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
162 |
if (r==0 && list_entry.Length()==anInput.Length()) |
0 | 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 |
{ |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
test.Printf(_L("Attribute %S not supported on this platform or requires parameter: r==%d\n"),&att_name,r); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
// For some reason the following attribtues come back "KErrNone" on |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
// emulator...so guard added |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
if (i != HALData::EDisplayMemoryHandle) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
test(r==KErrNotSupported || r==KErrArgument); |
0 | 244 |
} |
245 |
} |
|
246 |
User::Free(pE); |
|
247 |
User::Allocator().Check(); |
|
248 |
} |
|
249 |
||
250 |
void InputLine(const TDesC& aPrompt, TDes& aLine) |
|
251 |
{ |
|
252 |
test.Printf(_L("%S"),&aPrompt); |
|
253 |
aLine.SetLength(0); |
|
254 |
FOREVER |
|
255 |
{ |
|
256 |
TKeyCode k=test.Getch(); |
|
257 |
switch (k) |
|
258 |
{ |
|
259 |
case EKeyEnter: |
|
260 |
test.Printf(_L("\n")); |
|
261 |
return; |
|
262 |
case EKeyEscape: |
|
263 |
aLine.SetLength(0); |
|
264 |
test.Printf(_L("\n%S"),&aPrompt); |
|
265 |
break; |
|
266 |
case EKeyBackspace: |
|
267 |
case EKeyDelete: |
|
268 |
if (aLine.Length()>0) |
|
269 |
{ |
|
270 |
aLine.SetLength(aLine.Length()-1); |
|
271 |
test.Printf(_L("\x8")); |
|
272 |
} |
|
273 |
break; |
|
274 |
default: |
|
275 |
{ |
|
276 |
TChar ch((TUint)k); |
|
277 |
TBuf<1> b; |
|
278 |
b.Append(ch); |
|
279 |
aLine.Append(ch); |
|
280 |
test.Printf(_L("%S"),&b); |
|
281 |
break; |
|
282 |
} |
|
283 |
} |
|
284 |
} |
|
285 |
} |
|
286 |
||
287 |
void TestSet() |
|
288 |
{ |
|
289 |
TBuf<256> line; |
|
290 |
FOREVER |
|
291 |
{ |
|
292 |
TInt attrib=KErrNotFound; |
|
293 |
while (attrib<0) |
|
294 |
{ |
|
295 |
InputLine(_L("Attribute: "),line); |
|
296 |
if (line.Length()==0) |
|
297 |
return; |
|
298 |
attrib=MatchAttribute(line); |
|
299 |
if (attrib==KErrNotFound) |
|
300 |
test.Printf(_L("Unrecognised attribute\n")); |
|
301 |
else if (attrib==KErrGeneral) |
|
302 |
test.Printf(_L("Ambiguous attribute\n")); |
|
303 |
} |
|
304 |
TPtrC attrib_name(AttributeNames[attrib]); |
|
305 |
test.Printf(_L("Attribute %d (%S) selected\n"),attrib,&attrib_name); |
|
306 |
TInt value=0; |
|
307 |
TInt r=KErrGeneral; |
|
308 |
TBool set=ETrue; |
|
309 |
while(r!=KErrNone) |
|
310 |
{ |
|
311 |
InputLine(_L("Value: "),line); |
|
312 |
line.Trim(); |
|
313 |
TLex lex(line); |
|
314 |
if (line.MatchF(_L("r"))>=0) |
|
315 |
{ |
|
316 |
set=EFalse; |
|
317 |
r=KErrNone; |
|
318 |
} |
|
319 |
else if (line.MatchF(_L("0x"))>=0) |
|
320 |
{ |
|
321 |
lex.Inc(2); |
|
322 |
r=lex.Val((TUint&)value,EHex); |
|
323 |
} |
|
324 |
else |
|
325 |
{ |
|
326 |
r=lex.Val(value); |
|
327 |
} |
|
328 |
} |
|
329 |
if (set) |
|
330 |
{ |
|
331 |
r=HAL::Set((HAL::TAttribute)attrib,value); |
|
332 |
test.Printf(_L("Set returns %d\n"),r); |
|
333 |
} |
|
334 |
TInt v2; |
|
335 |
r=HAL::Get((HAL::TAttribute)attrib,v2); |
|
336 |
test.Printf(_L("Get returns %d, value %d(%08x)\n"),r,v2,v2); |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
GLDEF_C TInt E32Main() |
|
341 |
{ |
|
342 |
test.Title(); |
|
343 |
__UHEAP_MARK; |
|
344 |
__UHEAP_SETFAIL(RHeap::EDeterministic,1); |
|
345 |
TInt machine_id; |
|
346 |
TInt r=HAL::Get(HAL::EMachineUid,machine_id); |
|
347 |
__UHEAP_RESET; |
|
348 |
test(r==KErrNone); |
|
349 |
test.Printf(_L("Machine ID %08x\n"),machine_id); |
|
350 |
||
351 |
test.Start(_L("Check AttributeNames[] is up-to-date")); |
|
352 |
test_Equal(HAL::ENumHalAttributes, sizeof(AttributeNames)/sizeof(TText*)); |
|
353 |
||
354 |
test.Next(_L("Test Get")); |
|
355 |
TestGet(); |
|
356 |
||
357 |
test.Next(_L("Test GetAll")); |
|
358 |
TestGetAll(); |
|
359 |
||
360 |
test.Next(_L("Test Set")); |
|
361 |
TestSet(); |
|
362 |
||
363 |
test.End(); |
|
364 |
||
365 |
__UHEAP_MARKEND; // problem if HAL uses TLS |
|
366 |
||
367 |
return KErrNone; |
|
368 |
} |
|
369 |