First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // hal\tsrc\t_newhal.cpp
18 #define __E32TEST_EXTENSION__
23 RTest test(_L("T_NEWHAL"));
25 const TText* AttributeNames[]=
28 _S("EManufacturerHardwareRev"),
29 _S("EManufacturerSoftwareRev"),
30 _S("EManufacturerSoftwareBuild"),
34 _S("EDeviceFamilyRev"),
39 _S("ESystemStartupReason"),
40 _S("ESystemException"),
41 _S("ESystemTickPeriod"),
45 _S("EMemoryPageSize"),
47 _S("EPowerBatteryStatus"),
49 _S("EPowerBackupStatus"),
52 _S("EKeyboardDeviceKeys"),
53 _S("EKeyboardAppKeys"),
55 _S("EKeyboardClickState"),
56 _S("EKeyboardClickVolume"),
57 _S("EKeyboardClickVolumeMax"),
58 _S("EDisplayXPixels"),
59 _S("EDisplayYPixels"),
64 _S("EDisplayContrast"),
65 _S("EDisplayContrastMax"),
67 _S("EBacklightState"),
74 _S("EPenClickVolume"),
75 _S("EPenClickVolumeMax"),
81 _S("EMouseAcceleration"),
83 _S("EMouseButtonState"),
86 _S("ECaseSwitchDisplayOn"),
87 _S("ECaseSwitchDisplayOff"),
90 _S("EIntegratedPhone"),
91 _S("EDisplayBrightness"),
92 _S("EDisplayBrightnessMax"),
93 _S("EKeyboardBacklightState"),
94 _S("EAccessoryPower"),
97 _S("EMaxRAMDriveSize"),
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"),
115 _S("EClipboardDrive"),
116 _S("ECustomRestart"),
117 _S("ECustomRestartReason"),
118 _S("EDisplayNumberOfScreens"),
119 _S("ENanoTickPeriod"),
120 _S("EFastCounterFrequency"),
121 _S("EFastCounterCountsUp"),
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"),
145 _S("ECpuProfilingDefaultInterruptBase"),
150 TInt MatchAbbrev(const TDesC& anInput, const TText** aList, TInt aListLen)
152 TInt first_match=KErrNotFound;
155 for (i=0; i<aListLen; i++)
157 TPtrC list_entry(aList[i]);
158 TInt r=list_entry.FindF(anInput);
162 if (r==0 && list_entry.Length()==anInput.Length())
173 return KErrGeneral; // ambiguous
174 return first_match; // either KErrNotFound or match index
177 TInt MatchAttribute(const TDesC& anInput)
179 return MatchAbbrev(anInput, AttributeNames, sizeof(AttributeNames)/sizeof(TText*));
187 for (i=0; i<HAL::ENumHalAttributes; i++)
189 TPtrC att_name(AttributeNames[i]);
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);
196 test.Printf(_L("\nPress a key to continue...\n"));
205 User::Allocator().Check();
206 HAL::SEntry* pE=NULL;
208 TInt r=HAL::GetAll(nEntries, pE);
210 test.Printf(_L("%d attributes defined\n"),nEntries);
211 test(nEntries==HAL::ENumHalAttributes);
213 for (i=0; i<nEntries; ++i)
215 TPtrC att_name(AttributeNames[i]);
216 TInt f=pE[i].iProperties;
219 TInt r=HAL::Get((HAL::TAttribute)i,v2);
220 if (f & HAL::EEntryValid)
223 if (f & HAL::EEntryDynamic)
225 test.Printf(_L("Attribute %S dynamic "),&att_name);
228 test.Printf(_L("Values %d(%08x), %d(%08x)"),v,v,v2,v2);
230 test.Printf(_L("\n"));
234 test(v==v2); // constant attribute
239 test.Printf(_L("Attribute %S not supported on this platform or requires parameter\n"),&att_name,r);
240 test(r==KErrNotSupported || r==KErrArgument);
244 User::Allocator().Check();
247 void InputLine(const TDesC& aPrompt, TDes& aLine)
249 test.Printf(_L("%S"),&aPrompt);
253 TKeyCode k=test.Getch();
257 test.Printf(_L("\n"));
261 test.Printf(_L("\n%S"),&aPrompt);
265 if (aLine.Length()>0)
267 aLine.SetLength(aLine.Length()-1);
268 test.Printf(_L("\x8"));
277 test.Printf(_L("%S"),&b);
289 TInt attrib=KErrNotFound;
292 InputLine(_L("Attribute: "),line);
293 if (line.Length()==0)
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"));
301 TPtrC attrib_name(AttributeNames[attrib]);
302 test.Printf(_L("Attribute %d (%S) selected\n"),attrib,&attrib_name);
308 InputLine(_L("Value: "),line);
311 if (line.MatchF(_L("r"))>=0)
316 else if (line.MatchF(_L("0x"))>=0)
319 r=lex.Val((TUint&)value,EHex);
328 r=HAL::Set((HAL::TAttribute)attrib,value);
329 test.Printf(_L("Set returns %d\n"),r);
332 r=HAL::Get((HAL::TAttribute)attrib,v2);
333 test.Printf(_L("Get returns %d, value %d(%08x)\n"),r,v2,v2);
337 GLDEF_C TInt E32Main()
341 __UHEAP_SETFAIL(RHeap::EDeterministic,1);
343 TInt r=HAL::Get(HAL::EMachineUid,machine_id);
346 test.Printf(_L("Machine ID %08x\n"),machine_id);
348 test.Start(_L("Check AttributeNames[] is up-to-date"));
349 test_Equal(HAL::ENumHalAttributes, sizeof(AttributeNames)/sizeof(TText*));
351 test.Next(_L("Test Get"));
354 test.Next(_L("Test GetAll"));
357 test.Next(_L("Test Set"));
362 __UHEAP_MARKEND; // problem if HAL uses TLS