aboutsummaryrefslogtreecommitdiffhomepage
path: root/objectivec/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'objectivec/Tests')
-rw-r--r--objectivec/Tests/GPBArrayTests.m87
-rw-r--r--objectivec/Tests/GPBCodedInputStreamTests.m12
-rw-r--r--objectivec/Tests/GPBConcurrencyTests.m48
-rw-r--r--objectivec/Tests/GPBDictionaryTests+Bool.m5
-rw-r--r--objectivec/Tests/GPBDictionaryTests+Int32.m5
-rw-r--r--objectivec/Tests/GPBDictionaryTests+Int64.m5
-rw-r--r--objectivec/Tests/GPBDictionaryTests+String.m5
-rw-r--r--objectivec/Tests/GPBDictionaryTests+UInt32.m5
-rw-r--r--objectivec/Tests/GPBDictionaryTests+UInt64.m5
-rw-r--r--objectivec/Tests/GPBDictionaryTests.pddm4
-rw-r--r--objectivec/Tests/GPBMessageTests+Merge.m5
-rw-r--r--objectivec/Tests/GPBMessageTests+Runtime.m11
-rw-r--r--objectivec/Tests/GPBMessageTests+Serialization.m183
-rw-r--r--objectivec/Tests/GPBMessageTests.m285
-rw-r--r--objectivec/Tests/GPBPerfTests.m9
-rw-r--r--objectivec/Tests/GPBStringTests.m5
-rw-r--r--objectivec/Tests/GPBSwiftTests.swift57
-rw-r--r--objectivec/Tests/GPBTestUtilities.h7
-rw-r--r--objectivec/Tests/GPBTestUtilities.m20
-rw-r--r--objectivec/Tests/GPBUnknownFieldSetTest.m17
-rw-r--r--objectivec/Tests/GPBWireFormatTests.m28
-rw-r--r--objectivec/Tests/unittest_objc.proto2
-rw-r--r--objectivec/Tests/unittest_runtime_proto2.proto21
-rw-r--r--objectivec/Tests/unittest_runtime_proto3.proto21
24 files changed, 664 insertions, 188 deletions
diff --git a/objectivec/Tests/GPBArrayTests.m b/objectivec/Tests/GPBArrayTests.m
index 37724c59..0fb15e40 100644
--- a/objectivec/Tests/GPBArrayTests.m
+++ b/objectivec/Tests/GPBArrayTests.m
@@ -29,14 +29,11 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import <Foundation/Foundation.h>
-
#import <XCTest/XCTest.h>
#import "GPBArray.h"
-#ifndef GPBARRAYSIZE
-#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-#endif // GPBARRAYSIZE
+#import "GPBTestUtilities.h"
// To let the testing macros work, add some extra methods to simplify things.
@interface GPBEnumArray (TestingTweak)
@@ -233,6 +230,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
//% // Should be new object but equal.
//% XCTAssertNotEqual(array, array2);
//% XCTAssertEqualObjects(array, array2);
+//% [array2 release];
+//% [array release];
//%}
//%
//%- (void)testArrayFromArray {
@@ -248,6 +247,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
//% // Should be new pointer, but equal objects.
//% XCTAssertNotEqual(array, array2);
//% XCTAssertEqualObjects(array, array2);
+//% [array release];
//%}
//%
//%- (void)testAdds {
@@ -275,6 +275,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
//% XCTAssertEqual([array valueAtIndex:2], VAL3);
//% XCTAssertEqual([array valueAtIndex:3], VAL4);
//% XCTAssertEqual([array valueAtIndex:4], VAL1);
+//% [array2 release];
//%}
//%
//%- (void)testInsert {
@@ -307,6 +308,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
//% XCTAssertEqual([array valueAtIndex:3], VAL2);
//% XCTAssertEqual([array valueAtIndex:4], VAL3);
//% XCTAssertEqual([array valueAtIndex:5], VAL4);
+//% [array release];
//%}
//%
//%- (void)testRemove {
@@ -343,6 +345,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
//% XCTAssertEqual(array.count, 0U);
//% XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
//% NSException, NSRangeException);
+//% [array release];
//%}
//%
//%- (void)testInplaceMutation {
@@ -381,6 +384,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
//% NSException, NSRangeException);
//% XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
//% NSException, NSRangeException);
+//% [array release];
//%}
//%
//%- (void)testInternalResizing {
@@ -405,6 +409,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
//% XCTAssertEqual(array.count, 404U);
//% [array removeAll];
//% XCTAssertEqual(array.count, 0U);
+//% [array release];
//%}
//%
//%@end
@@ -558,6 +563,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new object but equal.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
}
- (void)testArrayFromArray {
@@ -573,6 +580,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new pointer, but equal objects.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array release];
}
- (void)testAdds {
@@ -600,6 +608,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:2], 3);
XCTAssertEqual([array valueAtIndex:3], 4);
XCTAssertEqual([array valueAtIndex:4], 1);
+ [array2 release];
}
- (void)testInsert {
@@ -632,6 +641,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:3], 2);
XCTAssertEqual([array valueAtIndex:4], 3);
XCTAssertEqual([array valueAtIndex:5], 4);
+ [array release];
}
- (void)testRemove {
@@ -668,6 +678,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 0U);
XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
NSException, NSRangeException);
+ [array release];
}
- (void)testInplaceMutation {
@@ -706,6 +717,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
NSException, NSRangeException);
XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
NSException, NSRangeException);
+ [array release];
}
- (void)testInternalResizing {
@@ -730,6 +742,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 404U);
[array removeAll];
XCTAssertEqual(array.count, 0U);
+ [array release];
}
@end
@@ -883,6 +896,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new object but equal.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
}
- (void)testArrayFromArray {
@@ -898,6 +913,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new pointer, but equal objects.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array release];
}
- (void)testAdds {
@@ -925,6 +941,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:2], 13U);
XCTAssertEqual([array valueAtIndex:3], 14U);
XCTAssertEqual([array valueAtIndex:4], 11U);
+ [array2 release];
}
- (void)testInsert {
@@ -957,6 +974,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:3], 12U);
XCTAssertEqual([array valueAtIndex:4], 13U);
XCTAssertEqual([array valueAtIndex:5], 14U);
+ [array release];
}
- (void)testRemove {
@@ -993,6 +1011,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 0U);
XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
NSException, NSRangeException);
+ [array release];
}
- (void)testInplaceMutation {
@@ -1031,6 +1050,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
NSException, NSRangeException);
XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
NSException, NSRangeException);
+ [array release];
}
- (void)testInternalResizing {
@@ -1055,6 +1075,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 404U);
[array removeAll];
XCTAssertEqual(array.count, 0U);
+ [array release];
}
@end
@@ -1208,6 +1229,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new object but equal.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
}
- (void)testArrayFromArray {
@@ -1223,6 +1246,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new pointer, but equal objects.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array release];
}
- (void)testAdds {
@@ -1250,6 +1274,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:2], 33LL);
XCTAssertEqual([array valueAtIndex:3], 34LL);
XCTAssertEqual([array valueAtIndex:4], 31LL);
+ [array2 release];
}
- (void)testInsert {
@@ -1282,6 +1307,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:3], 32LL);
XCTAssertEqual([array valueAtIndex:4], 33LL);
XCTAssertEqual([array valueAtIndex:5], 34LL);
+ [array release];
}
- (void)testRemove {
@@ -1318,6 +1344,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 0U);
XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
NSException, NSRangeException);
+ [array release];
}
- (void)testInplaceMutation {
@@ -1356,6 +1383,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
NSException, NSRangeException);
XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
NSException, NSRangeException);
+ [array release];
}
- (void)testInternalResizing {
@@ -1380,6 +1408,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 404U);
[array removeAll];
XCTAssertEqual(array.count, 0U);
+ [array release];
}
@end
@@ -1533,6 +1562,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new object but equal.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
}
- (void)testArrayFromArray {
@@ -1548,6 +1579,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new pointer, but equal objects.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array release];
}
- (void)testAdds {
@@ -1575,6 +1607,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:2], 43ULL);
XCTAssertEqual([array valueAtIndex:3], 44ULL);
XCTAssertEqual([array valueAtIndex:4], 41ULL);
+ [array2 release];
}
- (void)testInsert {
@@ -1607,6 +1640,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:3], 42ULL);
XCTAssertEqual([array valueAtIndex:4], 43ULL);
XCTAssertEqual([array valueAtIndex:5], 44ULL);
+ [array release];
}
- (void)testRemove {
@@ -1643,6 +1677,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 0U);
XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
NSException, NSRangeException);
+ [array release];
}
- (void)testInplaceMutation {
@@ -1681,6 +1716,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
NSException, NSRangeException);
XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
NSException, NSRangeException);
+ [array release];
}
- (void)testInternalResizing {
@@ -1705,6 +1741,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 404U);
[array removeAll];
XCTAssertEqual(array.count, 0U);
+ [array release];
}
@end
@@ -1858,6 +1895,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new object but equal.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
}
- (void)testArrayFromArray {
@@ -1873,6 +1912,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new pointer, but equal objects.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array release];
}
- (void)testAdds {
@@ -1900,6 +1940,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:2], 53.f);
XCTAssertEqual([array valueAtIndex:3], 54.f);
XCTAssertEqual([array valueAtIndex:4], 51.f);
+ [array2 release];
}
- (void)testInsert {
@@ -1932,6 +1973,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:3], 52.f);
XCTAssertEqual([array valueAtIndex:4], 53.f);
XCTAssertEqual([array valueAtIndex:5], 54.f);
+ [array release];
}
- (void)testRemove {
@@ -1968,6 +2010,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 0U);
XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
NSException, NSRangeException);
+ [array release];
}
- (void)testInplaceMutation {
@@ -2006,6 +2049,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
NSException, NSRangeException);
XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
NSException, NSRangeException);
+ [array release];
}
- (void)testInternalResizing {
@@ -2030,6 +2074,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 404U);
[array removeAll];
XCTAssertEqual(array.count, 0U);
+ [array release];
}
@end
@@ -2183,6 +2228,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new object but equal.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
}
- (void)testArrayFromArray {
@@ -2198,6 +2245,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new pointer, but equal objects.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array release];
}
- (void)testAdds {
@@ -2225,6 +2273,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:2], 63.);
XCTAssertEqual([array valueAtIndex:3], 64.);
XCTAssertEqual([array valueAtIndex:4], 61.);
+ [array2 release];
}
- (void)testInsert {
@@ -2257,6 +2306,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:3], 62.);
XCTAssertEqual([array valueAtIndex:4], 63.);
XCTAssertEqual([array valueAtIndex:5], 64.);
+ [array release];
}
- (void)testRemove {
@@ -2293,6 +2343,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 0U);
XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
NSException, NSRangeException);
+ [array release];
}
- (void)testInplaceMutation {
@@ -2331,6 +2382,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
NSException, NSRangeException);
XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
NSException, NSRangeException);
+ [array release];
}
- (void)testInternalResizing {
@@ -2355,6 +2407,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 404U);
[array removeAll];
XCTAssertEqual(array.count, 0U);
+ [array release];
}
@end
@@ -2508,6 +2561,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new object but equal.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
}
- (void)testArrayFromArray {
@@ -2523,6 +2578,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new pointer, but equal objects.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array release];
}
- (void)testAdds {
@@ -2550,6 +2606,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:2], FALSE);
XCTAssertEqual([array valueAtIndex:3], FALSE);
XCTAssertEqual([array valueAtIndex:4], TRUE);
+ [array2 release];
}
- (void)testInsert {
@@ -2582,6 +2639,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:3], TRUE);
XCTAssertEqual([array valueAtIndex:4], FALSE);
XCTAssertEqual([array valueAtIndex:5], FALSE);
+ [array release];
}
- (void)testRemove {
@@ -2618,6 +2676,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 0U);
XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
NSException, NSRangeException);
+ [array release];
}
- (void)testInplaceMutation {
@@ -2656,6 +2715,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
NSException, NSRangeException);
XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
NSException, NSRangeException);
+ [array release];
}
- (void)testInternalResizing {
@@ -2680,6 +2740,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 404U);
[array removeAll];
XCTAssertEqual(array.count, 0U);
+ [array release];
}
@end
@@ -2833,6 +2894,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new object but equal.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
}
- (void)testArrayFromArray {
@@ -2848,6 +2911,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
// Should be new pointer, but equal objects.
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
+ [array release];
}
- (void)testAdds {
@@ -2875,6 +2939,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:2], 73);
XCTAssertEqual([array valueAtIndex:3], 74);
XCTAssertEqual([array valueAtIndex:4], 71);
+ [array2 release];
}
- (void)testInsert {
@@ -2907,6 +2972,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:3], 72);
XCTAssertEqual([array valueAtIndex:4], 73);
XCTAssertEqual([array valueAtIndex:5], 74);
+ [array release];
}
- (void)testRemove {
@@ -2943,6 +3009,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 0U);
XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
NSException, NSRangeException);
+ [array release];
}
- (void)testInplaceMutation {
@@ -2981,6 +3048,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
NSException, NSRangeException);
XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
NSException, NSRangeException);
+ [array release];
}
- (void)testInternalResizing {
@@ -3005,6 +3073,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 404U);
[array removeAll];
XCTAssertEqual(array.count, 0U);
+ [array release];
}
@end
@@ -3165,6 +3234,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array2 rawValueAtIndex:1], 72);
XCTAssertEqual([array2 rawValueAtIndex:2], 1000);
XCTAssertEqual([array2 valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
+ [array2 release];
+ [array release];
}
- (void)testArrayFromArray {
@@ -3182,6 +3253,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertNotEqual(array, array2);
XCTAssertEqualObjects(array, array2);
XCTAssertEqual(array.validationFunc, array2.validationFunc);
+ [array release];
}
- (void)testUnknownAdds {
@@ -3197,7 +3269,6 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertThrowsSpecificNamed([array addValues:kValues1 count:GPBARRAYSIZE(kValues1)],
NSException, NSInvalidArgumentException);
XCTAssertEqual(array.count, 0U);
-
[array release];
}
@@ -3229,7 +3300,6 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
XCTAssertEqual([array rawValueAtIndex:3], 74);
XCTAssertEqual([array rawValueAtIndex:4], 71);
-
[array release];
}
@@ -3256,6 +3326,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertThrowsSpecificNamed([array insertValue:374 atIndex:3],
NSException, NSInvalidArgumentException);
XCTAssertEqual(array.count, 3U);
+ [array release];
}
- (void)testRawInsert {
@@ -3292,7 +3363,6 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array rawValueAtIndex:4], 73);
XCTAssertEqual([array rawValueAtIndex:5], 374);
XCTAssertEqual([array valueAtIndex:5], kGPBUnrecognizedEnumeratorValue);
-
[array release];
}
@@ -3313,6 +3383,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual([array valueAtIndex:1], 72);
XCTAssertEqual([array valueAtIndex:2], 73);
XCTAssertEqual([array valueAtIndex:3], 74);
+ [array release];
}
@@ -3336,6 +3407,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withRawValue:74],
NSException, NSRangeException);
+ [array release];
}
- (void)testRawInternalResizing {
@@ -3360,6 +3432,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) {
XCTAssertEqual(array.count, 404U);
[array removeAll];
XCTAssertEqual(array.count, 0U);
+ [array release];
}
@end
diff --git a/objectivec/Tests/GPBCodedInputStreamTests.m b/objectivec/Tests/GPBCodedInputStreamTests.m
index 0a709cbe..5f29d7c8 100644
--- a/objectivec/Tests/GPBCodedInputStreamTests.m
+++ b/objectivec/Tests/GPBCodedInputStreamTests.m
@@ -184,7 +184,7 @@
XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
TestAllTypes* message2 =
- [TestAllTypes parseFromData:rawBytes extensionRegistry:nil];
+ [TestAllTypes parseFromData:rawBytes extensionRegistry:nil error:NULL];
[self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
}
@@ -227,8 +227,9 @@
// reading.
GPBCodedInputStream* stream =
[GPBCodedInputStream streamWithData:message.data];
- TestAllTypes* message2 =
- [TestAllTypes parseFromCodedInputStream:stream extensionRegistry:nil];
+ TestAllTypes* message2 = [TestAllTypes parseFromCodedInputStream:stream
+ extensionRegistry:nil
+ error:NULL];
XCTAssertEqualObjects(message.optionalBytes, message2.optionalBytes);
@@ -280,8 +281,9 @@
NSData* data =
[rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
- TestAllTypes* message =
- [TestAllTypes parseFromCodedInputStream:input extensionRegistry:nil];
+ TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
+ extensionRegistry:nil
+ error:NULL];
// Make sure we can read string properties twice without crashing.
XCTAssertEqual([message.defaultString length], (NSUInteger)0);
XCTAssertEqualObjects(@"", message.defaultString);
diff --git a/objectivec/Tests/GPBConcurrencyTests.m b/objectivec/Tests/GPBConcurrencyTests.m
index 3749fc34..e500ad77 100644
--- a/objectivec/Tests/GPBConcurrencyTests.m
+++ b/objectivec/Tests/GPBConcurrencyTests.m
@@ -31,10 +31,16 @@
#import "GPBTestUtilities.h"
#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
static const int kNumThreads = 100;
static const int kNumMessages = 100;
+// NOTE: Most of these tests don't "fail" in the sense that the XCTAsserts
+// trip. Rather, the asserts simply exercise the apis, and if there is
+// a concurancy issue, the NSAsserts in the runtime code fire and/or the
+// code just crashes outright.
+
@interface ConcurrencyTests : GPBTestCase
@end
@@ -132,6 +138,48 @@ static const int kNumMessages = 100;
}
}
+- (void)readInt32Int32Map:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.iToI count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetInt32Int32MapField {
+ NSArray *messages =
+ [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readInt32Int32Map:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.iToI count], (NSUInteger)0);
+ }
+}
+
+- (void)readStringStringMap:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.strToStr count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetStringStringMapField {
+ NSArray *messages =
+ [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readStringStringMap:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.strToStr count], (NSUInteger)0);
+ }
+}
+
- (void)readOptionalForeignMessageExtension:(NSArray *)messages {
for (int i = 0; i < 10; i++) {
for (TestAllExtensions *message in messages) {
diff --git a/objectivec/Tests/GPBDictionaryTests+Bool.m b/objectivec/Tests/GPBDictionaryTests+Bool.m
index bc4998be..43650f51 100644
--- a/objectivec/Tests/GPBDictionaryTests+Bool.m
+++ b/objectivec/Tests/GPBDictionaryTests+Bool.m
@@ -33,12 +33,9 @@
#import "GPBDictionary.h"
+#import "GPBTestUtilities.h"
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
-#ifndef GPBARRAYSIZE
-#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-#endif // GPBARRAYSIZE
-
// Pull in the macros (using an external file because expanding all tests
// in a single file makes a file that is failing to work with within Xcode.
//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
diff --git a/objectivec/Tests/GPBDictionaryTests+Int32.m b/objectivec/Tests/GPBDictionaryTests+Int32.m
index 5e25799c..1ee099ee 100644
--- a/objectivec/Tests/GPBDictionaryTests+Int32.m
+++ b/objectivec/Tests/GPBDictionaryTests+Int32.m
@@ -33,6 +33,7 @@
#import "GPBDictionary.h"
+#import "GPBTestUtilities.h"
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
// Pull in the macros (using an external file because expanding all tests
@@ -42,10 +43,6 @@
//%PDDM-EXPAND TEST_FOR_POD_KEY(Int32, int32_t, 11, 12, 13, 14)
// This block of code is generated, do not edit it directly.
-#ifndef GPBARRAYSIZE
-#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-#endif // GPBARRAYSIZE
-
// To let the testing macros work, add some extra methods to simplify things.
@interface GPBInt32EnumDictionary (TestingTweak)
+ (instancetype)dictionaryWithValue:(int32_t)value forKey:(int32_t)key;
diff --git a/objectivec/Tests/GPBDictionaryTests+Int64.m b/objectivec/Tests/GPBDictionaryTests+Int64.m
index 6e794d38..4a94e033 100644
--- a/objectivec/Tests/GPBDictionaryTests+Int64.m
+++ b/objectivec/Tests/GPBDictionaryTests+Int64.m
@@ -33,6 +33,7 @@
#import "GPBDictionary.h"
+#import "GPBTestUtilities.h"
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
// Pull in the macros (using an external file because expanding all tests
@@ -42,10 +43,6 @@
//%PDDM-EXPAND TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL)
// This block of code is generated, do not edit it directly.
-#ifndef GPBARRAYSIZE
-#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-#endif // GPBARRAYSIZE
-
// To let the testing macros work, add some extra methods to simplify things.
@interface GPBInt64EnumDictionary (TestingTweak)
+ (instancetype)dictionaryWithValue:(int32_t)value forKey:(int64_t)key;
diff --git a/objectivec/Tests/GPBDictionaryTests+String.m b/objectivec/Tests/GPBDictionaryTests+String.m
index 95bf2d06..09fbc608 100644
--- a/objectivec/Tests/GPBDictionaryTests+String.m
+++ b/objectivec/Tests/GPBDictionaryTests+String.m
@@ -33,6 +33,7 @@
#import "GPBDictionary.h"
+#import "GPBTestUtilities.h"
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
// Pull in the macros (using an external file because expanding all tests
@@ -42,10 +43,6 @@
//%PDDM-EXPAND TESTS_FOR_POD_VALUES(String, NSString, *, Objects, @"foo", @"bar", @"baz", @"mumble")
// This block of code is generated, do not edit it directly.
-#ifndef GPBARRAYSIZE
-#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-#endif // GPBARRAYSIZE
-
// To let the testing macros work, add some extra methods to simplify things.
@interface GPBStringEnumDictionary (TestingTweak)
+ (instancetype)dictionaryWithValue:(int32_t)value forKey:(NSString *)key;
diff --git a/objectivec/Tests/GPBDictionaryTests+UInt32.m b/objectivec/Tests/GPBDictionaryTests+UInt32.m
index a89ded3d..f8d280fa 100644
--- a/objectivec/Tests/GPBDictionaryTests+UInt32.m
+++ b/objectivec/Tests/GPBDictionaryTests+UInt32.m
@@ -33,6 +33,7 @@
#import "GPBDictionary.h"
+#import "GPBTestUtilities.h"
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
// Pull in the macros (using an external file because expanding all tests
@@ -42,10 +43,6 @@
//%PDDM-EXPAND TEST_FOR_POD_KEY(UInt32, uint32_t, 1U, 2U, 3U, 4U)
// This block of code is generated, do not edit it directly.
-#ifndef GPBARRAYSIZE
-#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-#endif // GPBARRAYSIZE
-
// To let the testing macros work, add some extra methods to simplify things.
@interface GPBUInt32EnumDictionary (TestingTweak)
+ (instancetype)dictionaryWithValue:(int32_t)value forKey:(uint32_t)key;
diff --git a/objectivec/Tests/GPBDictionaryTests+UInt64.m b/objectivec/Tests/GPBDictionaryTests+UInt64.m
index 355639c6..cebd6df2 100644
--- a/objectivec/Tests/GPBDictionaryTests+UInt64.m
+++ b/objectivec/Tests/GPBDictionaryTests+UInt64.m
@@ -33,6 +33,7 @@
#import "GPBDictionary.h"
+#import "GPBTestUtilities.h"
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
// Pull in the macros (using an external file because expanding all tests
@@ -42,10 +43,6 @@
//%PDDM-EXPAND TEST_FOR_POD_KEY(UInt64, uint64_t, 31ULL, 32ULL, 33ULL, 34ULL)
// This block of code is generated, do not edit it directly.
-#ifndef GPBARRAYSIZE
-#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-#endif // GPBARRAYSIZE
-
// To let the testing macros work, add some extra methods to simplify things.
@interface GPBUInt64EnumDictionary (TestingTweak)
+ (instancetype)dictionaryWithValue:(int32_t)value forKey:(uint64_t)key;
diff --git a/objectivec/Tests/GPBDictionaryTests.pddm b/objectivec/Tests/GPBDictionaryTests.pddm
index 39793e03..ee26fac8 100644
--- a/objectivec/Tests/GPBDictionaryTests.pddm
+++ b/objectivec/Tests/GPBDictionaryTests.pddm
@@ -720,10 +720,6 @@
//
//%PDDM-DEFINE TEST_HELPERS(KEY_NAME, KEY_TYPE, KisP)
-//%#ifndef GPBARRAYSIZE
-//%#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-//%#endif // GPBARRAYSIZE
-//%
//%// To let the testing macros work, add some extra methods to simplify things.
//%@interface GPB##KEY_NAME##EnumDictionary (TestingTweak)
//%+ (instancetype)dictionaryWithValue:(int32_t)value forKey:(KEY_TYPE##KisP$S##KisP)key;
diff --git a/objectivec/Tests/GPBMessageTests+Merge.m b/objectivec/Tests/GPBMessageTests+Merge.m
index 599ad055..3b6fdbd4 100644
--- a/objectivec/Tests/GPBMessageTests+Merge.m
+++ b/objectivec/Tests/GPBMessageTests+Merge.m
@@ -35,6 +35,7 @@
#import "GPBMessage.h"
#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h"
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
@@ -431,7 +432,7 @@
XCTAssertNotNil(dst.oneofGroup);
XCTAssertNotEqual(dst.oneofGroup, mergedGroup); // Pointer comparision.
- // Back to something else ot make sure message clears out ok.
+ // Back to something else to make sure message clears out ok.
src.oneofInt32 = 10;
[dst mergeFrom:src];
@@ -640,7 +641,7 @@
XCTAssertEqualObjects(mergedSubMessage, subMessage);
XCTAssertEqualObjects(dst.oneofBytes, oneofBytesDefault);
- // Back to something else ot make sure message clears out ok.
+ // Back to something else to make sure message clears out ok.
src.oneofInt32 = 10;
[dst mergeFrom:src];
diff --git a/objectivec/Tests/GPBMessageTests+Runtime.m b/objectivec/Tests/GPBMessageTests+Runtime.m
index 6ad29ca5..4621f90f 100644
--- a/objectivec/Tests/GPBMessageTests+Runtime.m
+++ b/objectivec/Tests/GPBMessageTests+Runtime.m
@@ -35,6 +35,7 @@
#import "GPBMessage.h"
#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
@@ -772,6 +773,8 @@
XCTAssertThrowsSpecificNamed(msg.oneofEnum = 666, NSException,
NSInvalidArgumentException);
XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
+
+ [msg release];
}
- (void)testAccessingProto3UnknownEnumValues {
@@ -1261,7 +1264,7 @@
Message2_O_OneOfCase_OneofEnum,
};
- for (size_t i = 0; i < (sizeof(values) / sizeof((values[0]))); ++i) {
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
switch (values[i]) {
case Message2_O_OneOfCase_OneofInt32:
msg.oneofInt32 = 1;
@@ -1318,7 +1321,7 @@
msg.oneofEnum = Message2_Enum_Bar;
break;
default:
- XCTFail(@"shouldn't happen, loop: %zd", i);
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
break;
}
@@ -1770,7 +1773,7 @@
Message3_O_OneOfCase_OneofEnum,
};
- for (size_t i = 0; i < (sizeof(values) / sizeof((values[0]))); ++i) {
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
switch (values[i]) {
case Message3_O_OneOfCase_OneofInt32:
msg.oneofInt32 = 1;
@@ -1824,7 +1827,7 @@
msg.oneofEnum = Message3_Enum_Baz;
break;
default:
- XCTFail(@"shouldn't happen, loop: %zd", i);
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
break;
}
diff --git a/objectivec/Tests/GPBMessageTests+Serialization.m b/objectivec/Tests/GPBMessageTests+Serialization.m
index ddc2ae19..8867f56d 100644
--- a/objectivec/Tests/GPBMessageTests+Serialization.m
+++ b/objectivec/Tests/GPBMessageTests+Serialization.m
@@ -41,10 +41,6 @@
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
-#ifndef GPBARRAYSIZE
-#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-#endif // GPBARRAYSIZE
-
static NSData *DataFromCStr(const char *str) {
return [NSData dataWithBytes:str length:strlen(str)];
}
@@ -124,7 +120,8 @@ static NSData *DataFromCStr(const char *str) {
fooWithExtras.enumValue = DropUnknownsFooWithExtraFields_NestedEnum_Baz;
fooWithExtras.extraInt32Value = 2;
- DropUnknownsFoo *foo = [DropUnknownsFoo parseFromData:[fooWithExtras data]];
+ DropUnknownsFoo *foo =
+ [DropUnknownsFoo parseFromData:[fooWithExtras data] error:NULL];
XCTAssertEqual(foo.int32Value, 1);
XCTAssertEqual(foo.enumValue, DropUnknownsFoo_NestedEnum_Baz);
@@ -132,7 +129,8 @@ static NSData *DataFromCStr(const char *str) {
XCTAssertEqual([foo.unknownFields countOfFields], 0U);
[fooWithExtras release];
- fooWithExtras = [DropUnknownsFooWithExtraFields parseFromData:[foo data]];
+ fooWithExtras =
+ [DropUnknownsFooWithExtraFields parseFromData:[foo data] error:NULL];
XCTAssertEqual(fooWithExtras.int32Value, 1);
XCTAssertEqual(fooWithExtras.enumValue,
DropUnknownsFooWithExtraFields_NestedEnum_Baz);
@@ -153,7 +151,7 @@ static NSData *DataFromCStr(const char *str) {
rawValue:Message3_Enum_Extra3];
orig.oneofEnum = Message3_Enum_Extra3;
- Message2 *msg = [[Message2 alloc] initWithData:[orig data]];
+ Message2 *msg = [[Message2 alloc] initWithData:[orig data] error:NULL];
// None of the fields should be set.
@@ -214,7 +212,7 @@ static NSData *DataFromCStr(const char *str) {
// Everything should be there via raw values.
UnknownEnumsMyMessage *msg =
- [UnknownEnumsMyMessage parseFromData:[orig data]];
+ [UnknownEnumsMyMessage parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.e, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
XCTAssertEqual(UnknownEnumsMyMessage_E_RawValue(msg),
@@ -236,7 +234,7 @@ static NSData *DataFromCStr(const char *str) {
// Everything should go out and come back.
- orig = [UnknownEnumsMyMessagePlusExtra parseFromData:[msg data]];
+ orig = [UnknownEnumsMyMessagePlusExtra parseFromData:[msg data] error:NULL];
XCTAssertEqual(orig.e, UnknownEnumsMyEnumPlusExtra_EExtra);
XCTAssertEqual(orig.repeatedEArray.count, 1U);
@@ -255,7 +253,7 @@ static NSData *DataFromCStr(const char *str) {
//% MESSAGE *orig = [[MESSAGE alloc] init];
//% orig.oneof##FIELD = VALUE;
//% XCTAssertEqual(orig.oOneOfCase, MESSAGE##_O_OneOfCase_Oneof##FIELD);
-//% MESSAGE *msg = [MESSAGE parseFromData:[orig data]];
+//% MESSAGE *msg = [MESSAGE parseFromData:[orig data] error:NULL];
//% XCTAssertEqual(msg.oOneOfCase, MESSAGE##_O_OneOfCase_Oneof##FIELD);
//% XCTAssertEqual##EQ_SUFFIX(msg.oneof##FIELD, VALUE);
//% [orig release];
@@ -323,7 +321,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofInt32 = 1;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
XCTAssertEqual(msg.oneofInt32, 1);
[orig release];
@@ -333,7 +331,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofInt64 = 2;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
XCTAssertEqual(msg.oneofInt64, 2);
[orig release];
@@ -343,7 +341,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofUint32 = 3U;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
XCTAssertEqual(msg.oneofUint32, 3U);
[orig release];
@@ -353,7 +351,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofUint64 = 4U;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
XCTAssertEqual(msg.oneofUint64, 4U);
[orig release];
@@ -363,7 +361,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofSint32 = 5;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
XCTAssertEqual(msg.oneofSint32, 5);
[orig release];
@@ -373,7 +371,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofSint64 = 6;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
XCTAssertEqual(msg.oneofSint64, 6);
[orig release];
@@ -383,7 +381,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofFixed32 = 7U;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
XCTAssertEqual(msg.oneofFixed32, 7U);
[orig release];
@@ -393,7 +391,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofFixed64 = 8U;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
XCTAssertEqual(msg.oneofFixed64, 8U);
[orig release];
@@ -403,7 +401,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofSfixed32 = 9;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
XCTAssertEqual(msg.oneofSfixed32, 9);
[orig release];
@@ -413,7 +411,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofSfixed64 = 10;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
XCTAssertEqual(msg.oneofSfixed64, 10);
[orig release];
@@ -423,7 +421,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofFloat = 11.0f;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
XCTAssertEqual(msg.oneofFloat, 11.0f);
[orig release];
@@ -433,7 +431,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofDouble = 12.0;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
XCTAssertEqual(msg.oneofDouble, 12.0);
[orig release];
@@ -443,7 +441,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofBool = NO;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofBool);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBool);
XCTAssertEqual(msg.oneofBool, NO);
[orig release];
@@ -453,7 +451,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofString = @"foo";
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofString);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofString);
XCTAssertEqualObjects(msg.oneofString, @"foo");
[orig release];
@@ -463,7 +461,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
[orig release];
@@ -473,7 +471,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofGroup = group;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
XCTAssertEqualObjects(msg.oneofGroup, group);
[orig release];
@@ -483,7 +481,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofMessage = subMessage;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
XCTAssertEqualObjects(msg.oneofMessage, subMessage);
[orig release];
@@ -493,7 +491,7 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofEnum = Message2_Enum_Bar;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
- Message2 *msg = [Message2 parseFromData:[orig data]];
+ Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
[orig release];
@@ -516,7 +514,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofInt32 = 1;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
XCTAssertEqual(msg.oneofInt32, 1);
[orig release];
@@ -526,7 +524,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofInt64 = 2;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
XCTAssertEqual(msg.oneofInt64, 2);
[orig release];
@@ -536,7 +534,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofUint32 = 3U;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
XCTAssertEqual(msg.oneofUint32, 3U);
[orig release];
@@ -546,7 +544,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofUint64 = 4U;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
XCTAssertEqual(msg.oneofUint64, 4U);
[orig release];
@@ -556,7 +554,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofSint32 = 5;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
XCTAssertEqual(msg.oneofSint32, 5);
[orig release];
@@ -566,7 +564,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofSint64 = 6;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
XCTAssertEqual(msg.oneofSint64, 6);
[orig release];
@@ -576,7 +574,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofFixed32 = 7U;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
XCTAssertEqual(msg.oneofFixed32, 7U);
[orig release];
@@ -586,7 +584,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofFixed64 = 8U;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
XCTAssertEqual(msg.oneofFixed64, 8U);
[orig release];
@@ -596,7 +594,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofSfixed32 = 9;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
XCTAssertEqual(msg.oneofSfixed32, 9);
[orig release];
@@ -606,7 +604,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofSfixed64 = 10;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
XCTAssertEqual(msg.oneofSfixed64, 10);
[orig release];
@@ -616,7 +614,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofFloat = 11.0f;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
XCTAssertEqual(msg.oneofFloat, 11.0f);
[orig release];
@@ -626,7 +624,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofDouble = 12.0;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
XCTAssertEqual(msg.oneofDouble, 12.0);
[orig release];
@@ -636,7 +634,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofBool = YES;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofBool);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBool);
XCTAssertEqual(msg.oneofBool, YES);
[orig release];
@@ -646,7 +644,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofString = @"foo";
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofString);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofString);
XCTAssertEqualObjects(msg.oneofString, @"foo");
[orig release];
@@ -656,7 +654,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
[orig release];
@@ -668,7 +666,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofMessage = subMessage;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
XCTAssertEqualObjects(msg.oneofMessage, subMessage);
[orig release];
@@ -678,7 +676,7 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofEnum = Message2_Enum_Bar;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
- Message3 *msg = [Message3 parseFromData:[orig data]];
+ Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
[orig release];
@@ -695,7 +693,7 @@ static NSData *DataFromCStr(const char *str) {
- (void)testMap_StandardWireFormat {
NSData *data = DataFromCStr("\x0A\x04\x08\x01\x10\x01");
- TestMap *msg = [[TestMap alloc] initWithData:data];
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
XCTAssertEqual(msg.mapInt32Int32.count, 1U);
int32_t val = 666;
XCTAssertTrue([msg.mapInt32Int32 valueForKey:1 value:&val]);
@@ -709,7 +707,7 @@ static NSData *DataFromCStr(const char *str) {
// put value before key in wire format
NSData *data = DataFromCStr("\x0A\x04\x10\x01\x08\x02");
- TestMap *msg = [[TestMap alloc] initWithData:data];
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
XCTAssertEqual(msg.mapInt32Int32.count, 1U);
int32_t val = 666;
XCTAssertTrue([msg.mapInt32Int32 valueForKey:2 value:&val]);
@@ -723,7 +721,7 @@ static NSData *DataFromCStr(const char *str) {
// Two key fields in wire format
NSData *data = DataFromCStr("\x0A\x06\x08\x01\x08\x02\x10\x01");
- TestMap *msg = [[TestMap alloc] initWithData:data];
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
XCTAssertEqual(msg.mapInt32Int32.count, 1U);
int32_t val = 666;
XCTAssertTrue([msg.mapInt32Int32 valueForKey:2 value:&val]);
@@ -737,7 +735,7 @@ static NSData *DataFromCStr(const char *str) {
// Two value fields in wire format
NSData *data = DataFromCStr("\x0A\x06\x08\x01\x10\x01\x10\x02");
- TestMap *msg = [[TestMap alloc] initWithData:data];
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
XCTAssertEqual(msg.mapInt32Int32.count, 1U);
int32_t val = 666;
XCTAssertTrue([msg.mapInt32Int32 valueForKey:1 value:&val]);
@@ -751,7 +749,7 @@ static NSData *DataFromCStr(const char *str) {
// No key field in wire format
NSData *data = DataFromCStr("\x0A\x02\x10\x01");
- TestMap *msg = [[TestMap alloc] initWithData:data];
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
XCTAssertEqual(msg.mapInt32Int32.count, 1U);
int32_t val = 666;
XCTAssertTrue([msg.mapInt32Int32 valueForKey:0 value:&val]);
@@ -765,7 +763,7 @@ static NSData *DataFromCStr(const char *str) {
// No value field in wire format
NSData *data = DataFromCStr("\x0A\x02\x08\x01");
- TestMap *msg = [[TestMap alloc] initWithData:data];
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
XCTAssertEqual(msg.mapInt32Int32.count, 1U);
int32_t val = 666;
XCTAssertTrue([msg.mapInt32Int32 valueForKey:1 value:&val]);
@@ -779,7 +777,7 @@ static NSData *DataFromCStr(const char *str) {
// Unknown field in wire format
NSData *data = DataFromCStr("\x0A\x06\x08\x02\x10\x03\x18\x01");
- TestMap *msg = [[TestMap alloc] initWithData:data];
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
XCTAssertEqual(msg.mapInt32Int32.count, 1U);
int32_t val = 666;
XCTAssertTrue([msg.mapInt32Int32 valueForKey:2 value:&val]);
@@ -793,8 +791,12 @@ static NSData *DataFromCStr(const char *str) {
// corrupted data in wire format
NSData *data = DataFromCStr("\x0A\x06\x08\x02\x11\x03");
- XCTAssertThrowsSpecificNamed([TestMap parseFromData:data], NSException,
- NSParseErrorException);
+ NSError *error = nil;
+ TestMap *msg = [TestMap parseFromData:data error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBMessageErrorDomain);
+ XCTAssertEqual(error.code, GPBMessageErrorCodeMalformedData);
}
// TEST(GeneratedMapFieldTest, Proto2UnknownEnum)
@@ -810,14 +812,15 @@ static NSData *DataFromCStr(const char *str) {
[orig.unknownMapField setValue:Proto2MapEnumPlusExtra_EProto2MapEnumExtra
forKey:0];
- TestEnumMap *msg1 = [TestEnumMap parseFromData:[orig data]];
+ TestEnumMap *msg1 = [TestEnumMap parseFromData:[orig data] error:NULL];
XCTAssertEqual(msg1.knownMapField.count, 1U);
int32_t val = -1;
XCTAssertTrue([msg1.knownMapField valueForKey:0 value:&val]);
XCTAssertEqual(val, Proto2MapEnum_Proto2MapEnumFoo);
XCTAssertEqual(msg1.unknownFields.countOfFields, 1U);
- TestEnumMapPlusExtra *msg2 = [TestEnumMapPlusExtra parseFromData:[msg1 data]];
+ TestEnumMapPlusExtra *msg2 =
+ [TestEnumMapPlusExtra parseFromData:[msg1 data] error:NULL];
val = -1;
XCTAssertEqual(msg2.knownMapField.count, 1U);
XCTAssertTrue([msg2.knownMapField valueForKey:0 value:&val]);
@@ -833,6 +836,72 @@ static NSData *DataFromCStr(const char *str) {
[orig release];
}
-#pragma mark -
+#pragma mark - Map Round Tripping
+
+- (void)testProto2MapRoundTripping {
+ Message2 *msg = [[Message2 alloc] init];
+
+ // Key/Value data should result in different byte lengths on wire to ensure
+ // everything is right.
+ [msg.mapInt32Int32 setValue:1000 forKey:200];
+ [msg.mapInt32Int32 setValue:101 forKey:2001];
+ [msg.mapInt64Int64 setValue:1002 forKey:202];
+ [msg.mapInt64Int64 setValue:103 forKey:2003];
+ [msg.mapUint32Uint32 setValue:1004 forKey:204];
+ [msg.mapUint32Uint32 setValue:105 forKey:2005];
+ [msg.mapUint64Uint64 setValue:1006 forKey:206];
+ [msg.mapUint64Uint64 setValue:107 forKey:2007];
+ [msg.mapSint32Sint32 setValue:1008 forKey:208];
+ [msg.mapSint32Sint32 setValue:109 forKey:2009];
+ [msg.mapSint64Sint64 setValue:1010 forKey:210];
+ [msg.mapSint64Sint64 setValue:111 forKey:2011];
+ [msg.mapFixed32Fixed32 setValue:1012 forKey:212];
+ [msg.mapFixed32Fixed32 setValue:113 forKey:2013];
+ [msg.mapFixed64Fixed64 setValue:1014 forKey:214];
+ [msg.mapFixed64Fixed64 setValue:115 forKey:2015];
+ [msg.mapSfixed32Sfixed32 setValue:1016 forKey:216];
+ [msg.mapSfixed32Sfixed32 setValue:117 forKey:2017];
+ [msg.mapSfixed64Sfixed64 setValue:1018 forKey:218];
+ [msg.mapSfixed64Sfixed64 setValue:119 forKey:2019];
+ [msg.mapInt32Float setValue:1020.f forKey:220];
+ [msg.mapInt32Float setValue:121.f forKey:2021];
+ [msg.mapInt32Double setValue:1022. forKey:222];
+ [msg.mapInt32Double setValue:123. forKey:2023];
+ [msg.mapBoolBool setValue:false forKey:true];
+ [msg.mapBoolBool setValue:true forKey:false];
+ msg.mapStringString[@"224"] = @"1024";
+ msg.mapStringString[@"2025"] = @"125";
+ msg.mapStringBytes[@"226"] = DataFromCStr("1026");
+ msg.mapStringBytes[@"2027"] = DataFromCStr("127");
+ Message2 *val1 = [[Message2 alloc] init];
+ val1.optionalInt32 = 1028;
+ Message2 *val2 = [[Message2 alloc] init];
+ val2.optionalInt32 = 129;
+ [msg.mapStringMessage setValue:val1 forKey:@"228"];
+ [msg.mapStringMessage setValue:val2 forKey:@"2029"];
+ [msg.mapInt32Bytes setValue:DataFromCStr("1030 bytes") forKey:230];
+ [msg.mapInt32Bytes setValue:DataFromCStr("131") forKey:2031];
+ [msg.mapInt32Enum setValue:Message2_Enum_Bar forKey:232];
+ [msg.mapInt32Enum setValue:Message2_Enum_Baz forKey:2033];
+ Message2 *val3 = [[Message2 alloc] init];
+ val3.optionalInt32 = 1034;
+ Message2 *val4 = [[Message2 alloc] init];
+ val4.optionalInt32 = 135;
+ [msg.mapInt32Message setValue:val3 forKey:234];
+ [msg.mapInt32Message setValue:val4 forKey:2035];
+
+ NSData *data = [msg data];
+ Message2 *msg2 = [[Message2 alloc] initWithData:data error:NULL];
+
+ XCTAssertNotEqual(msg2, msg); // Pointer comparison
+ XCTAssertEqualObjects(msg2, msg);
+
+ [val4 release];
+ [val3 release];
+ [val2 release];
+ [val1 release];
+ [msg2 release];
+ [msg release];
+}
@end
diff --git a/objectivec/Tests/GPBMessageTests.m b/objectivec/Tests/GPBMessageTests.m
index 5ec67cd9..e0154c1a 100644
--- a/objectivec/Tests/GPBMessageTests.m
+++ b/objectivec/Tests/GPBMessageTests.m
@@ -34,6 +34,7 @@
#import "GPBArray_PackagePrivate.h"
#import "GPBDescriptor.h"
+#import "GPBDictionary_PackagePrivate.h"
#import "GPBField_PackagePrivate.h"
#import "GPBMessage_PackagePrivate.h"
#import "GPBUnknownFieldSet_PackagePrivate.h"
@@ -47,23 +48,9 @@
@implementation MessageTests
// TODO(thomasvl): this should get split into a few files of logic junks, it is
-// a jumble
-// of things at the moment (and the testutils have a bunch of the real
+// a jumble of things at the moment (and the testutils have a bunch of the real
// assertions).
-#ifdef DEBUG
-- (void)assertBlock:(void (^)())block
- throwsWithMessageInUserInfo:(GPBMessage *)message {
- @try {
- block();
- XCTAssertTrue(NO);
- }
- @catch (NSException *e) {
- XCTAssertEqualObjects([e userInfo][GPBExceptionMessageKey], message);
- }
-}
-#endif // DEBUG
-
- (TestAllTypes *)mergeSource {
TestAllTypes *message = [TestAllTypes message];
[message setOptionalInt32:1];
@@ -290,14 +277,18 @@
XCTAssertTrue(message.initialized);
}
-#ifdef DEBUG
-- (void)testUninitializedException {
+- (void)testDataFromUninitialized {
TestRequired *message = [TestRequired message];
- [self assertBlock:^{
- [message data];
- } throwsWithMessageInUserInfo:message];
-}
+ NSData *data = [message data];
+ // In DEBUG, the data generation will fail, but in non DEBUG, it passes
+ // because the check isn't done (for speed).
+#ifdef DEBUG
+ XCTAssertNil(data);
+#else
+ XCTAssertNotNil(data);
+ XCTAssertFalse(message.initialized);
#endif // DEBUG
+}
- (void)testInitialized {
// We're mostly testing that no exception is thrown.
@@ -305,18 +296,22 @@
XCTAssertFalse(message.initialized);
}
-#ifdef DEBUG
-- (void)testNestedUninitializedException {
+- (void)testDataFromNestedUninitialized {
TestRequiredForeign *message = [TestRequiredForeign message];
[message setOptionalMessage:[TestRequired message]];
message.repeatedMessageArray = [NSMutableArray array];
[message.repeatedMessageArray addObject:[TestRequired message]];
[message.repeatedMessageArray addObject:[TestRequired message]];
- [self assertBlock:^{
- [message data];
- } throwsWithMessageInUserInfo:message];
-}
+ NSData *data = [message data];
+ // In DEBUG, the data generation will fail, but in non DEBUG, it passes
+ // because the check isn't done (for speed).
+#ifdef DEBUG
+ XCTAssertNil(data);
+#else
+ XCTAssertNotNil(data);
+ XCTAssertFalse(message.initialized);
#endif // DEBUG
+}
- (void)testNestedInitialized {
// We're mostly testing that no exception is thrown.
@@ -330,13 +325,23 @@
XCTAssertFalse(message.initialized);
}
-#ifdef DEBUG
- (void)testParseUninitialized {
- [self assertBlock:^{
- [TestRequired parseFromData:GPBEmptyNSData()];
- } throwsWithMessageInUserInfo:[TestRequired message]];
-}
+ NSError *error = nil;
+ TestRequired *msg =
+ [TestRequired parseFromData:GPBEmptyNSData() error:&error];
+ // In DEBUG, the parse will fail, but in non DEBUG, it passes because
+ // the check isn't done (for speed).
+#ifdef DEBUG
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBMessageErrorDomain);
+ XCTAssertEqual(error.code, GPBMessageErrorCodeMissingRequiredField);
+#else
+ XCTAssertNotNil(msg);
+ XCTAssertNil(error);
+ XCTAssertFalse(msg.initialized);
#endif // DEBUG
+}
- (void)testCoding {
NSData *data =
@@ -1033,7 +1038,7 @@
message3.repeatedStringArray = [NSMutableArray arrayWithObject:@"wee"];
XCTAssertNotNil(message.repeatedInt32Array);
XCTAssertNotNil(message.repeatedStringArray);
- TestAllTypes *message4 = [message3 copy];
+ TestAllTypes *message4 = [[message3 copy] autorelease];
XCTAssertNotEqual(message3.repeatedInt32Array, message4.repeatedInt32Array);
XCTAssertEqualObjects(message3.repeatedInt32Array,
message4.repeatedInt32Array);
@@ -1156,6 +1161,205 @@
XCTAssertFalse([message hasA]);
}
+- (void)testDefaultingMaps {
+ // Basic tests for default creation of maps in a message.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [TestRecursiveMessageWithRepeatedField message];
+
+ // Simply accessing the map should not make any fields visible.
+ XCTAssertNotNil(message.a.a.iToI);
+ XCTAssertFalse([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+ XCTAssertNotNil(message2.a.a.strToStr);
+ XCTAssertFalse([message2 hasA]);
+ XCTAssertFalse([message2.a hasA]);
+
+ // But adding an element to the map should.
+ [message.a.a.iToI setValue:100 forKey:200];
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a hasA]);
+ XCTAssertEqual([message.a.a.iToI count], (NSUInteger)1);
+ [message2.a.a.strToStr setObject:@"foo" forKey:@"bar"];
+ XCTAssertTrue([message2 hasA]);
+ XCTAssertTrue([message2.a hasA]);
+ XCTAssertEqual([message2.a.a.strToStr count], (NSUInteger)1);
+}
+
+- (void)testAutocreatedMapShared {
+ // Multiple objects pointing to the same map.
+ TestRecursiveMessageWithRepeatedField *message1a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message1b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message1a.a.iToI = message1b.a.iToI;
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertFalse([message1b hasA]);
+ [message1a.a.iToI setValue:1 forKey:2];
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertTrue([message1b hasA]);
+ XCTAssertEqual(message1a.a.iToI, message1b.a.iToI);
+
+ TestRecursiveMessageWithRepeatedField *message2a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message2a.a.strToStr = message2b.a.strToStr;
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertFalse([message2b hasA]);
+ [message2a.a.strToStr setObject:@"bar" forKey:@"foo"];
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertTrue([message2b hasA]);
+ XCTAssertEqual(message2a.a.strToStr, message2b.a.strToStr);
+}
+
+- (void)testAutocreatedMapCopy {
+ // Copy should not copy autocreated maps.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.strToStr);
+ XCTAssertNotNil(message.iToI);
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [[message copy] autorelease];
+ // Pointer conparisions.
+ XCTAssertNotEqual(message.strToStr, message2.strToStr);
+ XCTAssertNotEqual(message.iToI, message2.iToI);
+
+ // Mutable copy should copy empty arrays that were explicitly set (end up
+ // with different objects that are equal).
+ TestRecursiveMessageWithRepeatedField *message3 =
+ [TestRecursiveMessageWithRepeatedField message];
+ message3.iToI = [GPBInt32Int32Dictionary dictionaryWithValue:10 forKey:20];
+ message3.strToStr =
+ [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"123"];
+ XCTAssertNotNil(message.iToI);
+ XCTAssertNotNil(message.iToI);
+ TestRecursiveMessageWithRepeatedField *message4 =
+ [[message3 copy] autorelease];
+ XCTAssertNotEqual(message3.iToI, message4.iToI);
+ XCTAssertEqualObjects(message3.iToI, message4.iToI);
+ XCTAssertNotEqual(message3.strToStr, message4.strToStr);
+ XCTAssertEqualObjects(message3.strToStr, message4.strToStr);
+}
+
+- (void)testAutocreatedMapRetain {
+ // Should be able to retain autocreated map while the creator is dealloced.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+
+ @autoreleasepool {
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [TestRecursiveMessageWithRepeatedField message];
+ message.iToI = message2.iToI;
+ message.strToStr = message2.strToStr;
+ // Pointer conparision
+ XCTAssertEqual(message.iToI->_autocreator, message2);
+ XCTAssertTrue([message.strToStr
+ isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(
+ ((GPBAutocreatedDictionary *)message.strToStr)->_autocreator,
+ message2);
+ }
+
+ XCTAssertNil(message.iToI->_autocreator);
+ XCTAssertTrue(
+ [message.strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertNil(
+ ((GPBAutocreatedDictionary *)message.strToStr)->_autocreator);
+}
+
+- (void)testSetNilAutocreatedMap {
+ // Setting map to nil should cause it to lose its delegate.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ GPBInt32Int32Dictionary *iToI = [message.iToI retain];
+ GPBAutocreatedDictionary *strToStr =
+ (GPBAutocreatedDictionary *)[message.strToStr retain];
+ XCTAssertTrue([strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(iToI->_autocreator, message);
+ XCTAssertEqual(strToStr->_autocreator, message);
+ message.iToI = nil;
+ message.strToStr = nil;
+ XCTAssertNil(iToI->_autocreator);
+ XCTAssertNil(strToStr->_autocreator);
+ [iToI release];
+ [strToStr release];
+}
+
+- (void)testReplaceAutocreatedMap {
+ // Replacing map should orphan the old one and cause its creator to become
+ // visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iToI);
+ XCTAssertFalse([message hasA]);
+ GPBInt32Int32Dictionary *iToI = [message.a.iToI retain];
+ XCTAssertEqual(iToI->_autocreator, message.a); // Pointer comparision
+ message.a.iToI = [GPBInt32Int32Dictionary dictionaryWithValue:6 forKey:7];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.iToI, iToI); // Pointer comparision
+ XCTAssertNil(iToI->_autocreator);
+ [iToI release];
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strToStr);
+ XCTAssertFalse([message hasA]);
+ GPBAutocreatedDictionary *strToStr =
+ (GPBAutocreatedDictionary *)[message.a.strToStr retain];
+ XCTAssertTrue([strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(strToStr->_autocreator, message.a); // Pointer comparision
+ message.a.strToStr =
+ [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"def"];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.strToStr, strToStr); // Pointer comparision
+ XCTAssertNil(strToStr->_autocreator);
+ [strToStr release];
+ }
+}
+
+- (void)testSetAutocreatedMapToSelf {
+ // Setting map to itself should cause it to become visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iToI);
+ XCTAssertFalse([message hasA]);
+ message.a.iToI = message.a.iToI;
+ XCTAssertTrue([message hasA]);
+ XCTAssertNil(message.a.iToI->_autocreator);
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strToStr);
+ XCTAssertFalse([message hasA]);
+ message.a.strToStr = message.a.strToStr;
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a.strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertNil(((GPBAutocreatedDictionary *)message.a.strToStr)->_autocreator);
+ }
+}
+
+- (void)testAutocreatedMapRemoveAllValues {
+ // Calling removeAll on autocreated map should not cause it to be visible.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ [message.a.iToI removeAll];
+ XCTAssertFalse([message hasA]);
+ [message.a.strToStr removeAllObjects];
+ XCTAssertFalse([message hasA]);
+}
+
- (void)testExtensionAccessors {
TestAllExtensions *message = [TestAllExtensions message];
[self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
@@ -1555,7 +1759,8 @@
GPBMessage *message = [GPBMessage message];
[message setUnknownFields:unknowns];
NSData *data = [message data];
- GPBMessage *message2 = [GPBMessage parseFromData:data extensionRegistry:nil];
+ GPBMessage *message2 =
+ [GPBMessage parseFromData:data extensionRegistry:nil error:NULL];
XCTAssertEqualObjects(message, message2);
}
@@ -1579,9 +1784,11 @@
GPBCodedInputStream *input =
[GPBCodedInputStream streamWithData:delimitedData];
GPBMessage *message3 = [GPBMessage parseDelimitedFromCodedInputStream:input
- extensionRegistry:nil];
+ extensionRegistry:nil
+ error:NULL];
GPBMessage *message4 = [GPBMessage parseDelimitedFromCodedInputStream:input
- extensionRegistry:nil];
+ extensionRegistry:nil
+ error:NULL];
XCTAssertEqualObjects(message1, message3);
XCTAssertEqualObjects(message2, message4);
}
@@ -1673,7 +1880,7 @@
XCTAssertEqual(msg.bar, EnumTestMsg_MyEnum_One);
XCTAssertEqual(msg.baz, EnumTestMsg_MyEnum_NegOne);
// Bounce to wire and back.
- EnumTestMsg *msgPrime = [EnumTestMsg parseFromData:[msg data]];
+ EnumTestMsg *msgPrime = [EnumTestMsg parseFromData:[msg data] error:NULL];
XCTAssertEqualObjects(msgPrime, msg);
XCTAssertEqual(msgPrime.foo, EnumTestMsg_MyEnum_Zero);
XCTAssertEqual(msgPrime.bar, EnumTestMsg_MyEnum_One);
@@ -1685,7 +1892,7 @@
XCTAssertEqual(msg.bar, EnumTestMsg_MyEnum_Two);
XCTAssertEqual(msg.baz, EnumTestMsg_MyEnum_NegTwo);
// Bounce to wire and back.
- msgPrime = [EnumTestMsg parseFromData:[msg data]];
+ msgPrime = [EnumTestMsg parseFromData:[msg data] error:NULL];
XCTAssertEqualObjects(msgPrime, msg);
XCTAssertEqual(msgPrime.foo, EnumTestMsg_MyEnum_Zero);
XCTAssertEqual(msgPrime.bar, EnumTestMsg_MyEnum_Two);
@@ -1706,7 +1913,7 @@
XCTAssertEqual([msg.mumbleArray valueAtIndex:3], EnumTestMsg_MyEnum_NegOne);
XCTAssertEqual([msg.mumbleArray valueAtIndex:4], EnumTestMsg_MyEnum_NegTwo);
// Bounce to wire and back.
- msgPrime = [EnumTestMsg parseFromData:[msg data]];
+ msgPrime = [EnumTestMsg parseFromData:[msg data] error:NULL];
XCTAssertEqualObjects(msgPrime, msg);
XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:0],
EnumTestMsg_MyEnum_Zero);
diff --git a/objectivec/Tests/GPBPerfTests.m b/objectivec/Tests/GPBPerfTests.m
index d09021af..1259d146 100644
--- a/objectivec/Tests/GPBPerfTests.m
+++ b/objectivec/Tests/GPBPerfTests.m
@@ -30,6 +30,7 @@
#import "GPBTestUtilities.h"
#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
#import "google/protobuf/UnittestObjc.pbobjc.h"
//
@@ -57,7 +58,7 @@ static const uint32_t kRepeatedCount = 100;
[self setAllFields:message repeatedCount:kRepeatedCount];
NSData* rawBytes = [message data];
[message release];
- message = [[TestAllTypes alloc] initWithData:rawBytes];
+ message = [[TestAllTypes alloc] initWithData:rawBytes error:NULL];
[message release];
}
}];
@@ -71,7 +72,7 @@ static const uint32_t kRepeatedCount = 100;
NSData* rawBytes = [message data];
[message release];
TestAllExtensions* message2 =
- [[TestAllExtensions alloc] initWithData:rawBytes];
+ [[TestAllExtensions alloc] initWithData:rawBytes error:NULL];
[message2 release];
}
}];
@@ -84,7 +85,7 @@ static const uint32_t kRepeatedCount = 100;
[self setPackedFields:message repeatedCount:kRepeatedCount];
NSData* rawBytes = [message data];
[message release];
- message = [[TestPackedTypes alloc] initWithData:rawBytes];
+ message = [[TestPackedTypes alloc] initWithData:rawBytes error:NULL];
[message release];
}
}];
@@ -98,7 +99,7 @@ static const uint32_t kRepeatedCount = 100;
NSData* rawBytes = [message data];
[message release];
TestPackedExtensions* message2 =
- [[TestPackedExtensions alloc] initWithData:rawBytes];
+ [[TestPackedExtensions alloc] initWithData:rawBytes error:NULL];
[message2 release];
}
}];
diff --git a/objectivec/Tests/GPBStringTests.m b/objectivec/Tests/GPBStringTests.m
index 30f13775..802afa7d 100644
--- a/objectivec/Tests/GPBStringTests.m
+++ b/objectivec/Tests/GPBStringTests.m
@@ -31,10 +31,7 @@
#import <XCTest/XCTest.h>
#import "GPBCodedInputStream_PackagePrivate.h"
-
-#ifndef GPBARRAYSIZE
-#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
-#endif // GPBARRAYSIZE
+#import "GPBTestUtilities.h"
@interface TestClass : NSObject
@property(nonatomic, retain) NSString *foo;
diff --git a/objectivec/Tests/GPBSwiftTests.swift b/objectivec/Tests/GPBSwiftTests.swift
index e7b6f94c..30b9cbd4 100644
--- a/objectivec/Tests/GPBSwiftTests.swift
+++ b/objectivec/Tests/GPBSwiftTests.swift
@@ -53,6 +53,12 @@ class GPBBridgeTests: XCTestCase {
msg.repeatedStringArray.addObject("pqr")
msg.repeatedEnumArray.addValue(Message2_Enum.Bar.rawValue)
msg.repeatedEnumArray.addValue(Message2_Enum.Baz.rawValue)
+ msg.mapInt32Int32.setValue(400, forKey:500)
+ msg.mapInt32Int32.setValue(401, forKey:501)
+ msg.mapStringString.setObject("foo", forKey:"bar")
+ msg.mapStringString.setObject("abc", forKey:"xyz")
+ msg.mapInt32Enum.setValue(Message2_Enum.Bar.rawValue, forKey:600)
+ msg.mapInt32Enum.setValue(Message2_Enum.Baz.rawValue, forKey:601)
// Check has*.
XCTAssertTrue(msg.hasOptionalInt32)
@@ -83,6 +89,20 @@ class GPBBridgeTests: XCTestCase {
XCTAssertEqual(msg.repeatedEnumArray.valueAtIndex(0), Message2_Enum.Bar.rawValue)
XCTAssertEqual(msg.repeatedEnumArray.valueAtIndex(1), Message2_Enum.Baz.rawValue)
XCTAssertEqual(msg.repeatedInt64Array.count, UInt(0))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(2))
+ var intValue: Int32 = 0;
+ XCTAssertTrue(msg.mapInt32Int32.valueForKey(500, value:&intValue))
+ XCTAssertEqual(intValue, Int32(400))
+ XCTAssertTrue(msg.mapInt32Int32.valueForKey(501, value:&intValue))
+ XCTAssertEqual(intValue, Int32(401))
+ XCTAssertEqual(msg.mapStringString.count, Int(2))
+ XCTAssertEqual(msg.mapStringString.objectForKey("bar") as! String, "foo")
+ XCTAssertEqual(msg.mapStringString.objectForKey("xyz") as! String, "abc")
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(2))
+ XCTAssertTrue(msg.mapInt32Enum.valueForKey(600, value:&intValue))
+ XCTAssertEqual(intValue, Message2_Enum.Bar.rawValue)
+ XCTAssertTrue(msg.mapInt32Enum.valueForKey(601, value:&intValue))
+ XCTAssertEqual(intValue, Message2_Enum.Baz.rawValue)
// Clearing a string with nil.
msg2.optionalString = nil
@@ -109,6 +129,9 @@ class GPBBridgeTests: XCTestCase {
XCTAssertEqual(msg.repeatedInt32Array.count, UInt(0))
XCTAssertEqual(msg.repeatedStringArray.count, Int(0))
XCTAssertEqual(msg.repeatedEnumArray.count, UInt(0))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(0))
+ XCTAssertEqual(msg.mapStringString.count, Int(0))
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(0))
}
func testProto3Basics() {
@@ -128,6 +151,13 @@ class GPBBridgeTests: XCTestCase {
msg.repeatedEnumArray.addValue(Message3_Enum.Bar.rawValue)
msg.repeatedEnumArray.addRawValue(666)
SetMessage3_OptionalEnum_RawValue(msg2, 666)
+ msg.mapInt32Int32.setValue(400, forKey:500)
+ msg.mapInt32Int32.setValue(401, forKey:501)
+ msg.mapStringString.setObject("foo", forKey:"bar")
+ msg.mapStringString.setObject("abc", forKey:"xyz")
+ msg.mapInt32Enum.setValue(Message2_Enum.Bar.rawValue, forKey:600)
+ // "proto3" syntax lets enum get unknown values.
+ msg.mapInt32Enum.setRawValue(666, forKey:601)
// Has only exists on for message fields.
XCTAssertTrue(msg.hasOptionalMessage)
@@ -152,6 +182,22 @@ class GPBBridgeTests: XCTestCase {
XCTAssertEqual(msg.repeatedEnumArray.rawValueAtIndex(1), 666)
XCTAssertEqual(msg2.optionalEnum, Message3_Enum.GPBUnrecognizedEnumeratorValue)
XCTAssertEqual(Message3_OptionalEnum_RawValue(msg2), Int32(666))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(2))
+ var intValue: Int32 = 0;
+ XCTAssertTrue(msg.mapInt32Int32.valueForKey(500, value:&intValue))
+ XCTAssertEqual(intValue, Int32(400))
+ XCTAssertTrue(msg.mapInt32Int32.valueForKey(501, value:&intValue))
+ XCTAssertEqual(intValue, Int32(401))
+ XCTAssertEqual(msg.mapStringString.count, Int(2))
+ XCTAssertEqual(msg.mapStringString.objectForKey("bar") as! String, "foo")
+ XCTAssertEqual(msg.mapStringString.objectForKey("xyz") as! String, "abc")
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(2))
+ XCTAssertTrue(msg.mapInt32Enum.valueForKey(600, value:&intValue))
+ XCTAssertEqual(intValue, Message2_Enum.Bar.rawValue)
+ XCTAssertTrue(msg.mapInt32Enum.valueForKey(601, value:&intValue))
+ XCTAssertEqual(intValue, Message3_Enum.GPBUnrecognizedEnumeratorValue.rawValue)
+ XCTAssertTrue(msg.mapInt32Enum.valueForKey(601, rawValue:&intValue))
+ XCTAssertEqual(intValue, 666)
// Clearing a string with nil.
msg2.optionalString = nil
@@ -175,6 +221,9 @@ class GPBBridgeTests: XCTestCase {
msg2.clear()
XCTAssertEqual(msg2.optionalEnum, Message3_Enum.Foo) // Default
XCTAssertEqual(Message3_OptionalEnum_RawValue(msg2), Message3_Enum.Foo.rawValue)
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(0))
+ XCTAssertEqual(msg.mapStringString.count, Int(0))
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(0))
}
func testAutoCreation() {
@@ -390,15 +439,21 @@ class GPBBridgeTests: XCTestCase {
msg.optionalGroup.a = 102
msg.repeatedStringArray.addObject("abc")
msg.repeatedStringArray.addObject("def")
+ msg.mapInt32Int32.setValue(200, forKey:300)
+ msg.mapInt32Int32.setValue(201, forKey:201)
+ msg.mapStringString.setObject("foo", forKey:"bar")
+ msg.mapStringString.setObject("abc", forKey:"xyz")
let data = msg.data()
- let msg2 = Message2(data: data)
+ let msg2 = Message2(data: data, error:nil)
XCTAssertTrue(msg2 !== msg) // New instance
XCTAssertEqual(msg.optionalInt32, Int32(100))
XCTAssertEqual(msg.optionalInt64, Int64(101))
XCTAssertEqual(msg.optionalGroup.a, Int32(102))
XCTAssertEqual(msg.repeatedStringArray.count, Int(2))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(2))
+ XCTAssertEqual(msg.mapStringString.count, Int(2))
XCTAssertEqual(msg2, msg)
}
diff --git a/objectivec/Tests/GPBTestUtilities.h b/objectivec/Tests/GPBTestUtilities.h
index 37e30f96..6ae68c3a 100644
--- a/objectivec/Tests/GPBTestUtilities.h
+++ b/objectivec/Tests/GPBTestUtilities.h
@@ -37,6 +37,13 @@
@class TestPackedExtensions;
@class GPBExtensionRegistry;
+
+// Helper for uses of C arrays in tests cases.
+#ifndef GPBARRAYSIZE
+#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
+#endif // GPBARRAYSIZE
+
+
// The number of repetitions of any repeated objects inside of test messages.
extern const uint32_t kGPBDefaultRepeatCount;
diff --git a/objectivec/Tests/GPBTestUtilities.m b/objectivec/Tests/GPBTestUtilities.m
index d664a88a..6058dfc1 100644
--- a/objectivec/Tests/GPBTestUtilities.m
+++ b/objectivec/Tests/GPBTestUtilities.m
@@ -32,6 +32,7 @@
#import "google/protobuf/MapUnittest.pbobjc.h"
#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
const uint32_t kGPBDefaultRepeatCount = 2;
@@ -1060,25 +1061,6 @@ const uint32_t kGPBDefaultRepeatCount = 2;
}
- (void)setAllMapFields:(TestMap *)message numEntries:(uint32_t)count {
- message.mapInt32Int32 = [GPBInt32Int32Dictionary dictionary];
- message.mapInt64Int64 = [GPBInt64Int64Dictionary dictionary];
- message.mapUint32Uint32 = [GPBUInt32UInt32Dictionary dictionary];
- message.mapUint64Uint64 = [GPBUInt64UInt64Dictionary dictionary];
- message.mapSint32Sint32 = [GPBInt32Int32Dictionary dictionary];
- message.mapSint64Sint64 = [GPBInt64Int64Dictionary dictionary];
- message.mapFixed32Fixed32 = [GPBUInt32UInt32Dictionary dictionary];
- message.mapFixed64Fixed64 = [GPBUInt64UInt64Dictionary dictionary];
- message.mapSfixed32Sfixed32 = [GPBInt32Int32Dictionary dictionary];
- message.mapSfixed64Sfixed64 = [GPBInt64Int64Dictionary dictionary];
- message.mapInt32Float = [GPBInt32FloatDictionary dictionary];
- message.mapInt32Double = [GPBInt32DoubleDictionary dictionary];
- message.mapBoolBool = [GPBBoolBoolDictionary dictionary];
- message.mapStringString = [NSMutableDictionary dictionary];
- message.mapInt32Bytes = [GPBInt32ObjectDictionary dictionary];
- message.mapInt32Enum = [GPBInt32EnumDictionary
- dictionaryWithValidationFunction:MapEnum_IsValidValue];
- message.mapInt32ForeignMessage = [GPBInt32ObjectDictionary dictionary];
-
for (uint32_t i = 0; i < count; i++) {
[message.mapInt32Int32 setValue:(i + 1) forKey:100 + i * 100];
[message.mapInt64Int64 setValue:(i + 1) forKey:101 + i * 100];
diff --git a/objectivec/Tests/GPBUnknownFieldSetTest.m b/objectivec/Tests/GPBUnknownFieldSetTest.m
index 80186088..491bba9e 100644
--- a/objectivec/Tests/GPBUnknownFieldSetTest.m
+++ b/objectivec/Tests/GPBUnknownFieldSetTest.m
@@ -56,7 +56,7 @@
- (void)setUp {
allFields_ = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
allFieldsData_ = [allFields_ data];
- emptyMessage_ = [TestEmptyMessage parseFromData:allFieldsData_];
+ emptyMessage_ = [TestEmptyMessage parseFromData:allFieldsData_ error:NULL];
unknownFields_ = emptyMessage_.unknownFields;
}
@@ -176,7 +176,7 @@
[fields addField:field];
NSData* data = fields.data;
- TestAllTypes* destination = [TestAllTypes parseFromData:data];
+ TestAllTypes* destination = [TestAllTypes parseFromData:data error:NULL];
[self assertAllFieldsSet:destination repeatedCount:kGPBDefaultRepeatCount];
XCTAssertEqual(destination.unknownFields.countOfFields, (NSUInteger)1);
@@ -191,8 +191,10 @@
// when parsing.
NSData* bizarroData = [self getBizarroData];
- TestAllTypes* allTypesMessage = [TestAllTypes parseFromData:bizarroData];
- TestEmptyMessage* emptyMessage = [TestEmptyMessage parseFromData:bizarroData];
+ TestAllTypes* allTypesMessage =
+ [TestAllTypes parseFromData:bizarroData error:NULL];
+ TestEmptyMessage* emptyMessage =
+ [TestEmptyMessage parseFromData:bizarroData error:NULL];
// All fields should have been interpreted as unknown, so the debug strings
// should be the same.
@@ -204,7 +206,7 @@
// they are declared as extension numbers.
TestEmptyMessageWithExtensions* message =
- [TestEmptyMessageWithExtensions parseFromData:allFieldsData_];
+ [TestEmptyMessageWithExtensions parseFromData:allFieldsData_ error:NULL];
XCTAssertEqual(unknownFields_.countOfFields,
message.unknownFields.countOfFields);
@@ -217,8 +219,9 @@
NSData* bizarroData = [self getBizarroData];
TestAllExtensions* allExtensionsMessage =
- [TestAllExtensions parseFromData:bizarroData];
- TestEmptyMessage* emptyMessage = [TestEmptyMessage parseFromData:bizarroData];
+ [TestAllExtensions parseFromData:bizarroData error:NULL];
+ TestEmptyMessage* emptyMessage =
+ [TestEmptyMessage parseFromData:bizarroData error:NULL];
// All fields should have been interpreted as unknown, so the debug strings
// should be the same.
diff --git a/objectivec/Tests/GPBWireFormatTests.m b/objectivec/Tests/GPBWireFormatTests.m
index 1344af08..fc5c4bda 100644
--- a/objectivec/Tests/GPBWireFormatTests.m
+++ b/objectivec/Tests/GPBWireFormatTests.m
@@ -47,7 +47,7 @@
NSData* rawBytes = message.data;
XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
- TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes];
+ TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL];
[self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
}
@@ -59,7 +59,8 @@
NSData* rawBytes = message.data;
XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
- TestPackedTypes* message2 = [TestPackedTypes parseFromData:rawBytes];
+ TestPackedTypes* message2 =
+ [TestPackedTypes parseFromData:rawBytes error:NULL];
[self assertPackedFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
}
@@ -74,7 +75,7 @@
NSData* rawBytes = message.data;
XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
- TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes];
+ TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL];
[self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
}
@@ -103,8 +104,9 @@
GPBExtensionRegistry* registry = [self extensionRegistry];
- TestAllExtensions* message2 =
- [TestAllExtensions parseFromData:rawBytes extensionRegistry:registry];
+ TestAllExtensions* message2 = [TestAllExtensions parseFromData:rawBytes
+ extensionRegistry:registry
+ error:NULL];
[self assertAllExtensionsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
}
@@ -124,8 +126,9 @@
GPBExtensionRegistry* registry = [self extensionRegistry];
- TestPackedExtensions* message2 =
- [TestPackedExtensions parseFromData:rawBytes extensionRegistry:registry];
+ TestPackedExtensions* message2 = [TestPackedExtensions parseFromData:rawBytes
+ extensionRegistry:registry
+ error:NULL];
[self assertPackedExtensionsSet:message2
repeatedCount:kGPBDefaultRepeatCount];
@@ -151,7 +154,7 @@ const int kUnknownTypeId = 1550055;
NSData* data = [message_set data];
// Parse back using RawMessageSet and check the contents.
- RawMessageSet* raw = [RawMessageSet parseFromData:data];
+ RawMessageSet* raw = [RawMessageSet parseFromData:data error:NULL];
XCTAssertEqual([raw.unknownFields countOfFields], (NSUInteger)0);
@@ -163,11 +166,13 @@ const int kUnknownTypeId = 1550055;
XCTAssertEqual([raw.itemArray[2] typeId], kUnknownTypeId);
TestMessageSetExtension1* message1 =
- [TestMessageSetExtension1 parseFromData:[raw.itemArray[0] message]];
+ [TestMessageSetExtension1 parseFromData:[raw.itemArray[0] message]
+ error:NULL];
XCTAssertEqual(message1.i, 123);
TestMessageSetExtension2* message2 =
- [TestMessageSetExtension2 parseFromData:[raw.itemArray[1] message]];
+ [TestMessageSetExtension2 parseFromData:[raw.itemArray[1] message]
+ error:NULL];
XCTAssertEqualObjects(message2.str, @"foo");
XCTAssertEqualObjects([raw.itemArray[2] message],
@@ -209,7 +214,8 @@ const int kUnknownTypeId = 1550055;
// Parse as a TestMessageSet and check the contents.
TestMessageSet* messageSet =
[TestMessageSet parseFromData:data
- extensionRegistry:[UnittestMsetRoot extensionRegistry]];
+ extensionRegistry:[UnittestMsetRoot extensionRegistry]
+ error:NULL];
XCTAssertEqual(
[[messageSet
diff --git a/objectivec/Tests/unittest_objc.proto b/objectivec/Tests/unittest_objc.proto
index d288a30d..3bb92761 100644
--- a/objectivec/Tests/unittest_objc.proto
+++ b/objectivec/Tests/unittest_objc.proto
@@ -44,6 +44,8 @@ message TestRecursiveMessageWithRepeatedField {
optional TestRecursiveMessageWithRepeatedField a = 1;
repeated int32 i = 2;
repeated string str = 3;
+ map<int32, int32> i_to_i = 4;
+ map<string, string> str_to_str = 5;
}
// Recursive message and extension to for testing autocreators at different
diff --git a/objectivec/Tests/unittest_runtime_proto2.proto b/objectivec/Tests/unittest_runtime_proto2.proto
index f9fd3c35..12a2da68 100644
--- a/objectivec/Tests/unittest_runtime_proto2.proto
+++ b/objectivec/Tests/unittest_runtime_proto2.proto
@@ -105,4 +105,25 @@ message Message2 {
Message2 oneof_message = 68;
Enum oneof_enum = 69 [default = BAZ];
}
+
+ // Some token map cases, too many combinations to list them all.
+ map<int32 , int32 > map_int32_int32 = 70;
+ map<int64 , int64 > map_int64_int64 = 71;
+ map<uint32 , uint32 > map_uint32_uint32 = 72;
+ map<uint64 , uint64 > map_uint64_uint64 = 73;
+ map<sint32 , sint32 > map_sint32_sint32 = 74;
+ map<sint64 , sint64 > map_sint64_sint64 = 75;
+ map<fixed32 , fixed32 > map_fixed32_fixed32 = 76;
+ map<fixed64 , fixed64 > map_fixed64_fixed64 = 77;
+ map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 78;
+ map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 79;
+ map<int32 , float > map_int32_float = 80;
+ map<int32 , double > map_int32_double = 81;
+ map<bool , bool > map_bool_bool = 82;
+ map<string , string > map_string_string = 83;
+ map<string , bytes > map_string_bytes = 84;
+ map<string , Message2> map_string_message = 85;
+ map<int32 , bytes > map_int32_bytes = 86;
+ map<int32 , Enum > map_int32_enum = 87;
+ map<int32 , Message2> map_int32_message = 88;
}
diff --git a/objectivec/Tests/unittest_runtime_proto3.proto b/objectivec/Tests/unittest_runtime_proto3.proto
index b6a2f4dc..feb7029d 100644
--- a/objectivec/Tests/unittest_runtime_proto3.proto
+++ b/objectivec/Tests/unittest_runtime_proto3.proto
@@ -98,4 +98,25 @@ message Message3 {
Message3 oneof_message = 68;
Enum oneof_enum = 69;
}
+
+ // Some token map cases, too many combinations to list them all.
+ map<int32 , int32 > map_int32_int32 = 70;
+ map<int64 , int64 > map_int64_int64 = 71;
+ map<uint32 , uint32 > map_uint32_uint32 = 72;
+ map<uint64 , uint64 > map_uint64_uint64 = 73;
+ map<sint32 , sint32 > map_sint32_sint32 = 74;
+ map<sint64 , sint64 > map_sint64_sint64 = 75;
+ map<fixed32 , fixed32 > map_fixed32_fixed32 = 76;
+ map<fixed64 , fixed64 > map_fixed64_fixed64 = 77;
+ map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 78;
+ map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 79;
+ map<int32 , float > map_int32_float = 80;
+ map<int32 , double > map_int32_double = 81;
+ map<bool , bool > map_bool_bool = 82;
+ map<string , string > map_string_string = 83;
+ map<string , bytes > map_string_bytes = 84;
+ map<string , Message3> map_string_message = 85;
+ map<int32 , bytes > map_int32_bytes = 86;
+ map<int32 , Enum > map_int32_enum = 87;
+ map<int32 , Message3> map_int32_message = 88;
}