Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: third_party/protobuf/js/binary/decoder_test.js

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/protobuf/js/binary/decoder.js ('k') | third_party/protobuf/js/binary/encoder.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 141
142 // Encoding values outside the valid range should assert. 142 // Encoding values outside the valid range should assert.
143 assertThrows(function() {writeValue.call(encoder, lowerLimit * 1.1);}); 143 assertThrows(function() {writeValue.call(encoder, lowerLimit * 1.1);});
144 assertThrows(function() {writeValue.call(encoder, upperLimit * 1.1);}); 144 assertThrows(function() {writeValue.call(encoder, upperLimit * 1.1);});
145 } 145 }
146 146
147 describe('binaryDecoderTest', function() { 147 describe('binaryDecoderTest', function() {
148 /** 148 /**
149 * Tests the decoder instance cache. 149 * Tests the decoder instance cache.
150 * @suppress {visibility}
150 */ 151 */
151 it('testInstanceCache', /** @suppress {visibility} */ function() { 152 it('testInstanceCache', function() {
152 // Empty the instance caches. 153 // Empty the instance caches.
153 jspb.BinaryDecoder.instanceCache_ = []; 154 jspb.BinaryDecoder.instanceCache_ = [];
154 155
155 // Allocating and then freeing a decoder should put it in the instance 156 // Allocating and then freeing a decoder should put it in the instance
156 // cache. 157 // cache.
157 jspb.BinaryDecoder.alloc().free(); 158 jspb.BinaryDecoder.alloc().free();
158 159
159 assertEquals(1, jspb.BinaryDecoder.instanceCache_.length); 160 assertEquals(1, jspb.BinaryDecoder.instanceCache_.length);
160 161
161 // Allocating and then freeing three decoders should leave us with three in 162 // Allocating and then freeing three decoders should leave us with three in
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 assertEquals(hashA, decoder.readVarintHash64()); 203 assertEquals(hashA, decoder.readVarintHash64());
203 assertEquals(hashB, decoder.readVarintHash64()); 204 assertEquals(hashB, decoder.readVarintHash64());
204 assertEquals(hashC, decoder.readVarintHash64()); 205 assertEquals(hashC, decoder.readVarintHash64());
205 assertEquals(hashD, decoder.readVarintHash64()); 206 assertEquals(hashD, decoder.readVarintHash64());
206 207
207 assertEquals(hashA, decoder.readFixedHash64()); 208 assertEquals(hashA, decoder.readFixedHash64());
208 assertEquals(hashB, decoder.readFixedHash64()); 209 assertEquals(hashB, decoder.readFixedHash64());
209 assertEquals(hashC, decoder.readFixedHash64()); 210 assertEquals(hashC, decoder.readFixedHash64());
210 assertEquals(hashD, decoder.readFixedHash64()); 211 assertEquals(hashD, decoder.readFixedHash64());
211 }); 212 });
212
213 /**
214 * Test encoding and decoding utf-8.
215 */
216 it('testUtf8', function() {
217 var encoder = new jspb.BinaryEncoder();
218 213
219 var ascii = "ASCII should work in 3, 2, 1..."
220 var utf8_two_bytes = "©";
221 var utf8_three_bytes = "❄";
222 var utf8_four_bytes = "😁";
223
224 encoder.writeString(ascii);
225 encoder.writeString(utf8_two_bytes);
226 encoder.writeString(utf8_three_bytes);
227 encoder.writeString(utf8_four_bytes);
228
229 var decoder = jspb.BinaryDecoder.alloc(encoder.end());
230
231 assertEquals(ascii, decoder.readString(ascii.length));
232 assertEquals(utf8_two_bytes, decoder.readString(utf8_two_bytes.length));
233 assertEquals(utf8_three_bytes, decoder.readString(utf8_three_bytes.length));
234 assertEquals(utf8_four_bytes, decoder.readString(utf8_four_bytes.length));
235 });
236 214
237 /** 215 /**
238 * Verifies that misuse of the decoder class triggers assertions. 216 * Verifies that misuse of the decoder class triggers assertions.
239 * @suppress {checkTypes|visibility} 217 * @suppress {checkTypes|visibility}
240 */ 218 */
241 it('testDecodeErrors', function() { 219 it('testDecodeErrors', function() {
242 // Reading a value past the end of the stream should trigger an assertion. 220 // Reading a value past the end of the stream should trigger an assertion.
243 var decoder = jspb.BinaryDecoder.alloc([0, 1, 2]); 221 var decoder = jspb.BinaryDecoder.alloc([0, 1, 2]);
244 assertThrows(function() {decoder.readUint64()}); 222 assertThrows(function() {decoder.readUint64()});
245 223
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 326
349 doTestSignedValue( 327 doTestSignedValue(
350 jspb.BinaryDecoder.prototype.readDouble, 328 jspb.BinaryDecoder.prototype.readDouble,
351 jspb.BinaryEncoder.prototype.writeDouble, 329 jspb.BinaryEncoder.prototype.writeDouble,
352 jspb.BinaryConstants.FLOAT64_EPS * 10, 330 jspb.BinaryConstants.FLOAT64_EPS * 10,
353 -jspb.BinaryConstants.FLOAT64_MAX, 331 -jspb.BinaryConstants.FLOAT64_MAX,
354 jspb.BinaryConstants.FLOAT64_MAX, 332 jspb.BinaryConstants.FLOAT64_MAX,
355 function(x) { return x; }); 333 function(x) { return x; });
356 }); 334 });
357 }); 335 });
OLDNEW
« no previous file with comments | « third_party/protobuf/js/binary/decoder.js ('k') | third_party/protobuf/js/binary/encoder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698