os/kernelhwsrv/kerneltest/e32test/hcr/t_hcrut.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 // Hardware Configuration Respoitory Test Application
    15 //
    16 
    17 #define __E32TEST_EXTENSION__
    18 #include <e32test.h>
    19 #include <e32svr.h>
    20 #include <u32hal.h>
    21 #include <hal.h>
    22 #include <hal_data.h>
    23 #include <drivers/hcr.h>
    24 
    25 #include "hcr_hai.h" // for SSettingC structure
    26 #include "hcr_uids.h"
    27 
    28 using namespace HCR;
    29 
    30 #include "d_hcrut.h"
    31 
    32 #include "d_hcrsim_testdata.h"
    33 
    34 #define __TRACE_LINE__()	test.Printf(_L("%d\n"),__LINE__)
    35 
    36 RTest test(_L("T_HCRUT"));
    37 
    38 _LIT(KTestDriver,"d_hcrut");
    39 
    40 RHcrTest HcrTest;
    41 
    42 
    43 void TestBoundaryFindSettingsInCategory()
    44     {
    45     TInt32 firstEl;
    46     TInt32 lastEl;
    47 
    48 
    49     //Test low end boundary conditions in the compiled repository, first and 
    50     //end elements don't belong to the repository
    51     TUint32 TestCat = KHCRUID_TestCategory1;
    52     TInt NumInTestCat = 15;
    53     
    54     test_KErrNone(HcrTest.Test_FindCompiledSettingsInCategory(TestCat,
    55             &firstEl, &lastEl));
    56     test_Equal((lastEl - firstEl + 1), NumInTestCat);
    57 
    58     // Load file repository data for the boundary test condition
    59     const TText * fileBc0 = (const TText *)"filerepos_bc0.dat";
    60     test_KErrNone(HcrTest.Test_SwitchFileRepository(fileBc0));
    61 
    62     // Test the low end boundary conditions in the file repository.
    63     // First element in the category is also the first element in the
    64     // repository
    65     TestCat = 0x00000001;
    66     NumInTestCat = 4;
    67 
    68     test_KErrNone(HcrTest.Test_FindFileSettingsInCategory(TestCat,
    69             &firstEl, &lastEl));
    70     test_Equal((lastEl - firstEl + 1), NumInTestCat);
    71 
    72     // Test the high end boundary conditions in the file repository.
    73     // Last element in the category is also the last element in the
    74     // repository
    75     TestCat = 0xFFFFFFFF;
    76     NumInTestCat = 4;
    77 
    78     test_KErrNone(HcrTest.Test_FindFileSettingsInCategory(TestCat,
    79             &firstEl, &lastEl));
    80     test_Equal((lastEl - firstEl + 1), NumInTestCat);
    81 
    82 
    83 
    84     //Load relevant coreImg repository
    85     const TText * fileBc1 = (const TText *)"filerepos_bc1.dat";
    86     test_KErrNone(HcrTest.Test_SwitchFileRepository(fileBc1));
    87 
    88 
    89     //Test the low end boundary condition when first element of the 
    90     //repository does not belong to the requested category, so first element
    91     // in TestBc1Cat0 is second in the repository.
    92     TestCat = 0x2;
    93     NumInTestCat = 4;
    94 
    95     test_KErrNone(HcrTest.Test_FindFileSettingsInCategory(TestCat,
    96             &firstEl, &lastEl));
    97     test_Equal((lastEl - firstEl + 1), NumInTestCat);
    98 
    99 
   100 
   101     //Test the high end boundary condition when last element in the 
   102     // repository does not belong to TestBc1Cat1 in opposite to the previous
   103     //element which part of this category.
   104     TestCat = 0x10000002;
   105     NumInTestCat = 7;
   106 
   107     test_KErrNone(HcrTest.Test_FindFileSettingsInCategory(TestCat,
   108             &firstEl, &lastEl));
   109     test_Equal((lastEl - firstEl + 1), NumInTestCat);
   110 
   111 
   112     //The required category has only one element and it's first setting
   113     //in the repository
   114     TestCat = 0x01;
   115     NumInTestCat = 1;
   116 
   117     test_KErrNone(HcrTest.Test_FindFileSettingsInCategory(TestCat,
   118             &firstEl, &lastEl));
   119     test_Equal((lastEl - firstEl + 1), NumInTestCat);
   120 
   121     //The required category has only one element and it's the last setting
   122     //in the repository
   123     TestCat = 0xFFFFFFFF;
   124     NumInTestCat = 1;
   125 
   126     test_KErrNone(HcrTest.Test_FindFileSettingsInCategory(TestCat,
   127             &firstEl, &lastEl));
   128     test_Equal((lastEl - firstEl + 1), NumInTestCat);
   129 
   130 
   131     //Standard use case, all elements of the category are situated somewhere
   132     //in the middle of the repository
   133     TestCat = 0x10000002;
   134     NumInTestCat = 7;
   135 
   136     test_KErrNone(HcrTest.Test_FindFileSettingsInCategory(TestCat,
   137             &firstEl, &lastEl));
   138     test_Equal((lastEl - firstEl + 1), NumInTestCat);
   139     }
   140 
   141 //---------------------------------------------
   142 //! @SYMTestCaseID 
   143 //! @SYMTestType
   144 //! @SYMPREQ 
   145 //! @SYMTestCaseDesc
   146 //! @SYMTestActions 
   147 //!
   148 //! @SYMTestExpectedResults 
   149 //!		
   150 //! @SYMTestPriority 
   151 //! @SYMTestStatus
   152 //---------------------------------------------
   153 TInt TestBasics ()
   154 	{
   155 	test.Next(_L("Check Integrity test"));
   156 #ifdef __WINS__
   157 	test.Printf(_L("Skipped on the emulator"));
   158 #else
   159 	test_KErrNone( HcrTest.Test_CheckIntegrity());	
   160 #endif // __WINS__
   161 
   162 	test.Next(_L("Check Content test"));
   163 #ifdef __WINS__
   164 	test.Printf(_L("Skipped on the emulator"));
   165 #else
   166 	test_KErrNone( HcrTest.Test_CheckContent());	
   167 #endif // __WINS__
   168 
   169 	
   170 	test.Next(_L("Switch repository test"));
   171 	test_KErrNone(HcrTest.Test_SwitchRepository());
   172 	
   173 	test.Next(_L("Invoke FindSettingsInCategory boundary conditon tests"));
   174 	TestBoundaryFindSettingsInCategory();
   175 		
   176 	// Wait for idle + async cleanup (waits for DKernelEventHandler to go away)
   177 	TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
   178 	test_KErrNone(r);
   179 
   180     User::After(5000000);
   181     
   182 
   183     return KErrNone;
   184     }
   185 
   186 
   187 TInt TRepositoryGetWordValueUnitTests ()
   188 	{
   189 	test.Next(_L("Unit tests for HCR::TRepositoryFile::GetWordValue && HCR::TRepositoryCompiled::GetWordValue"));
   190 
   191 	SSettingC* setting;
   192 	for(setting = SettingsList; setting < SettingsList + sizeof(SettingsList) / sizeof(SSettingC); ++setting)
   193 		{
   194 		TCategoryUid category = setting->iName.iId.iCat;
   195 		TElementId key = setting->iName.iId.iKey;
   196 		TInt type = setting->iName.iType;
   197 		test_KErrNone( HcrTest.Test_TRepositoryGetWordValue(category, key, type));
   198 	
   199 		}
   200 
   201 	// Wait for idle + async cleanup (waits for DKernelEventHandler to go away)
   202 	TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
   203 	test_KErrNone(r);
   204 
   205     return KErrNone;
   206     }
   207 
   208 TInt NegativeTestsLargeValues ()
   209 	{
   210 	test.Next(_L("Negative tests for HCR::TRepository::GetLargeValues"));
   211 
   212 	TInt expectedError = KErrArgument;
   213 
   214 	test_KErrNone( HcrTest.Test_NegativeTestsLargeValues(expectedError));
   215 
   216 	// Wait for idle + async cleanup (waits for DKernelEventHandler to go away)
   217 	TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
   218 	test_KErrNone(r);
   219 
   220     return KErrNone;
   221     }
   222 
   223 
   224 GLDEF_C TInt E32Main()
   225     {
   226 	TInt r;
   227 	    
   228     test.Title();
   229 	test.Start(_L("=== HCR Test Suite"));
   230 
   231 
   232 	test.Next(_L("=== Open test LDD"));
   233 	r = User::LoadLogicalDevice(KTestDriver);
   234 	test_Assert((r==KErrNone || r==KErrAlreadyExists),void (0));
   235 		
   236 	r = HcrTest.Open();
   237 	test_KErrNone(r);
   238     // Do test cases
   239     //
   240     TestBasics();
   241 
   242 	NegativeTestsLargeValues();
   243 	TRepositoryGetWordValueUnitTests();
   244 
   245 	test.Next(_L("=== Close LDD"));
   246 	HcrTest.Close();
   247 	
   248 	r = User::FreeLogicalDevice(RHcrTest::Name());
   249     test_KErrNone(r);
   250 
   251 	test.End();
   252 	
   253 	return(KErrNone);
   254     }
   255