Differences From Artifact [3fa2e6f5e3]:
- File tests/OFDictionary/OFDictionary.m — part of check-in [4eae61a78f] at 2009-07-19 14:05:30 on branch trunk — Rename andFoo: to foo: in all methods. (user: js, size: 4518) [annotate] [blame] [check-ins using]
To Artifact [cdca107008]:
- File
tests/OFDictionary/OFDictionary.m
— part of check-in
[bbf1f79b8f]
at
2009-09-08 16:06:10
on branch trunk
— New OFDictionary implementation and removal of a hack in OFList.
The new implementation is easier to use as it does automatic resizing,
but therefore it's not realtime-capable anymore. The new implementation
should also be a little bit faster.I decided to change the implementation as only very few need a
realtime-capable dictionary and those few will most likely write their
own implementation for their specific case anyway.As the new implementation no longer uses OFList, this also made it
possible to remove a hack from OFList. (user: js, size: 4105) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include <string.h> #import "OFAutoreleasePool.h" #import "OFDictionary.h" #import "OFString.h" #import "OFExceptions.h" | | | | | | | | < < < < < < < < < < < < | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | #include <string.h> #import "OFAutoreleasePool.h" #import "OFDictionary.h" #import "OFString.h" #import "OFExceptions.h" #define TESTS 14 int main() { int i = 0; OFDictionary *dict = [OFMutableDictionary dictionary]; OFDictionary *dict2; OFArray *keys, *objs; OFIterator *iter; of_iterator_pair_t pair[2]; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFString *key1 = [OFString stringWithString: @"key1"]; OFString *key2 = [OFString stringWithString: @"key2"]; OFString *value1 = [OFString stringWithString: @"value1"]; OFString *value2 = [OFString stringWithString: @"value2"]; [dict setObject: value1 forKey: key1]; [dict setObject: value2 forKey: key2]; [pool release]; i++; if (strcmp([[dict objectForKey: @"key1"] cString], "value1")) { printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); return 1; } i++; if (strcmp([[dict objectForKey: key2] cString], "value2")) { printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); return 1; } i++; iter = [dict iterator]; pair[0] = [iter nextKeyObjectPair]; pair[1] = [iter nextKeyObjectPair]; if (![pair[0].key isEqual: @"key1"] || ![pair[0].object isEqual: @"value1"] || ![pair[1].key isEqual: @"key2"] || ![pair[1].object isEqual: @"value2"]) { printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); return 1; } i++; if ([dict count] != 2) { printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); return 1; } i++; if ([iter nextKeyObjectPair].object != nil) { printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); return 1; } i++; if ([dict objectForKey: @"key3"] != nil) { printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); return 1; } i++; [dict release]; dict = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar", @"baz", @"qux", nil]; if (![[dict objectForKey: @"foo"] isEqual: @"bar"]) { printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS); return 1; } i++; |
︙ | ︙ |