kerneltest/e32test/hcr/t_hcr.cpp
changeset 47 46fffbe7b5a7
parent 43 96e5fb8b040d
equal deleted inserted replaced
46:0bf4040442f9 47:46fffbe7b5a7
    31 _LIT8(KTestEmpty,		"empty.dat");
    31 _LIT8(KTestEmpty,		"empty.dat");
    32 _LIT8(KTestMegaLarge1,	"megalarge1.dat");
    32 _LIT8(KTestMegaLarge1,	"megalarge1.dat");
    33 _LIT8(KTestMegaLarge2,	"megalarge2.dat");
    33 _LIT8(KTestMegaLarge2,	"megalarge2.dat");
    34 _LIT8(KTestClearRepos,	"");
    34 _LIT8(KTestClearRepos,	"");
    35 
    35 
       
    36 
       
    37 static const TInt KSimOwnThread = 0;
       
    38 static const TInt KSimClientThread = 1;
       
    39 static TInt gHcrThread = KSimOwnThread;
       
    40 
       
    41 //Calculation of the fraction defined by f for the number x
       
    42 #define _FRACTION(x, f)    (x>f ? x/f : x)
    36 
    43 
    37 
    44 
    38 RTest test(_L("T_HCR"));
    45 RTest test(_L("T_HCR"));
    39 RHcrSimTestChannel HcrSimTest;
    46 RHcrSimTestChannel HcrSimTest;
    40 
    47 
   323 			r = dval.Create(setting->iName.iLen - 1);
   330 			r = dval.Create(setting->iName.iLen - 1);
   324 			test_KErrNone(r);
   331 			test_KErrNone(r);
   325 			r = HcrSimTest.GetData(id, dval);
   332 			r = HcrSimTest.GetData(id, dval);
   326 			test_Equal(KErrTooBig, r);
   333 			test_Equal(KErrTooBig, r);
   327 			dval.Close();
   334 			dval.Close();
       
   335 			
       
   336 			TUint8* pval;
       
   337 			pval = (TUint8*) User::Alloc(setting->iName.iLen);
       
   338 			test_NotNull(pval);
       
   339 			//
       
   340 			TUint16 actuallength;
       
   341 			r = HcrSimTest.GetData(id, (unsigned short)( setting->iName.iLen - 1), pval, actuallength);
       
   342 			test_Equal(KErrTooBig, r);
       
   343 			//
       
   344 			User::Free(pval);
   328 			}
   345 			}
   329 		if (setting->iName.iType != ETypeText8)
   346 		if (setting->iName.iType != ETypeText8)
   330 			{
   347 			{
   331 			TBuf8<KMaxSettingLength> dval;
   348 			TBuf8<KMaxSettingLength> dval;
   332 			TText8* pval;
   349 			TText8* pval;
   348 			r = dval.Create(setting->iName.iLen - 1);
   365 			r = dval.Create(setting->iName.iLen - 1);
   349 			test_KErrNone(r);
   366 			test_KErrNone(r);
   350 			r = HcrSimTest.GetString(id, dval);
   367 			r = HcrSimTest.GetString(id, dval);
   351 			test_Equal(KErrTooBig, r);
   368 			test_Equal(KErrTooBig, r);
   352 			dval.Close();
   369 			dval.Close();
       
   370 			
       
   371 			TText8* pval;
       
   372 			pval = (TText8*) User::Alloc(setting->iName.iLen);
       
   373 			test_NotNull(pval);
       
   374 			//
       
   375 			TUint16 actuallength;
       
   376 			r = HcrSimTest.GetString(id, (unsigned short)(setting->iName.iLen >> 1), pval, actuallength);
       
   377 			test_Equal(KErrTooBig, r);
       
   378 			//
       
   379 			User::Free(pval);
   353 			}
   380 			}
   354 		if (setting->iName.iType != ETypeArrayInt32)
   381 		if (setting->iName.iType != ETypeArrayInt32)
   355 			{
   382 			{
   356 			TInt32* pval;
   383 			TInt32* pval;
   357 			pval = (TInt32*) User::Alloc(setting->iName.iLen);
   384 			pval = (TInt32*) User::Alloc(setting->iName.iLen);
   368 			TInt32* pval;
   395 			TInt32* pval;
   369 			pval = (TInt32*) User::Alloc(setting->iName.iLen);
   396 			pval = (TInt32*) User::Alloc(setting->iName.iLen);
   370 			test_NotNull(pval);
   397 			test_NotNull(pval);
   371 			//
   398 			//
   372 			TUint16 actuallength;
   399 			TUint16 actuallength;
   373 			r = HcrSimTest.GetArray(id, (TUint16) (setting->iName.iLen / 2), pval, actuallength);
   400 			r = HcrSimTest.GetArray(id, (TUint16) (setting->iName.iLen >> 1), pval, actuallength);
   374 			test_Equal(KErrTooBig, r);
   401 			test_Equal(KErrTooBig, r);
   375 			//
   402 			//
   376 			User::Free(pval);
   403 			User::Free(pval);
   377 			}
   404 			}
   378 		if (setting->iName.iType != ETypeArrayUInt32)
   405 		if (setting->iName.iType != ETypeArrayUInt32)
   849 		test_Equal(*v, r);
   876 		test_Equal(*v, r);
   850 		}
   877 		}
   851 	numsettings.Close();
   878 	numsettings.Close();
   852 	}
   879 	}
   853 
   880 
       
   881 
       
   882 
   854 void HcrSimFindSettingsCategory(SSettingC* aRepository, TUint aNumberOfSettings)
   883 void HcrSimFindSettingsCategory(SSettingC* aRepository, TUint aNumberOfSettings)
   855 	{
   884     {
   856 	test.Next(_L("FindSettingsCategory"));
   885     test.Next(_L("FindSettingsCategory"));
   857 	TInt r;
   886     TInt r;
   858 	// Build a hash table with number of settings for each category
   887     
   859 	RHashMap<TUint32, TInt> numsettings;
   888     // Build a hash table with number of settings for each category
   860 	SSettingC* setting;
   889     RHashMap<TUint32, TInt> numsettings;
   861 	TInt* pV = NULL;
   890     SSettingC* setting;
   862 	TInt value = 0;
   891     TInt* pV = NULL;
   863 	for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   892     TInt value = 0;
   864 		{
   893     for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   865 		pV = numsettings.Find(setting->iName.iId.iCat);
   894         {
   866 		if(pV)
   895         pV = numsettings.Find(setting->iName.iId.iCat);
   867 		    value = *pV;
   896         if(pV)
   868 		if (!pV)
   897             value = *pV;
   869 			{
   898         if (!pV)
   870 			r = numsettings.Insert(setting->iName.iId.iCat, 1);
   899             {
   871 			test_KErrNone(r);
   900             r = numsettings.Insert(setting->iName.iId.iCat, 1);
   872 			}
   901             test_KErrNone(r);
   873 		else
   902             }
   874 			{
   903         else
   875 			r = numsettings.Remove(setting->iName.iId.iCat);
   904             {
   876 			test_KErrNone(r);
   905             r = numsettings.Remove(setting->iName.iId.iCat);
   877 			r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
   906             test_KErrNone(r);
   878 			test_KErrNone(r);
   907             r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
   879 			}
   908             test_KErrNone(r);
   880 		}
   909             }
   881 
   910         }
   882 	// 
   911 
   883 	RHashMap<TUint32, TInt>::TIter catiter(numsettings);
   912     // 
   884 	for (;;)
   913     RHashMap<TUint32, TInt>::TIter catiter(numsettings);
   885 		{
   914     for (;;)
   886 		const TUint32* nextcat = catiter.NextKey();
   915         {
   887 		if (!nextcat)
   916         const TUint32* nextcat = catiter.NextKey();
   888 			{
   917         if (!nextcat)
   889 			break;
   918             {
   890 			}
   919             break;
   891 		test.Printf(_L("Category %08x"), *nextcat);
   920             }
   892 		const TInt* v = numsettings.Find(*nextcat);
   921         test.Printf(_L("Category %08x"), *nextcat);
   893 		test_NotNull(v);
   922         const TInt* v = numsettings.Find(*nextcat);
   894 
   923         test_NotNull(v);
   895 		// Allocate memory for holding array of settings
   924 
   896 		TElementId* elids;
   925         // Allocate memory for holding array of settings
   897 		TSettingType* types;
   926         TElementId* elids;
   898 		TUint16* lens;
   927         TSettingType* types;
   899 		elids = (TElementId*) User::Alloc(*v * sizeof(TElementId));
   928         TUint16* lens;
   900 		test_NotNull(elids);
   929         
   901 		types = (TSettingType*) User::Alloc(*v * sizeof(TSettingType));
   930         TInt maxNum;
   902 		test_NotNull(types);
   931         
   903 		lens = (TUint16*) User::Alloc(*v * sizeof(TUint16));
   932         
   904 		test_NotNull(lens);
   933         // Try all permutations of optional values
   905 		
   934         TInt i;
   906 		// Try all permutations of optional values
   935         for (i = 0; i < 3; i++)
   907 		TInt i;
   936             {
   908 		for (i = 0; i < 3; i++)
   937             test.Printf(_L("."));
   909 			{
   938 
   910 			test.Printf(_L("."));
   939             TUint32 numfound;
   911 			Mem::Fill(elids, *v * sizeof(TElementId), 0xcc);
   940 
   912 			Mem::Fill(types, *v * sizeof(TSettingType), 0xcc);
   941             //maxNum is equal:  
   913 			Mem::Fill(lens, *v * sizeof(TUint16), 0xcc);
   942             //0 - 1, the total elements from the category
   914 			TUint32 numfound;
   943             //1 - 1/2 of total number of elements from the category
   915 			r = HcrSimTest.FindSettings(*nextcat,
   944             //2 - 1 + 1/2 of total number of element from the category
   916 				*v, numfound,
   945 
   917 				elids,
   946             if(i == 0)
   918 				i & 0x1 ? types : NULL,
   947                 maxNum = *v;
   919 				i & 0x2 ? lens : NULL);
   948             else if(i == 1)
   920 			numfound = r;
   949                 maxNum = _FRACTION((*v), 2);
   921 			test_Compare(0, <=, r);
   950             else
   922 			test_Equal(*v, r);
   951                 maxNum = *v + _FRACTION((*v), 2);
   923 			
   952 
   924 
   953 
   925 			// Check returned list of element ids
   954             elids = (TElementId*) User::Alloc(maxNum * sizeof(TElementId));
   926 			TUint j;
   955             test_NotNull(elids);
   927 			for (j = 0; j < numfound; j++)
   956             types = (TSettingType*) User::Alloc(maxNum * sizeof(TSettingType));
   928 				{
   957             test_NotNull(types);
   929 				// Find current element in the test array
   958             lens = (TUint16*) User::Alloc(maxNum * sizeof(TUint16));
   930 				for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   959             test_NotNull(lens);
   931 					{
   960 
   932 					if ((setting->iName.iId.iCat == *nextcat) && (setting->iName.iId.iKey == elids[j]))
   961             Mem::Fill(elids, maxNum * sizeof(TElementId), 0xcc);
   933 						{
   962             Mem::Fill(types, maxNum * sizeof(TSettingType), 0xcc);
   934 						break;
   963             Mem::Fill(lens,  maxNum * sizeof(TUint16), 0xcc);
   935 						}
   964 
   936 					}
   965 
   937 				test_Compare(setting,<,aRepository+aNumberOfSettings); // Fail if element not found
   966             r = HcrSimTest.FindSettings(*nextcat,
   938 				switch (setting->iName.iType)
   967                     maxNum, elids,
   939 					{
   968                     i & 0x1 ? types : NULL,
   940 					case ETypeInt32:
   969                     i & 0x2 ? lens : NULL);
   941 					case ETypeInt16:
   970             numfound = r;
   942 					case ETypeInt8:
   971             test_Compare(0, <=, r);
   943 					case ETypeBool:
   972             
   944 					case ETypeUInt32:
   973             if(i < 2)
   945 					case ETypeUInt16:
   974                 {
   946 					case ETypeUInt8:
   975                 //for 0 & 1 the number of settings returned must be equal maxNum
   947 					case ETypeLinAddr:
   976                 test_Equal(maxNum, r);
   948 						if (i & 0x1)
   977                 }
   949 							{
   978             else
   950 							test_Equal(setting->iName.iType, types[j]);
   979                 {
   951 							}
   980                 //for 2, it's equal the real number of settings
   952 						if (i & 0x2)
   981                 test_Equal((*v), r);
   953 							{
   982                 }
   954 							test_Equal(0, lens[j]);
   983 
   955 							}
   984 
   956 						break;
   985 
   957 						// Fall-through
   986             // Check returned list of element ids
   958 					case ETypeBinData:
   987             TUint j;
   959 					case ETypeText8:
   988             for (j = 0; j < numfound; j++)
   960 					case ETypeArrayInt32:
   989                 {
   961 					case ETypeArrayUInt32:
   990                 // Find current element in the test array
   962 					case ETypeInt64:
   991                 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
   963 					case ETypeUInt64:
   992                     {
   964 						if (i & 0x1)
   993                     if ((setting->iName.iId.iCat == *nextcat) && (setting->iName.iId.iKey == elids[j]))
   965 							{
   994                         {
   966 							test_Equal(setting->iName.iType, types[j]);
   995                         break;
   967 							}
   996                         }
   968 						if (i & 0x2)
   997                     }
   969 							{
   998                 test_Compare(setting,<,aRepository+aNumberOfSettings); // Fail if element not found
   970 							test_Equal(setting->iName.iLen, lens[j]);
   999                 switch (setting->iName.iType)
   971 							}
  1000                     {
   972 						break;
  1001                     case ETypeInt32:
   973 					default:
  1002                     case ETypeInt16:
   974 						test(EFalse);
  1003                     case ETypeInt8:
   975 					}
  1004                     case ETypeBool:
   976 				}
  1005                     case ETypeUInt32:
   977 			// Check all expected elements are in the returned list of element ids
  1006                     case ETypeUInt16:
   978 			for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
  1007                     case ETypeUInt8:
   979 				{
  1008                     case ETypeLinAddr:
   980 				if ((setting->iName.iId.iCat == *nextcat))
  1009                         if (i & 0x1)
   981 					{
  1010                             {
   982 					for (j = 0; j < numfound; j++)
  1011                             test_Equal(setting->iName.iType, types[j]);
   983 						{
  1012                             }
   984 						if (elids[j] == setting->iName.iId.iKey)
  1013                         if (i & 0x2)
   985 							{
  1014                             {
   986 							break;
  1015                             test_Equal(0, lens[j]);
   987 							}
  1016                             }
   988 						}
  1017                         break;
   989 					test_Compare(j, <=, numfound);
  1018                         // Fall-through
   990 					}
  1019                     case ETypeBinData:
   991 				}
  1020                     case ETypeText8:
   992 			}
  1021                     case ETypeArrayInt32:
   993 		User::Free(elids);
  1022                     case ETypeArrayUInt32:
   994 		User::Free(types);
  1023                     case ETypeInt64:
   995 		User::Free(lens);
  1024                     case ETypeUInt64:
   996 		test.Printf(_L("\n"));
  1025                         if (i & 0x1)
   997 		}
  1026                             {
   998 	numsettings.Close();
  1027                             test_Equal(setting->iName.iType, types[j]);
   999 	}
  1028                             }
       
  1029                         if (i & 0x2)
       
  1030                             {
       
  1031                             test_Equal(setting->iName.iLen, lens[j]);
       
  1032                             }
       
  1033                         break;
       
  1034                     default:
       
  1035                         test(EFalse);
       
  1036                     }
       
  1037                 }
       
  1038             // Check all expected elements are in the returned list of element ids
       
  1039             for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
       
  1040                 {
       
  1041                 if ((setting->iName.iId.iCat == *nextcat))
       
  1042                     {
       
  1043                     for (j = 0; j < numfound; j++)
       
  1044                         {
       
  1045                         if (elids[j] == setting->iName.iId.iKey)
       
  1046                             {
       
  1047                             break;
       
  1048                             }
       
  1049                         }
       
  1050                     test_Compare(j, <=, numfound);
       
  1051                     }
       
  1052                 }
       
  1053 
       
  1054             User::Free(elids);
       
  1055             User::Free(types);
       
  1056             User::Free(lens);
       
  1057             }
       
  1058 
       
  1059         test.Printf(_L("\n"));
       
  1060         }
       
  1061     numsettings.Close();
       
  1062     }
  1000 
  1063 
  1001 struct TTestFindSettingsPatternArgs
  1064 struct TTestFindSettingsPatternArgs
  1002 	{
  1065 	{
  1003 	TUint32 iMask;
  1066 	TUint32 iMask;
  1004 	TUint32 iPattern;
  1067 	TUint32 iPattern;
  1005 	};
  1068 	};
  1006 
  1069 
  1007 const TTestFindSettingsPatternArgs KTestFindSettingsPatternArgs[] = {
  1070 const TTestFindSettingsPatternArgs KTestFindSettingsPatternArgs[] = {
  1008 //	 iMask	   iPattern
  1071 //	 iMask	   iPattern
  1009 	{0x00000000, 0x00000000},
  1072 	{0x00000000, 0x00000000},
  1010 /*  {0xfffffff0, 0x00000000},
  1073     {0xfffffff0, 0x00000000},
  1011 	{0xffffffff, 0x00000001},*/
  1074 	{0xffffffff, 0x00000001}
  1012 };
  1075 };
  1013 
  1076 
  1014 void HcrSimFindSettingsPattern(SSettingC* aRepository, TUint aNumberOfSettings)
  1077 void HcrSimFindSettingsPattern(SSettingC* aRepository, TUint aNumberOfSettings)
  1015 	{
  1078     {
  1016 	test.Next(_L("FindSettingsPattern"));
  1079     test.Next(_L("FindSettingsPattern"));
  1017 	TInt r;
  1080     TInt r;
  1018 	TUint i;
  1081     TUint i;
  1019 
  1082 
  1020 	// Allocate memory for holding array of settings
  1083     // Allocate memory for holding array of settings
  1021 	TElementId* elids;
  1084     TElementId* elids;
  1022 	TSettingType* types;
  1085     TSettingType* types;
  1023 	TUint16* lens;
  1086     TUint16* lens;
  1024 	elids = (TElementId*) User::Alloc(aNumberOfSettings * sizeof(TElementId));
  1087     TInt maxNum;
  1025 	test_NotNull(elids);
  1088 
  1026 	types = (TSettingType*) User::Alloc(aNumberOfSettings * sizeof(TSettingType));
  1089     // Build a hash table with number of settings for each category
  1027 	test_NotNull(types);
  1090     RHashMap<TUint32, TInt> numsettings;
  1028 	lens = (TUint16*) User::Alloc(aNumberOfSettings * sizeof(TUint16));
  1091     SSettingC* setting;
  1029 	test_NotNull(lens);
  1092     TInt* pV = NULL;
  1030 
  1093     TInt value = 0;
  1031 	for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
  1094     for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
  1032 		{
  1095         {
  1033 		test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
  1096         pV = numsettings.Find(setting->iName.iId.iCat);
  1034 			KTestFindSettingsPatternArgs[i].iMask,
  1097         if(pV)
  1035 			KTestFindSettingsPatternArgs[i].iPattern);
  1098             value = *pV;
  1036 
  1099         if (!pV)
  1037 		// Test each category
  1100             {
  1038 		TUint j;
  1101             r = numsettings.Insert(setting->iName.iId.iCat, 1);
  1039 		for (j = 0; j < sizeof(KTestCategories) / sizeof(TCategoryUid); j++)
  1102             test_KErrNone(r);
  1040 			{
  1103             }
  1041 			test.Printf(_L("Category 0x%08x: "), KTestCategories[j]);
  1104         else
  1042 
  1105             {
  1043 			// Test all possible permutations of optional arguments
  1106             r = numsettings.Remove(setting->iName.iId.iCat);
  1044 			TUint k;
  1107             test_KErrNone(r);
  1045 			for (k = 0; k < 3; k++)
  1108             r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
  1046 				{
  1109             test_KErrNone(r);
  1047 				TUint32 numfound;
  1110             }
  1048 				// Actual API call
  1111         }
  1049 				r = HcrSimTest.FindSettings(
  1112 
  1050 					KTestCategories[j],
  1113     // Hash map includes the number of settings of each category 
  1051 					aNumberOfSettings,
  1114     RHashMap<TUint32, TInt>::TIter catiter(numsettings);
  1052 					KTestFindSettingsPatternArgs[i].iMask,
  1115     for (;;)
  1053 					KTestFindSettingsPatternArgs[i].iPattern,
  1116         {
  1054 					numfound,
  1117         const TUint32* nextcat = catiter.NextKey();
  1055 					elids,
  1118         if (!nextcat)
  1056 					(k & 0x1 ? types : NULL),
  1119             {
  1057 					(k & 0x2 ? lens : NULL));
  1120             break;
  1058 				test_Compare(0, <=, r);
  1121             }
  1059 				
  1122         test.Printf(_L("Category %08x"), *nextcat);
  1060 				numfound = r;
  1123         const TInt* v = numsettings.Find(*nextcat);
  1061 			
  1124         test_NotNull(v);
  1062 				test.Printf(_L("%d match(es)\n"), r);
  1125 
  1063 
  1126 
  1064 				// Check that all returned element ids satisfy the conditions
  1127 
  1065 				TUint l;
  1128         for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
  1066 				for (l = 0; l < numfound; l++)
  1129             {
  1067 					{
  1130             test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
  1068 					test_Assert(
  1131                     KTestFindSettingsPatternArgs[i].iMask,
  1069 						(KTestFindSettingsPatternArgs[i].iMask & KTestFindSettingsPatternArgs[i].iPattern) ==
  1132                     KTestFindSettingsPatternArgs[i].iPattern);
  1070 						(KTestFindSettingsPatternArgs[i].iMask & elids[l]), test.Printf(_L("!!%08x!!\n"), elids[l])
  1133 
  1071 						);
  1134             TUint k;
  1072 					//Somehow the macro test_Compare consider TInt32 instead TUint32
  1135             for (k = 0; k < 3; k++)
  1073 					//as a result comparasion is done by this way:
  1136                 {
  1074 					//RTEST: (0x0 (0) < 0x80000000 (-2147483648)) == EFalse at line 1038
  1137                 TUint32 numfound;
  1075 					//althought 0x80000000 > 0, with the signed form this number will be
  1138 
  1076 					//-2147483648.
  1139                 // aMaxNum is less than the total number of settings in the 
  1077 					//test_Compare(KTestFindSettingsPatternArgs[i].iAtId, <=, elids[l]);
  1140                 // category
  1078 					}
  1141                 //0 - all elements from the category are requested
  1079 
  1142                 //1 - 1/2 of total number of elements from the category
  1080 				// Check that all elements that satisfy the conditions have been returned
  1143                 //2 - 1 + 1/2 of total number of element from the category
  1081 				SSettingC* setting;
  1144                 if(k == 0)
  1082 				TUint32 numsettings = 0;
  1145                     maxNum = *v;
  1083 				for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
  1146                 else if(k == 1)
  1084 					{
  1147                     maxNum = _FRACTION((*v), 2);
  1085 					if ((setting->iName.iId.iCat == KTestCategories[j])
  1148                 else
  1086 						&& ((KTestFindSettingsPatternArgs[i].iMask & KTestFindSettingsPatternArgs[i].iPattern) ==
  1149                     maxNum = (*v) + _FRACTION((*v), 2);
  1087 							(KTestFindSettingsPatternArgs[i].iMask & setting->iName.iId.iKey)))
  1150 
  1088 						{
  1151                 elids = (TElementId*) User::Alloc(maxNum * sizeof(TElementId));
  1089 						for (l = 0; l < numfound; l++)
  1152                 test_NotNull(elids);
  1090 							{
  1153                 types = (TSettingType*) User::Alloc(maxNum * sizeof(TSettingType));
  1091 							if (setting->iName.iId.iKey == elids[l])
  1154                 test_NotNull(types);
  1092 								{
  1155                 lens = (TUint16*) User::Alloc(maxNum * sizeof(TUint16));
  1093 								break;
  1156                 test_NotNull(lens);
  1094 								}
  1157 
  1095 							}
  1158 
  1096 						test_Assert(l < numfound, test.Printf(_L("!!%08x!!\n"), elids[l]));
  1159                 // Actual API call
  1097 
  1160                 r = HcrSimTest.FindSettings(
  1098 						// Check type and size returned
  1161                         *nextcat,
  1099 						switch (setting->iName.iType)
  1162                         maxNum,
  1100 							{
  1163                         KTestFindSettingsPatternArgs[i].iMask,
  1101 							case ETypeInt32:
  1164                         KTestFindSettingsPatternArgs[i].iPattern,
  1102 							case ETypeInt16:
  1165                         elids,
  1103 							case ETypeInt8:
  1166                         (k & 0x1 ? types : NULL),
  1104 							case ETypeBool:
  1167                         (k & 0x2 ? lens : NULL));
  1105 							case ETypeUInt32:
  1168                 test_Compare(0, <=, r);
  1106 							case ETypeUInt16:
  1169                 test_Compare(maxNum, >=, r);
  1107 							case ETypeUInt8:
  1170 
  1108 							case ETypeLinAddr:
  1171                 numfound = r;
  1109 								if (k & 0x1)
  1172                 test.Printf(_L("%d match(es)\n"), r);
  1110 									{
  1173 
  1111 									test_Equal(setting->iName.iType, types[l]);
  1174                 // Check that all returned element ids satisfy the conditions
  1112 									}
  1175                 TUint32 l;
  1113 								if (k & 0x2)
  1176                 for (l = 0; l < numfound; l++)
  1114 									{
  1177                     {
  1115 									test_Equal(0, lens[l]);
  1178                     test_Assert(
  1116 									}
  1179                             (KTestFindSettingsPatternArgs[i].iMask & KTestFindSettingsPatternArgs[i].iPattern) ==
  1117 								break;
  1180                             (KTestFindSettingsPatternArgs[i].iMask & elids[l]), test.Printf(_L("!!%08x!!\n"), elids[l])
  1118 								// Fall-through
  1181                     );
  1119 							case ETypeBinData:
  1182 
  1120 							case ETypeText8:
  1183                     //Somehow the macro test_Compare consider TInt32 instead TUint32
  1121 							case ETypeArrayInt32:
  1184                     //as a result comparasion is done by this way:
  1122 							case ETypeArrayUInt32:
  1185                     //RTEST: (0x0 (0) < 0x80000000 (-2147483648)) == EFalse at line 1038
  1123 							case ETypeInt64:
  1186                     //althought 0x80000000 > 0, with the signed form this number will be
  1124 							case ETypeUInt64:
  1187                     //-2147483648.
  1125 								if (k & 0x1)
  1188                     //test_Compare(KTestFindSettingsPatternArgs[i].iAtId, <=, elids[l]);
  1126 									{
  1189                     }
  1127 									test_Equal(setting->iName.iType, types[l]);
  1190 
  1128 									}
  1191                 // Check that all elements that satisfy the conditions have been returned
  1129 								if (k & 0x2)
  1192                 SSettingC* setting;
  1130 									{
  1193                 TUint32 numsettings = 0;
  1131 									test_Equal(setting->iName.iLen, lens[l]);
  1194 
  1132 									}
  1195                 //Flag indicates that the element is found
  1133 								break;
  1196                 TBool fFlag = EFalse;
  1134 							default:
  1197 
  1135 								test(EFalse);
  1198                 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
  1136 							}
  1199                     {
  1137 						numsettings++;
  1200                     if ((setting->iName.iId.iCat == *nextcat)
  1138 						}
  1201                             && ((KTestFindSettingsPatternArgs[i].iMask & KTestFindSettingsPatternArgs[i].iPattern) ==
  1139 					}
  1202                             (KTestFindSettingsPatternArgs[i].iMask & setting->iName.iId.iKey)))
  1140 				test_Equal(numsettings, numfound);
  1203                         {
  1141 				}
  1204                         for (l = 0; l < numfound; l++)
  1142 			}
  1205                             {
  1143 		}
  1206                             if (setting->iName.iId.iKey == elids[l])
  1144 		
  1207                                 {
  1145 	// Free memory
  1208                                 fFlag = ETrue;
  1146 	User::Free(elids);
  1209                                 break;
  1147 	User::Free(types);
  1210                                 }
  1148 	User::Free(lens);
  1211                             }
       
  1212 
       
  1213                         if(fFlag)
       
  1214                             {
       
  1215                             test_Assert(l < numfound, test.Printf(_L("!!%08x!!\n"), elids[l]));
       
  1216 
       
  1217                             // Check type and size returned
       
  1218                             switch (setting->iName.iType)
       
  1219                                 {
       
  1220                                 case ETypeInt32:
       
  1221                                 case ETypeInt16:
       
  1222                                 case ETypeInt8:
       
  1223                                 case ETypeBool:
       
  1224                                 case ETypeUInt32:
       
  1225                                 case ETypeUInt16:
       
  1226                                 case ETypeUInt8:
       
  1227                                 case ETypeLinAddr:
       
  1228                                     if (k & 0x1)
       
  1229                                         {
       
  1230                                         test_Equal(setting->iName.iType, types[l]);
       
  1231                                         }
       
  1232                                      if (k & 0x2)
       
  1233                                         {
       
  1234                                         test_Equal(0, lens[l]);
       
  1235                                         }
       
  1236                                     break;
       
  1237                                     // Fall-through
       
  1238                                 case ETypeBinData:
       
  1239                                 case ETypeText8:
       
  1240                                 case ETypeArrayInt32:
       
  1241                                 case ETypeArrayUInt32:
       
  1242                                 case ETypeInt64:
       
  1243                                 case ETypeUInt64:
       
  1244                                     if (k & 0x1)
       
  1245                                         {
       
  1246                                         test_Equal(setting->iName.iType, types[l]);
       
  1247                                         }
       
  1248                                     if (k & 0x2)
       
  1249                                         {
       
  1250                                         test_Equal(setting->iName.iLen, lens[l]);
       
  1251                                         }
       
  1252                                     break;
       
  1253                                 default:
       
  1254                                     test(EFalse);
       
  1255                                 }
       
  1256                             numsettings++;
       
  1257                             fFlag = EFalse;
       
  1258                             }
       
  1259                         }
       
  1260                     }
       
  1261                 
       
  1262                 test_Equal(numsettings, numfound);
       
  1263 
       
  1264                 // Free memory
       
  1265                 User::Free(elids);
       
  1266                 User::Free(types);
       
  1267                 User::Free(lens);
       
  1268 
       
  1269                 }
       
  1270             }
       
  1271         }
       
  1272     numsettings.Close();
  1149 	}
  1273 	}
       
  1274 
       
  1275 
       
  1276 
       
  1277 void HcrSimFindSettingsCategoryNegative(SSettingC* aRepository, TUint aNumberOfSettings)
       
  1278     {
       
  1279     
       
  1280     TInt r;
       
  1281     // Build a hash table with number of settings for each category
       
  1282     RHashMap<TUint32, TInt> numsettings;
       
  1283     SSettingC* setting;
       
  1284     TInt* pV = NULL;
       
  1285     TInt value = 0;
       
  1286     //Iterator object of the number of elements in the category
       
  1287     RHashMap<TUint32, TInt>::TIter catiter(numsettings);
       
  1288 
       
  1289     
       
  1290     test.Next(_L("FindSettingsCategoryNegative invalid user parameters"));
       
  1291         for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
       
  1292             {
       
  1293             pV = numsettings.Find(setting->iName.iId.iCat);
       
  1294             if(pV)
       
  1295                 value = *pV;
       
  1296             if (!pV)
       
  1297                 {
       
  1298                 r = numsettings.Insert(setting->iName.iId.iCat, 1);
       
  1299                 test_KErrNone(r);
       
  1300                 }
       
  1301             else
       
  1302                 {
       
  1303                 r = numsettings.Remove(setting->iName.iId.iCat);
       
  1304                 test_KErrNone(r);
       
  1305                 r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
       
  1306                 test_KErrNone(r);
       
  1307                 }
       
  1308             }
       
  1309 
       
  1310         // 
       
  1311         for (;;)
       
  1312             {
       
  1313             const TUint32* nextcat = catiter.NextKey();
       
  1314             if (!nextcat)
       
  1315                 {
       
  1316                 break;
       
  1317                 }
       
  1318             test.Printf(_L("Category %08x"), *nextcat);
       
  1319             const TInt* v = numsettings.Find(*nextcat);
       
  1320             test_NotNull(v);
       
  1321 
       
  1322             // Allocate memory for holding array of settings
       
  1323             TElementId* elids;
       
  1324             TSettingType* types;
       
  1325             TUint16* lens;
       
  1326             elids = (TElementId*) User::Alloc(*v * sizeof(TElementId));
       
  1327             test_NotNull(elids);
       
  1328             types = (TSettingType*) User::Alloc(*v * sizeof(TSettingType));
       
  1329             test_NotNull(types);
       
  1330             lens = (TUint16*) User::Alloc(*v * sizeof(TUint16));
       
  1331             test_NotNull(lens);
       
  1332 
       
  1333             
       
  1334             test.Printf(_L("."));
       
  1335             Mem::Fill(elids, *v * sizeof(TElementId), 0xcc);
       
  1336             Mem::Fill(types, *v * sizeof(TSettingType), 0xcc);
       
  1337             Mem::Fill(lens, *v * sizeof(TUint16), 0xcc);
       
  1338 
       
  1339             TInt i;
       
  1340             for (i = 0; i < 3; i++)
       
  1341                 {
       
  1342                 //Perform the following permutations:
       
  1343                 // 0 - negative aMaxNum AND aElIds != NULL
       
  1344                 // 1 - positive aMaxNum AND aElIds == NULL
       
  1345                 // 2 - negative aMaxNum AND aElIds == NULL
       
  1346                 
       
  1347                 switch(i)
       
  1348                     {
       
  1349                     case 0:
       
  1350                         r = HcrSimTest.FindSettings(*nextcat,
       
  1351                                 (-1)*(*v), elids, types, lens);
       
  1352 
       
  1353                         test_Equal(KErrArgument, r);
       
  1354                         break;
       
  1355 
       
  1356                     case 1:
       
  1357                         r = HcrSimTest.FindSettings(*nextcat,
       
  1358                                 *v, NULL, types, lens);
       
  1359 
       
  1360                         test_Equal(KErrArgument, r);
       
  1361                         break;
       
  1362 
       
  1363                     case 2:
       
  1364                         r = HcrSimTest.FindSettings(*nextcat,
       
  1365                                 (-1)*(*v), NULL, types, lens);
       
  1366 
       
  1367                         test_Equal(KErrArgument, r);
       
  1368                         break;
       
  1369                     
       
  1370                     }
       
  1371                 }
       
  1372 
       
  1373 
       
  1374                 User::Free(elids);
       
  1375                 User::Free(types);
       
  1376                 User::Free(lens);
       
  1377                 test.Printf(_L("\n"));
       
  1378             }
       
  1379         numsettings.Close();
       
  1380 
       
  1381     }
       
  1382 
       
  1383 
       
  1384 void HcrSimFindSettingsPatternNegative(TUint aNumberOfSettings)
       
  1385     {
       
  1386     
       
  1387     TInt r;
       
  1388     TUint i;
       
  1389 
       
  1390     // Allocate memory for holding array of settings
       
  1391     TElementId* elids;
       
  1392     TSettingType* types;
       
  1393     TUint16* lens;
       
  1394     elids = (TElementId*) User::Alloc(aNumberOfSettings * sizeof(TElementId));
       
  1395     test_NotNull(elids);
       
  1396     types = (TSettingType*) User::Alloc(aNumberOfSettings * sizeof(TSettingType));
       
  1397     test_NotNull(types);
       
  1398     lens = (TUint16*) User::Alloc(aNumberOfSettings * sizeof(TUint16));
       
  1399     test_NotNull(lens);
       
  1400 
       
  1401     test.Next(_L("FindSettingsPattern, invalid user parameters"));
       
  1402     for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
       
  1403         {
       
  1404         test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
       
  1405                 KTestFindSettingsPatternArgs[i].iMask,
       
  1406                 KTestFindSettingsPatternArgs[i].iPattern);
       
  1407 
       
  1408         // Test each category
       
  1409         TUint j;
       
  1410         for (j = 0; j < sizeof(KTestCategories) / sizeof(TCategoryUid); j++)
       
  1411             {
       
  1412             test.Printf(_L("Category 0x%08x: "), KTestCategories[j]);
       
  1413 
       
  1414             // Test all possible permutations of optional arguments
       
  1415             TInt k;
       
  1416             for (k = 0; k < 3; k++)
       
  1417                 {
       
  1418                 //Perform the following permutations:
       
  1419                 // 0 - negative aMaxNum AND aElIds != NULL
       
  1420                 // 1 - positive aMaxNum AND aElIds == NULL
       
  1421                 // 2 - negative aMaxNum AND aElIds == NULL
       
  1422                 
       
  1423                 switch(k)
       
  1424                     {
       
  1425                     case 0:
       
  1426                     // Actual API call
       
  1427                     r = HcrSimTest.FindSettings(
       
  1428                             KTestCategories[j],
       
  1429                             (-1) * static_cast<TInt>(aNumberOfSettings),
       
  1430                             KTestFindSettingsPatternArgs[i].iMask,
       
  1431                             KTestFindSettingsPatternArgs[i].iPattern,
       
  1432                             elids,
       
  1433                             types, lens);
       
  1434                     test_Equal(KErrArgument,r);
       
  1435                     break;
       
  1436 
       
  1437                     
       
  1438                     case 1:
       
  1439                         // Actual API call
       
  1440                         r = HcrSimTest.FindSettings(
       
  1441                                 KTestCategories[j],
       
  1442                                 aNumberOfSettings,
       
  1443                                 KTestFindSettingsPatternArgs[i].iMask,
       
  1444                                 KTestFindSettingsPatternArgs[i].iPattern,
       
  1445                                 NULL,
       
  1446                                 types, lens);
       
  1447                         test_Equal(KErrArgument,r);
       
  1448                         break;
       
  1449 
       
  1450                         
       
  1451                     case 2:
       
  1452                         // Actual API call
       
  1453                         r = HcrSimTest.FindSettings(
       
  1454                                 KTestCategories[j],
       
  1455                                 (-1) * static_cast<TInt>(aNumberOfSettings),
       
  1456                                 KTestFindSettingsPatternArgs[i].iMask,
       
  1457                                 KTestFindSettingsPatternArgs[i].iPattern,
       
  1458                                 NULL,
       
  1459                                 types, lens);
       
  1460                         test_Equal(KErrArgument,r);
       
  1461                         break;
       
  1462                 
       
  1463                     }
       
  1464                 
       
  1465                 }
       
  1466             }
       
  1467         }
       
  1468     
       
  1469     // Free memory
       
  1470     User::Free(elids);
       
  1471     User::Free(types);
       
  1472     User::Free(lens);
       
  1473     }        
       
  1474 
       
  1475          
       
  1476             
       
  1477 
       
  1478 void HcrSimFindSettingsPatternMemAllocFails(TUint aNumberOfSettings)
       
  1479     {
       
  1480     TInt r;
       
  1481     TUint i;
       
  1482 
       
  1483     // Allocate memory for holding array of settings
       
  1484     TElementId* elids;
       
  1485     TSettingType* types;
       
  1486     TUint16* lens;
       
  1487     elids = (TElementId*) User::Alloc(aNumberOfSettings * sizeof(TElementId));
       
  1488     test_NotNull(elids);
       
  1489     types = (TSettingType*) User::Alloc(aNumberOfSettings * sizeof(TSettingType));
       
  1490     test_NotNull(types);
       
  1491     lens = (TUint16*) User::Alloc(aNumberOfSettings * sizeof(TUint16));
       
  1492     test_NotNull(lens);
       
  1493 
       
  1494     test.Next(_L("FindSettingsPattern, memory allocation failure"));
       
  1495     for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
       
  1496         {
       
  1497         test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
       
  1498                 KTestFindSettingsPatternArgs[i].iMask,
       
  1499                 KTestFindSettingsPatternArgs[i].iPattern);
       
  1500 
       
  1501         // Test each category
       
  1502         TUint j;
       
  1503         for (j = 0; j < sizeof(KTestCategories) / sizeof(TCategoryUid); j++)
       
  1504             {
       
  1505             test.Printf(_L("Category 0x%08x: "), KTestCategories[j]);
       
  1506             //Memory allocation fail test. By this code we simulate the memory
       
  1507             //allocation failure at place defined by allocFactor. The loop will 
       
  1508             //continue until the next allocation is not failed. When we reached 
       
  1509             //this point it means we've gone through all possible allocations in
       
  1510             //the tested method below.
       
  1511             TInt allocFactor = 1;
       
  1512             //Memory allocation fails
       
  1513             do
       
  1514                 {
       
  1515                 __KHEAP_MARK;
       
  1516                 __KHEAP_SETFAIL(RAllocator::EFailNext, allocFactor);
       
  1517                 r = HcrSimTest.FindSettings(
       
  1518                         KTestCategories[j],
       
  1519                         aNumberOfSettings,
       
  1520                         KTestFindSettingsPatternArgs[i].iMask,
       
  1521                         KTestFindSettingsPatternArgs[i].iPattern,
       
  1522                         elids,
       
  1523                         types, lens);
       
  1524                 __KHEAP_MARKEND;
       
  1525 
       
  1526                 __KHEAP_RESET;
       
  1527 
       
  1528                 //Let's arrise the memory allocation failure at another place
       
  1529                 allocFactor ++;
       
  1530 
       
  1531                 }while(r == KErrNoMemory);
       
  1532 
       
  1533             }
       
  1534         }
       
  1535 
       
  1536 
       
  1537 
       
  1538     // Free memory
       
  1539     User::Free(elids);
       
  1540     User::Free(types);
       
  1541     User::Free(lens);
       
  1542 
       
  1543     }
       
  1544 
  1150 
  1545 
  1151 void HcrSimApiNegative(const TInt aExpectedErrorCode, const TUint32 aCategory, const TUint32 aSettingId)
  1546 void HcrSimApiNegative(const TInt aExpectedErrorCode, const TUint32 aCategory, const TUint32 aSettingId)
  1152 	{
  1547 	{
  1153 	test.Next(_L("ApiNegative"));
  1548 	test.Next(_L("ApiNegative"));
  1154 	test.Printf(_L("Expected error: %d\nSetting (%08x, %08x)\n"), aExpectedErrorCode, aCategory, aSettingId);
  1549 	test.Printf(_L("Expected error: %d\nSetting (%08x, %08x)\n"), aExpectedErrorCode, aCategory, aSettingId);
  1258 		}
  1653 		}
  1259 
  1654 
  1260 		{
  1655 		{
  1261 		TSettingType type = ETypeUndefined;
  1656 		TSettingType type = ETypeUndefined;
  1262 		TUint16 len = 0;
  1657 		TUint16 len = 0;
  1263 		TUint32 numfound = 0;
       
  1264 		TElementId elid = 0;
  1658 		TElementId elid = 0;
  1265 		
  1659 		
  1266 
  1660 
  1267 		//
  1661 		//
  1268 		r = HcrSimTest.GetTypeAndSize(id, type, len);
  1662 		r = HcrSimTest.GetTypeAndSize(id, type, len);
  1272 		r = HcrSimTest.FindNumSettingsInCategory(id.iCat);
  1666 		r = HcrSimTest.FindNumSettingsInCategory(id.iCat);
  1273 		if (aExpectedErrorCode == KErrNotFound)
  1667 		if (aExpectedErrorCode == KErrNotFound)
  1274 			{
  1668 			{
  1275 			test_Equal(0, r);
  1669 			test_Equal(0, r);
  1276 			}
  1670 			}
       
  1671 		else
       
  1672 			{
       
  1673 			test_Equal(aExpectedErrorCode, r);
       
  1674 			}
  1277 		
  1675 		
  1278 		//
  1676 		//
  1279 		r = HcrSimTest.FindSettings(id.iCat, 1, numfound, &elid, &type, &len);
  1677 		r = HcrSimTest.FindSettings(id.iCat, 1, &elid, &type, &len);
  1280 		if (aExpectedErrorCode == KErrNotFound)
  1678 		if (aExpectedErrorCode == KErrNotFound)
  1281 			{
  1679 			{
  1282 			test_Equal(0, r);
  1680 			test_Equal(0, r);
  1283 			}
  1681 			}
       
  1682 		else
       
  1683 			{
       
  1684 			test_Equal(aExpectedErrorCode, r);
       
  1685 			}
  1284 
  1686 
  1285 		//
  1687 		//
  1286 		r = HcrSimTest.FindSettings(id.iCat, 1, 0, 0, numfound, &elid, &type, &len);
  1688 		r = HcrSimTest.FindSettings(id.iCat, 1, 0, 0, &elid, &type, &len);
  1287 		if (aExpectedErrorCode == KErrNotFound)
  1689 		if (aExpectedErrorCode == KErrNotFound)
  1288 			{
  1690 			{
  1289 			test_Equal(0, r);
  1691 			test_Equal(0, r);
  1290 			}
  1692 			}
  1291 		
  1693 		else
       
  1694 			{
       
  1695 			test_Equal(aExpectedErrorCode, r);
       
  1696 			}
  1292 		}
  1697 		}
  1293 		{
  1698 		{
  1294 		SSettingId settingid;
  1699 		SSettingId settingid;
  1295 		settingid.iCat = id.iCat;
  1700 		settingid.iCat = id.iCat;
  1296 		settingid.iKey = id.iKey;	
  1701 		settingid.iKey = id.iKey;	
  1298 		TInt32 val;
  1703 		TInt32 val;
  1299 		TInt err;
  1704 		TInt err;
  1300 		TSettingType type;
  1705 		TSettingType type;
  1301 		TInt i;
  1706 		TInt i;
  1302 
  1707 
  1303 		for(i = 0; i < 4; ++i)
  1708 		for(i = 0; i < 5; ++i)
  1304 			{
  1709 			{
  1305 			// test parameter combinations where aIds[], aValues[], aErrors[] are NULL
  1710 			// test parameter combinations where aIds[], aValues[], aErrors[] are NULL
  1306 			r = HcrSimTest.GetWordSettings(i, (i==1)?NULL:&settingid, (i==2)?NULL:&val, &type, (i==3)?NULL:&err);
  1711 			r = HcrSimTest.GetWordSettings((i==1)?0:1, (i==2)?NULL:&settingid, (i==3)?NULL:&val, &type, (i==4)?NULL:&err);
  1307 			if(r != KErrArgument)
  1712 			if (aExpectedErrorCode != KErrNotFound)
  1308 				{
  1713 				{
       
  1714 				// HCR did not initialise properly - HCR will not bother checking validity of arguments
  1309 				test_Equal(aExpectedErrorCode, r);
  1715 				test_Equal(aExpectedErrorCode, r);
  1310 				}
  1716 				}
       
  1717 			else if (i > 0)
       
  1718 				{
       
  1719 				// One of the arguments is invalid
       
  1720 				test_Equal(KErrArgument, r);
       
  1721 				}
       
  1722 			else
       
  1723 				{
       
  1724 				// Arguments are fine but element does not exist
       
  1725 				test_Equal(0, r);
       
  1726 				}
  1311 			}	
  1727 			}	
  1312 		}
  1728 		}
  1313 
  1729 
  1314 	}
  1730 	}
       
  1731 
  1315 
  1732 
  1316 void HcrSimTestApiTests(SSettingC* aRepository, TUint aNumberOfSettings)
  1733 void HcrSimTestApiTests(SSettingC* aRepository, TUint aNumberOfSettings)
  1317 	{
  1734 	{
  1318 	if (aRepository && aNumberOfSettings > 0)
  1735 	if (aRepository && aNumberOfSettings > 0)
  1319 		{
  1736 		{
  1322 		HcrSimSettingProperties(aRepository, aNumberOfSettings);
  1739 		HcrSimSettingProperties(aRepository, aNumberOfSettings);
  1323 		HcrSimMultipleGet(aRepository, aNumberOfSettings);
  1740 		HcrSimMultipleGet(aRepository, aNumberOfSettings);
  1324 		HcrSimNumSettingsInCategory(aRepository, aNumberOfSettings);
  1741 		HcrSimNumSettingsInCategory(aRepository, aNumberOfSettings);
  1325 		HcrSimFindSettingsCategory(aRepository, aNumberOfSettings);
  1742 		HcrSimFindSettingsCategory(aRepository, aNumberOfSettings);
  1326 		HcrSimFindSettingsPattern(aRepository, aNumberOfSettings);
  1743 		HcrSimFindSettingsPattern(aRepository, aNumberOfSettings);
       
  1744 		
       
  1745 		HcrSimFindSettingsCategoryNegative(aRepository, aNumberOfSettings);
       
  1746 		HcrSimFindSettingsPatternNegative(aNumberOfSettings);
       
  1747 		if(gHcrThread == KSimOwnThread)
       
  1748 		    HcrSimFindSettingsPatternMemAllocFails(aNumberOfSettings);
  1327 		}
  1749 		}
  1328 
  1750 
  1329 	HcrSimApiNegative(KErrNotFound, KTestInvalidCategory, KTestInvalidSettingId);
  1751 	HcrSimApiNegative(KErrNotFound, KTestInvalidCategory, KTestInvalidSettingId);
  1330 	HcrSimApiNegative(KErrNotFound, KTestInvalidCategory, 1);
  1752 	HcrSimApiNegative(KErrNotFound, KTestInvalidCategory, 1);
  1331 	}
  1753 	}
  1383 	{
  1805 	{
  1384 	test.Next(_L("HCR Simulator tests"));
  1806 	test.Next(_L("HCR Simulator tests"));
  1385 	test.Start(_L("Load Device Driver"));
  1807 	test.Start(_L("Load Device Driver"));
  1386 	test.Printf(_L("%S\n"), &aDriver);
  1808 	test.Printf(_L("%S\n"), &aDriver);
  1387 	TInt r;
  1809 	TInt r;
       
  1810 	
  1388 	r = User::LoadLogicalDevice(aDriver);
  1811 	r = User::LoadLogicalDevice(aDriver);
  1389 	if (r == KErrAlreadyExists)
  1812 	if (r == KErrAlreadyExists)
  1390 		{
  1813 		{
  1391 		test.Printf(_L("Unload Device Driver and load it again\n"));
  1814 		test.Printf(_L("Unload Device Driver and load it again\n"));
  1392 		r = User::FreeLogicalDevice(aDriver);
  1815 		r = User::FreeLogicalDevice(aDriver);
  1406 	
  1829 	
  1407 	test.Next(_L("Initialise HCR"));
  1830 	test.Next(_L("Initialise HCR"));
  1408 	r = HcrSimTest.InitExtension();
  1831 	r = HcrSimTest.InitExtension();
  1409 	test_KErrNone(r);
  1832 	test_KErrNone(r);
  1410 	
  1833 	
       
  1834 	//Initialize static variable with the right HCR client type
       
  1835 	if(aDriver.Compare(KTestHcrSimOwn) == 0)
       
  1836 	    gHcrThread = KSimOwnThread;
       
  1837 	else if(aDriver.Compare(KTestHcrSimClient) == 0)
       
  1838 	    gHcrThread = KSimClientThread;
       
  1839 	else
       
  1840 		test(EFalse);
       
  1841 	
  1411 	test.Next(_L("Compiled"));
  1842 	test.Next(_L("Compiled"));
  1412 	test.Start(_L("Initialisation"));
  1843 	test.Start(_L("Initialisation"));
  1413 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
  1844 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
  1414 	test_KErrNone(r);
  1845 	test_KErrNone(r);
  1415 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  1846 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  1416 	test_KErrNone(r);
  1847 	test_KErrNone(r);
  1417 	HcrSimTestApiTests(SettingsList, sizeof(SettingsList) / sizeof(SSettingC));
  1848 	HcrSimTestApiTests(SettingsList, sizeof(SettingsList) / sizeof(SSettingC));
  1418 	test.End();
  1849 	test.End();    
  1419 
  1850 		
  1420 	test.Next(_L("Compiled+File"));
  1851 	test.Next(_L("Compiled+File"));
  1421 	test.Start(_L("Initialisation"));
  1852 	test.Start(_L("Initialisation"));
  1422 	r = HcrSimTest.SwitchRepository(KTestFileRepos, HCRInternal::ECoreRepos);
  1853 	r = HcrSimTest.SwitchRepository(KTestFileRepos, HCRInternal::ECoreRepos);
  1423 	test_KErrNone(r);
  1854 	test_KErrNone(r);
  1424 	r = HcrSimTest.CheckIntegrity();
  1855 	r = HcrSimTest.CheckIntegrity();
  1532 	r = HcrSimTest.CheckIntegrity();
  1963 	r = HcrSimTest.CheckIntegrity();
  1533 	test_KErrNone(r);
  1964 	test_KErrNone(r);
  1534 	HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
  1965 	HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
  1535 	test.End();
  1966 	test.End();
  1536 
  1967 
       
  1968 	test.Next(_L("Empty+File+Empty"));
       
  1969 	test.Start(_L("Initialisation"));
       
  1970 	r = HcrSimTest.SwitchRepository(KTestEmpty, HCRInternal::EOverrideRepos);
       
  1971 	test_KErrNone(r);
       
  1972 	r = HcrSimTest.CheckIntegrity();
       
  1973 	test_KErrNone(r);
       
  1974 	HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
       
  1975 	test.End();
       
  1976 
  1537 	test.Next(_L("No Repository (Empty)"));
  1977 	test.Next(_L("No Repository (Empty)"));
  1538 	test.Start(_L("Initialisation"));
  1978 	test.Start(_L("Initialisation"));
  1539 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
  1979 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
       
  1980 	test_KErrNone(r);
       
  1981 	r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
  1540 	test_KErrNone(r);
  1982 	test_KErrNone(r);
  1541 	r = HcrSimTest.CheckIntegrity();
  1983 	r = HcrSimTest.CheckIntegrity();
  1542 	test_KErrNone(r);
  1984 	test_KErrNone(r);
  1543 	HcrSimTestApiTests(NULL, 0);
  1985 	HcrSimTestApiTests(NULL, 0);
  1544 	test.End();
  1986 	test.End();
  1702 		TInt nosettings;
  2144 		TInt nosettings;
  1703 		nosettings = HcrSimTest.FindNumSettingsInCategory(cat);
  2145 		nosettings = HcrSimTest.FindNumSettingsInCategory(cat);
  1704 		test_Compare(0, <=, nosettings);
  2146 		test_Compare(0, <=, nosettings);
  1705 		if (nosettings > 0)
  2147 		if (nosettings > 0)
  1706 			{
  2148 			{
  1707 			TUint32 numfound;
       
  1708 			TElementId* elids;
  2149 			TElementId* elids;
  1709 			TSettingType* types;
  2150 			TSettingType* types;
  1710 			TUint16* lens;
  2151 			TUint16* lens;
  1711 			elids = (TElementId*) User::Alloc(nosettings * sizeof(TElementId));
  2152 			elids = (TElementId*) User::Alloc(nosettings * sizeof(TElementId));
  1712 			test_NotNull(elids);
  2153 			test_NotNull(elids);
  1713 			types = (TSettingType*) User::Alloc(nosettings * sizeof(TSettingType));
  2154 			types = (TSettingType*) User::Alloc(nosettings * sizeof(TSettingType));
  1714 			test_NotNull(types);
  2155 			test_NotNull(types);
  1715 			lens = (TUint16*) User::Alloc(nosettings * sizeof(TUint16));
  2156 			lens = (TUint16*) User::Alloc(nosettings * sizeof(TUint16));
  1716 			test_NotNull(lens);
  2157 			test_NotNull(lens);
  1717 			r = HcrSimTest.FindSettings(cat, nosettings, numfound, elids, types, lens);
  2158 			r = HcrSimTest.FindSettings(cat, nosettings, elids, types, lens);
  1718 			test_Equal(nosettings, r);
  2159 			test_Equal(nosettings, r);
  1719 			test_Equal(nosettings, numfound);
  2160 			
  1720 			TInt i;
  2161 			TInt i;
  1721 			for (i = 0; i < nosettings; i++)
  2162 			for (i = 0; i < nosettings; i++)
  1722 				{
  2163 				{
  1723 				TSettingId id(cat, *(elids + i));
  2164 				TSettingId id(cat, *(elids + i));
  1724 				test.Printf(_L("%08x %08x %08x %04x "), cat, *(elids + i), *(types + i), *(lens + i));
  2165 				test.Printf(_L("%08x %08x %08x %04x "), cat, *(elids + i), *(types + i), *(lens + i));
  1955 		r = HcrSimTest.Open(aDriver);
  2396 		r = HcrSimTest.Open(aDriver);
  1956 		test_KErrNone(r);
  2397 		test_KErrNone(r);
  1957 		//
  2398 		//
  1958 		HcrRealRetrieveKernelExtensionTestResults();
  2399 		HcrRealRetrieveKernelExtensionTestResults();
  1959 		HcrRealSettingDiscovery();
  2400 		HcrRealSettingDiscovery();
       
  2401 
       
  2402 		// Initialize static variable with the right HCR client type
       
  2403 		if(aDriver.Compare(KTestHcrRealOwn) == 0)
       
  2404 			gHcrThread = KSimOwnThread;
       
  2405 		else if(aDriver.Compare(KTestHcrRealClient) == 0)
       
  2406 			gHcrThread = KSimClientThread;
       
  2407 		else
       
  2408 			test(EFalse);
       
  2409 		//
       
  2410 		TBool smr;
       
  2411 		TBool smrrep;
       
  2412 		r = HcrSimTest.HasRepositoryInSmr(smr, smrrep);
       
  2413 		test_KErrNone(r);
       
  2414 		if (smrrep)
       
  2415 			{
       
  2416 			// File + NAND
       
  2417 			HcrSimTestApiTests(SettingsList6, sizeof(SettingsList6) / sizeof(SSettingC));
       
  2418 			}
       
  2419 		else
       
  2420 			{
       
  2421 			// File
       
  2422 			HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
       
  2423 			}
  1960 		//
  2424 		//
  1961 		test.Next(_L("Close LDD"));
  2425 		test.Next(_L("Close LDD"));
  1962 		HcrSimTest.Close();
  2426 		HcrSimTest.Close();
  1963 		r = User::FreeLogicalDevice(aDriver);
  2427 		r = User::FreeLogicalDevice(aDriver);
  1964 		test_KErrNone(r);
  2428 		test_KErrNone(r);
  2129 	{
  2593 	{
  2130 	__UHEAP_MARK;
  2594 	__UHEAP_MARK;
  2131 
  2595 
  2132 	test.Title();
  2596 	test.Title();
  2133 	test.Start(_L("HCR Test Suite"));
  2597 	test.Start(_L("HCR Test Suite"));
  2134 	
  2598 		
  2135 	
       
  2136 	
  2599 	
  2137 	//Order the the test lists in descend(the setting with the smallest
  2600 	//Order the the test lists in descend(the setting with the smallest
  2138 	//setting Id is first)
  2601 	//setting Id is first)
  2139 	TLinearOrder<SSettingC> order(CompareEntries);
  2602 	TLinearOrder<SSettingC> order(CompareEntries);
  2140 	//Build the ordered ids arrays
  2603 	//Build the ordered ids arrays
  2165 
  2628 
  2166 	RArray<SSettingC> rSettingsList7(sizeof(SSettingC), SettingsList7,
  2629 	RArray<SSettingC> rSettingsList7(sizeof(SSettingC), SettingsList7,
  2167 			sizeof(SettingsList7)/sizeof(SettingsList7[0]));
  2630 			sizeof(SettingsList7)/sizeof(SettingsList7[0]));
  2168 	rSettingsList7.Sort(order);
  2631 	rSettingsList7.Sort(order);
  2169 
  2632 
  2170 
  2633 	
  2171     //Functional API tests
  2634     //Functional API test
  2172 	RomHeaderTests();
  2635 	RomHeaderTests();
  2173 	HcrRealTests(KTestHcrRealOwn);
  2636 	HcrRealTests(KTestHcrRealOwn);
  2174 	HcrRealTests(KTestHcrRealClient);
  2637 	HcrRealTests(KTestHcrRealClient);
  2175 	HcrPslTests(KTestHcrSimOwn);
  2638 	HcrPslTests(KTestHcrSimOwn);
  2176 	HcrPslTests(KTestHcrSimClient);
  2639 	HcrPslTests(KTestHcrSimClient);