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); |