kerneltest/e32test/digitiser/t_ldddigitisertest.cpp
changeset 0 a41df078684a
child 215 8096a832df02
child 271 dc268b18d709
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-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 // e32test\digitiser\t_ldddigitisertest.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <e32hal.h>
       
    20 #include "d_lddDigitisertest.h"
       
    21 #include <hal.h>
       
    22 
       
    23 _LIT(KLddFileName, "D_LDDDIGITISERTEST.LDD");
       
    24 
       
    25 RLddDigitiserTest gLDD;
       
    26 GLDEF_D RTest test(_L("Digitiser LDD tests"));
       
    27 
       
    28 void DoTestOnUnregisteredDevice()
       
    29 	{
       
    30 	__UHEAP_MARK;
       
    31 	test.Printf(_L("DoTestOnUnregisteredDevice(): should return KErrNotSupported coz NO DEVICE IS REGISTERED !!!"));
       
    32  	TInt r;
       
    33 	TInt halApiVal;	
       
    34 	TInt unregisteredDeviceNumber=99; // Its highly unlikely that this device number is registered 
       
    35 
       
    36     r=HAL::Get(unregisteredDeviceNumber,HALData::EPointer3D,halApiVal);
       
    37 	test(r==KErrNotSupported);
       
    38 	
       
    39 	r=HAL::Get(unregisteredDeviceNumber,HALData::EPointer3DMaxProximity,halApiVal);
       
    40 	test(r==KErrNotSupported);
       
    41 	
       
    42     r=HAL::Get(unregisteredDeviceNumber,HALData::EPointer3DThetaSupported,halApiVal);
       
    43 	test(r==KErrNotSupported);
       
    44 	
       
    45     r=HAL::Get(unregisteredDeviceNumber,HALData::EPointer3DPhiSupported,halApiVal);
       
    46 	test(r==KErrNotSupported);
       
    47 	
       
    48     r=HAL::Get(unregisteredDeviceNumber,HALData::EPointer3DRotationSupported,halApiVal);
       
    49 	test(r==KErrNotSupported);
       
    50 	
       
    51     r=HAL::Get(unregisteredDeviceNumber,HALData::EPointer3DPressureSupported,halApiVal);
       
    52 	test(r==KErrNotSupported);
       
    53 	
       
    54     r=HAL::Get(unregisteredDeviceNumber,HALData::EPointer3DProximityStep,halApiVal);
       
    55 	test(r==KErrNotSupported);
       
    56 	
       
    57     r=HAL::Get(unregisteredDeviceNumber,HALData::EPointerMaxPointers,halApiVal);
       
    58 	test(r==KErrNotSupported);
       
    59 	
       
    60     r=HAL::Get(unregisteredDeviceNumber,HALData::EPointerNumberOfPointers,halApiVal);
       
    61 	test(r==KErrNotSupported);
       
    62 	
       
    63     r=HAL::Get(unregisteredDeviceNumber,HALData::EPointer3DMaxPressure,halApiVal);
       
    64 	test(r==KErrNotSupported);
       
    65 	
       
    66 	r=HAL::Get(unregisteredDeviceNumber,HALData::EPointer3DPressureStep,halApiVal);
       
    67 	test(r==KErrNotSupported);
       
    68     
       
    69     test.Printf(_L("Successully Finished Testing the DoTestOnUnregisteredDevice\n"));
       
    70 	__UHEAP_MARKEND;
       
    71 	}
       
    72 
       
    73 void DoTestDerivedeAtributes()
       
    74 	{
       
    75 	__UHEAP_MARK;
       
    76 	TInt r;
       
    77 	TInt halApiVal;
       
    78 	TInt testDriverVal;
       
    79 	TInt testDeviceNumber;
       
    80     
       
    81 	//new Values for HAL::Set
       
    82 	TInt halPointer3DMaxProximity=45;
       
    83 	TInt halPointerNumberOfPointers=5;
       
    84  
       
    85 	// New attribute values for Driver APIs
       
    86 	TInt newPointer3D=0;
       
    87 	TInt newPointer3DMaxProximity=50;
       
    88 	TInt newPointer3DThetaSupported=0;
       
    89 	TInt newPointer3DPhiSupported=0;
       
    90 	TInt newPointer3DRotationSupported=0;
       
    91 	TInt newPointer3DPressureSupported=0;
       
    92 	TInt newPointer3DProximityStep=6;
       
    93 	TInt newPointerMaxPointers=7;
       
    94 	TInt newPointerNumberOfPointers=2;
       
    95 	TInt newPointer3DMaxPressure=501;
       
    96 	TInt newPointer3DPressureStep=50;
       
    97 
       
    98 /*
       
    99 The following sequence should be followed
       
   100 
       
   101 a)	Load the test Driver
       
   102 
       
   103 b)	Open the channel
       
   104 
       
   105 c)	Register Kernel Hal Handler
       
   106 
       
   107 d)  Get the Registered Device Number
       
   108 
       
   109 e)	Initialise HAL data
       
   110 
       
   111 f)	Get/Set HAL Data  using HAL APIS (HAL::GET, HAL::SET)
       
   112 
       
   113 g)	Get/Set the HAL data  throught the test driver APIS
       
   114 
       
   115 h)	Compare the results and make sure that data recived are same and data set 
       
   116     using HAL library apis received with test driver APIS  and vice versa.
       
   117 
       
   118 i)	Do it for all the new Digitiser Attributes (11 at  the moment)
       
   119 
       
   120 j)	.....
       
   121 
       
   122 k)	De-register the Kernel HAL handler
       
   123 
       
   124 l)	Unload the Driver
       
   125 
       
   126 m)	END...
       
   127 
       
   128 */
       
   129    	test.Printf(_L("Testing Derived Attributes using a test Driver for Digitiser\n"));
       
   130 	r=User::LoadLogicalDevice(KLddFileName);
       
   131 	test(r==KErrNone);
       
   132 
       
   133 	r=gLDD.Open();
       
   134 	test(r==KErrNone);
       
   135 
       
   136 	r=gLDD.registerHalHandler();
       
   137     test(r==KErrNone || r==KErrNotSupported);
       
   138 
       
   139     testDeviceNumber=gLDD.getRegisteredDeviceNumber();
       
   140 	test(testDeviceNumber != KErrNotFound);
       
   141 	gLDD.initialiseHalData();
       
   142 
       
   143     r=HAL::Get(testDeviceNumber,HALData::EPointer3D,halApiVal);
       
   144 	test(r==KErrNone);
       
   145 	testDriverVal=gLDD.getPointer3D();
       
   146     test(halApiVal == testDriverVal);
       
   147 	
       
   148     r=HAL::Get(testDeviceNumber,HALData::EPointer3DMaxProximity,halApiVal);
       
   149 	test(r==KErrNone);
       
   150 	testDriverVal=gLDD.getPointer3DMaxProximity();
       
   151     test(halApiVal == testDriverVal);
       
   152 
       
   153     r=HAL::Get(testDeviceNumber,HALData::EPointer3DThetaSupported,halApiVal);
       
   154     test(r==KErrNone);
       
   155     testDriverVal=gLDD.getPointer3DThetaSupported();
       
   156     test(halApiVal == testDriverVal);
       
   157 
       
   158     r=HAL::Get(testDeviceNumber,HALData::EPointer3DPhiSupported,halApiVal);
       
   159     test(r==KErrNone);
       
   160     testDriverVal=gLDD.getPointer3DPhiSupported();
       
   161     test(halApiVal == testDriverVal);
       
   162 
       
   163     r=HAL::Get(testDeviceNumber,HALData::EPointer3DRotationSupported,halApiVal);
       
   164     test(r==KErrNone);
       
   165     testDriverVal=gLDD.getPointer3DRotationSupported();
       
   166     test(halApiVal == testDriverVal);
       
   167 
       
   168     r=HAL::Get(testDeviceNumber,HALData::EPointer3DPressureSupported,halApiVal);
       
   169     test(r==KErrNone);
       
   170     testDriverVal=gLDD.getPointer3DPressureSupported();
       
   171     test(halApiVal == testDriverVal);
       
   172 
       
   173     r=HAL::Get(testDeviceNumber,HALData::EPointer3DProximityStep,halApiVal);
       
   174     test(r==KErrNone);
       
   175     testDriverVal=gLDD.getPointer3DProximityStep();
       
   176     test(halApiVal == testDriverVal);
       
   177 
       
   178     r=HAL::Get(testDeviceNumber,HALData::EPointerMaxPointers,halApiVal);
       
   179     test(r==KErrNone);
       
   180     testDriverVal=gLDD.getPointerMaxPointers();
       
   181     test(halApiVal == testDriverVal);
       
   182 
       
   183     r=HAL::Get(testDeviceNumber,HALData::EPointerNumberOfPointers,halApiVal);
       
   184     test(r==KErrNone);
       
   185     testDriverVal=gLDD.getPointerNumberOfPointers();
       
   186     test(halApiVal == testDriverVal);
       
   187 
       
   188     r=HAL::Get(testDeviceNumber,HALData::EPointer3DMaxPressure,halApiVal);
       
   189     test(r==KErrNone);
       
   190     testDriverVal=gLDD.getPointer3DMaxPressure();
       
   191     test(halApiVal == testDriverVal);
       
   192 
       
   193 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DPressureStep,halApiVal);
       
   194     test(r==KErrNone);
       
   195     testDriverVal=gLDD.getPointer3DPressureStep();
       
   196     test(halApiVal == testDriverVal);
       
   197 
       
   198 	// There are just 2 settable HAL Values. Set them using HAL APIs and get the same using
       
   199 	// Test Driver APIs.
       
   200 	r=HAL::Set(testDeviceNumber,HALData::EPointer3DMaxProximity,halPointer3DMaxProximity);
       
   201     test(r==KErrNone);
       
   202     testDriverVal=gLDD.getPointer3DMaxProximity();
       
   203     test(halPointer3DMaxProximity == testDriverVal);
       
   204 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DMaxProximity,halApiVal);
       
   205 	test(r==KErrNone);
       
   206 	test(halApiVal == halPointer3DMaxProximity);
       
   207 
       
   208     r=HAL::Set(testDeviceNumber,HALData::EPointerNumberOfPointers,halPointerNumberOfPointers);
       
   209     test(r==KErrNone);
       
   210     testDriverVal=gLDD.getPointerNumberOfPointers();
       
   211     test(halPointerNumberOfPointers == testDriverVal);
       
   212 	r=HAL::Get(testDeviceNumber,HALData::EPointerNumberOfPointers,halApiVal);
       
   213 	test(r==KErrNone);
       
   214 	test(halApiVal == halPointerNumberOfPointers);
       
   215    
       
   216 	// Set the Attributes values using the Driver APis and make sure  that the same is
       
   217 	// received with HAL::Get APis
       
   218     gLDD.setPointer3D(newPointer3D);
       
   219     r=HAL::Get(testDeviceNumber,HALData::EPointer3D,halApiVal);
       
   220 	test(r==KErrNone);
       
   221 	test(halApiVal == newPointer3D);
       
   222 	
       
   223     gLDD.setPointer3DMaxProximity(newPointer3DMaxProximity);
       
   224 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DMaxProximity,halApiVal);
       
   225 	test(r==KErrNone);
       
   226 	test(halApiVal == newPointer3DMaxProximity);
       
   227 	
       
   228     gLDD.setPointer3DThetaSupported(newPointer3DThetaSupported);
       
   229 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DThetaSupported,halApiVal);
       
   230 	test(r==KErrNone);
       
   231 	test(halApiVal == newPointer3DThetaSupported);
       
   232 
       
   233     gLDD.setPointer3DPhiSupported(newPointer3DPhiSupported);
       
   234 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DPhiSupported,halApiVal);
       
   235 	test(r==KErrNone);
       
   236 	test(halApiVal == newPointer3DPhiSupported);
       
   237 
       
   238     gLDD.setPointer3DRotationSupported(newPointer3DRotationSupported);
       
   239 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DRotationSupported,halApiVal);
       
   240 	test(r==KErrNone);
       
   241 	test(halApiVal == newPointer3DRotationSupported);
       
   242 
       
   243     gLDD.setPointer3DPressureSupported(newPointer3DPressureSupported);
       
   244 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DPressureSupported,halApiVal);
       
   245 	test(r==KErrNone);
       
   246 	test(halApiVal == newPointer3DPressureSupported);
       
   247 
       
   248     gLDD.setPointer3DProximityStep(newPointer3DProximityStep);
       
   249 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DProximityStep,halApiVal);
       
   250 	test(r==KErrNone);
       
   251 	test(halApiVal == newPointer3DProximityStep);
       
   252 
       
   253     gLDD.setPointerMaxPointers(newPointerMaxPointers);
       
   254 	r=HAL::Get(testDeviceNumber,HALData::EPointerMaxPointers,halApiVal);
       
   255 	test(r==KErrNone);
       
   256 	test(halApiVal == newPointerMaxPointers);
       
   257 
       
   258     gLDD.setPointerNumberOfPointers(newPointerNumberOfPointers);
       
   259 	r=HAL::Get(testDeviceNumber,HALData::EPointerNumberOfPointers,halApiVal);
       
   260 	test(r==KErrNone);
       
   261 	test(halApiVal == newPointerNumberOfPointers);
       
   262 
       
   263     gLDD.setPointer3DMaxPressure(newPointer3DMaxPressure);	
       
   264 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DMaxPressure,halApiVal);
       
   265 	test(r==KErrNone);
       
   266 	test(halApiVal == newPointer3DMaxPressure);
       
   267 
       
   268 	gLDD.setPointer3DPressureStep(newPointer3DPressureStep);
       
   269 	
       
   270 	r=HAL::Get(testDeviceNumber,HALData::EPointer3DPressureStep,halApiVal);
       
   271 	test(r==KErrNone);
       
   272 	test(halApiVal == newPointer3DPressureStep);  
       
   273 	
       
   274 	r=gLDD.removeHalHandler();
       
   275     test(r == KErrNone);
       
   276 
       
   277 	gLDD.Close();
       
   278 
       
   279 	r = User::FreeLogicalDevice(KLddFileName);;
       
   280 	test(r==KErrNone);
       
   281 	User::After(100000);
       
   282 
       
   283 	// Finished Testing Derived attributes
       
   284    	test.Printf(_L("Successully Finished Testing the Derived attributes\n"));
       
   285    	__UHEAP_MARKEND;
       
   286 	}
       
   287 
       
   288 void DoTestNonDerivedAtributes()
       
   289 	{
       
   290 	__UHEAP_MARK;
       
   291 	// The following 4 HAL attributes would be tested using HAL::GET,HAL:SET APIs
       
   292 	// 1. EPointer3DEnterHighPressureThreshold
       
   293 	// 2. EPointer3DExitHighPressureThreshold
       
   294 	// 3. EPointer3DEnterCloseProximityThreshold
       
   295 	// 4. EPointer3DExitCloseProximityThreshold
       
   296 	//////////********TEST STEPS********////////////////////
       
   297 	// Step1: Get  the existing/default  values using HAL:GET() and save them (for restoring it at Step4)
       
   298 	// Step2: Set new valuee using HAL:SET()
       
   299 	// Step3: Make sure that the new values are set  by camparing the new valuee with the values got by HAL:GET()
       
   300 	// Step4: Restore the orginal values( saved at Step1)
       
   301    
       
   302 	TInt r;
       
   303 	TInt halGetVal;
       
   304 	// Save the  Original Values
       
   305 	TInt origPointer3DEnterHighPressureThreshold;
       
   306 	TInt origPointer3DExitHighPressureThreshold;
       
   307 	TInt origPointer3DEnterCloseProximityThreshold;
       
   308 	TInt origPointer3DExitCloseProximityThreshold;
       
   309 
       
   310 	// New values to be set
       
   311     TInt newPointer3DEnterHighPressureThreshold = 500;
       
   312 	TInt newPointer3DExitHighPressureThreshold = 300;
       
   313 	TInt newPointer3DEnterCloseProximityThreshold = 20;
       
   314 	TInt newPointer3DExitCloseProximityThreshold = 35;
       
   315 
       
   316 	test.Printf(_L("Testing Non-Derived attributes\n"));
       
   317     
       
   318 	// Test EPointer3DEnterHighPressureThreshold
       
   319 	r=HAL::Get(HALData::EPointer3DEnterHighPressureThreshold,origPointer3DEnterHighPressureThreshold);
       
   320 	test(r==KErrNone);
       
   321 	r=HAL::Set(HALData::EPointer3DEnterHighPressureThreshold,newPointer3DEnterHighPressureThreshold);
       
   322 	test(r==KErrNone);
       
   323 	r=HAL::Get(HALData::EPointer3DEnterHighPressureThreshold,halGetVal);
       
   324 	test(r==KErrNone);
       
   325 	test(halGetVal == newPointer3DEnterHighPressureThreshold); 
       
   326 	r=HAL::Set(HALData::EPointer3DEnterHighPressureThreshold,origPointer3DEnterHighPressureThreshold);
       
   327 	test(r==KErrNone);
       
   328 	r=HAL::Get(HALData::EPointer3DEnterHighPressureThreshold,halGetVal);
       
   329 	test(r==KErrNone);
       
   330 	test(halGetVal == origPointer3DEnterHighPressureThreshold); 
       
   331 
       
   332 	// Test EPointer3DExitHighPressureThreshold
       
   333 	r=HAL::Get(HALData::EPointer3DExitHighPressureThreshold,origPointer3DExitHighPressureThreshold);
       
   334 	test(r==KErrNone);
       
   335 	r=HAL::Set(HALData::EPointer3DExitHighPressureThreshold,newPointer3DExitHighPressureThreshold);
       
   336 	test(r==KErrNone);
       
   337 	r=HAL::Get(HALData::EPointer3DExitHighPressureThreshold,halGetVal);
       
   338 	test(r==KErrNone);
       
   339 	test(halGetVal == newPointer3DExitHighPressureThreshold);
       
   340 	r=HAL::Set(HALData::EPointer3DExitHighPressureThreshold,origPointer3DExitHighPressureThreshold);
       
   341 	test(r==KErrNone);
       
   342 	r=HAL::Get(HALData::EPointer3DExitHighPressureThreshold,halGetVal);
       
   343 	test(r==KErrNone);
       
   344 	test(halGetVal == origPointer3DExitHighPressureThreshold); 	
       
   345 	
       
   346 	// Test EPointer3DEnterCloseProximityThreshold
       
   347 	r=HAL::Get(HALData::EPointer3DEnterCloseProximityThreshold,origPointer3DEnterCloseProximityThreshold);
       
   348 	test(r==KErrNone);
       
   349 	r=HAL::Set(HALData::EPointer3DEnterCloseProximityThreshold,newPointer3DEnterCloseProximityThreshold);
       
   350    	test(r==KErrNone);
       
   351    	r=HAL::Get(HALData::EPointer3DEnterCloseProximityThreshold,halGetVal);
       
   352 	test(r==KErrNone);
       
   353 	test(halGetVal == newPointer3DEnterCloseProximityThreshold); 
       
   354 	r=HAL::Set(HALData::EPointer3DEnterCloseProximityThreshold,origPointer3DEnterCloseProximityThreshold);
       
   355 	test(r==KErrNone);
       
   356 	r=HAL::Get(HALData::EPointer3DEnterCloseProximityThreshold,halGetVal);
       
   357 	test(r==KErrNone);
       
   358 	test(halGetVal == origPointer3DEnterCloseProximityThreshold); 
       
   359 
       
   360 	// Test EPointer3DExitCloseProximityThreshold
       
   361 	r=HAL::Get(HALData::EPointer3DExitCloseProximityThreshold,origPointer3DExitCloseProximityThreshold);
       
   362 	test(r==KErrNone);
       
   363 	r=HAL::Set(HALData::EPointer3DExitCloseProximityThreshold,newPointer3DExitCloseProximityThreshold);
       
   364    	test(r==KErrNone);
       
   365    	r=HAL::Get(HALData::EPointer3DExitCloseProximityThreshold,halGetVal);
       
   366 	test(r==KErrNone);
       
   367 	test(halGetVal == newPointer3DExitCloseProximityThreshold); 
       
   368 	r=HAL::Set(HALData::EPointer3DExitCloseProximityThreshold,origPointer3DExitCloseProximityThreshold);
       
   369 	test(r==KErrNone);
       
   370 	r=HAL::Get(HALData::EPointer3DExitCloseProximityThreshold,halGetVal);
       
   371 	test(r==KErrNone);
       
   372 	test(halGetVal == origPointer3DExitCloseProximityThreshold);
       
   373 	
       
   374 	// Finished Testing non-derived attributes
       
   375 	test.Printf(_L("Successully Finished Testing the non-derived attributes\n"));
       
   376 	__UHEAP_MARKEND;
       
   377 	}
       
   378 
       
   379 GLDEF_C TInt E32Main()
       
   380 //
       
   381 // Test Digitiser LDD
       
   382 //
       
   383 	{
       
   384 	TInt machineUid=0;
       
   385 	// This Testing is performed only on H4,Wins and WinEmulator, so need to get the machinUID
       
   386     const TInt r = HAL::Get(HAL::EMachineUid, machineUid);
       
   387 	if(r==KErrNone) 
       
   388 		{
       
   389 		test.Start(_L("Test Start : LDDDigitiserTest"));
       
   390 		// Non-Derived attributes are tested using a Test Driver for Digitiser which is supported only on H4,Wins and WinEmulator
       
   391 		if((machineUid == HAL::EMachineUid_OmapH4) || (machineUid == HAL::EMachineUid_Win32Emulator))
       
   392 			{
       
   393 			DoTestNonDerivedAtributes();
       
   394 			}		
       
   395 		// Derived attributes are tested using a Test Driver for Digitiser which is supported only on H4
       
   396         if(machineUid == HAL::EMachineUid_OmapH4) 
       
   397 			{
       
   398 			 DoTestOnUnregisteredDevice(); 
       
   399 			 DoTestDerivedeAtributes();	
       
   400 			}
       
   401 		}
       
   402 	test.End();
       
   403 	test.Close();
       
   404  	return(KErrNone);
       
   405     }