Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Hardware Configuration Respoitory Test Application
17 #define __E32TEST_EXTENSION__
21 #include <e32hashtab.h>
24 #include "d_hcrsim_testdata.h"
27 _LIT8(KTestFileRepos, "filerepos.dat");
28 _LIT8(KTestNandRepos, "nandrepos.dat");
29 _LIT8(KTestCorrupt1, "corrupt1.dat");
30 _LIT8(KTestCorrupt2, "corrupt2.dat");
31 _LIT8(KTestEmpty, "empty.dat");
32 _LIT8(KTestMegaLarge1, "megalarge1.dat");
33 _LIT8(KTestMegaLarge2, "megalarge2.dat");
34 _LIT8(KTestClearRepos, "");
37 static const TInt KSimOwnThread = 0;
38 static const TInt KSimClientThread = 1;
39 static TInt gHcrThread = KSimOwnThread;
41 //Calculation of the fraction defined by f for the number x
42 #define _FRACTION(x, f) (x>f ? x/f : x)
45 RTest test(_L("T_HCR"));
46 RHcrSimTestChannel HcrSimTest;
48 //Helper function to compare two SSettingId parameters. It's used in
49 //GetMultipleWord settings array
50 TInt CompareEntries (const SSettingC& a1, const SSettingC& a2)
52 if (a1.iName.iId.iCat > a2.iName.iId.iCat)
55 if (a1.iName.iId.iCat < a2.iName.iId.iCat)
58 // Categories are the same at this point, check keys.
59 if (a1.iName.iId.iKey > a2.iName.iId.iKey)
62 if (a1.iName.iId.iKey < a2.iName.iId.iKey)
65 // Both Categories and jeys are the same here.
71 void HcrSimGetSettings(SSettingC* aRepository, TUint aNumberOfSettings)
73 test.Next(_L("GetSettings"));
76 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
78 TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey);
79 test.Printf(_L("(0x%08x, 0x%08x)\n"), id.iCat, id.iKey);
80 switch (setting->iName.iType)
85 r = HcrSimTest.GetInt(id, val);
87 test_Equal(setting->iValue.iLit.iInt32, val);
93 r = HcrSimTest.GetInt(id, val);
95 test_Equal(setting->iValue.iLit.iInt16, val);
101 r = HcrSimTest.GetInt(id, val);
103 test_Equal(setting->iValue.iLit.iInt8, val);
109 r = HcrSimTest.GetBool(id, val);
111 test_Equal(setting->iValue.iLit.iBool, val);
117 r = HcrSimTest.GetUInt(id, val);
119 test_Equal(setting->iValue.iLit.iUInt32, val);
125 r = HcrSimTest.GetUInt(id, val);
127 test_Equal(setting->iValue.iLit.iUInt16, val);
133 r = HcrSimTest.GetUInt(id, val);
135 test_Equal(setting->iValue.iLit.iUInt8, val);
141 r = HcrSimTest.GetLinAddr(id, val);
143 test_Equal(setting->iValue.iLit.iAddress, val);
148 TBuf8<KMaxSettingLength> dval;
150 pval = (TUint8*) User::Alloc(setting->iName.iLen);
153 r = HcrSimTest.GetData(id, dval);
156 TUint16 actuallength;
157 r = HcrSimTest.GetData(id, setting->iName.iLen, pval, actuallength);
160 test_Equal(0, Mem::Compare(
161 setting->iValue.iPtr.iData, setting->iName.iLen,
162 pval, actuallength));
163 test_Equal(0, Mem::Compare(
164 setting->iValue.iPtr.iData, setting->iName.iLen,
165 dval.Ptr(), dval.Length()));
171 TBuf8<KMaxSettingLength> dval;
173 pval = (TText8*) User::Alloc(setting->iName.iLen);
176 r = HcrSimTest.GetString(id, dval);
179 TUint16 actuallength;
180 r = HcrSimTest.GetString(id, setting->iName.iLen, pval, actuallength);
183 test_Equal(0, Mem::Compare(
184 setting->iValue.iPtr.iString8, setting->iName.iLen,
185 pval, actuallength));
186 test_Equal(0, Mem::Compare(
187 setting->iValue.iPtr.iString8, setting->iName.iLen,
188 dval.Ptr(), dval.Length()));
192 case ETypeArrayInt32:
195 pval = (TInt32*) User::Alloc(setting->iName.iLen);
198 TUint16 actuallength;
199 r = HcrSimTest.GetArray(id, setting->iName.iLen, pval, actuallength);
202 test_Equal(setting->iName.iLen, actuallength);
203 TInt32* pexpected = setting->iValue.iPtr.iArrayInt32;
205 for (i = 0; i < setting->iName.iLen / sizeof(TInt32); i++)
207 test_Equal(*(pexpected + i), *(pval + i));
212 case ETypeArrayUInt32:
215 pval = (TUint32*) User::Alloc(setting->iName.iLen);
218 TUint16 actuallength;
219 r = HcrSimTest.GetArray(id, setting->iName.iLen, pval, actuallength);
222 test_Equal(setting->iName.iLen, actuallength);
223 TUint32* pexpected = setting->iValue.iPtr.iArrayUInt32;
225 for (i = 0; i < setting->iName.iLen / sizeof(TUint32); i++)
227 test_Equal(*(pexpected + i), *(pval + i));
235 r = HcrSimTest.GetInt(id, val);
237 test_Equal(*setting->iValue.iPtr.iInt64, val);
243 r = HcrSimTest.GetUInt(id, val);
245 test_Equal(*setting->iValue.iPtr.iUInt64, val);
254 void HcrSimGetSettingsNegative(SSettingC* aRepository, TUint aNumberOfSettings)
256 test.Next(_L("GetSettingsNegative"));
259 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
261 TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey);
262 test.Printf(_L("(0x%08x, 0x%08x)\n"), id.iCat, id.iKey);
263 if (setting->iName.iType != ETypeInt32)
266 r = HcrSimTest.GetInt(id, val);
267 test_Equal(KErrArgument, r);
269 if (setting->iName.iType != ETypeInt16)
272 r = HcrSimTest.GetInt(id, val);
273 test_Equal(KErrArgument, r);
275 if (setting->iName.iType != ETypeInt8)
278 r = HcrSimTest.GetInt(id, val);
279 test_Equal(KErrArgument, r);
281 if (setting->iName.iType != ETypeBool)
284 r = HcrSimTest.GetBool(id, val);
285 test_Equal(KErrArgument, r);
287 if (setting->iName.iType != ETypeUInt32)
290 r = HcrSimTest.GetUInt(id, val);
291 test_Equal(KErrArgument, r);
293 if (setting->iName.iType != ETypeUInt16)
296 r = HcrSimTest.GetUInt(id, val);
297 test_Equal(KErrArgument, r);
299 if (setting->iName.iType != ETypeUInt8)
302 r = HcrSimTest.GetUInt(id, val);
303 test_Equal(KErrArgument, r);
305 if (setting->iName.iType != ETypeLinAddr)
308 r = HcrSimTest.GetLinAddr(id, val);
309 test_Equal(KErrArgument, r);
311 if (setting->iName.iType != ETypeBinData)
313 TBuf8<KMaxSettingLength> dval;
315 pval = (TUint8*) User::Alloc(setting->iName.iLen);
318 r = HcrSimTest.GetData(id, dval);
319 test_Equal(KErrArgument, r);
321 TUint16 actuallength;
322 r = HcrSimTest.GetData(id, setting->iName.iLen, pval, actuallength);
323 test_Equal(KErrArgument, r);
327 else if (setting->iName.iLen > 1)
330 r = dval.Create(setting->iName.iLen - 1);
332 r = HcrSimTest.GetData(id, dval);
333 test_Equal(KErrTooBig, r);
337 pval = (TUint8*) User::Alloc(setting->iName.iLen);
340 TUint16 actuallength;
341 r = HcrSimTest.GetData(id, (unsigned short)( setting->iName.iLen - 1), pval, actuallength);
342 test_Equal(KErrTooBig, r);
346 if (setting->iName.iType != ETypeText8)
348 TBuf8<KMaxSettingLength> dval;
350 pval = (TText8*) User::Alloc(setting->iName.iLen);
353 r = HcrSimTest.GetString(id, dval);
354 test_Equal(KErrArgument, r);
356 TUint16 actuallength;
357 r = HcrSimTest.GetString(id, setting->iName.iLen, pval, actuallength);
358 test_Equal(KErrArgument, r);
362 else if (setting->iName.iLen > 1)
365 r = dval.Create(setting->iName.iLen - 1);
367 r = HcrSimTest.GetString(id, dval);
368 test_Equal(KErrTooBig, r);
372 pval = (TText8*) User::Alloc(setting->iName.iLen);
375 TUint16 actuallength;
376 r = HcrSimTest.GetString(id, (unsigned short)(setting->iName.iLen >> 1), pval, actuallength);
377 test_Equal(KErrTooBig, r);
381 if (setting->iName.iType != ETypeArrayInt32)
384 pval = (TInt32*) User::Alloc(setting->iName.iLen);
387 TUint16 actuallength;
388 r = HcrSimTest.GetArray(id, setting->iName.iLen, pval, actuallength);
389 test_Equal(KErrArgument, r);
396 pval = (TInt32*) User::Alloc(setting->iName.iLen);
399 TUint16 actuallength;
400 r = HcrSimTest.GetArray(id, (TUint16) (setting->iName.iLen >> 1), pval, actuallength);
401 test_Equal(KErrTooBig, r);
405 if (setting->iName.iType != ETypeArrayUInt32)
408 pval = (TUint32*) User::Alloc(setting->iName.iLen);
411 TUint16 actuallength;
412 r = HcrSimTest.GetArray(id, setting->iName.iLen, pval, actuallength);
413 test_Equal(KErrArgument, r);
417 if (setting->iName.iType != ETypeInt64)
420 r = HcrSimTest.GetInt(id, val);
421 test_Equal(KErrArgument, r);
423 if (setting->iName.iType != ETypeUInt64)
426 r = HcrSimTest.GetUInt(id, val);
427 test_Equal(KErrArgument, r);
432 void HcrSimSettingProperties(SSettingC* aRepository, TUint aNumberOfSettings)
434 test.Next(_L("SettingProperties"));
437 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
439 TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey);
440 test.Printf(_L("(0x%08x, 0x%08x)\n"), id.iCat, id.iKey);
441 TSettingType type = ETypeUndefined;
442 TUint16 size = KMaxSettingLength + 1;
443 r = HcrSimTest.GetTypeAndSize(id, type, size);
445 switch (setting->iName.iType)
455 test_Equal(setting->iName.iType, type);
461 case ETypeArrayInt32:
462 case ETypeArrayUInt32:
465 test_Equal(setting->iName.iType, type);
466 test_Equal(setting->iName.iLen, size);
471 test.Printf(_L("."));
473 test.Printf(_L("\n"));
476 void HcrSimMultipleGet(SSettingC* aRepository, TUint aNumberOfSettings)
478 test.Next(_L("MultipleGet"));
480 SSettingId largesetting;
481 largesetting.iCat = 0;
482 largesetting.iKey = 0;
491 test.Start(_L("Multiple Get on individual settings"));
493 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
495 if (setting->iName.iType < 0x00010000)
497 test.Printf(_L("(0x%08x, 0x%08x)\n"), id.iCat, id.iKey);
505 test.Next(_L("Multiple Get, with non-existing category or element id"));
507 // Try all permutations of optional values
508 // i == 0 || i == 1 Just a single setting from the repostitory
509 // i == 2 || i == 3 Valid category and invalid element id
510 // i == 4 || i == 5 Invalid category and valid element id
511 // i == 6 || i == 7 Invalid category and element id
512 for (i = 0; i < 8; i++)
514 //Just a single setting from the repository
517 //test.Printf(_L("Single setting, valid element && valid category\n"));
518 id.iCat = setting->iName.iId.iCat;
519 id.iKey = setting->iName.iId.iKey;
521 //test.Printf(_L("-Permutation %02x\n"), i);
522 r = HcrSimTest.GetWordSettings(1, &id, &val,
523 (i & 0x1 ? &type : NULL), &err);
524 //HCR should return 1
526 test_Equal(setting->iValue.iLit.iInt32, val);
529 test_Equal(setting->iName.iType, type);
535 //Valid category and invalid element id
538 //test.Printf(_L("Single setting, invalid element && valid category\n"));
539 id.iCat = setting->iName.iId.iCat;
540 id.iKey = KTestInvalidSettingId;
543 r = HcrSimTest.GetWordSettings(1, &id, &val,
544 (i & 0x1 ? &type : NULL), &err);
546 //HCR should return 0
551 //HCR returns ETypeUndefined
555 test_Equal(KErrNotFound,err);
558 //Invalid category and valid element id
561 id.iCat = KTestInvalidCategory;
562 id.iKey = setting->iName.iId.iKey;
564 //test.Printf(_L("Single setting, invalid element && valid category\n"));
565 r = HcrSimTest.GetWordSettings(1, &id, &val,
566 (i & 0x1 ? &type : NULL), &err);
567 //HCR should return 1
572 //HCR returns ETypeUndefined
576 test_Equal(KErrNotFound, err);
579 //Invalid category and element id
582 id.iCat = KTestInvalidCategory;
583 id.iKey = KTestInvalidSettingId;
585 //test.Printf(_L("Single setting, invalid element && valid category\n"));
586 r = HcrSimTest.GetWordSettings(1, &id, &val,
587 (i & 0x1 ? &type : NULL), &err);
588 //HCR should return 1
593 //HCR returns ETypeUndefined
596 test_Equal(KErrNotFound, err);
600 else if (largesetting.iKey == 0)
603 largesetting.iCat = setting->iName.iId.iCat;
604 largesetting.iKey = setting->iName.iId.iKey;
610 test.Next(_L("Multiple Get, some user input parameters are wrong"));
614 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
616 if (setting->iName.iType < 0x00010000)
620 test_Compare(0, <, nosettings);
630 ids = (SSettingId*) User::Alloc(sizeof(SSettingId) * nosettings);
632 vals = (TInt32*) User::Alloc(sizeof(TInt32) * nosettings);
634 types = (TSettingType*) User::Alloc(sizeof(TSettingType) * nosettings);
636 errs = (TInt*) User::Alloc(sizeof(TInt) * nosettings);
641 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
643 if (setting->iName.iType < 0x00010000)
645 ids[n].iCat = setting->iName.iId.iCat;
646 ids[n].iKey = setting->iName.iId.iKey;
650 test_Equal(nosettings, n);
654 test.Next(_L("Number of settings is negative \n"));
655 r = HcrSimTest.GetWordSettings(-1 * nosettings, ids, vals, types, errs);
657 //HCR returns KErrArgument
658 test_Equal(KErrArgument, r);
661 test.Printf(_L("Pointer to errors array is NULL \n"));
662 r = HcrSimTest.GetWordSettings(nosettings, ids, vals, types, NULL);
664 //HCR returns KErrArgument
665 test_Equal(KErrArgument, r);
668 test.Printf(_L("Pointer to ids is NULL \n"));
669 r = HcrSimTest.GetWordSettings(nosettings, NULL, vals, types, errs);
671 //HCR returns KErrArgument
672 test_Equal(KErrArgument, r);
681 test.Next(_L("Multiple Get on all settings"));
683 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
685 if (setting->iName.iType < 0x00010000)
689 test_Compare(0, <, nosettings);
692 ids = (SSettingId*) User::Alloc(sizeof(SSettingId) * nosettings);
694 vals = (TInt32*) User::Alloc(sizeof(TInt32) * nosettings);
696 types = (TSettingType*) User::Alloc(sizeof(TSettingType) * nosettings);
698 errs = (TInt*) User::Alloc(sizeof(TInt) * nosettings);
703 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
705 if (setting->iName.iType < 0x00010000)
707 ids[n].iCat = setting->iName.iId.iCat;
708 ids[n].iKey = setting->iName.iId.iKey;
712 test_Equal(nosettings, n);
715 // Try all permutations of optional values
717 for (i = 0; i < 2; i++)
719 r = HcrSimTest.GetWordSettings(nosettings, ids, vals,
720 (i & 0x1 ? types : NULL), errs);
721 //HCR returns number of found elements
722 test_Equal(nosettings, r);
726 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
728 if (setting->iName.iType < 0x00010000)
730 test_Equal(setting->iValue.iLit.iInt32, vals[n]);
733 test_Equal(setting->iName.iType,types[n]);
735 test_KErrNone(errs[n]);
739 test_Equal(nosettings, n);
746 test.Next(_L("Multiple Get on all settings + inexistent"));
748 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
750 if (setting->iName.iType < 0x00010000)
754 test_Compare(0, <, nosettings);
756 ids = (SSettingId*) User::Alloc(sizeof(SSettingId) * nosettings);
758 vals = (TInt32*) User::Alloc(sizeof(TInt32) * nosettings);
760 types = (TSettingType*) User::Alloc(sizeof(TSettingType) * nosettings);
762 errs = (TInt*) User::Alloc(sizeof(TInt) * nosettings);
764 ids[0].iCat = KTestInvalidCategory;
765 ids[0].iKey = KTestInvalidSettingId;
769 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
771 if (setting->iName.iType < 0x00010000)
773 ids[n].iCat = setting->iName.iId.iCat;
774 ids[n].iKey = setting->iName.iId.iKey;
779 test_Equal(nosettings, n);
781 // Try all permutations of optional values
782 for (i = 0; i < 2; i++)
784 r = HcrSimTest.GetWordSettings(nosettings, ids, vals,
785 (i & 0x1 ? types : NULL), errs);
786 test_Equal(nosettings - 1, r);
791 test_Equal(ETypeUndefined, types[0]);
793 test_Equal(KErrNotFound, errs[0]);
796 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
798 if (setting->iName.iType < 0x00010000)
800 test_Equal(setting->iValue.iLit.iInt32, vals[n]);
803 test_Equal(setting->iName.iType, types[n]);
806 test_KErrNone(errs[n]);
811 test_Equal(nosettings, n);
818 test.Next(_L("Multiple Get on a large setting"));
819 if (largesetting.iKey)
824 r = HcrSimTest.GetWordSettings(1, &largesetting, &value, &type, &theerror);
826 test_Equal(KErrArgument, theerror);
830 test.Printf(_L("No large setting found in repositories!\n"));
835 void HcrSimNumSettingsInCategory(SSettingC* aRepository, TUint aNumberOfSettings)
837 test.Next(_L("NumSettingsInCategory"));
839 // Build a hash table with number of settings for each category
840 RHashMap<TUint32, TInt> numsettings;
844 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
846 pV = numsettings.Find(setting->iName.iId.iCat);
851 r = numsettings.Insert(setting->iName.iId.iCat, 1);
856 r = numsettings.Remove(setting->iName.iId.iCat);
858 r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
863 // Now compare hash table with values returned by FindNumSettingsInCategory
864 RHashMap<TUint32, TInt>::TIter catiter(numsettings);
867 const TUint32* nextcat = catiter.NextKey();
872 test.Printf(_L("Category %08x\n"), *nextcat);
873 const TInt* v = numsettings.Find(*nextcat);
875 r = HcrSimTest.FindNumSettingsInCategory(*nextcat);
883 void HcrSimFindSettingsCategory(SSettingC* aRepository, TUint aNumberOfSettings)
885 test.Next(_L("FindSettingsCategory"));
888 // Build a hash table with number of settings for each category
889 RHashMap<TUint32, TInt> numsettings;
893 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
895 pV = numsettings.Find(setting->iName.iId.iCat);
900 r = numsettings.Insert(setting->iName.iId.iCat, 1);
905 r = numsettings.Remove(setting->iName.iId.iCat);
907 r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
913 RHashMap<TUint32, TInt>::TIter catiter(numsettings);
916 const TUint32* nextcat = catiter.NextKey();
921 test.Printf(_L("Category %08x"), *nextcat);
922 const TInt* v = numsettings.Find(*nextcat);
925 // Allocate memory for holding array of settings
933 // Try all permutations of optional values
935 for (i = 0; i < 3; i++)
937 test.Printf(_L("."));
942 //0 - 1, the total elements from the category
943 //1 - 1/2 of total number of elements from the category
944 //2 - 1 + 1/2 of total number of element from the category
949 maxNum = _FRACTION((*v), 2);
951 maxNum = *v + _FRACTION((*v), 2);
954 elids = (TElementId*) User::Alloc(maxNum * sizeof(TElementId));
956 types = (TSettingType*) User::Alloc(maxNum * sizeof(TSettingType));
958 lens = (TUint16*) User::Alloc(maxNum * sizeof(TUint16));
961 Mem::Fill(elids, maxNum * sizeof(TElementId), 0xcc);
962 Mem::Fill(types, maxNum * sizeof(TSettingType), 0xcc);
963 Mem::Fill(lens, maxNum * sizeof(TUint16), 0xcc);
966 r = HcrSimTest.FindSettings(*nextcat,
968 i & 0x1 ? types : NULL,
969 i & 0x2 ? lens : NULL);
971 test_Compare(0, <=, r);
975 //for 0 & 1 the number of settings returned must be equal maxNum
976 test_Equal(maxNum, r);
980 //for 2, it's equal the real number of settings
986 // Check returned list of element ids
988 for (j = 0; j < numfound; j++)
990 // Find current element in the test array
991 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
993 if ((setting->iName.iId.iCat == *nextcat) && (setting->iName.iId.iKey == elids[j]))
998 test_Compare(setting,<,aRepository+aNumberOfSettings); // Fail if element not found
999 switch (setting->iName.iType)
1011 test_Equal(setting->iName.iType, types[j]);
1015 test_Equal(0, lens[j]);
1021 case ETypeArrayInt32:
1022 case ETypeArrayUInt32:
1027 test_Equal(setting->iName.iType, types[j]);
1031 test_Equal(setting->iName.iLen, lens[j]);
1038 // Check all expected elements are in the returned list of element ids
1039 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
1041 if ((setting->iName.iId.iCat == *nextcat))
1043 for (j = 0; j < numfound; j++)
1045 if (elids[j] == setting->iName.iId.iKey)
1050 test_Compare(j, <=, numfound);
1059 test.Printf(_L("\n"));
1061 numsettings.Close();
1064 struct TTestFindSettingsPatternArgs
1070 const TTestFindSettingsPatternArgs KTestFindSettingsPatternArgs[] = {
1072 {0x00000000, 0x00000000},
1073 {0xfffffff0, 0x00000000},
1074 {0xffffffff, 0x00000001}
1077 void HcrSimFindSettingsPattern(SSettingC* aRepository, TUint aNumberOfSettings)
1079 test.Next(_L("FindSettingsPattern"));
1083 // Allocate memory for holding array of settings
1085 TSettingType* types;
1089 // Build a hash table with number of settings for each category
1090 RHashMap<TUint32, TInt> numsettings;
1094 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
1096 pV = numsettings.Find(setting->iName.iId.iCat);
1101 r = numsettings.Insert(setting->iName.iId.iCat, 1);
1106 r = numsettings.Remove(setting->iName.iId.iCat);
1108 r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
1113 // Hash map includes the number of settings of each category
1114 RHashMap<TUint32, TInt>::TIter catiter(numsettings);
1117 const TUint32* nextcat = catiter.NextKey();
1122 test.Printf(_L("Category %08x"), *nextcat);
1123 const TInt* v = numsettings.Find(*nextcat);
1128 for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
1130 test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
1131 KTestFindSettingsPatternArgs[i].iMask,
1132 KTestFindSettingsPatternArgs[i].iPattern);
1135 for (k = 0; k < 3; k++)
1139 // aMaxNum is less than the total number of settings in the
1141 //0 - all elements from the category are requested
1142 //1 - 1/2 of total number of elements from the category
1143 //2 - 1 + 1/2 of total number of element from the category
1147 maxNum = _FRACTION((*v), 2);
1149 maxNum = (*v) + _FRACTION((*v), 2);
1151 elids = (TElementId*) User::Alloc(maxNum * sizeof(TElementId));
1152 test_NotNull(elids);
1153 types = (TSettingType*) User::Alloc(maxNum * sizeof(TSettingType));
1154 test_NotNull(types);
1155 lens = (TUint16*) User::Alloc(maxNum * sizeof(TUint16));
1160 r = HcrSimTest.FindSettings(
1163 KTestFindSettingsPatternArgs[i].iMask,
1164 KTestFindSettingsPatternArgs[i].iPattern,
1166 (k & 0x1 ? types : NULL),
1167 (k & 0x2 ? lens : NULL));
1168 test_Compare(0, <=, r);
1169 test_Compare(maxNum, >=, r);
1172 test.Printf(_L("%d match(es)\n"), r);
1174 // Check that all returned element ids satisfy the conditions
1176 for (l = 0; l < numfound; l++)
1179 (KTestFindSettingsPatternArgs[i].iMask & KTestFindSettingsPatternArgs[i].iPattern) ==
1180 (KTestFindSettingsPatternArgs[i].iMask & elids[l]), test.Printf(_L("!!%08x!!\n"), elids[l])
1183 //Somehow the macro test_Compare consider TInt32 instead TUint32
1184 //as a result comparasion is done by this way:
1185 //RTEST: (0x0 (0) < 0x80000000 (-2147483648)) == EFalse at line 1038
1186 //althought 0x80000000 > 0, with the signed form this number will be
1188 //test_Compare(KTestFindSettingsPatternArgs[i].iAtId, <=, elids[l]);
1191 // Check that all elements that satisfy the conditions have been returned
1193 TUint32 numsettings = 0;
1195 //Flag indicates that the element is found
1196 TBool fFlag = EFalse;
1198 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
1200 if ((setting->iName.iId.iCat == *nextcat)
1201 && ((KTestFindSettingsPatternArgs[i].iMask & KTestFindSettingsPatternArgs[i].iPattern) ==
1202 (KTestFindSettingsPatternArgs[i].iMask & setting->iName.iId.iKey)))
1204 for (l = 0; l < numfound; l++)
1206 if (setting->iName.iId.iKey == elids[l])
1215 test_Assert(l < numfound, test.Printf(_L("!!%08x!!\n"), elids[l]));
1217 // Check type and size returned
1218 switch (setting->iName.iType)
1230 test_Equal(setting->iName.iType, types[l]);
1234 test_Equal(0, lens[l]);
1240 case ETypeArrayInt32:
1241 case ETypeArrayUInt32:
1246 test_Equal(setting->iName.iType, types[l]);
1250 test_Equal(setting->iName.iLen, lens[l]);
1262 test_Equal(numsettings, numfound);
1272 numsettings.Close();
1277 void HcrSimFindSettingsCategoryNegative(SSettingC* aRepository, TUint aNumberOfSettings)
1281 // Build a hash table with number of settings for each category
1282 RHashMap<TUint32, TInt> numsettings;
1286 //Iterator object of the number of elements in the category
1287 RHashMap<TUint32, TInt>::TIter catiter(numsettings);
1290 test.Next(_L("FindSettingsCategoryNegative invalid user parameters"));
1291 for (setting = aRepository; setting < aRepository + aNumberOfSettings; setting++)
1293 pV = numsettings.Find(setting->iName.iId.iCat);
1298 r = numsettings.Insert(setting->iName.iId.iCat, 1);
1303 r = numsettings.Remove(setting->iName.iId.iCat);
1305 r = numsettings.Insert(setting->iName.iId.iCat, value + 1);
1313 const TUint32* nextcat = catiter.NextKey();
1318 test.Printf(_L("Category %08x"), *nextcat);
1319 const TInt* v = numsettings.Find(*nextcat);
1322 // Allocate memory for holding array of settings
1324 TSettingType* types;
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));
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);
1340 for (i = 0; i < 3; i++)
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
1350 r = HcrSimTest.FindSettings(*nextcat,
1351 (-1)*(*v), elids, types, lens);
1353 test_Equal(KErrArgument, r);
1357 r = HcrSimTest.FindSettings(*nextcat,
1358 *v, NULL, types, lens);
1360 test_Equal(KErrArgument, r);
1364 r = HcrSimTest.FindSettings(*nextcat,
1365 (-1)*(*v), NULL, types, lens);
1367 test_Equal(KErrArgument, r);
1377 test.Printf(_L("\n"));
1379 numsettings.Close();
1384 void HcrSimFindSettingsPatternNegative(TUint aNumberOfSettings)
1390 // Allocate memory for holding array of settings
1392 TSettingType* types;
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));
1401 test.Next(_L("FindSettingsPattern, invalid user parameters"));
1402 for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
1404 test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
1405 KTestFindSettingsPatternArgs[i].iMask,
1406 KTestFindSettingsPatternArgs[i].iPattern);
1408 // Test each category
1410 for (j = 0; j < sizeof(KTestCategories) / sizeof(TCategoryUid); j++)
1412 test.Printf(_L("Category 0x%08x: "), KTestCategories[j]);
1414 // Test all possible permutations of optional arguments
1416 for (k = 0; k < 3; k++)
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
1427 r = HcrSimTest.FindSettings(
1429 (-1) * static_cast<TInt>(aNumberOfSettings),
1430 KTestFindSettingsPatternArgs[i].iMask,
1431 KTestFindSettingsPatternArgs[i].iPattern,
1434 test_Equal(KErrArgument,r);
1440 r = HcrSimTest.FindSettings(
1443 KTestFindSettingsPatternArgs[i].iMask,
1444 KTestFindSettingsPatternArgs[i].iPattern,
1447 test_Equal(KErrArgument,r);
1453 r = HcrSimTest.FindSettings(
1455 (-1) * static_cast<TInt>(aNumberOfSettings),
1456 KTestFindSettingsPatternArgs[i].iMask,
1457 KTestFindSettingsPatternArgs[i].iPattern,
1460 test_Equal(KErrArgument,r);
1478 void HcrSimFindSettingsPatternMemAllocFails(TUint aNumberOfSettings)
1483 // Allocate memory for holding array of settings
1485 TSettingType* types;
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));
1494 test.Next(_L("FindSettingsPattern, memory allocation failure"));
1495 for (i = 0; i < sizeof(KTestFindSettingsPatternArgs) / sizeof(TTestFindSettingsPatternArgs); i++)
1497 test.Printf(_L("iMask=0x%08x iPattern=0x%08x\n"),
1498 KTestFindSettingsPatternArgs[i].iMask,
1499 KTestFindSettingsPatternArgs[i].iPattern);
1501 // Test each category
1503 for (j = 0; j < sizeof(KTestCategories) / sizeof(TCategoryUid); j++)
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
1516 __KHEAP_SETFAIL(RAllocator::EFailNext, allocFactor);
1517 r = HcrSimTest.FindSettings(
1520 KTestFindSettingsPatternArgs[i].iMask,
1521 KTestFindSettingsPatternArgs[i].iPattern,
1528 //Let's arrise the memory allocation failure at another place
1531 }while(r == KErrNoMemory);
1546 void HcrSimApiNegative(const TInt aExpectedErrorCode, const TUint32 aCategory, const TUint32 aSettingId)
1548 test.Next(_L("ApiNegative"));
1549 test.Printf(_L("Expected error: %d\nSetting (%08x, %08x)\n"), aExpectedErrorCode, aCategory, aSettingId);
1550 TSettingId id(aCategory, aSettingId);
1554 r = HcrSimTest.GetInt(id, val);
1555 test_Equal(aExpectedErrorCode, r);
1559 r = HcrSimTest.GetInt(id, val);
1560 test_Equal(aExpectedErrorCode, r);
1564 r = HcrSimTest.GetInt(id, val);
1565 test_Equal(aExpectedErrorCode, r);
1569 r = HcrSimTest.GetBool(id, val);
1570 test_Equal(aExpectedErrorCode, r);
1574 r = HcrSimTest.GetUInt(id, val);
1575 test_Equal(aExpectedErrorCode, r);
1579 r = HcrSimTest.GetUInt(id, val);
1580 test_Equal(aExpectedErrorCode, r);
1584 r = HcrSimTest.GetUInt(id, val);
1585 test_Equal(aExpectedErrorCode, r);
1589 r = HcrSimTest.GetLinAddr(id, val);
1590 test_Equal(aExpectedErrorCode, r);
1593 TBuf8<KMaxSettingLength> dval;
1595 pval = (TUint8*) User::Alloc(KMaxSettingLength);
1598 r = HcrSimTest.GetData(id, dval);
1599 test_Equal(aExpectedErrorCode, r);
1601 TUint16 actuallength;
1602 r = HcrSimTest.GetData(id, KMaxSettingLength, pval, actuallength);
1603 test_Equal(aExpectedErrorCode, r);
1608 TBuf8<KMaxSettingLength> dval;
1610 pval = (TText8*) User::Alloc(KMaxSettingLength);
1613 r = HcrSimTest.GetString(id, dval);
1614 test_Equal(aExpectedErrorCode, r);
1616 TUint16 actuallength;
1617 r = HcrSimTest.GetString(id, KMaxSettingLength, pval, actuallength);
1618 test_Equal(aExpectedErrorCode, r);
1624 pval = (TInt32*) User::Alloc(KMaxSettingLength);
1627 TUint16 actuallength;
1628 r = HcrSimTest.GetArray(id, KMaxSettingLength, pval, actuallength);
1629 test_Equal(aExpectedErrorCode, r);
1635 pval = (TUint32*) User::Alloc(KMaxSettingLength);
1638 TUint16 actuallength;
1639 r = HcrSimTest.GetArray(id, KMaxSettingLength, pval, actuallength);
1640 test_Equal(aExpectedErrorCode, r);
1646 r = HcrSimTest.GetInt(id, val);
1647 test_Equal(aExpectedErrorCode, r);
1651 r = HcrSimTest.GetUInt(id, val);
1652 test_Equal(aExpectedErrorCode, r);
1656 TSettingType type = ETypeUndefined;
1658 TElementId elid = 0;
1662 r = HcrSimTest.GetTypeAndSize(id, type, len);
1663 test_Equal(aExpectedErrorCode, r);
1666 r = HcrSimTest.FindNumSettingsInCategory(id.iCat);
1667 if (aExpectedErrorCode == KErrNotFound)
1673 test_Equal(aExpectedErrorCode, r);
1677 r = HcrSimTest.FindSettings(id.iCat, 1, &elid, &type, &len);
1678 if (aExpectedErrorCode == KErrNotFound)
1684 test_Equal(aExpectedErrorCode, r);
1688 r = HcrSimTest.FindSettings(id.iCat, 1, 0, 0, &elid, &type, &len);
1689 if (aExpectedErrorCode == KErrNotFound)
1695 test_Equal(aExpectedErrorCode, r);
1699 SSettingId settingid;
1700 settingid.iCat = id.iCat;
1701 settingid.iKey = id.iKey;
1708 for(i = 0; i < 5; ++i)
1710 // test parameter combinations where aIds[], aValues[], aErrors[] are NULL
1711 r = HcrSimTest.GetWordSettings((i==1)?0:1, (i==2)?NULL:&settingid, (i==3)?NULL:&val, &type, (i==4)?NULL:&err);
1712 if (aExpectedErrorCode != KErrNotFound)
1714 // HCR did not initialise properly - HCR will not bother checking validity of arguments
1715 test_Equal(aExpectedErrorCode, r);
1719 // One of the arguments is invalid
1720 test_Equal(KErrArgument, r);
1724 // Arguments are fine but element does not exist
1733 void HcrSimTestApiTests(SSettingC* aRepository, TUint aNumberOfSettings)
1735 if (aRepository && aNumberOfSettings > 0)
1737 HcrSimGetSettings(aRepository, aNumberOfSettings);
1738 HcrSimGetSettingsNegative(aRepository, aNumberOfSettings);
1739 HcrSimSettingProperties(aRepository, aNumberOfSettings);
1740 HcrSimMultipleGet(aRepository, aNumberOfSettings);
1741 HcrSimNumSettingsInCategory(aRepository, aNumberOfSettings);
1742 HcrSimFindSettingsCategory(aRepository, aNumberOfSettings);
1743 HcrSimFindSettingsPattern(aRepository, aNumberOfSettings);
1745 HcrSimFindSettingsCategoryNegative(aRepository, aNumberOfSettings);
1746 HcrSimFindSettingsPatternNegative(aNumberOfSettings);
1747 if(gHcrThread == KSimOwnThread)
1748 HcrSimFindSettingsPatternMemAllocFails(aNumberOfSettings);
1751 HcrSimApiNegative(KErrNotFound, KTestInvalidCategory, KTestInvalidSettingId);
1752 HcrSimApiNegative(KErrNotFound, KTestInvalidCategory, 1);
1755 void HcrPslTests(const TDesC& aDriver)
1757 test.Next(_L("PSL tests"));
1758 test.Start(_L("Load Device Driver"));
1759 test.Printf(_L("%S\n"), &aDriver);
1761 r = User::LoadLogicalDevice(aDriver);
1762 if (r == KErrAlreadyExists)
1764 test.Printf(_L("Unload Device Driver and load it again\n"));
1765 r = User::FreeLogicalDevice(aDriver);
1767 r = User::LoadLogicalDevice(aDriver);
1775 test.Next(_L("Open test channel"));
1776 r = HcrSimTest.Open(aDriver);
1779 test.Next(_L("Fail PSL object creation"));
1780 r = HcrSimTest.InitExtension(ETestVariantObjectCreateFail);
1781 test_Equal(KErrNoMemory, r);
1782 HcrSimApiNegative(KErrNotReady, 1, 1);
1784 test.Next(_L("Fail PSL initialisation"));
1785 r = HcrSimTest.InitExtension(ETestInitialisationFail);
1786 test_Equal(KErrBadPower, r); // the random error code used in the test PSL
1787 HcrSimApiNegative(KErrNotReady, 1, 1);
1789 test.Next(_L("PSL's GetCompiledRepositoryAddress negative tests"));
1790 r = HcrSimTest.InitExtension(ETestNullRepositoryKErrNone); // *** Null Repository but returns KErrNone
1791 test_Equal(KErrArgument, r);
1793 test.Next(_L("PSL's GetCompiledRepositoryAddress return wrong error code"));
1794 r = HcrSimTest.InitExtension(ETestBadErrorCode); // *** Null Repository but returns KErrNone
1795 test_Equal(KErrCommsParity, r);
1797 test.Next(_L("Close test channel and unload device driver"));
1799 r = User::FreeLogicalDevice(aDriver);
1804 void HcrSimTests(const TDesC& aDriver)
1806 test.Next(_L("HCR Simulator tests"));
1807 test.Start(_L("Load Device Driver"));
1808 test.Printf(_L("%S\n"), &aDriver);
1811 r = User::LoadLogicalDevice(aDriver);
1812 if (r == KErrAlreadyExists)
1814 test.Printf(_L("Unload Device Driver and load it again\n"));
1815 r = User::FreeLogicalDevice(aDriver);
1817 r = User::LoadLogicalDevice(aDriver);
1825 test.Next(_L("Open test channel"));
1826 r = HcrSimTest.Open(aDriver);
1828 HcrSimApiNegative(KErrNotReady, 1, 1);
1830 test.Next(_L("Initialise HCR"));
1831 r = HcrSimTest.InitExtension();
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;
1842 test.Next(_L("Compiled"));
1843 test.Start(_L("Initialisation"));
1844 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
1846 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
1848 HcrSimTestApiTests(SettingsList, sizeof(SettingsList) / sizeof(SSettingC));
1851 test.Next(_L("Compiled+File"));
1852 test.Start(_L("Initialisation"));
1853 r = HcrSimTest.SwitchRepository(KTestFileRepos, HCRInternal::ECoreRepos);
1855 r = HcrSimTest.CheckIntegrity();
1857 HcrSimTestApiTests(SettingsList2, sizeof(SettingsList2) / sizeof(SSettingC));
1860 test.Next(_L("Compiled+File+Nand"));
1861 test.Start(_L("Initialisation"));
1862 r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
1864 r = HcrSimTest.CheckIntegrity();
1866 HcrSimTestApiTests(SettingsList3, sizeof(SettingsList3) / sizeof(SSettingC));
1869 test.Next(_L("Compiled+Nand"));
1870 test.Start(_L("Initialisation"));
1871 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
1873 r = HcrSimTest.CheckIntegrity();
1875 HcrSimTestApiTests(SettingsList4, sizeof(SettingsList4) / sizeof(SSettingC));
1878 test.Next(_L("Compiled+Empty+Nand"));
1879 test.Start(_L("Initialisation"));
1880 r = HcrSimTest.SwitchRepository(KTestEmpty, HCRInternal::ECoreRepos);
1882 r = HcrSimTest.CheckIntegrity();
1884 HcrSimTestApiTests(SettingsList4, sizeof(SettingsList4) / sizeof(SSettingC));
1887 // Reload device driver without a compiled repository this time
1888 test.Next(_L("Reload Device Driver"));
1890 r = User::FreeLogicalDevice(aDriver);
1892 r = User::LoadLogicalDevice(aDriver);
1894 r = HcrSimTest.Open(aDriver);
1896 r = HcrSimTest.InitExtension(ETestNullRepository); // *** The NULL Repository ***
1899 test.Next(_L("NULL+File"));
1900 test.Start(_L("Initialisation"));
1901 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
1903 r = HcrSimTest.CheckIntegrity();
1905 HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
1908 test.Next(_L("NULL+File+Nand"));
1909 test.Start(_L("Initialisation"));
1910 r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
1912 r = HcrSimTest.CheckIntegrity();
1914 HcrSimTestApiTests(SettingsList6, sizeof(SettingsList6) / sizeof(SSettingC));
1917 test.Next(_L("NULL+Nand"));
1918 test.Start(_L("Initialisation"));
1919 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
1921 r = HcrSimTest.CheckIntegrity();
1923 HcrSimTestApiTests(SettingsList5, sizeof(SettingsList5) / sizeof(SSettingC));
1926 test.Next(_L("Reload Device Driver"));
1928 r = User::FreeLogicalDevice(aDriver);
1930 r = User::LoadLogicalDevice(aDriver);
1932 r = HcrSimTest.Open(aDriver);
1934 r = HcrSimTest.InitExtension(ETestEmptyRepository); // *** The Empty Repository ***
1937 test.Next(_L("Empty+Nand"));
1938 test.Start(_L("Initialisation"));
1939 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
1941 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
1943 r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
1945 r = HcrSimTest.CheckIntegrity();
1947 HcrSimTestApiTests(SettingsList5, sizeof(SettingsList5) / sizeof(SSettingC));
1950 test.Next(_L("Empty+File+Nand"));
1951 test.Start(_L("Initialisation"));
1952 r = HcrSimTest.SwitchRepository(KTestFileRepos, HCRInternal::ECoreRepos);
1954 r = HcrSimTest.CheckIntegrity();
1956 HcrSimTestApiTests(SettingsList6, sizeof(SettingsList6) / sizeof(SSettingC));
1959 test.Next(_L("Empty+File"));
1960 test.Start(_L("Initialisation"));
1961 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
1963 r = HcrSimTest.CheckIntegrity();
1965 HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
1968 test.Next(_L("Empty+File+Empty"));
1969 test.Start(_L("Initialisation"));
1970 r = HcrSimTest.SwitchRepository(KTestEmpty, HCRInternal::EOverrideRepos);
1972 r = HcrSimTest.CheckIntegrity();
1974 HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
1977 test.Next(_L("No Repository (Empty)"));
1978 test.Start(_L("Initialisation"));
1979 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
1981 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
1983 r = HcrSimTest.CheckIntegrity();
1985 HcrSimTestApiTests(NULL, 0);
1988 test.Next(_L("All Repositories Empty"));
1989 test.Start(_L("Initialisation"));
1990 r = HcrSimTest.SwitchRepository(KTestEmpty, HCRInternal::ECoreRepos);
1992 r = HcrSimTest.SwitchRepository(KTestEmpty, HCRInternal::EOverrideRepos);
1994 r = HcrSimTest.CheckIntegrity();
1996 HcrSimTestApiTests(NULL, 0);
1999 test.Next(_L("Reload Device Driver"));
2001 r = User::FreeLogicalDevice(aDriver);
2003 r = User::LoadLogicalDevice(aDriver);
2005 r = HcrSimTest.Open(aDriver);
2007 r = HcrSimTest.InitExtension(ETestIgnoreCoreImgRepository); // *** Ignore Core Image Repository ***
2010 test.Next(_L("Compiled+File(Ignored)+Nand")); // Should be same as Compiled+Nand
2011 test.Start(_L("Initialisation"));
2012 r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
2014 r = HcrSimTest.CheckIntegrity();
2016 HcrSimTestApiTests(SettingsList4, sizeof(SettingsList4) / sizeof(SSettingC));
2019 test.Next(_L("Reload Device Driver (Corrupt1)"));
2021 r = User::FreeLogicalDevice(aDriver);
2023 r = User::LoadLogicalDevice(aDriver);
2025 r = HcrSimTest.Open(aDriver);
2027 r = HcrSimTest.InitExtension(ETestCorruptRepository1); // *** Repository not ordered ***
2029 test_Equal(KErrCorrupt, r);
2034 test.Next(_L("Reload Device Driver (Corrupt2)"));
2036 r = User::FreeLogicalDevice(aDriver);
2038 r = User::LoadLogicalDevice(aDriver);
2040 r = HcrSimTest.Open(aDriver);
2042 r = HcrSimTest.InitExtension(ETestCorruptRepository2); // *** Repository with duplicates ***
2044 test_Equal(KErrAlreadyExists, r);
2049 test.Next(_L("Reload Device Driver (NULL ordered list)"));
2051 r = User::FreeLogicalDevice(aDriver);
2053 r = User::LoadLogicalDevice(aDriver);
2055 r = HcrSimTest.Open(aDriver);
2057 r = HcrSimTest.InitExtension(ETestNullOrderedList); // *** Repository where iOrderedSettingList==NULL ***
2059 test_Equal(KErrNotFound, r);
2064 test.Next(_L("Reload Device Driver (Default)"));
2066 r = User::FreeLogicalDevice(aDriver);
2068 r = User::LoadLogicalDevice(aDriver);
2070 r = HcrSimTest.Open(aDriver);
2072 r = HcrSimTest.InitExtension(); // *** Default Repository ***
2075 test.Next(_L("Compiled+Corrupt1+Nand"));
2076 test.Start(_L("Initialisation"));
2077 r = HcrSimTest.SwitchRepository(KTestCorrupt1, HCRInternal::ECoreRepos);
2079 r = HcrSimTest.SwitchRepository(KTestNandRepos, HCRInternal::EOverrideRepos);
2081 r = HcrSimTest.CheckIntegrity();
2082 test_Equal(KErrCorrupt, r);
2085 test.Next(_L("Compiled+Corrupt2+Nand"));
2086 test.Start(_L("Initialisation"));
2087 r = HcrSimTest.SwitchRepository(KTestCorrupt2, HCRInternal::ECoreRepos);
2089 r = HcrSimTest.CheckIntegrity();
2090 test_Equal(KErrAlreadyExists, r);
2093 test.Next(_L("Compiled+File+Corrupt1"));
2094 test.Start(_L("Initialisation"));
2095 r = HcrSimTest.SwitchRepository(KTestFileRepos, HCRInternal::ECoreRepos);
2097 r = HcrSimTest.SwitchRepository(KTestCorrupt1, HCRInternal::EOverrideRepos);
2099 r = HcrSimTest.CheckIntegrity();
2100 test_Equal(KErrCorrupt, r);
2103 test.Next(_L("Compiled+File+Corrupt2"));
2104 test.Start(_L("Initialisation"));
2105 r = HcrSimTest.SwitchRepository(KTestCorrupt2, HCRInternal::EOverrideRepos);
2107 r = HcrSimTest.CheckIntegrity();
2108 test_Equal(KErrAlreadyExists, r);
2111 test.Next(_L("Close test channel and unload device driver"));
2113 r = User::FreeLogicalDevice(aDriver);
2118 void RomHeaderTests()
2120 test.Next(_L("Rom Header"));
2122 test.Printf(_L("Not available on the emulator.\n"));
2124 const TRomHeader* romheader = (TRomHeader*) UserSvr::RomHeaderAddress();
2125 test.Printf(_L("HCR File Address: %08x\n"), romheader->iHcrFileAddress);
2126 test(romheader->iHcrFileAddress);
2127 if (romheader->iPageableRomStart)
2129 // If this is a paged ROM, HCR file must be in the unpaged area
2130 test_Compare(romheader->iRomBase + romheader->iPageableRomStart, >, romheader->iHcrFileAddress);
2135 void HcrRealSettingDiscovery()
2137 test.Next(_L("Setting Discovery"));
2140 test.Printf(_L("Category Element Type Len Value\n"));
2141 test.Printf(_L("--------------------------------------------------\n"));
2142 for (cat = KHCRUID_ALLOCATED_MIN; cat <= KHCRUID_ALLOCATED_MAX; cat++)
2145 nosettings = HcrSimTest.FindNumSettingsInCategory(cat);
2146 test_Compare(0, <=, nosettings);
2150 TSettingType* types;
2152 elids = (TElementId*) User::Alloc(nosettings * sizeof(TElementId));
2153 test_NotNull(elids);
2154 types = (TSettingType*) User::Alloc(nosettings * sizeof(TSettingType));
2155 test_NotNull(types);
2156 lens = (TUint16*) User::Alloc(nosettings * sizeof(TUint16));
2158 r = HcrSimTest.FindSettings(cat, nosettings, elids, types, lens);
2159 test_Equal(nosettings, r);
2162 for (i = 0; i < nosettings; i++)
2164 TSettingId id(cat, *(elids + i));
2165 test.Printf(_L("%08x %08x %08x %04x "), cat, *(elids + i), *(types + i), *(lens + i));
2166 switch (*(types + i))
2171 r = HcrSimTest.GetInt(id, val);
2173 test.Printf(_L("%08x"), val);
2179 r = HcrSimTest.GetInt(id, val);
2181 test.Printf(_L("%04x"), val);
2187 r = HcrSimTest.GetInt(id, val);
2189 test.Printf(_L("%02x"), val);
2195 r = HcrSimTest.GetBool(id, val);
2197 test.Printf(_L("%b"), val ? 1 : 0);
2203 r = HcrSimTest.GetUInt(id, val);
2205 test.Printf(_L("%08x"), val);
2211 r = HcrSimTest.GetUInt(id, val);
2213 test.Printf(_L("%04x"), val);
2219 r = HcrSimTest.GetUInt(id, val);
2221 test.Printf(_L("%02x"), val);
2227 r = HcrSimTest.GetLinAddr(id, val);
2229 test.Printf(_L("%08x"), val);
2234 TBuf8<KMaxSettingLength> dval;
2236 pval = (TUint8*) User::Alloc(*(lens + i));
2239 r = HcrSimTest.GetData(id, dval);
2241 test_Equal(*(lens + i), dval.Length());
2243 TUint16 actuallength;
2244 r = HcrSimTest.GetData(id, *(lens + i), pval, actuallength);
2246 test_Equal(*(lens + i), actuallength);
2249 for (j = 0; j < 6 && j < dval.Length(); j++)
2251 test.Printf(_L("%02x "), dval[j]);
2260 TBuf8<KMaxSettingLength> dval;
2262 pval = (TText8*) User::Alloc(*(lens + i));
2265 r = HcrSimTest.GetString(id, dval);
2267 test_Equal(*(lens + i), dval.Length());
2269 TUint16 actuallength;
2270 r = HcrSimTest.GetString(id, *(lens + i), pval, actuallength);
2272 test_Equal(*(lens + i), actuallength);
2275 for (j = 0; j < 15 && j < dval.Length(); j++)
2277 test.Printf(_L("%c "), dval[j]);
2283 case ETypeArrayInt32:
2286 pval = (TInt32*) User::Alloc(*(lens + i));
2289 TUint16 actuallength;
2290 r = HcrSimTest.GetArray(id, *(lens + i), pval, actuallength);
2293 test_Equal(*(lens + i), actuallength);
2296 for (j = 0; j < 2 && j < actuallength / sizeof(TInt32); j++)
2298 test.Printf(_L("%08x "), pval[0]);
2304 case ETypeArrayUInt32:
2307 pval = (TUint32*) User::Alloc(*(lens + i));
2310 TUint16 actuallength;
2311 r = HcrSimTest.GetArray(id, *(lens + i), pval, actuallength);
2315 for (j = 0; j < 2 && j < actuallength / sizeof(TUint32); j++)
2317 test.Printf(_L("%08x "), pval[0]);
2320 test_Equal(*(lens + i), actuallength);
2327 r = HcrSimTest.GetInt(id, val);
2329 test.Printf(_L("%016lx"), val);
2336 r = HcrSimTest.GetUInt(id, val);
2338 test.Printf(_L("%016lx"), val);
2344 test.Printf(_L("\n"));
2352 void HcrRealRetrieveKernelExtensionTestResults()
2354 test.Next(_L("Retrieve kernel extension test results"));
2358 r = HcrSimTest.GetInitExtensionTestResults(kextline, kexterror);
2362 test.Printf(_L("Test not run\n"));
2364 else if (kextline == 0)
2366 test.Printf(_L("Test passed\n"));
2370 test.Printf(_L("Test kernel extension error at line %d (error %d)\n"), kextline, kexterror);
2375 void HcrRealTests(const TDesC& aDriver)
2377 test.Next(_L("HCR real tests"));
2378 test.Start(_L("Load LDD"));
2379 test.Printf(_L("%S\n"), &aDriver);
2381 r = User::LoadLogicalDevice(aDriver);
2382 if (r == KErrNotFound)
2384 test.Printf(_L("%S not found. Skipping tests.\n"), &aDriver);
2388 if (r == KErrAlreadyExists)
2390 test.Printf(_L("Unload Device Driver and load it again\n"));
2391 r = User::FreeLogicalDevice(aDriver);
2393 r = User::LoadLogicalDevice(aDriver);
2396 r = HcrSimTest.Open(aDriver);
2399 HcrRealRetrieveKernelExtensionTestResults();
2400 HcrRealSettingDiscovery();
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;
2412 r = HcrSimTest.HasRepositoryInSmr(smr, smrrep);
2417 HcrSimTestApiTests(SettingsList6, sizeof(SettingsList6) / sizeof(SSettingC));
2422 HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC));
2425 test.Next(_L("Close LDD"));
2427 r = User::FreeLogicalDevice(aDriver);
2433 void HcrSimBenchmarkTests(const TDesC& aDriver)
2435 test.Next(_L("Simulated HCR Benchmark"));
2436 test.Start(_L("Initialisation"));
2437 test.Printf(_L("%S\n"), &aDriver);
2439 r = User::LoadLogicalDevice(aDriver);
2440 if (r == KErrAlreadyExists)
2442 test.Printf(_L("Unload Device Driver and load it again\n"));
2443 r = User::FreeLogicalDevice(aDriver);
2445 r = User::LoadLogicalDevice(aDriver);
2452 r = HcrSimTest.Open(aDriver);
2454 r = HcrSimTest.InitExtension();
2456 r = HcrSimTest.CheckIntegrity();
2459 test.Next(_L("Get Setting"));
2462 TUint32 int1000 = 0;
2464 TUint32 array1000 = 0;
2466 TUint32 des1000 = 0;
2471 _LIT(KTestBenchLine, "%-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d\n");
2472 test.Printf(_L("HCR Int1 Int1000 Arr1 Arr1000 Des1 Des1000 FNS FS GTS GWS\n"));
2473 // Default configuration
2474 TSettingId idint1(1, 1);
2475 TSettingId idstring1(KTestCategories[2], 0x6000);
2476 test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
2477 test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
2478 test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
2479 test.Printf(_L("C?? "));
2480 test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
2482 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::ECoreRepos);
2484 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
2486 r = HcrSimTest.CheckIntegrity();
2488 test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
2489 test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
2490 test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
2491 test.Printf(_L("C__ "));
2492 test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
2494 TSettingId idint1000(KTestBenchmarkCategoryId, 1000);
2495 TSettingId idstring1000(KTestBenchmarkCategoryId, 1001);
2496 r = HcrSimTest.SwitchRepository(KTestMegaLarge1, HCRInternal::ECoreRepos);
2498 r = HcrSimTest.CheckIntegrity();
2500 test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
2501 test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1000, int1000));
2502 test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
2503 test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1000, array1000));
2504 test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
2505 test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1000, des1000));
2507 test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindNumSettingsInCategory(KTestBenchmarkCategoryId, fns));
2508 test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindSettings(KTestBenchmarkCategoryId, fs));
2509 test_KErrNone(HcrSimTest.BenchmarkGetTypeAndSize(idstring1000, gts));
2510 test_Equal(KTestBenchmarkNumberOfSettingsInCategory - 1, HcrSimTest.BenchmarkGetWordSettings(KTestBenchmarkCategoryId, gws));
2512 test.Printf(_L("CF_ "));
2513 test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
2515 r = HcrSimTest.SwitchRepository(KTestMegaLarge2, HCRInternal::EOverrideRepos);
2517 r = HcrSimTest.CheckIntegrity();
2519 test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
2520 test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1000, int1000));
2521 test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
2522 test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1000, array1000));
2523 test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
2524 test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1000, des1000));
2526 test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindNumSettingsInCategory(KTestBenchmarkCategoryId, fns));
2527 test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindSettings(KTestBenchmarkCategoryId, fs));
2528 test_KErrNone(HcrSimTest.BenchmarkGetTypeAndSize(idstring1000, gts));
2529 test_Equal(KTestBenchmarkNumberOfSettingsInCategory - 1, HcrSimTest.BenchmarkGetWordSettings(KTestBenchmarkCategoryId, gws));
2531 test.Printf(_L("CFN "));
2532 test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
2534 r = HcrSimTest.SwitchRepository(KTestClearRepos, HCRInternal::EOverrideRepos);
2536 r = HcrSimTest.CheckIntegrity();
2538 test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1, int1));
2539 test_KErrNone(HcrSimTest.BenchmarkGetSettingInt(idint1000, int1000));
2540 test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1, array1));
2541 test_KErrNone(HcrSimTest.BenchmarkGetSettingArray(idstring1000, array1000));
2542 test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1, des1));
2543 test_KErrNone(HcrSimTest.BenchmarkGetSettingDes(idstring1000, des1000));
2545 test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindNumSettingsInCategory(KTestBenchmarkCategoryId, fns));
2546 test_Equal(KTestBenchmarkNumberOfSettingsInCategory, HcrSimTest.BenchmarkFindSettings(KTestBenchmarkCategoryId, fs));
2547 test_KErrNone(HcrSimTest.BenchmarkGetTypeAndSize(idstring1000, gts));
2548 test_Equal(KTestBenchmarkNumberOfSettingsInCategory - 1, HcrSimTest.BenchmarkGetWordSettings(KTestBenchmarkCategoryId, gws));
2550 test.Printf(_L("C_N "));
2551 test.Printf(KTestBenchLine, int1, int1000, array1, array1000, des1, des1000, fns, fs, gts, gws);
2553 test.Next(_L("Unload LDD"));
2555 r = User::FreeLogicalDevice(aDriver);
2560 void HcrRealBenchmarkTests(const TDesC& aDriver)
2563 test.Next(_L("Real HCR Benchmark"));
2564 test.Start(_L("Initialisation"));
2565 test.Printf(_L("%S\n"), &aDriver);
2566 r = User::LoadLogicalDevice(aDriver);
2567 if (r == KErrNotFound)
2569 test.Printf(_L("%S not found. Skipping tests.\n"), &aDriver);
2573 if (r == KErrAlreadyExists)
2575 test.Printf(_L("Unload Device Driver and load it again\n"));
2576 r = User::FreeLogicalDevice(aDriver);
2578 r = User::LoadLogicalDevice(aDriver);
2581 r = HcrSimTest.Open(aDriver);
2584 test.Next(_L("Close LDD"));
2586 r = User::FreeLogicalDevice(aDriver);
2592 GLDEF_C TInt E32Main()
2597 test.Start(_L("HCR Test Suite"));
2600 //Order the the test lists in descend(the setting with the smallest
2601 //setting Id is first)
2602 TLinearOrder<SSettingC> order(CompareEntries);
2603 //Build the ordered ids arrays
2604 RArray<SSettingC> rSettingsList(sizeof(SSettingC), SettingsList,
2605 sizeof(SettingsList)/sizeof(SettingsList[0]));
2607 rSettingsList.Sort(order);
2609 RArray<SSettingC> rSettingsList2(sizeof(SSettingC), SettingsList2,
2610 sizeof(SettingsList2)/sizeof(SettingsList2[0]));
2611 rSettingsList2.Sort(order);
2613 RArray<SSettingC> rSettingsList3(sizeof(SSettingC), SettingsList3,
2614 sizeof(SettingsList3)/sizeof(SettingsList3[0]));
2615 rSettingsList3.Sort(order);
2617 RArray<SSettingC> rSettingsList4(sizeof(SSettingC), SettingsList4,
2618 sizeof(SettingsList4)/sizeof(SettingsList4[0]));
2619 rSettingsList4.Sort(order);
2621 RArray<SSettingC> rSettingsList5(sizeof(SSettingC), SettingsList5,
2622 sizeof(SettingsList5)/sizeof(SettingsList5[0]));
2623 rSettingsList5.Sort(order);
2625 RArray<SSettingC> rSettingsList6(sizeof(SSettingC), SettingsList6,
2626 sizeof(SettingsList6)/sizeof(SettingsList6[0]));
2627 rSettingsList6.Sort(order);
2629 RArray<SSettingC> rSettingsList7(sizeof(SSettingC), SettingsList7,
2630 sizeof(SettingsList7)/sizeof(SettingsList7[0]));
2631 rSettingsList7.Sort(order);
2634 //Functional API test
2636 HcrRealTests(KTestHcrRealOwn);
2637 HcrRealTests(KTestHcrRealClient);
2638 HcrPslTests(KTestHcrSimOwn);
2639 HcrPslTests(KTestHcrSimClient);
2640 HcrSimTests(KTestHcrSimOwn);
2641 HcrSimTests(KTestHcrSimClient);
2645 HcrSimBenchmarkTests(KTestHcrSimOwn);
2646 HcrSimBenchmarkTests(KTestHcrSimClient);
2647 HcrRealBenchmarkTests(KTestHcrRealOwn);
2648 HcrRealBenchmarkTests(KTestHcrRealClient);