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 12 matching lines...) Expand all Loading... |
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 // Test suite is written using Jasmine -- see http://jasmine.github.io/ | 31 // Test suite is written using Jasmine -- see http://jasmine.github.io/ |
32 | 32 |
| 33 goog.require('goog.crypt.base64'); |
33 goog.require('goog.testing.asserts'); | 34 goog.require('goog.testing.asserts'); |
| 35 goog.require('jspb.Message'); |
| 36 |
| 37 // CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test |
34 goog.require('proto.jspb.test.ExtendsWithMessage'); | 38 goog.require('proto.jspb.test.ExtendsWithMessage'); |
35 goog.require('proto.jspb.test.ForeignEnum'); | 39 goog.require('proto.jspb.test.ForeignEnum'); |
36 goog.require('proto.jspb.test.ForeignMessage'); | 40 goog.require('proto.jspb.test.ForeignMessage'); |
37 goog.require('proto.jspb.test.TestAllTypes'); | 41 goog.require('proto.jspb.test.TestAllTypes'); |
38 goog.require('proto.jspb.test.TestExtendable'); | 42 goog.require('proto.jspb.test.TestExtendable'); |
| 43 goog.require('proto.jspb.test.extendOptionalBool'); |
| 44 goog.require('proto.jspb.test.extendOptionalBytes'); |
| 45 goog.require('proto.jspb.test.extendOptionalDouble'); |
| 46 goog.require('proto.jspb.test.extendOptionalFixed32'); |
| 47 goog.require('proto.jspb.test.extendOptionalFixed64'); |
| 48 goog.require('proto.jspb.test.extendOptionalFloat'); |
| 49 goog.require('proto.jspb.test.extendOptionalForeignEnum'); |
| 50 goog.require('proto.jspb.test.extendOptionalInt32'); |
| 51 goog.require('proto.jspb.test.extendOptionalInt64'); |
| 52 goog.require('proto.jspb.test.extendOptionalSfixed32'); |
| 53 goog.require('proto.jspb.test.extendOptionalSfixed64'); |
| 54 goog.require('proto.jspb.test.extendOptionalSint32'); |
| 55 goog.require('proto.jspb.test.extendOptionalSint64'); |
| 56 goog.require('proto.jspb.test.extendOptionalString'); |
| 57 goog.require('proto.jspb.test.extendOptionalUint32'); |
| 58 goog.require('proto.jspb.test.extendOptionalUint64'); |
| 59 goog.require('proto.jspb.test.extendPackedRepeatedBoolList'); |
| 60 goog.require('proto.jspb.test.extendPackedRepeatedDoubleList'); |
| 61 goog.require('proto.jspb.test.extendPackedRepeatedFixed32List'); |
| 62 goog.require('proto.jspb.test.extendPackedRepeatedFixed64List'); |
| 63 goog.require('proto.jspb.test.extendPackedRepeatedFloatList'); |
| 64 goog.require('proto.jspb.test.extendPackedRepeatedForeignEnumList'); |
| 65 goog.require('proto.jspb.test.extendPackedRepeatedInt32List'); |
| 66 goog.require('proto.jspb.test.extendPackedRepeatedInt64List'); |
| 67 goog.require('proto.jspb.test.extendPackedRepeatedSfixed32List'); |
| 68 goog.require('proto.jspb.test.extendPackedRepeatedSfixed64List'); |
| 69 goog.require('proto.jspb.test.extendPackedRepeatedSint32List'); |
| 70 goog.require('proto.jspb.test.extendPackedRepeatedSint64List'); |
| 71 goog.require('proto.jspb.test.extendPackedRepeatedUint32List'); |
| 72 goog.require('proto.jspb.test.extendPackedRepeatedUint64List'); |
| 73 goog.require('proto.jspb.test.extendRepeatedBoolList'); |
| 74 goog.require('proto.jspb.test.extendRepeatedBytesList'); |
| 75 goog.require('proto.jspb.test.extendRepeatedDoubleList'); |
| 76 goog.require('proto.jspb.test.extendRepeatedFixed32List'); |
| 77 goog.require('proto.jspb.test.extendRepeatedFixed64List'); |
| 78 goog.require('proto.jspb.test.extendRepeatedFloatList'); |
| 79 goog.require('proto.jspb.test.extendRepeatedForeignEnumList'); |
| 80 goog.require('proto.jspb.test.extendRepeatedInt32List'); |
| 81 goog.require('proto.jspb.test.extendRepeatedInt64List'); |
| 82 goog.require('proto.jspb.test.extendRepeatedSfixed32List'); |
| 83 goog.require('proto.jspb.test.extendRepeatedSfixed64List'); |
| 84 goog.require('proto.jspb.test.extendRepeatedSint32List'); |
| 85 goog.require('proto.jspb.test.extendRepeatedSint64List'); |
| 86 goog.require('proto.jspb.test.extendRepeatedStringList'); |
| 87 goog.require('proto.jspb.test.extendRepeatedUint32List'); |
| 88 goog.require('proto.jspb.test.extendRepeatedUint64List'); |
| 89 |
39 | 90 |
40 var suite = {}; | 91 var suite = {}; |
41 | 92 |
| 93 var BYTES = new Uint8Array([1, 2, 8, 9]); |
| 94 |
| 95 var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES); |
| 96 |
| 97 |
42 /** | 98 /** |
43 * Helper: fill all fields on a TestAllTypes message. | 99 * Helper: fill all fields on a TestAllTypes message. |
44 * @param {proto.jspb.test.TestAllTypes} msg | 100 * @param {proto.jspb.test.TestAllTypes} msg |
45 */ | 101 */ |
46 function fillAllFields(msg) { | 102 function fillAllFields(msg) { |
47 msg.setOptionalInt32(-42); | 103 msg.setOptionalInt32(-42); |
48 // can be exactly represented by JS number (64-bit double, i.e., 52-bit | 104 // can be exactly represented by JS number (64-bit double, i.e., 52-bit |
49 // mantissa). | 105 // mantissa). |
50 msg.setOptionalInt64(-0x7fffffff00000000); | 106 msg.setOptionalInt64(-0x7fffffff00000000); |
51 msg.setOptionalUint32(0x80000000); | 107 msg.setOptionalUint32(0x80000000); |
52 msg.setOptionalUint64(0xf000000000000000); | 108 msg.setOptionalUint64(0xf000000000000000); |
53 msg.setOptionalSint32(-100); | 109 msg.setOptionalSint32(-100); |
54 msg.setOptionalSint64(-0x8000000000000000); | 110 msg.setOptionalSint64(-0x8000000000000000); |
55 msg.setOptionalFixed32(1234); | 111 msg.setOptionalFixed32(1234); |
56 msg.setOptionalFixed64(0x1234567800000000); | 112 msg.setOptionalFixed64(0x1234567800000000); |
57 msg.setOptionalSfixed32(-1234); | 113 msg.setOptionalSfixed32(-1234); |
58 msg.setOptionalSfixed64(-0x1234567800000000); | 114 msg.setOptionalSfixed64(-0x1234567800000000); |
59 msg.setOptionalFloat(1.5); | 115 msg.setOptionalFloat(1.5); |
60 msg.setOptionalDouble(-1.5); | 116 msg.setOptionalDouble(-1.5); |
61 msg.setOptionalBool(true); | 117 msg.setOptionalBool(true); |
62 msg.setOptionalString('hello world'); | 118 msg.setOptionalString('hello world'); |
63 msg.setOptionalBytes('bytes'); | 119 msg.setOptionalBytes(BYTES); |
64 msg.setOptionalGroup(new proto.jspb.test.TestAllTypes.OptionalGroup()); | 120 msg.setOptionalGroup(new proto.jspb.test.TestAllTypes.OptionalGroup()); |
65 msg.getOptionalGroup().setA(100); | 121 msg.getOptionalGroup().setA(100); |
66 var submsg = new proto.jspb.test.ForeignMessage(); | 122 var submsg = new proto.jspb.test.ForeignMessage(); |
67 submsg.setC(16); | 123 submsg.setC(16); |
68 msg.setOptionalForeignMessage(submsg); | 124 msg.setOptionalForeignMessage(submsg); |
69 msg.setOptionalForeignEnum(proto.jspb.test.ForeignEnum.FOREIGN_FOO); | 125 msg.setOptionalForeignEnum(proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
70 msg.setOptionalInt32String('-12345'); | |
71 msg.setOptionalUint32String('12345'); | |
72 msg.setOptionalInt64String('-123456789012345'); | |
73 msg.setOptionalUint64String('987654321098765'); | |
74 msg.setOneofString('oneof'); | 126 msg.setOneofString('oneof'); |
75 | 127 |
| 128 |
76 msg.setRepeatedInt32List([-42]); | 129 msg.setRepeatedInt32List([-42]); |
77 msg.setRepeatedInt64List([-0x7fffffff00000000]); | 130 msg.setRepeatedInt64List([-0x7fffffff00000000]); |
78 msg.setRepeatedUint32List([0x80000000]); | 131 msg.setRepeatedUint32List([0x80000000]); |
79 msg.setRepeatedUint64List([0xf000000000000000]); | 132 msg.setRepeatedUint64List([0xf000000000000000]); |
80 msg.setRepeatedSint32List([-100]); | 133 msg.setRepeatedSint32List([-100]); |
81 msg.setRepeatedSint64List([-0x8000000000000000]); | 134 msg.setRepeatedSint64List([-0x8000000000000000]); |
82 msg.setRepeatedFixed32List([1234]); | 135 msg.setRepeatedFixed32List([1234]); |
83 msg.setRepeatedFixed64List([0x1234567800000000]); | 136 msg.setRepeatedFixed64List([0x1234567800000000]); |
84 msg.setRepeatedSfixed32List([-1234]); | 137 msg.setRepeatedSfixed32List([-1234]); |
85 msg.setRepeatedSfixed64List([-0x1234567800000000]); | 138 msg.setRepeatedSfixed64List([-0x1234567800000000]); |
86 msg.setRepeatedFloatList([1.5]); | 139 msg.setRepeatedFloatList([1.5]); |
87 msg.setRepeatedDoubleList([-1.5]); | 140 msg.setRepeatedDoubleList([-1.5]); |
88 msg.setRepeatedBoolList([true]); | 141 msg.setRepeatedBoolList([true]); |
89 msg.setRepeatedStringList(['hello world']); | 142 msg.setRepeatedStringList(['hello world']); |
90 msg.setRepeatedBytesList(['bytes']); | 143 msg.setRepeatedBytesList([BYTES, BYTES]); |
91 msg.setRepeatedGroupList([new proto.jspb.test.TestAllTypes.RepeatedGroup()]); | 144 msg.setRepeatedGroupList([new proto.jspb.test.TestAllTypes.RepeatedGroup()]); |
92 msg.getRepeatedGroupList()[0].setA(100); | 145 msg.getRepeatedGroupList()[0].setA(100); |
93 submsg = new proto.jspb.test.ForeignMessage(); | 146 submsg = new proto.jspb.test.ForeignMessage(); |
94 submsg.setC(1000); | 147 submsg.setC(1000); |
95 msg.setRepeatedForeignMessageList([submsg]); | 148 msg.setRepeatedForeignMessageList([submsg]); |
96 msg.setRepeatedForeignEnumList([proto.jspb.test.ForeignEnum.FOREIGN_FOO]); | 149 msg.setRepeatedForeignEnumList([proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
97 | 150 |
98 msg.setPackedRepeatedInt32List([-42]); | 151 msg.setPackedRepeatedInt32List([-42]); |
99 msg.setPackedRepeatedInt64List([-0x7fffffff00000000]); | 152 msg.setPackedRepeatedInt64List([-0x7fffffff00000000]); |
100 msg.setPackedRepeatedUint32List([0x80000000]); | 153 msg.setPackedRepeatedUint32List([0x80000000]); |
101 msg.setPackedRepeatedUint64List([0xf000000000000000]); | 154 msg.setPackedRepeatedUint64List([0xf000000000000000]); |
102 msg.setPackedRepeatedSint32List([-100]); | 155 msg.setPackedRepeatedSint32List([-100]); |
103 msg.setPackedRepeatedSint64List([-0x8000000000000000]); | 156 msg.setPackedRepeatedSint64List([-0x8000000000000000]); |
104 msg.setPackedRepeatedFixed32List([1234]); | 157 msg.setPackedRepeatedFixed32List([1234]); |
105 msg.setPackedRepeatedFixed64List([0x1234567800000000]); | 158 msg.setPackedRepeatedFixed64List([0x1234567800000000]); |
106 msg.setPackedRepeatedSfixed32List([-1234]); | 159 msg.setPackedRepeatedSfixed32List([-1234]); |
107 msg.setPackedRepeatedSfixed64List([-0x1234567800000000]); | 160 msg.setPackedRepeatedSfixed64List([-0x1234567800000000]); |
108 msg.setPackedRepeatedFloatList([1.5]); | 161 msg.setPackedRepeatedFloatList([1.5]); |
109 msg.setPackedRepeatedDoubleList([-1.5]); | 162 msg.setPackedRepeatedDoubleList([-1.5]); |
110 msg.setPackedRepeatedBoolList([true]); | 163 msg.setPackedRepeatedBoolList([true]); |
111 | 164 |
112 msg.setRepeatedInt32StringList(['-12345']); | |
113 msg.setRepeatedUint32StringList(['12345']); | |
114 msg.setRepeatedInt64StringList(['-123456789012345']); | |
115 msg.setRepeatedUint64StringList(['987654321098765']); | |
116 msg.setPackedRepeatedInt32StringList(['-12345']); | |
117 msg.setPackedRepeatedUint32StringList(['12345']); | |
118 msg.setPackedRepeatedInt64StringList(['-123456789012345']); | |
119 msg.setPackedRepeatedUint64StringList(['987654321098765']); | |
120 } | 165 } |
121 | 166 |
122 | 167 |
123 /** | 168 /** |
124 * Helper: compare a bytes field to a string with codepoints 0--255. | 169 * Helper: compare a bytes field to an expected value |
125 * @param {Uint8Array|string} arr | 170 * @param {Uint8Array|string} arr |
126 * @param {string} str | 171 * @param {Uint8Array} expected |
127 * @return {boolean} | 172 * @return {boolean} |
128 */ | 173 */ |
129 function bytesCompare(arr, str) { | 174 function bytesCompare(arr, expected) { |
130 if (arr.length != str.length) { | 175 if (goog.isString(arr)) { |
| 176 arr = goog.crypt.base64.decodeStringToUint8Array(arr); |
| 177 } |
| 178 if (arr.length != expected.length) { |
131 return false; | 179 return false; |
132 } | 180 } |
133 if (typeof arr == 'string') { | 181 for (var i = 0; i < arr.length; i++) { |
134 for (var i = 0; i < arr.length; i++) { | 182 if (arr[i] != expected[i]) { |
135 if (arr.charCodeAt(i) != str.charCodeAt(i)) { | 183 return false; |
136 return false; | |
137 } | |
138 } | 184 } |
139 return true; | |
140 } else { | |
141 for (var i = 0; i < arr.length; i++) { | |
142 if (arr[i] != str.charCodeAt(i)) { | |
143 return false; | |
144 } | |
145 } | |
146 return true; | |
147 } | 185 } |
| 186 return true; |
148 } | 187 } |
149 | 188 |
150 | 189 |
151 /** | 190 /** |
152 * Helper: verify contents of given TestAllTypes message as set by | 191 * Helper: verify contents of given TestAllTypes message as set by |
153 * fillAllFields(). | 192 * fillAllFields(). |
154 * @param {proto.jspb.test.TestAllTypes} msg | 193 * @param {proto.jspb.test.TestAllTypes} original |
| 194 * @param {proto.jspb.test.TestAllTypes} copy |
155 */ | 195 */ |
156 function checkAllFields(msg) { | 196 function checkAllFields(original, copy) { |
157 assertEquals(msg.getOptionalInt32(), -42); | 197 assertTrue(jspb.Message.equals(original, copy)); |
158 assertEquals(msg.getOptionalInt64(), -0x7fffffff00000000); | 198 |
159 assertEquals(msg.getOptionalUint32(), 0x80000000); | 199 assertEquals(copy.getOptionalInt32(), -42); |
160 assertEquals(msg.getOptionalUint64(), 0xf000000000000000); | 200 assertEquals(copy.getOptionalInt64(), -0x7fffffff00000000); |
161 assertEquals(msg.getOptionalSint32(), -100); | 201 assertEquals(copy.getOptionalUint32(), 0x80000000); |
162 assertEquals(msg.getOptionalSint64(), -0x8000000000000000); | 202 assertEquals(copy.getOptionalUint64(), 0xf000000000000000); |
163 assertEquals(msg.getOptionalFixed32(), 1234); | 203 assertEquals(copy.getOptionalSint32(), -100); |
164 assertEquals(msg.getOptionalFixed64(), 0x1234567800000000); | 204 assertEquals(copy.getOptionalSint64(), -0x8000000000000000); |
165 assertEquals(msg.getOptionalSfixed32(), -1234); | 205 assertEquals(copy.getOptionalFixed32(), 1234); |
166 assertEquals(msg.getOptionalSfixed64(), -0x1234567800000000); | 206 assertEquals(copy.getOptionalFixed64(), 0x1234567800000000); |
167 assertEquals(msg.getOptionalFloat(), 1.5); | 207 assertEquals(copy.getOptionalSfixed32(), -1234); |
168 assertEquals(msg.getOptionalDouble(), -1.5); | 208 assertEquals(copy.getOptionalSfixed64(), -0x1234567800000000); |
169 assertEquals(msg.getOptionalBool(), true); | 209 assertEquals(copy.getOptionalFloat(), 1.5); |
170 assertEquals(msg.getOptionalString(), 'hello world'); | 210 assertEquals(copy.getOptionalDouble(), -1.5); |
171 assertEquals(true, bytesCompare(msg.getOptionalBytes(), 'bytes')); | 211 assertEquals(copy.getOptionalBool(), true); |
172 assertEquals(msg.getOptionalGroup().getA(), 100); | 212 assertEquals(copy.getOptionalString(), 'hello world'); |
173 assertEquals(msg.getOptionalForeignMessage().getC(), 16); | 213 assertEquals(true, bytesCompare(copy.getOptionalBytes(), BYTES)); |
174 assertEquals(msg.getOptionalForeignEnum(), | 214 assertEquals(true, bytesCompare(copy.getOptionalBytes_asU8(), BYTES)); |
| 215 assertEquals( |
| 216 copy.getOptionalBytes_asB64(), goog.crypt.base64.encodeByteArray(BYTES)); |
| 217 |
| 218 assertEquals(copy.getOptionalGroup().getA(), 100); |
| 219 assertEquals(copy.getOptionalForeignMessage().getC(), 16); |
| 220 assertEquals(copy.getOptionalForeignEnum(), |
175 proto.jspb.test.ForeignEnum.FOREIGN_FOO); | 221 proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
176 assertEquals(msg.getOptionalInt32String(), '-12345'); | 222 |
177 assertEquals(msg.getOptionalUint32String(), '12345'); | 223 |
178 assertEquals(msg.getOptionalInt64String(), '-123456789012345'); | 224 assertEquals(copy.getOneofString(), 'oneof'); |
179 assertEquals(msg.getOptionalUint64String(), '987654321098765'); | 225 assertEquals(copy.getOneofFieldCase(), |
180 assertEquals(msg.getOneofString(), 'oneof'); | |
181 assertEquals(msg.getOneofFieldCase(), | |
182 proto.jspb.test.TestAllTypes.OneofFieldCase.ONEOF_STRING); | 226 proto.jspb.test.TestAllTypes.OneofFieldCase.ONEOF_STRING); |
183 | 227 |
184 assertElementsEquals(msg.getRepeatedInt32List(), [-42]); | 228 assertElementsEquals(copy.getRepeatedInt32List(), [-42]); |
185 assertElementsEquals(msg.getRepeatedInt64List(), [-0x7fffffff00000000]); | 229 assertElementsEquals(copy.getRepeatedInt64List(), [-0x7fffffff00000000]); |
186 assertElementsEquals(msg.getRepeatedUint32List(), [0x80000000]); | 230 assertElementsEquals(copy.getRepeatedUint32List(), [0x80000000]); |
187 assertElementsEquals(msg.getRepeatedUint64List(), [0xf000000000000000]); | 231 assertElementsEquals(copy.getRepeatedUint64List(), [0xf000000000000000]); |
188 assertElementsEquals(msg.getRepeatedSint32List(), [-100]); | 232 assertElementsEquals(copy.getRepeatedSint32List(), [-100]); |
189 assertElementsEquals(msg.getRepeatedSint64List(), [-0x8000000000000000]); | 233 assertElementsEquals(copy.getRepeatedSint64List(), [-0x8000000000000000]); |
190 assertElementsEquals(msg.getRepeatedFixed32List(), [1234]); | 234 assertElementsEquals(copy.getRepeatedFixed32List(), [1234]); |
191 assertElementsEquals(msg.getRepeatedFixed64List(), [0x1234567800000000]); | 235 assertElementsEquals(copy.getRepeatedFixed64List(), [0x1234567800000000]); |
192 assertElementsEquals(msg.getRepeatedSfixed32List(), [-1234]); | 236 assertElementsEquals(copy.getRepeatedSfixed32List(), [-1234]); |
193 assertElementsEquals(msg.getRepeatedSfixed64List(), [-0x1234567800000000]); | 237 assertElementsEquals(copy.getRepeatedSfixed64List(), [-0x1234567800000000]); |
194 assertElementsEquals(msg.getRepeatedFloatList(), [1.5]); | 238 assertElementsEquals(copy.getRepeatedFloatList(), [1.5]); |
195 assertElementsEquals(msg.getRepeatedDoubleList(), [-1.5]); | 239 assertElementsEquals(copy.getRepeatedDoubleList(), [-1.5]); |
196 assertElementsEquals(msg.getRepeatedBoolList(), [true]); | 240 assertElementsEquals(copy.getRepeatedBoolList(), [true]); |
197 assertElementsEquals(msg.getRepeatedStringList(), ['hello world']); | 241 assertElementsEquals(copy.getRepeatedStringList(), ['hello world']); |
198 assertEquals(msg.getRepeatedBytesList().length, 1); | 242 assertEquals(copy.getRepeatedBytesList().length, 2); |
199 assertEquals(true, bytesCompare(msg.getRepeatedBytesList()[0], 'bytes')); | 243 assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[0], BYTES)); |
200 assertEquals(msg.getRepeatedGroupList().length, 1); | 244 assertEquals(true, bytesCompare(copy.getRepeatedBytesList()[0], BYTES)); |
201 assertEquals(msg.getRepeatedGroupList()[0].getA(), 100); | 245 assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[1], BYTES)); |
202 assertEquals(msg.getRepeatedForeignMessageList().length, 1); | 246 assertEquals(copy.getRepeatedBytesList_asB64()[0], BYTES_B64); |
203 assertEquals(msg.getRepeatedForeignMessageList()[0].getC(), 1000); | 247 assertEquals(copy.getRepeatedBytesList_asB64()[1], BYTES_B64); |
204 assertElementsEquals(msg.getRepeatedForeignEnumList(), | 248 assertEquals(copy.getRepeatedGroupList().length, 1); |
| 249 assertEquals(copy.getRepeatedGroupList()[0].getA(), 100); |
| 250 assertEquals(copy.getRepeatedForeignMessageList().length, 1); |
| 251 assertEquals(copy.getRepeatedForeignMessageList()[0].getC(), 1000); |
| 252 assertElementsEquals(copy.getRepeatedForeignEnumList(), |
205 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); | 253 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
206 | 254 |
207 assertElementsEquals(msg.getPackedRepeatedInt32List(), [-42]); | 255 assertElementsEquals(copy.getPackedRepeatedInt32List(), [-42]); |
208 assertElementsEquals(msg.getPackedRepeatedInt64List(), | 256 assertElementsEquals(copy.getPackedRepeatedInt64List(), |
209 [-0x7fffffff00000000]); | 257 [-0x7fffffff00000000]); |
210 assertElementsEquals(msg.getPackedRepeatedUint32List(), [0x80000000]); | 258 assertElementsEquals(copy.getPackedRepeatedUint32List(), [0x80000000]); |
211 assertElementsEquals(msg.getPackedRepeatedUint64List(), [0xf000000000000000]); | 259 assertElementsEquals(copy.getPackedRepeatedUint64List(), |
212 assertElementsEquals(msg.getPackedRepeatedSint32List(), [-100]); | 260 [0xf000000000000000]); |
213 assertElementsEquals(msg.getPackedRepeatedSint64List(), | 261 assertElementsEquals(copy.getPackedRepeatedSint32List(), [-100]); |
| 262 assertElementsEquals(copy.getPackedRepeatedSint64List(), |
214 [-0x8000000000000000]); | 263 [-0x8000000000000000]); |
215 assertElementsEquals(msg.getPackedRepeatedFixed32List(), [1234]); | 264 assertElementsEquals(copy.getPackedRepeatedFixed32List(), [1234]); |
216 assertElementsEquals(msg.getPackedRepeatedFixed64List(), | 265 assertElementsEquals(copy.getPackedRepeatedFixed64List(), |
217 [0x1234567800000000]); | 266 [0x1234567800000000]); |
218 assertElementsEquals(msg.getPackedRepeatedSfixed32List(), [-1234]); | 267 assertElementsEquals(copy.getPackedRepeatedSfixed32List(), [-1234]); |
219 assertElementsEquals(msg.getPackedRepeatedSfixed64List(), | 268 assertElementsEquals(copy.getPackedRepeatedSfixed64List(), |
220 [-0x1234567800000000]); | 269 [-0x1234567800000000]); |
221 assertElementsEquals(msg.getPackedRepeatedFloatList(), [1.5]); | 270 assertElementsEquals(copy.getPackedRepeatedFloatList(), [1.5]); |
222 assertElementsEquals(msg.getPackedRepeatedDoubleList(), [-1.5]); | 271 assertElementsEquals(copy.getPackedRepeatedDoubleList(), [-1.5]); |
223 assertElementsEquals(msg.getPackedRepeatedBoolList(), [true]); | |
224 | 272 |
225 assertEquals(msg.getRepeatedInt32StringList().length, 1); | |
226 assertElementsEquals(msg.getRepeatedInt32StringList(), ['-12345']); | |
227 assertEquals(msg.getRepeatedUint32StringList().length, 1); | |
228 assertElementsEquals(msg.getRepeatedUint32StringList(), ['12345']); | |
229 assertEquals(msg.getRepeatedInt64StringList().length, 1); | |
230 assertElementsEquals(msg.getRepeatedInt64StringList(), ['-123456789012345']); | |
231 assertEquals(msg.getRepeatedUint64StringList().length, 1); | |
232 assertElementsEquals(msg.getRepeatedUint64StringList(), ['987654321098765']); | |
233 | |
234 assertEquals(msg.getPackedRepeatedInt32StringList().length, 1); | |
235 assertElementsEquals(msg.getPackedRepeatedInt32StringList(), ['-12345']); | |
236 assertEquals(msg.getPackedRepeatedUint32StringList().length, 1); | |
237 assertElementsEquals(msg.getPackedRepeatedUint32StringList(), ['12345']); | |
238 assertEquals(msg.getPackedRepeatedInt64StringList().length, 1); | |
239 assertElementsEquals(msg.getPackedRepeatedInt64StringList(), | |
240 ['-123456789012345']); | |
241 assertEquals(msg.getPackedRepeatedUint64StringList().length, 1); | |
242 assertElementsEquals(msg.getPackedRepeatedUint64StringList(), | |
243 ['987654321098765']); | |
244 } | 273 } |
245 | 274 |
246 | 275 |
247 /** | 276 /** |
248 * Helper: verify that all expected extensions are present. | 277 * Helper: verify that all expected extensions are present. |
249 * @param {!proto.jspb.test.TestExtendable} msg | 278 * @param {!proto.jspb.test.TestExtendable} msg |
250 */ | 279 */ |
251 function checkExtensions(msg) { | 280 function checkExtensions(msg) { |
252 assertEquals(-42, | 281 assertEquals(-42, |
253 msg.getExtension(proto.jspb.test.extendOptionalInt32)); | 282 msg.getExtension(proto.jspb.test.extendOptionalInt32)); |
(...skipping 16 matching lines...) Expand all Loading... |
270 assertEquals(-0x1234567800000000, | 299 assertEquals(-0x1234567800000000, |
271 msg.getExtension(proto.jspb.test.extendOptionalSfixed64)); | 300 msg.getExtension(proto.jspb.test.extendOptionalSfixed64)); |
272 assertEquals(1.5, | 301 assertEquals(1.5, |
273 msg.getExtension(proto.jspb.test.extendOptionalFloat)); | 302 msg.getExtension(proto.jspb.test.extendOptionalFloat)); |
274 assertEquals(-1.5, | 303 assertEquals(-1.5, |
275 msg.getExtension(proto.jspb.test.extendOptionalDouble)); | 304 msg.getExtension(proto.jspb.test.extendOptionalDouble)); |
276 assertEquals(true, | 305 assertEquals(true, |
277 msg.getExtension(proto.jspb.test.extendOptionalBool)); | 306 msg.getExtension(proto.jspb.test.extendOptionalBool)); |
278 assertEquals('hello world', | 307 assertEquals('hello world', |
279 msg.getExtension(proto.jspb.test.extendOptionalString)); | 308 msg.getExtension(proto.jspb.test.extendOptionalString)); |
280 assertEquals(true, | 309 assertEquals( |
281 bytesCompare(msg.getExtension(proto.jspb.test.extendOptionalBytes), | 310 true, bytesCompare( |
282 'bytes')); | 311 msg.getExtension(proto.jspb.test.extendOptionalBytes), BYTES)); |
283 assertEquals(16, | 312 assertEquals(16, |
284 msg.getExtension( | 313 msg.getExtension( |
285 proto.jspb.test.ExtendsWithMessage.optionalExtension).getFoo()); | 314 proto.jspb.test.ExtendsWithMessage.optionalExtension).getFoo()); |
286 assertEquals(proto.jspb.test.ForeignEnum.FOREIGN_FOO, | 315 |
287 msg.getExtension(proto.jspb.test.extendOptionalForeignEnum)); | |
288 assertEquals('-12345', | |
289 msg.getExtension(proto.jspb.test.extendOptionalInt32String)); | |
290 assertEquals('12345', | |
291 msg.getExtension(proto.jspb.test.extendOptionalUint32String)); | |
292 assertEquals('-123456789012345', | |
293 msg.getExtension(proto.jspb.test.extendOptionalInt64String)); | |
294 assertEquals('987654321098765', | |
295 msg.getExtension(proto.jspb.test.extendOptionalUint64String)); | |
296 | 316 |
297 assertElementsEquals( | 317 assertElementsEquals( |
298 msg.getExtension(proto.jspb.test.extendRepeatedInt32List), | 318 msg.getExtension(proto.jspb.test.extendRepeatedInt32List), |
299 [-42]); | 319 [-42]); |
300 assertElementsEquals( | 320 assertElementsEquals( |
301 msg.getExtension(proto.jspb.test.extendRepeatedInt64List), | 321 msg.getExtension(proto.jspb.test.extendRepeatedInt64List), |
302 [-0x7fffffff00000000]); | 322 [-0x7fffffff00000000]); |
303 assertElementsEquals( | 323 assertElementsEquals( |
304 msg.getExtension(proto.jspb.test.extendRepeatedUint32List), | 324 msg.getExtension(proto.jspb.test.extendRepeatedUint32List), |
305 [0x80000000]); | 325 [0x80000000]); |
(...skipping 23 matching lines...) Expand all Loading... |
329 [1.5]); | 349 [1.5]); |
330 assertElementsEquals( | 350 assertElementsEquals( |
331 msg.getExtension(proto.jspb.test.extendRepeatedDoubleList), | 351 msg.getExtension(proto.jspb.test.extendRepeatedDoubleList), |
332 [-1.5]); | 352 [-1.5]); |
333 assertElementsEquals( | 353 assertElementsEquals( |
334 msg.getExtension(proto.jspb.test.extendRepeatedBoolList), | 354 msg.getExtension(proto.jspb.test.extendRepeatedBoolList), |
335 [true]); | 355 [true]); |
336 assertElementsEquals( | 356 assertElementsEquals( |
337 msg.getExtension(proto.jspb.test.extendRepeatedStringList), | 357 msg.getExtension(proto.jspb.test.extendRepeatedStringList), |
338 ['hello world']); | 358 ['hello world']); |
339 assertEquals(true, | 359 assertEquals( |
| 360 true, |
340 bytesCompare( | 361 bytesCompare( |
341 msg.getExtension(proto.jspb.test.extendRepeatedBytesList)[0], | 362 msg.getExtension(proto.jspb.test.extendRepeatedBytesList)[0], BYTES)); |
342 'bytes')); | |
343 assertEquals(1000, | 363 assertEquals(1000, |
344 msg.getExtension( | 364 msg.getExtension( |
345 proto.jspb.test.ExtendsWithMessage.repeatedExtensionList)[0] | 365 proto.jspb.test.ExtendsWithMessage.repeatedExtensionList)[0] |
346 .getFoo()); | 366 .getFoo()); |
347 assertElementsEquals( | 367 assertElementsEquals( |
348 msg.getExtension(proto.jspb.test.extendRepeatedForeignEnumList), | 368 msg.getExtension(proto.jspb.test.extendRepeatedForeignEnumList), |
349 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); | 369 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
350 | 370 |
351 assertElementsEquals( | |
352 msg.getExtension(proto.jspb.test.extendRepeatedInt32StringList), | |
353 ['-12345']); | |
354 assertElementsEquals( | |
355 msg.getExtension(proto.jspb.test.extendRepeatedUint32StringList), | |
356 ['12345']); | |
357 assertElementsEquals( | |
358 msg.getExtension(proto.jspb.test.extendRepeatedInt64StringList), | |
359 ['-123456789012345']); | |
360 assertElementsEquals( | |
361 msg.getExtension(proto.jspb.test.extendRepeatedUint64StringList), | |
362 ['987654321098765']); | |
363 | 371 |
364 assertElementsEquals( | 372 assertElementsEquals( |
365 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32List), | 373 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32List), |
366 [-42]); | 374 [-42]); |
367 assertElementsEquals( | 375 assertElementsEquals( |
368 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64List), | 376 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64List), |
369 [-0x7fffffff00000000]); | 377 [-0x7fffffff00000000]); |
370 assertElementsEquals( | 378 assertElementsEquals( |
371 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32List), | 379 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32List), |
372 [0x80000000]); | 380 [0x80000000]); |
(...skipping 24 matching lines...) Expand all Loading... |
397 assertElementsEquals( | 405 assertElementsEquals( |
398 msg.getExtension(proto.jspb.test.extendPackedRepeatedDoubleList), | 406 msg.getExtension(proto.jspb.test.extendPackedRepeatedDoubleList), |
399 [-1.5]); | 407 [-1.5]); |
400 assertElementsEquals( | 408 assertElementsEquals( |
401 msg.getExtension(proto.jspb.test.extendPackedRepeatedBoolList), | 409 msg.getExtension(proto.jspb.test.extendPackedRepeatedBoolList), |
402 [true]); | 410 [true]); |
403 assertElementsEquals( | 411 assertElementsEquals( |
404 msg.getExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList), | 412 msg.getExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList), |
405 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); | 413 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
406 | 414 |
407 assertElementsEquals( | |
408 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32StringList), | |
409 ['-12345']); | |
410 assertElementsEquals( | |
411 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32StringList), | |
412 ['12345']); | |
413 assertElementsEquals( | |
414 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64StringList), | |
415 ['-123456789012345']); | |
416 assertElementsEquals( | |
417 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint64StringList), | |
418 ['987654321098765']); | |
419 } | 415 } |
420 | 416 |
421 | 417 |
422 describe('protoBinaryTest', function() { | 418 describe('protoBinaryTest', function() { |
423 /** | 419 /** |
424 * Tests a basic serialization-deserializaton round-trip with all supported | 420 * Tests a basic serialization-deserializaton round-trip with all supported |
425 * field types (on the TestAllTypes message type). | 421 * field types (on the TestAllTypes message type). |
426 */ | 422 */ |
427 it('testRoundTrip', function() { | 423 it('testRoundTrip', function() { |
428 var msg = new proto.jspb.test.TestAllTypes(); | 424 var msg = new proto.jspb.test.TestAllTypes(); |
429 fillAllFields(msg); | 425 fillAllFields(msg); |
430 var encoded = msg.serializeBinary(); | 426 var encoded = msg.serializeBinary(); |
431 var decoded = proto.jspb.test.TestAllTypes.deserializeBinary(encoded); | 427 var decoded = proto.jspb.test.TestAllTypes.deserializeBinary(encoded); |
432 checkAllFields(decoded); | 428 checkAllFields(msg, decoded); |
433 }); | 429 }); |
434 | 430 |
| 431 /** |
| 432 * Test that base64 string and Uint8Array are interchangeable in bytes fields. |
| 433 */ |
| 434 it('testBytesFieldsGettersInterop', function() { |
| 435 var msg = new proto.jspb.test.TestAllTypes(); |
| 436 // Set from a base64 string and check all the getters work. |
| 437 msg.setOptionalBytes(BYTES_B64); |
| 438 assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
| 439 assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
| 440 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 441 |
| 442 // Test binary serialize round trip doesn't break it. |
| 443 msg = proto.jspb.test.TestAllTypes.deserializeBinary(msg.serializeBinary()); |
| 444 assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
| 445 assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
| 446 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 447 |
| 448 msg = new proto.jspb.test.TestAllTypes(); |
| 449 // Set from a Uint8Array and check all the getters work. |
| 450 msg.setOptionalBytes(BYTES); |
| 451 assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
| 452 assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
| 453 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 454 |
| 455 }); |
| 456 |
| 457 /** |
| 458 * Test that bytes setters will receive result of any of the getters. |
| 459 */ |
| 460 it('testBytesFieldsSettersInterop', function() { |
| 461 var msg = new proto.jspb.test.TestAllTypes(); |
| 462 msg.setOptionalBytes(BYTES); |
| 463 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 464 |
| 465 msg.setOptionalBytes(msg.getOptionalBytes()); |
| 466 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 467 msg.setOptionalBytes(msg.getOptionalBytes_asB64()); |
| 468 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 469 msg.setOptionalBytes(msg.getOptionalBytes_asU8()); |
| 470 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 471 }); |
| 472 |
| 473 /** |
| 474 * Test that bytes setters will receive result of any of the getters. |
| 475 */ |
| 476 it('testRepeatedBytesGetters', function() { |
| 477 var msg = new proto.jspb.test.TestAllTypes(); |
| 478 |
| 479 function assertGetters() { |
| 480 assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[0])); |
| 481 assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[1])); |
| 482 assertTrue(msg.getRepeatedBytesList_asU8()[0] instanceof Uint8Array); |
| 483 assertTrue(msg.getRepeatedBytesList_asU8()[1] instanceof Uint8Array); |
| 484 |
| 485 assertTrue(bytesCompare(msg.getRepeatedBytesList()[0], BYTES)); |
| 486 assertTrue(bytesCompare(msg.getRepeatedBytesList()[1], BYTES)); |
| 487 assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[0], BYTES)); |
| 488 assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[1], BYTES)); |
| 489 assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[0], BYTES)); |
| 490 assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[1], BYTES)); |
| 491 } |
| 492 |
| 493 msg.setRepeatedBytesList([BYTES, BYTES]); |
| 494 assertGetters(); |
| 495 |
| 496 msg.setRepeatedBytesList([BYTES_B64, BYTES_B64]); |
| 497 assertGetters(); |
| 498 |
| 499 msg.setRepeatedBytesList(null); |
| 500 assertEquals(0, msg.getRepeatedBytesList().length); |
| 501 assertEquals(0, msg.getRepeatedBytesList_asB64().length); |
| 502 assertEquals(0, msg.getRepeatedBytesList_asU8().length); |
| 503 }); |
435 | 504 |
436 /** | 505 /** |
437 * Helper: fill all extension values. | 506 * Helper: fill all extension values. |
438 * @param {proto.jspb.test.TestExtendable} msg | 507 * @param {proto.jspb.test.TestExtendable} msg |
439 */ | 508 */ |
440 function fillExtensions(msg) { | 509 function fillExtensions(msg) { |
441 msg.setExtension( | 510 msg.setExtension( |
442 proto.jspb.test.extendOptionalInt32, -42); | 511 proto.jspb.test.extendOptionalInt32, -42); |
443 msg.setExtension( | 512 msg.setExtension( |
444 proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000); | 513 proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000); |
(...skipping 14 matching lines...) Expand all Loading... |
459 msg.setExtension( | 528 msg.setExtension( |
460 proto.jspb.test.extendOptionalSfixed64, -0x1234567800000000); | 529 proto.jspb.test.extendOptionalSfixed64, -0x1234567800000000); |
461 msg.setExtension( | 530 msg.setExtension( |
462 proto.jspb.test.extendOptionalFloat, 1.5); | 531 proto.jspb.test.extendOptionalFloat, 1.5); |
463 msg.setExtension( | 532 msg.setExtension( |
464 proto.jspb.test.extendOptionalDouble, -1.5); | 533 proto.jspb.test.extendOptionalDouble, -1.5); |
465 msg.setExtension( | 534 msg.setExtension( |
466 proto.jspb.test.extendOptionalBool, true); | 535 proto.jspb.test.extendOptionalBool, true); |
467 msg.setExtension( | 536 msg.setExtension( |
468 proto.jspb.test.extendOptionalString, 'hello world'); | 537 proto.jspb.test.extendOptionalString, 'hello world'); |
469 msg.setExtension( | 538 msg.setExtension(proto.jspb.test.extendOptionalBytes, BYTES); |
470 proto.jspb.test.extendOptionalBytes, 'bytes'); | |
471 var submsg = new proto.jspb.test.ExtendsWithMessage(); | 539 var submsg = new proto.jspb.test.ExtendsWithMessage(); |
472 submsg.setFoo(16); | 540 submsg.setFoo(16); |
473 msg.setExtension( | 541 msg.setExtension( |
474 proto.jspb.test.ExtendsWithMessage.optionalExtension, submsg); | 542 proto.jspb.test.ExtendsWithMessage.optionalExtension, submsg); |
475 msg.setExtension( | 543 msg.setExtension( |
476 proto.jspb.test.extendOptionalForeignEnum, | 544 proto.jspb.test.extendOptionalForeignEnum, |
477 proto.jspb.test.ForeignEnum.FOREIGN_FOO); | 545 proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
478 msg.setExtension( | 546 |
479 proto.jspb.test.extendOptionalInt32String, '-12345'); | |
480 msg.setExtension( | |
481 proto.jspb.test.extendOptionalUint32String, '12345'); | |
482 msg.setExtension( | |
483 proto.jspb.test.extendOptionalInt64String, '-123456789012345'); | |
484 msg.setExtension( | |
485 proto.jspb.test.extendOptionalUint64String, '987654321098765'); | |
486 | 547 |
487 msg.setExtension( | 548 msg.setExtension( |
488 proto.jspb.test.extendRepeatedInt32List, [-42]); | 549 proto.jspb.test.extendRepeatedInt32List, [-42]); |
489 msg.setExtension( | 550 msg.setExtension( |
490 proto.jspb.test.extendRepeatedInt64List, [-0x7fffffff00000000]); | 551 proto.jspb.test.extendRepeatedInt64List, [-0x7fffffff00000000]); |
491 msg.setExtension( | 552 msg.setExtension( |
492 proto.jspb.test.extendRepeatedUint32List, [0x80000000]); | 553 proto.jspb.test.extendRepeatedUint32List, [0x80000000]); |
493 msg.setExtension( | 554 msg.setExtension( |
494 proto.jspb.test.extendRepeatedUint64List, [0xf000000000000000]); | 555 proto.jspb.test.extendRepeatedUint64List, [0xf000000000000000]); |
495 msg.setExtension( | 556 msg.setExtension( |
496 proto.jspb.test.extendRepeatedSint32List, [-100]); | 557 proto.jspb.test.extendRepeatedSint32List, [-100]); |
497 msg.setExtension( | 558 msg.setExtension( |
498 proto.jspb.test.extendRepeatedSint64List, [-0x8000000000000000]); | 559 proto.jspb.test.extendRepeatedSint64List, [-0x8000000000000000]); |
499 msg.setExtension( | 560 msg.setExtension( |
500 proto.jspb.test.extendRepeatedFixed32List, [1234]); | 561 proto.jspb.test.extendRepeatedFixed32List, [1234]); |
501 msg.setExtension( | 562 msg.setExtension( |
502 proto.jspb.test.extendRepeatedFixed64List, [0x1234567800000000]); | 563 proto.jspb.test.extendRepeatedFixed64List, [0x1234567800000000]); |
503 msg.setExtension( | 564 msg.setExtension( |
504 proto.jspb.test.extendRepeatedSfixed32List, [-1234]); | 565 proto.jspb.test.extendRepeatedSfixed32List, [-1234]); |
505 msg.setExtension( | 566 msg.setExtension( |
506 proto.jspb.test.extendRepeatedSfixed64List, [-0x1234567800000000]); | 567 proto.jspb.test.extendRepeatedSfixed64List, [-0x1234567800000000]); |
507 msg.setExtension( | 568 msg.setExtension( |
508 proto.jspb.test.extendRepeatedFloatList, [1.5]); | 569 proto.jspb.test.extendRepeatedFloatList, [1.5]); |
509 msg.setExtension( | 570 msg.setExtension( |
510 proto.jspb.test.extendRepeatedDoubleList, [-1.5]); | 571 proto.jspb.test.extendRepeatedDoubleList, [-1.5]); |
511 msg.setExtension( | 572 msg.setExtension( |
512 proto.jspb.test.extendRepeatedBoolList, [true]); | 573 proto.jspb.test.extendRepeatedBoolList, [true]); |
513 msg.setExtension( | 574 msg.setExtension( |
514 proto.jspb.test.extendRepeatedStringList, ['hello world']); | 575 proto.jspb.test.extendRepeatedStringList, ['hello world']); |
515 msg.setExtension( | 576 msg.setExtension(proto.jspb.test.extendRepeatedBytesList, [BYTES]); |
516 proto.jspb.test.extendRepeatedBytesList, ['bytes']); | |
517 submsg = new proto.jspb.test.ExtendsWithMessage(); | 577 submsg = new proto.jspb.test.ExtendsWithMessage(); |
518 submsg.setFoo(1000); | 578 submsg.setFoo(1000); |
519 msg.setExtension( | 579 msg.setExtension( |
520 proto.jspb.test.ExtendsWithMessage.repeatedExtensionList, [submsg]); | 580 proto.jspb.test.ExtendsWithMessage.repeatedExtensionList, [submsg]); |
521 msg.setExtension(proto.jspb.test.extendRepeatedForeignEnumList, | 581 msg.setExtension(proto.jspb.test.extendRepeatedForeignEnumList, |
522 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); | 582 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
523 | 583 |
524 msg.setExtension( | |
525 proto.jspb.test.extendRepeatedInt32StringList, ['-12345']); | |
526 msg.setExtension( | |
527 proto.jspb.test.extendRepeatedUint32StringList, ['12345']); | |
528 msg.setExtension( | |
529 proto.jspb.test.extendRepeatedInt64StringList, ['-123456789012345']); | |
530 msg.setExtension( | |
531 proto.jspb.test.extendRepeatedUint64StringList, ['987654321098765']); | |
532 | 584 |
533 msg.setExtension( | 585 msg.setExtension( |
534 proto.jspb.test.extendPackedRepeatedInt32List, [-42]); | 586 proto.jspb.test.extendPackedRepeatedInt32List, [-42]); |
535 msg.setExtension( | 587 msg.setExtension( |
536 proto.jspb.test.extendPackedRepeatedInt64List, [-0x7fffffff00000000]); | 588 proto.jspb.test.extendPackedRepeatedInt64List, [-0x7fffffff00000000]); |
537 msg.setExtension( | 589 msg.setExtension( |
538 proto.jspb.test.extendPackedRepeatedUint32List, [0x80000000]); | 590 proto.jspb.test.extendPackedRepeatedUint32List, [0x80000000]); |
539 msg.setExtension( | 591 msg.setExtension( |
540 proto.jspb.test.extendPackedRepeatedUint64List, [0xf000000000000000]); | 592 proto.jspb.test.extendPackedRepeatedUint64List, [0xf000000000000000]); |
541 msg.setExtension( | 593 msg.setExtension( |
(...skipping 11 matching lines...) Expand all Loading... |
553 [-0x1234567800000000]); | 605 [-0x1234567800000000]); |
554 msg.setExtension( | 606 msg.setExtension( |
555 proto.jspb.test.extendPackedRepeatedFloatList, [1.5]); | 607 proto.jspb.test.extendPackedRepeatedFloatList, [1.5]); |
556 msg.setExtension( | 608 msg.setExtension( |
557 proto.jspb.test.extendPackedRepeatedDoubleList, [-1.5]); | 609 proto.jspb.test.extendPackedRepeatedDoubleList, [-1.5]); |
558 msg.setExtension( | 610 msg.setExtension( |
559 proto.jspb.test.extendPackedRepeatedBoolList, [true]); | 611 proto.jspb.test.extendPackedRepeatedBoolList, [true]); |
560 msg.setExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList, | 612 msg.setExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList, |
561 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); | 613 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
562 | 614 |
563 msg.setExtension( | |
564 proto.jspb.test.extendPackedRepeatedInt32StringList, | |
565 ['-12345']); | |
566 msg.setExtension( | |
567 proto.jspb.test.extendPackedRepeatedUint32StringList, | |
568 ['12345']); | |
569 msg.setExtension( | |
570 proto.jspb.test.extendPackedRepeatedInt64StringList, | |
571 ['-123456789012345']); | |
572 msg.setExtension( | |
573 proto.jspb.test.extendPackedRepeatedUint64StringList, | |
574 ['987654321098765']); | |
575 } | 615 } |
576 | 616 |
577 | 617 |
578 /** | 618 /** |
579 * Tests extension serialization and deserialization. | 619 * Tests extension serialization and deserialization. |
580 */ | 620 */ |
581 it('testExtensions', function() { | 621 it('testExtensions', function() { |
582 var msg = new proto.jspb.test.TestExtendable(); | 622 var msg = new proto.jspb.test.TestExtendable(); |
583 fillExtensions(msg); | 623 fillExtensions(msg); |
584 var encoded = msg.serializeBinary(); | 624 var encoded = msg.serializeBinary(); |
585 var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); | 625 var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); |
586 checkExtensions(decoded); | 626 checkExtensions(decoded); |
587 }); | 627 }); |
588 }); | 628 }); |
OLD | NEW |