Add a unittest for ObjC TextFormat extension support.
This commit is contained in:
parent
af2d4134e0
commit
92a879b2eb
@ -558,6 +558,7 @@ objectivec_EXTRA_DIST= \
|
||||
objectivec/Tests/GPBUtilitiesTests.m \
|
||||
objectivec/Tests/GPBWellKnownTypesTest.m \
|
||||
objectivec/Tests/GPBWireFormatTests.m \
|
||||
objectivec/Tests/text_format_extensions_unittest_data.txt \
|
||||
objectivec/Tests/text_format_map_unittest_data.txt \
|
||||
objectivec/Tests/text_format_unittest_data.txt \
|
||||
objectivec/Tests/unittest_cycle.proto \
|
||||
|
@ -92,6 +92,7 @@
|
||||
F4E675A11B21D0000054530B /* Struct.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675911B21D0000054530B /* Struct.pbobjc.m */; };
|
||||
F4E675A31B21D0000054530B /* Type.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675931B21D0000054530B /* Type.pbobjc.m */; };
|
||||
F4E675A51B21D0000054530B /* Wrappers.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675951B21D0000054530B /* Wrappers.pbobjc.m */; };
|
||||
F4F53F8A219CC4F2001EABF4 /* text_format_extensions_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F4F53F89219CC4F2001EABF4 /* text_format_extensions_unittest_data.txt */; };
|
||||
F4F8D8831D789FD9002CE128 /* GPBUnittestProtos2.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F8D8811D789FCE002CE128 /* GPBUnittestProtos2.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
@ -265,6 +266,7 @@
|
||||
F4E675AB1B21D05C0054530B /* struct.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = struct.proto; path = ../src/google/protobuf/struct.proto; sourceTree = "<group>"; };
|
||||
F4E675AC1B21D05C0054530B /* type.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = type.proto; path = ../src/google/protobuf/type.proto; sourceTree = "<group>"; };
|
||||
F4E675AD1B21D05C0054530B /* wrappers.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = wrappers.proto; path = ../src/google/protobuf/wrappers.proto; sourceTree = "<group>"; };
|
||||
F4F53F89219CC4F2001EABF4 /* text_format_extensions_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_extensions_unittest_data.txt; sourceTree = "<group>"; };
|
||||
F4F8D8811D789FCE002CE128 /* GPBUnittestProtos2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos2.m; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@ -494,6 +496,7 @@
|
||||
7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */,
|
||||
8B4248DB1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m */,
|
||||
7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */,
|
||||
F4F53F89219CC4F2001EABF4 /* text_format_extensions_unittest_data.txt */,
|
||||
F45E57C61AE6DC6A000B7D99 /* text_format_map_unittest_data.txt */,
|
||||
F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */,
|
||||
8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */,
|
||||
@ -671,6 +674,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8B210CCE159383D60032D72D /* golden_message in Resources */,
|
||||
F4F53F8A219CC4F2001EABF4 /* text_format_extensions_unittest_data.txt in Resources */,
|
||||
F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */,
|
||||
8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */,
|
||||
F45E57C71AE6DC6A000B7D99 /* text_format_map_unittest_data.txt in Resources */,
|
||||
|
@ -93,6 +93,7 @@
|
||||
F4E675D51B21D1620054530B /* Struct.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C21B21D1440054530B /* Struct.pbobjc.m */; };
|
||||
F4E675D61B21D1620054530B /* Type.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C51B21D1440054530B /* Type.pbobjc.m */; };
|
||||
F4E675D71B21D1620054530B /* Wrappers.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C71B21D1440054530B /* Wrappers.pbobjc.m */; };
|
||||
F4F53F8C219CC5DF001EABF4 /* text_format_extensions_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F4F53F8B219CC5DF001EABF4 /* text_format_extensions_unittest_data.txt */; };
|
||||
F4F8D8861D78A193002CE128 /* GPBUnittestProtos2.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F8D8841D78A186002CE128 /* GPBUnittestProtos2.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
@ -268,6 +269,7 @@
|
||||
F4E675DD1B21D1DE0054530B /* struct.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = struct.proto; path = ../src/google/protobuf/struct.proto; sourceTree = "<group>"; };
|
||||
F4E675DE1B21D1DE0054530B /* type.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = type.proto; path = ../src/google/protobuf/type.proto; sourceTree = "<group>"; };
|
||||
F4E675DF1B21D1DE0054530B /* wrappers.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = wrappers.proto; path = ../src/google/protobuf/wrappers.proto; sourceTree = "<group>"; };
|
||||
F4F53F8B219CC5DF001EABF4 /* text_format_extensions_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_extensions_unittest_data.txt; sourceTree = "<group>"; };
|
||||
F4F8D8841D78A186002CE128 /* GPBUnittestProtos2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos2.m; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@ -500,6 +502,7 @@
|
||||
7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */,
|
||||
8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */,
|
||||
7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */,
|
||||
F4F53F8B219CC5DF001EABF4 /* text_format_extensions_unittest_data.txt */,
|
||||
F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */,
|
||||
F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */,
|
||||
8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */,
|
||||
@ -678,6 +681,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8B210CCE159383D60032D72D /* golden_message in Resources */,
|
||||
F4F53F8C219CC5DF001EABF4 /* text_format_extensions_unittest_data.txt in Resources */,
|
||||
F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */,
|
||||
8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */,
|
||||
F45E57C91AE6DC98000B7D99 /* text_format_map_unittest_data.txt in Resources */,
|
||||
|
@ -169,7 +169,27 @@
|
||||
[expected release];
|
||||
}
|
||||
|
||||
// TODO(thomasvl): add test with extensions once those format with correct names.
|
||||
- (void)testTextFormatExtensions {
|
||||
TestAllExtensions *message = [TestAllExtensions message];
|
||||
|
||||
// Not kGPBDefaultRepeatCount because we are comparing to golden master file
|
||||
// which was generated with 2.
|
||||
[self setAllExtensions:message repeatedCount:2];
|
||||
|
||||
NSString *result = GPBTextFormatForMessage(message, nil);
|
||||
|
||||
// NOTE: ObjC TextFormat doesn't have the proper extension names so it
|
||||
// uses comments for the ObjC name and raw numbers for the fields instead
|
||||
// of the bracketed extension name.
|
||||
NSString *fileName = @"text_format_extensions_unittest_data.txt";
|
||||
NSData *resultData = [result dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSData *expectedData =
|
||||
[self getDataFileNamed:fileName dataToWrite:resultData];
|
||||
NSString *expected = [[NSString alloc] initWithData:expectedData
|
||||
encoding:NSUTF8StringEncoding];
|
||||
XCTAssertEqualObjects(expected, result);
|
||||
[expected release];
|
||||
}
|
||||
|
||||
- (void)testSetRepeatedFields {
|
||||
TestAllTypes *message = [TestAllTypes message];
|
||||
|
140
objectivec/Tests/text_format_extensions_unittest_data.txt
Normal file
140
objectivec/Tests/text_format_extensions_unittest_data.txt
Normal file
@ -0,0 +1,140 @@
|
||||
1: 101 # [UnittestRoot_optionalInt32Extension]
|
||||
2: 102 # [UnittestRoot_optionalInt64Extension]
|
||||
3: 103 # [UnittestRoot_optionalUint32Extension]
|
||||
4: 104 # [UnittestRoot_optionalUint64Extension]
|
||||
5: 105 # [UnittestRoot_optionalSint32Extension]
|
||||
6: 106 # [UnittestRoot_optionalSint64Extension]
|
||||
7: 107 # [UnittestRoot_optionalFixed32Extension]
|
||||
8: 108 # [UnittestRoot_optionalFixed64Extension]
|
||||
9: 109 # [UnittestRoot_optionalSfixed32Extension]
|
||||
10: 110 # [UnittestRoot_optionalSfixed64Extension]
|
||||
11: 111 # [UnittestRoot_optionalFloatExtension]
|
||||
12: 112 # [UnittestRoot_optionalDoubleExtension]
|
||||
13: true # [UnittestRoot_optionalBoolExtension]
|
||||
14: "115" # [UnittestRoot_optionalStringExtension]
|
||||
15: "\001\000\002\003\000\005" # [UnittestRoot_optionalBytesExtension]
|
||||
16 { # [UnittestRoot_optionalGroupExtension]
|
||||
a: 117
|
||||
}
|
||||
18 { # [UnittestRoot_optionalNestedMessageExtension]
|
||||
bb: 118
|
||||
}
|
||||
19 { # [UnittestRoot_optionalForeignMessageExtension]
|
||||
c: 119
|
||||
}
|
||||
20 { # [UnittestRoot_optionalImportMessageExtension]
|
||||
d: 120
|
||||
}
|
||||
21: 3 # [UnittestRoot_optionalNestedEnumExtension]
|
||||
22: 6 # [UnittestRoot_optionalForeignEnumExtension]
|
||||
23: 9 # [UnittestRoot_optionalImportEnumExtension]
|
||||
24: "124" # [UnittestRoot_optionalStringPieceExtension]
|
||||
25: "125" # [UnittestRoot_optionalCordExtension]
|
||||
# [UnittestRoot_repeatedInt32Extension]
|
||||
31: 201
|
||||
31: 301
|
||||
# [UnittestRoot_repeatedInt64Extension]
|
||||
32: 202
|
||||
32: 302
|
||||
# [UnittestRoot_repeatedUint32Extension]
|
||||
33: 203
|
||||
33: 303
|
||||
# [UnittestRoot_repeatedUint64Extension]
|
||||
34: 204
|
||||
34: 304
|
||||
# [UnittestRoot_repeatedSint32Extension]
|
||||
35: 205
|
||||
35: 305
|
||||
# [UnittestRoot_repeatedSint64Extension]
|
||||
36: 206
|
||||
36: 306
|
||||
# [UnittestRoot_repeatedFixed32Extension]
|
||||
37: 207
|
||||
37: 307
|
||||
# [UnittestRoot_repeatedFixed64Extension]
|
||||
38: 208
|
||||
38: 308
|
||||
# [UnittestRoot_repeatedSfixed32Extension]
|
||||
39: 209
|
||||
39: 309
|
||||
# [UnittestRoot_repeatedSfixed64Extension]
|
||||
40: 210
|
||||
40: 310
|
||||
# [UnittestRoot_repeatedFloatExtension]
|
||||
41: 211
|
||||
41: 311
|
||||
# [UnittestRoot_repeatedDoubleExtension]
|
||||
42: 212
|
||||
42: 312
|
||||
# [UnittestRoot_repeatedBoolExtension]
|
||||
43: false
|
||||
43: true
|
||||
# [UnittestRoot_repeatedStringExtension]
|
||||
44: "215"
|
||||
44: "315"
|
||||
# [UnittestRoot_repeatedBytesExtension]
|
||||
45: "\330\000\000\000"
|
||||
45: "<\001\000\000"
|
||||
# [UnittestRoot_repeatedGroupExtension]
|
||||
46 {
|
||||
a: 217
|
||||
}
|
||||
46 {
|
||||
a: 317
|
||||
}
|
||||
# [UnittestRoot_repeatedNestedMessageExtension]
|
||||
48 {
|
||||
bb: 218
|
||||
}
|
||||
48 {
|
||||
bb: 318
|
||||
}
|
||||
# [UnittestRoot_repeatedForeignMessageExtension]
|
||||
49 {
|
||||
c: 219
|
||||
}
|
||||
49 {
|
||||
c: 319
|
||||
}
|
||||
# [UnittestRoot_repeatedImportMessageExtension]
|
||||
50 {
|
||||
d: 220
|
||||
}
|
||||
50 {
|
||||
d: 320
|
||||
}
|
||||
# [UnittestRoot_repeatedNestedEnumExtension]
|
||||
51: 3
|
||||
51: 2
|
||||
# [UnittestRoot_repeatedForeignEnumExtension]
|
||||
52: 6
|
||||
52: 5
|
||||
# [UnittestRoot_repeatedImportEnumExtension]
|
||||
53: 9
|
||||
53: 8
|
||||
# [UnittestRoot_repeatedStringPieceExtension]
|
||||
54: "224"
|
||||
54: "324"
|
||||
# [UnittestRoot_repeatedCordExtension]
|
||||
55: "225"
|
||||
55: "325"
|
||||
61: 401 # [UnittestRoot_defaultInt32Extension]
|
||||
62: 402 # [UnittestRoot_defaultInt64Extension]
|
||||
63: 403 # [UnittestRoot_defaultUint32Extension]
|
||||
64: 404 # [UnittestRoot_defaultUint64Extension]
|
||||
65: 405 # [UnittestRoot_defaultSint32Extension]
|
||||
66: 406 # [UnittestRoot_defaultSint64Extension]
|
||||
67: 407 # [UnittestRoot_defaultFixed32Extension]
|
||||
68: 408 # [UnittestRoot_defaultFixed64Extension]
|
||||
69: 409 # [UnittestRoot_defaultSfixed32Extension]
|
||||
70: 410 # [UnittestRoot_defaultSfixed64Extension]
|
||||
71: 411 # [UnittestRoot_defaultFloatExtension]
|
||||
72: 412 # [UnittestRoot_defaultDoubleExtension]
|
||||
73: false # [UnittestRoot_defaultBoolExtension]
|
||||
74: "415" # [UnittestRoot_defaultStringExtension]
|
||||
75: "\240\001\000\000" # [UnittestRoot_defaultBytesExtension]
|
||||
81: 1 # [UnittestRoot_defaultNestedEnumExtension]
|
||||
82: 4 # [UnittestRoot_defaultForeignEnumExtension]
|
||||
83: 7 # [UnittestRoot_defaultImportEnumExtension]
|
||||
84: "424" # [UnittestRoot_defaultStringPieceExtension]
|
||||
85: "425" # [UnittestRoot_defaultCordExtension]
|
Loading…
Reference in New Issue
Block a user