OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 @interface WireFormatTests : GPBTestCase | 40 @interface WireFormatTests : GPBTestCase |
41 @end | 41 @end |
42 | 42 |
43 @implementation WireFormatTests | 43 @implementation WireFormatTests |
44 | 44 |
45 - (void)testSerialization { | 45 - (void)testSerialization { |
46 TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount]; | 46 TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount]; |
47 | 47 |
48 NSData* rawBytes = message.data; | 48 NSData* rawBytes = message.data; |
49 [self assertFieldsInOrder:rawBytes]; | |
50 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); | 49 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); |
51 | 50 |
52 TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL]; | 51 TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL]; |
53 | 52 |
54 [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; | 53 [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; |
55 } | 54 } |
56 | 55 |
57 - (void)testSerializationPacked { | 56 - (void)testSerializationPacked { |
58 TestPackedTypes* message = | 57 TestPackedTypes* message = |
59 [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; | 58 [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; |
60 | 59 |
61 NSData* rawBytes = message.data; | 60 NSData* rawBytes = message.data; |
62 [self assertFieldsInOrder:rawBytes]; | |
63 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); | 61 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); |
64 | 62 |
65 TestPackedTypes* message2 = | 63 TestPackedTypes* message2 = |
66 [TestPackedTypes parseFromData:rawBytes error:NULL]; | 64 [TestPackedTypes parseFromData:rawBytes error:NULL]; |
67 | 65 |
68 [self assertPackedFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; | 66 [self assertPackedFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; |
69 } | 67 } |
70 | 68 |
71 - (void)testSerializeExtensions { | 69 - (void)testSerializeExtensions { |
72 // TestAllTypes and TestAllExtensions should have compatible wire formats, | 70 // TestAllTypes and TestAllExtensions should have compatible wire formats, |
73 // so if we serealize a TestAllExtensions then parse it as TestAllTypes | 71 // so if we serealize a TestAllExtensions then parse it as TestAllTypes |
74 // it should work. | 72 // it should work. |
75 | 73 |
76 TestAllExtensions* message = | 74 TestAllExtensions* message = |
77 [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; | 75 [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; |
78 NSData* rawBytes = message.data; | 76 NSData* rawBytes = message.data; |
79 [self assertFieldsInOrder:rawBytes]; | |
80 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); | 77 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); |
81 | 78 |
82 TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL]; | 79 TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL]; |
83 | 80 |
84 [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; | 81 [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; |
85 } | 82 } |
86 | 83 |
87 - (void)testSerializePackedExtensions { | 84 - (void)testSerializePackedExtensions { |
88 // TestPackedTypes and TestPackedExtensions should have compatible wire | 85 // TestPackedTypes and TestPackedExtensions should have compatible wire |
89 // formats; check that they serialize to the same string. | 86 // formats; check that they serialize to the same string. |
90 TestPackedExtensions* message = | 87 TestPackedExtensions* message = |
91 [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; | 88 [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; |
92 NSData* rawBytes = message.data; | 89 NSData* rawBytes = message.data; |
93 [self assertFieldsInOrder:rawBytes]; | |
94 | 90 |
95 TestPackedTypes* message2 = | 91 TestPackedTypes* message2 = |
96 [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; | 92 [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; |
97 NSData* rawBytes2 = message2.data; | 93 NSData* rawBytes2 = message2.data; |
98 | 94 |
99 XCTAssertEqualObjects(rawBytes, rawBytes2); | 95 XCTAssertEqualObjects(rawBytes, rawBytes2); |
100 } | 96 } |
101 | 97 |
102 - (void)testParseExtensions { | 98 - (void)testParseExtensions { |
103 // TestAllTypes and TestAllExtensions should have compatible wire formats, | 99 // TestAllTypes and TestAllExtensions should have compatible wire formats, |
104 // so if we serialize a TestAllTypes then parse it as TestAllExtensions | 100 // so if we serialize a TestAllTypes then parse it as TestAllExtensions |
105 // it should work. | 101 // it should work. |
106 | 102 |
107 TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount]; | 103 TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount]; |
108 NSData* rawBytes = message.data; | 104 NSData* rawBytes = message.data; |
109 [self assertFieldsInOrder:rawBytes]; | |
110 | 105 |
111 GPBExtensionRegistry* registry = [self extensionRegistry]; | 106 GPBExtensionRegistry* registry = [self extensionRegistry]; |
112 | 107 |
113 TestAllExtensions* message2 = [TestAllExtensions parseFromData:rawBytes | 108 TestAllExtensions* message2 = [TestAllExtensions parseFromData:rawBytes |
114 extensionRegistry:registry | 109 extensionRegistry:registry |
115 error:NULL]; | 110 error:NULL]; |
116 | 111 |
117 [self assertAllExtensionsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; | 112 [self assertAllExtensionsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; |
118 } | 113 } |
119 | 114 |
120 | 115 |
121 - (void)testExtensionsSerializedSize { | 116 - (void) testExtensionsSerializedSize { |
122 size_t allSet = [self allSetRepeatedCount:kGPBDefaultRepeatCount].serializedSi
ze; | 117 size_t allSet = [self allSetRepeatedCount:kGPBDefaultRepeatCount].serializedSi
ze; |
123 size_t extensionSet = [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCou
nt].serializedSize; | 118 size_t extensionSet = [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCou
nt].serializedSize; |
124 XCTAssertEqual(allSet, extensionSet); | 119 XCTAssertEqual(allSet, extensionSet); |
125 } | 120 } |
126 | 121 |
127 - (void)testParsePackedExtensions { | 122 - (void)testParsePackedExtensions { |
128 // Ensure that packed extensions can be properly parsed. | 123 // Ensure that packed extensions can be properly parsed. |
129 TestPackedExtensions* message = | 124 TestPackedExtensions* message = |
130 [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; | 125 [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; |
131 NSData* rawBytes = message.data; | 126 NSData* rawBytes = message.data; |
132 [self assertFieldsInOrder:rawBytes]; | |
133 | 127 |
134 GPBExtensionRegistry* registry = [self extensionRegistry]; | 128 GPBExtensionRegistry* registry = [self extensionRegistry]; |
135 | 129 |
136 TestPackedExtensions* message2 = [TestPackedExtensions parseFromData:rawBytes | 130 TestPackedExtensions* message2 = [TestPackedExtensions parseFromData:rawBytes |
137 extensionRegistry:registry | 131 extensionRegistry:registry |
138 error:NULL]; | 132 error:NULL]; |
139 | 133 |
140 [self assertPackedExtensionsSet:message2 | 134 [self assertPackedExtensionsSet:message2 |
141 repeatedCount:kGPBDefaultRepeatCount]; | 135 repeatedCount:kGPBDefaultRepeatCount]; |
142 } | 136 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (tag == 0) { | 243 if (tag == 0) { |
250 break; | 244 break; |
251 } | 245 } |
252 | 246 |
253 XCTAssertGreaterThan(tag, previousTag); | 247 XCTAssertGreaterThan(tag, previousTag); |
254 [input skipField:tag]; | 248 [input skipField:tag]; |
255 } | 249 } |
256 } | 250 } |
257 | 251 |
258 @end | 252 @end |
OLD | NEW |