diff --git a/Tests/CFDictionary/bridge.m b/Tests/CFDictionary/bridge.m index 69686fc..d7ceeb7 100644 --- a/Tests/CFDictionary/bridge.m +++ b/Tests/CFDictionary/bridge.m @@ -113,18 +113,32 @@ void testLargeDict(void) } } + Boolean removedAbsent = true; + Boolean remainingPresent = true; + int firstPresent = -1; + int firstMissing = -1; for (int i = 0; i < count; i++) { id key = [[NSString alloc] initWithFormat:@"key-%d", i]; void *value = CFDictionaryGetValue(cfdict, (__bridge const void *)key); - + if (i < removeCount) { - PASS_CF(value == NULL, "CFDictionaryGetValue returns no value for non-existant key '%@'", key); + if (value != NULL) { + if (removedAbsent) firstPresent = i; + removedAbsent = false; + } } else { - PASS_CF(value != NULL, "CFDictionaryGetValue returns value for existant key '%@'", key); + if (value == NULL) { + if (remainingPresent) firstMissing = i; + remainingPresent = false; + } } - + [key release]; } + if (!removedAbsent) fprintf(stderr, " removed key still present: key-%d\n", firstPresent); + PASS_CF(removedAbsent, "CFDictionaryGetValue returns no value for the %d removed keys", removeCount); + if (!remainingPresent) fprintf(stderr, " missing key: key-%d\n", firstMissing); + PASS_CF(remainingPresent, "CFDictionaryGetValue returns a value for all remaining keys"); CFRelease(cfdict); } diff --git a/Tests/CFDictionary/general.m b/Tests/CFDictionary/general.m index 3a23292..6689ed8 100644 --- a/Tests/CFDictionary/general.m +++ b/Tests/CFDictionary/general.m @@ -9,49 +9,75 @@ int main (void) int key, value, i; int removeCount, count = sizeof(keys)/sizeof(*keys); CFTypeRef cfkey, cfvalue; + Boolean ok; + int firstBad; + ok = true; + firstBad = -1; for (i = 0; i < count; i++) { key = keys[i]; cfkey = CFNumberCreate (NULL, kCFNumberIntType, &key); cfvalue = CFNumberCreate (NULL, kCFNumberIntType, &i); CFDictionarySetValue(cfdict, cfkey, cfvalue); CFNumberRef cfvalue2 = CFDictionaryGetValue(cfdict, cfkey); - PASS_CFEQ(cfvalue, cfvalue2, "set and get values are equal"); + if (cfvalue2 == NULL || !CFEqual(cfvalue, cfvalue2)) { + if (ok) firstBad = key; + ok = false; + } CFRelease(cfkey); CFRelease(cfvalue); } - + if (!ok) fprintf(stderr, " first mismatch at key %d\n", firstBad); + PASS_CF(ok, "set and get values are equal for all %d keys", count); + key = 57; cfkey = CFNumberCreate (NULL, kCFNumberIntType, &key); PASS_CF(CFDictionaryGetValue(cfdict, cfkey) == NULL, "CFDictionaryGetValue returns NULL for nonexistant key"); CFRelease(cfkey); - - for (i = 0; i < count; i++) { - key = keys[i]; - cfkey = CFNumberCreate (NULL, kCFNumberIntType, &key); - cfvalue = CFDictionaryGetValue(cfdict, cfkey); - PASS_CF(cfvalue != NULL, "CFDictionaryGetValue returns value for existant key %d", key); - if (cfvalue) { - CFNumberGetValue(cfvalue, kCFNumberIntType, &value); - PASS_CF(value == i, "CFDictionaryGetValue returns correct value %d == %d for key %d", value, i, key); + + { + Boolean allPresent = true; + Boolean allCorrect = true; + int firstMissing = -1; + int firstWrong = -1; + for (i = 0; i < count; i++) { + key = keys[i]; + cfkey = CFNumberCreate (NULL, kCFNumberIntType, &key); + cfvalue = CFDictionaryGetValue(cfdict, cfkey); + if (cfvalue == NULL) { + if (allPresent) firstMissing = key; + allPresent = false; + } else { + CFNumberGetValue(cfvalue, kCFNumberIntType, &value); + if (value != i) { + if (allCorrect) firstWrong = key; + allCorrect = false; + } + } + CFRelease(cfkey); } - CFRelease(cfkey); + if (!allPresent) fprintf(stderr, " first missing key %d\n", firstMissing); + PASS_CF(allPresent, "CFDictionaryGetValue returns a value for all %d existant keys", count); + if (!allCorrect) fprintf(stderr, " first incorrect value at key %d\n", firstWrong); + PASS_CF(allCorrect, "CFDictionaryGetValue returns the correct value for all existant keys"); } - + PASS_CF(CFDictionaryGetCount(cfdict) == count, "CFDictionaryGetCount returns correct value"); - + CFDictionaryRemoveAllValues(cfdict); PASS_CF(CFDictionaryGetCount(cfdict) == 0, "CFDictionaryRemoveAllValues removes all values"); - + // test large dictionary - + count = 5000; removeCount = 0; CFStringRef keyFormat = CFSTR("key-%d"); + ok = true; + firstBad = -1; for (i = 0; i < count; i++) { - + cfkey = CFStringCreateWithFormat(NULL, NULL, keyFormat, i); cfvalue = CFNumberCreate(NULL, kCFNumberIntType, &i); CFDictionarySetValue(cfdict, cfkey, cfvalue); @@ -63,25 +89,47 @@ int main (void) int keyToRemove = removeCount++; cfkey = CFStringCreateWithFormat(NULL, NULL, keyFormat, keyToRemove); cfvalue = CFDictionaryGetValue(cfdict, cfkey); - PASS_CF(cfvalue != NULL, "CFDictionaryGetValue returns value for key 'key-%d' to remove", keyToRemove); + if (cfvalue == NULL) { + if (ok) firstBad = keyToRemove; + ok = false; + } CFDictionaryRemoveValue(cfdict, cfkey); CFRelease(cfkey); } } - - for (i = 0; i < count; i++) { - cfkey = CFStringCreateWithFormat(NULL, NULL, keyFormat, i); - cfvalue = CFDictionaryGetValue(cfdict, cfkey); - if (i < removeCount) { - PASS_CF(cfvalue == NULL, "CFDictionaryGetValue returns no value for non-existant key 'key-%d': %p", i, cfvalue); - } else { - CFNumberRef cfvalue2 = CFNumberCreate(NULL, kCFNumberIntType, &i); - PASS_CFEQ(cfvalue, cfvalue2, "CFDictionaryGetValue returns correct value for existant key 'key-%d': %p", i, cfvalue); + if (!ok) fprintf(stderr, " first missing key before removal: key-%d\n", firstBad); + PASS_CF(ok, "CFDictionaryGetValue returns a value for each of the %d keys before removal", removeCount); + + { + Boolean removedAbsent = true; + Boolean remainingCorrect = true; + int firstPresent = -1; + int firstWrong = -1; + for (i = 0; i < count; i++) { + cfkey = CFStringCreateWithFormat(NULL, NULL, keyFormat, i); + cfvalue = CFDictionaryGetValue(cfdict, cfkey); + if (i < removeCount) { + if (cfvalue != NULL) { + if (removedAbsent) firstPresent = i; + removedAbsent = false; + } + } else { + CFNumberRef cfvalue2 = CFNumberCreate(NULL, kCFNumberIntType, &i); + if (cfvalue == NULL || !CFEqual(cfvalue, cfvalue2)) { + if (remainingCorrect) firstWrong = i; + remainingCorrect = false; + } + CFRelease(cfvalue2); + } + CFRelease(cfkey); } - CFRelease(cfkey); + if (!removedAbsent) fprintf(stderr, " removed key still present: key-%d\n", firstPresent); + PASS_CF(removedAbsent, "CFDictionaryGetValue returns no value for the %d removed keys", removeCount); + if (!remainingCorrect) fprintf(stderr, " first incorrect value at key-%d\n", firstWrong); + PASS_CF(remainingCorrect, "CFDictionaryGetValue returns the correct value for all remaining keys"); } - + CFRelease(cfdict); - + return 0; -} \ No newline at end of file +}