kerneltest/e32test/hcr/t_hcrut.cpp
changeset 14 5d2844f35677
parent 4 56f325a607ea
equal deleted inserted replaced
8:538db54a451d 14:5d2844f35677
    18 #include <e32test.h>
    18 #include <e32test.h>
    19 #include <e32svr.h>
    19 #include <e32svr.h>
    20 #include <u32hal.h>
    20 #include <u32hal.h>
    21 #include <hal.h>
    21 #include <hal.h>
    22 #include <hal_data.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 
    23 #include "d_hcrut.h"
    30 #include "d_hcrut.h"
    24 
    31 
       
    32 #include "d_hcrsim_testdata.h"
       
    33 
    25 #define __TRACE_LINE__()	test.Printf(_L("%d\n"),__LINE__)
    34 #define __TRACE_LINE__()	test.Printf(_L("%d\n"),__LINE__)
    26 
    35 
    27 RTest test(_L("T_HCRUT"));
    36 RTest test(_L("T_HCRUT"));
    28 
    37 
    29 _LIT(KTestDriver,"d_hcrut");
    38 _LIT(KTestDriver,"d_hcrut");
    30 	
    39 
    31 RHcrTest HcrTest;
    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     }
    32 
   140 
    33 //---------------------------------------------
   141 //---------------------------------------------
    34 //! @SYMTestCaseID 
   142 //! @SYMTestCaseID 
    35 //! @SYMTestType
   143 //! @SYMTestType
    36 //! @SYMPREQ 
   144 //! @SYMPREQ 
    42 //! @SYMTestPriority 
   150 //! @SYMTestPriority 
    43 //! @SYMTestStatus
   151 //! @SYMTestStatus
    44 //---------------------------------------------
   152 //---------------------------------------------
    45 TInt TestBasics ()
   153 TInt TestBasics ()
    46 	{
   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 	
    47 	test.Next(_L("Switch repository test"));
   170 	test.Next(_L("Switch repository test"));
    48 
   171 	test_KErrNone(HcrTest.Test_SwitchRepository());
    49 	test_KErrNone( HcrTest.Test_SwitchRepository());
   172 	
    50 
   173 	test.Next(_L("Invoke FindSettingsInCategory boundary conditon tests"));
       
   174 	TestBoundaryFindSettingsInCategory();
       
   175 		
    51 	// Wait for idle + async cleanup (waits for DKernelEventHandler to go away)
   176 	// Wait for idle + async cleanup (waits for DKernelEventHandler to go away)
    52 	TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
   177 	TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
    53 	test_KErrNone(r);
   178 	test_KErrNone(r);
    54 
   179 
    55     User::After(1000000);
   180     User::After(5000000);
       
   181     
    56 
   182 
    57     return KErrNone;
   183     return KErrNone;
    58     }
   184     }
    59 
   185 
    60 
   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     }
    61 
   222 
    62 
   223 
    63 GLDEF_C TInt E32Main()
   224 GLDEF_C TInt E32Main()
    64     {
   225     {
    65 	TInt r;
   226 	TInt r;
    76 	test_KErrNone(r);
   237 	test_KErrNone(r);
    77     // Do test cases
   238     // Do test cases
    78     //
   239     //
    79     TestBasics();
   240     TestBasics();
    80 
   241 
       
   242 	NegativeTestsLargeValues();
       
   243 	TRepositoryGetWordValueUnitTests();
       
   244 
    81 	test.Next(_L("=== Close LDD"));
   245 	test.Next(_L("=== Close LDD"));
    82 	HcrTest.Close();
   246 	HcrTest.Close();
    83 	
   247 	
    84 	r = User::FreeLogicalDevice(RHcrTest::Name());
   248 	r = User::FreeLogicalDevice(RHcrTest::Name());
    85     test_KErrNone(r);
   249     test_KErrNone(r);