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]; |
49 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); | 50 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); |
50 | 51 |
51 TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL]; | 52 TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL]; |
52 | 53 |
53 [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; | 54 [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; |
54 } | 55 } |
55 | 56 |
56 - (void)testSerializationPacked { | 57 - (void)testSerializationPacked { |
57 TestPackedTypes* message = | 58 TestPackedTypes* message = |
58 [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; | 59 [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; |
59 | 60 |
60 NSData* rawBytes = message.data; | 61 NSData* rawBytes = message.data; |
| 62 [self assertFieldsInOrder:rawBytes]; |
61 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); | 63 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); |
62 | 64 |
63 TestPackedTypes* message2 = | 65 TestPackedTypes* message2 = |
64 [TestPackedTypes parseFromData:rawBytes error:NULL]; | 66 [TestPackedTypes parseFromData:rawBytes error:NULL]; |
65 | 67 |
66 [self assertPackedFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; | 68 [self assertPackedFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; |
67 } | 69 } |
68 | 70 |
69 - (void)testSerializeExtensions { | 71 - (void)testSerializeExtensions { |
70 // TestAllTypes and TestAllExtensions should have compatible wire formats, | 72 // TestAllTypes and TestAllExtensions should have compatible wire formats, |
71 // so if we serealize a TestAllExtensions then parse it as TestAllTypes | 73 // so if we serealize a TestAllExtensions then parse it as TestAllTypes |
72 // it should work. | 74 // it should work. |
73 | 75 |
74 TestAllExtensions* message = | 76 TestAllExtensions* message = |
75 [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; | 77 [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; |
76 NSData* rawBytes = message.data; | 78 NSData* rawBytes = message.data; |
| 79 [self assertFieldsInOrder:rawBytes]; |
77 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); | 80 XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); |
78 | 81 |
79 TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL]; | 82 TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL]; |
80 | 83 |
81 [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; | 84 [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; |
82 } | 85 } |
83 | 86 |
84 - (void)testSerializePackedExtensions { | 87 - (void)testSerializePackedExtensions { |
85 // TestPackedTypes and TestPackedExtensions should have compatible wire | 88 // TestPackedTypes and TestPackedExtensions should have compatible wire |
86 // formats; check that they serialize to the same string. | 89 // formats; check that they serialize to the same string. |
87 TestPackedExtensions* message = | 90 TestPackedExtensions* message = |
88 [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; | 91 [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; |
89 NSData* rawBytes = message.data; | 92 NSData* rawBytes = message.data; |
| 93 [self assertFieldsInOrder:rawBytes]; |
90 | 94 |
91 TestPackedTypes* message2 = | 95 TestPackedTypes* message2 = |
92 [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; | 96 [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; |
93 NSData* rawBytes2 = message2.data; | 97 NSData* rawBytes2 = message2.data; |
94 | 98 |
95 XCTAssertEqualObjects(rawBytes, rawBytes2); | 99 XCTAssertEqualObjects(rawBytes, rawBytes2); |
96 } | 100 } |
97 | 101 |
98 - (void)testParseExtensions { | 102 - (void)testParseExtensions { |
99 // TestAllTypes and TestAllExtensions should have compatible wire formats, | 103 // TestAllTypes and TestAllExtensions should have compatible wire formats, |
100 // so if we serialize a TestAllTypes then parse it as TestAllExtensions | 104 // so if we serialize a TestAllTypes then parse it as TestAllExtensions |
101 // it should work. | 105 // it should work. |
102 | 106 |
103 TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount]; | 107 TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount]; |
104 NSData* rawBytes = message.data; | 108 NSData* rawBytes = message.data; |
| 109 [self assertFieldsInOrder:rawBytes]; |
105 | 110 |
106 GPBExtensionRegistry* registry = [self extensionRegistry]; | 111 GPBExtensionRegistry* registry = [self extensionRegistry]; |
107 | 112 |
108 TestAllExtensions* message2 = [TestAllExtensions parseFromData:rawBytes | 113 TestAllExtensions* message2 = [TestAllExtensions parseFromData:rawBytes |
109 extensionRegistry:registry | 114 extensionRegistry:registry |
110 error:NULL]; | 115 error:NULL]; |
111 | 116 |
112 [self assertAllExtensionsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; | 117 [self assertAllExtensionsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; |
113 } | 118 } |
114 | 119 |
115 | 120 |
116 - (void) testExtensionsSerializedSize { | 121 - (void)testExtensionsSerializedSize { |
117 size_t allSet = [self allSetRepeatedCount:kGPBDefaultRepeatCount].serializedSi
ze; | 122 size_t allSet = [self allSetRepeatedCount:kGPBDefaultRepeatCount].serializedSi
ze; |
118 size_t extensionSet = [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCou
nt].serializedSize; | 123 size_t extensionSet = [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCou
nt].serializedSize; |
119 XCTAssertEqual(allSet, extensionSet); | 124 XCTAssertEqual(allSet, extensionSet); |
120 } | 125 } |
121 | 126 |
122 - (void)testParsePackedExtensions { | 127 - (void)testParsePackedExtensions { |
123 // Ensure that packed extensions can be properly parsed. | 128 // Ensure that packed extensions can be properly parsed. |
124 TestPackedExtensions* message = | 129 TestPackedExtensions* message = |
125 [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; | 130 [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; |
126 NSData* rawBytes = message.data; | 131 NSData* rawBytes = message.data; |
| 132 [self assertFieldsInOrder:rawBytes]; |
127 | 133 |
128 GPBExtensionRegistry* registry = [self extensionRegistry]; | 134 GPBExtensionRegistry* registry = [self extensionRegistry]; |
129 | 135 |
130 TestPackedExtensions* message2 = [TestPackedExtensions parseFromData:rawBytes | 136 TestPackedExtensions* message2 = [TestPackedExtensions parseFromData:rawBytes |
131 extensionRegistry:registry | 137 extensionRegistry:registry |
132 error:NULL]; | 138 error:NULL]; |
133 | 139 |
134 [self assertPackedExtensionsSet:message2 | 140 [self assertPackedExtensionsSet:message2 |
135 repeatedCount:kGPBDefaultRepeatCount]; | 141 repeatedCount:kGPBDefaultRepeatCount]; |
136 } | 142 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (tag == 0) { | 249 if (tag == 0) { |
244 break; | 250 break; |
245 } | 251 } |
246 | 252 |
247 XCTAssertGreaterThan(tag, previousTag); | 253 XCTAssertGreaterThan(tag, previousTag); |
248 [input skipField:tag]; | 254 [input skipField:tag]; |
249 } | 255 } |
250 } | 256 } |
251 | 257 |
252 @end | 258 @end |
OLD | NEW |