diff options
Diffstat (limited to 'objectivec/Tests/GPBDictionaryTests+String.m')
-rw-r--r-- | objectivec/Tests/GPBDictionaryTests+String.m | 95 |
1 files changed, 60 insertions, 35 deletions
diff --git a/objectivec/Tests/GPBDictionaryTests+String.m b/objectivec/Tests/GPBDictionaryTests+String.m index 5df1d51d..82d7952b 100644 --- a/objectivec/Tests/GPBDictionaryTests+String.m +++ b/objectivec/Tests/GPBDictionaryTests+String.m @@ -45,7 +45,6 @@ // To let the testing macros work, add some extra methods to simplify things. @interface GPBStringEnumDictionary (TestingTweak) -+ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(NSString *)key; - (instancetype)initWithEnums:(const int32_t [])values forKeys:(const NSString * [])keys count:(NSUInteger)count; @@ -64,14 +63,6 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } @implementation GPBStringEnumDictionary (TestingTweak) -+ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(NSString *)key { - // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the - // type correct. - return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue - rawValues:&value - forKeys:&key - count:1] autorelease]; -} - (instancetype)initWithEnums:(const int32_t [])values forKeys:(const NSString * [])keys count:(NSUInteger)count { @@ -103,7 +94,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBStringUInt32Dictionary *dict = [GPBStringUInt32Dictionary dictionaryWithUInt32:100U forKey:@"foo"]; + GPBStringUInt32Dictionary *dict = [[GPBStringUInt32Dictionary alloc] init]; + [dict setUInt32:100U forKey:@"foo"]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); uint32_t value; @@ -116,6 +108,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(aValue, 100U); XCTAssertNotEqual(stop, NULL); }]; + [dict release]; } - (void)testBasics { @@ -258,17 +251,18 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); GPBStringUInt32Dictionary *dict2 = - [GPBStringUInt32Dictionary dictionaryWithDictionary:dict]; + [[GPBStringUInt32Dictionary alloc] initWithDictionary:dict]; XCTAssertNotNil(dict2); // Should be new pointer, but equal objects. XCTAssertNotEqual(dict, dict2); XCTAssertEqualObjects(dict, dict2); + [dict2 release]; [dict release]; } - (void)testAdds { - GPBStringUInt32Dictionary *dict = [GPBStringUInt32Dictionary dictionary]; + GPBStringUInt32Dictionary *dict = [[GPBStringUInt32Dictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -299,6 +293,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]); XCTAssertEqual(value, 103U); [dict2 release]; + [dict release]; } - (void)testRemove { @@ -460,7 +455,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBStringInt32Dictionary *dict = [GPBStringInt32Dictionary dictionaryWithInt32:200 forKey:@"foo"]; + GPBStringInt32Dictionary *dict = [[GPBStringInt32Dictionary alloc] init]; + [dict setInt32:200 forKey:@"foo"]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); int32_t value; @@ -473,6 +469,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(aValue, 200); XCTAssertNotEqual(stop, NULL); }]; + [dict release]; } - (void)testBasics { @@ -615,17 +612,18 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); GPBStringInt32Dictionary *dict2 = - [GPBStringInt32Dictionary dictionaryWithDictionary:dict]; + [[GPBStringInt32Dictionary alloc] initWithDictionary:dict]; XCTAssertNotNil(dict2); // Should be new pointer, but equal objects. XCTAssertNotEqual(dict, dict2); XCTAssertEqualObjects(dict, dict2); + [dict2 release]; [dict release]; } - (void)testAdds { - GPBStringInt32Dictionary *dict = [GPBStringInt32Dictionary dictionary]; + GPBStringInt32Dictionary *dict = [[GPBStringInt32Dictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -656,6 +654,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]); XCTAssertEqual(value, 203); [dict2 release]; + [dict release]; } - (void)testRemove { @@ -817,7 +816,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBStringUInt64Dictionary *dict = [GPBStringUInt64Dictionary dictionaryWithUInt64:300U forKey:@"foo"]; + GPBStringUInt64Dictionary *dict = [[GPBStringUInt64Dictionary alloc] init]; + [dict setUInt64:300U forKey:@"foo"]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); uint64_t value; @@ -830,6 +830,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(aValue, 300U); XCTAssertNotEqual(stop, NULL); }]; + [dict release]; } - (void)testBasics { @@ -972,17 +973,18 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); GPBStringUInt64Dictionary *dict2 = - [GPBStringUInt64Dictionary dictionaryWithDictionary:dict]; + [[GPBStringUInt64Dictionary alloc] initWithDictionary:dict]; XCTAssertNotNil(dict2); // Should be new pointer, but equal objects. XCTAssertNotEqual(dict, dict2); XCTAssertEqualObjects(dict, dict2); + [dict2 release]; [dict release]; } - (void)testAdds { - GPBStringUInt64Dictionary *dict = [GPBStringUInt64Dictionary dictionary]; + GPBStringUInt64Dictionary *dict = [[GPBStringUInt64Dictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -1013,6 +1015,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]); XCTAssertEqual(value, 303U); [dict2 release]; + [dict release]; } - (void)testRemove { @@ -1174,7 +1177,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBStringInt64Dictionary *dict = [GPBStringInt64Dictionary dictionaryWithInt64:400 forKey:@"foo"]; + GPBStringInt64Dictionary *dict = [[GPBStringInt64Dictionary alloc] init]; + [dict setInt64:400 forKey:@"foo"]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); int64_t value; @@ -1187,6 +1191,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(aValue, 400); XCTAssertNotEqual(stop, NULL); }]; + [dict release]; } - (void)testBasics { @@ -1329,17 +1334,18 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); GPBStringInt64Dictionary *dict2 = - [GPBStringInt64Dictionary dictionaryWithDictionary:dict]; + [[GPBStringInt64Dictionary alloc] initWithDictionary:dict]; XCTAssertNotNil(dict2); // Should be new pointer, but equal objects. XCTAssertNotEqual(dict, dict2); XCTAssertEqualObjects(dict, dict2); + [dict2 release]; [dict release]; } - (void)testAdds { - GPBStringInt64Dictionary *dict = [GPBStringInt64Dictionary dictionary]; + GPBStringInt64Dictionary *dict = [[GPBStringInt64Dictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -1370,6 +1376,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]); XCTAssertEqual(value, 403); [dict2 release]; + [dict release]; } - (void)testRemove { @@ -1531,7 +1538,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBStringBoolDictionary *dict = [GPBStringBoolDictionary dictionaryWithBool:YES forKey:@"foo"]; + GPBStringBoolDictionary *dict = [[GPBStringBoolDictionary alloc] init]; + [dict setBool:YES forKey:@"foo"]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); BOOL value; @@ -1544,6 +1552,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(aValue, YES); XCTAssertNotEqual(stop, NULL); }]; + [dict release]; } - (void)testBasics { @@ -1686,17 +1695,18 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); GPBStringBoolDictionary *dict2 = - [GPBStringBoolDictionary dictionaryWithDictionary:dict]; + [[GPBStringBoolDictionary alloc] initWithDictionary:dict]; XCTAssertNotNil(dict2); // Should be new pointer, but equal objects. XCTAssertNotEqual(dict, dict2); XCTAssertEqualObjects(dict, dict2); + [dict2 release]; [dict release]; } - (void)testAdds { - GPBStringBoolDictionary *dict = [GPBStringBoolDictionary dictionary]; + GPBStringBoolDictionary *dict = [[GPBStringBoolDictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -1727,6 +1737,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertTrue([dict getBool:&value forKey:@"mumble"]); XCTAssertEqual(value, NO); [dict2 release]; + [dict release]; } - (void)testRemove { @@ -1888,7 +1899,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBStringFloatDictionary *dict = [GPBStringFloatDictionary dictionaryWithFloat:500.f forKey:@"foo"]; + GPBStringFloatDictionary *dict = [[GPBStringFloatDictionary alloc] init]; + [dict setFloat:500.f forKey:@"foo"]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); float value; @@ -1901,6 +1913,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(aValue, 500.f); XCTAssertNotEqual(stop, NULL); }]; + [dict release]; } - (void)testBasics { @@ -2043,17 +2056,18 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); GPBStringFloatDictionary *dict2 = - [GPBStringFloatDictionary dictionaryWithDictionary:dict]; + [[GPBStringFloatDictionary alloc] initWithDictionary:dict]; XCTAssertNotNil(dict2); // Should be new pointer, but equal objects. XCTAssertNotEqual(dict, dict2); XCTAssertEqualObjects(dict, dict2); + [dict2 release]; [dict release]; } - (void)testAdds { - GPBStringFloatDictionary *dict = [GPBStringFloatDictionary dictionary]; + GPBStringFloatDictionary *dict = [[GPBStringFloatDictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -2084,6 +2098,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]); XCTAssertEqual(value, 503.f); [dict2 release]; + [dict release]; } - (void)testRemove { @@ -2245,7 +2260,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBStringDoubleDictionary *dict = [GPBStringDoubleDictionary dictionaryWithDouble:600. forKey:@"foo"]; + GPBStringDoubleDictionary *dict = [[GPBStringDoubleDictionary alloc] init]; + [dict setDouble:600. forKey:@"foo"]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); double value; @@ -2258,6 +2274,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(aValue, 600.); XCTAssertNotEqual(stop, NULL); }]; + [dict release]; } - (void)testBasics { @@ -2400,17 +2417,18 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); GPBStringDoubleDictionary *dict2 = - [GPBStringDoubleDictionary dictionaryWithDictionary:dict]; + [[GPBStringDoubleDictionary alloc] initWithDictionary:dict]; XCTAssertNotNil(dict2); // Should be new pointer, but equal objects. XCTAssertNotEqual(dict, dict2); XCTAssertEqualObjects(dict, dict2); + [dict2 release]; [dict release]; } - (void)testAdds { - GPBStringDoubleDictionary *dict = [GPBStringDoubleDictionary dictionary]; + GPBStringDoubleDictionary *dict = [[GPBStringDoubleDictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -2441,6 +2459,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]); XCTAssertEqual(value, 603.); [dict2 release]; + [dict release]; } - (void)testRemove { @@ -2602,7 +2621,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBStringEnumDictionary *dict = [GPBStringEnumDictionary dictionaryWithEnum:700 forKey:@"foo"]; + GPBStringEnumDictionary *dict = [[GPBStringEnumDictionary alloc] init]; + [dict setEnum:700 forKey:@"foo"]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); int32_t value; @@ -2615,6 +2635,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(aValue, 700); XCTAssertNotEqual(stop, NULL); }]; + [dict release]; } - (void)testBasics { @@ -2757,17 +2778,18 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); GPBStringEnumDictionary *dict2 = - [GPBStringEnumDictionary dictionaryWithDictionary:dict]; + [[GPBStringEnumDictionary alloc] initWithDictionary:dict]; XCTAssertNotNil(dict2); // Should be new pointer, but equal objects. XCTAssertNotEqual(dict, dict2); XCTAssertEqualObjects(dict, dict2); + [dict2 release]; [dict release]; } - (void)testAdds { - GPBStringEnumDictionary *dict = [GPBStringEnumDictionary dictionary]; + GPBStringEnumDictionary *dict = [[GPBStringEnumDictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -2798,6 +2820,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]); XCTAssertEqual(value, 703); [dict2 release]; + [dict release]; } - (void)testRemove { @@ -3120,19 +3143,20 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); GPBStringEnumDictionary *dict2 = - [GPBStringEnumDictionary dictionaryWithDictionary:dict]; + [[GPBStringEnumDictionary alloc] initWithDictionary:dict]; XCTAssertNotNil(dict2); // Should be new pointer, but equal objects. XCTAssertNotEqual(dict, dict2); XCTAssertEqualObjects(dict, dict2); XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison + [dict2 release]; [dict release]; } - (void)testUnknownAdds { GPBStringEnumDictionary *dict = - [GPBStringEnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue]; + [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -3172,6 +3196,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]); XCTAssertEqual(value, 803); [dict2 release]; + [dict release]; } - (void)testUnknownRemove { |