aboutsummaryrefslogtreecommitdiff
path: root/js/binary/decoder_test.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/binary/decoder_test.js')
-rw-r--r--js/binary/decoder_test.js38
1 files changed, 20 insertions, 18 deletions
diff --git a/js/binary/decoder_test.js b/js/binary/decoder_test.js
index cb8aff96..b19e1d1b 100644
--- a/js/binary/decoder_test.js
+++ b/js/binary/decoder_test.js
@@ -211,6 +211,25 @@ describe('binaryDecoderTest', function() {
});
/**
+ * Tests reading and writing large strings
+ */
+ it('testLargeStrings', function() {
+ var encoder = new jspb.BinaryEncoder();
+
+ var len = 150000;
+ var long_string = '';
+ for (var i = 0; i < len; i++) {
+ long_string += 'a';
+ }
+
+ encoder.writeString(long_string);
+
+ var decoder = jspb.BinaryDecoder.alloc(encoder.end());
+
+ assertEquals(long_string, decoder.readString(len));
+ });
+
+ /**
* Test encoding and decoding utf-8.
*/
it('testUtf8', function() {
@@ -251,24 +270,7 @@ describe('binaryDecoderTest', function() {
assertThrows(function() {decoder.readSignedVarint64()});
decoder.reset();
assertThrows(function() {decoder.readZigzagVarint64()});
-
- // Positive 32-bit varints encoded with 1 bits in positions 33 through 35
- // should trigger assertions.
- decoder.setBlock([255, 255, 255, 255, 0x1F]);
- assertThrows(function() {decoder.readUnsignedVarint32()});
-
- decoder.setBlock([255, 255, 255, 255, 0x2F]);
- assertThrows(function() {decoder.readUnsignedVarint32()});
-
- decoder.setBlock([255, 255, 255, 255, 0x4F]);
- assertThrows(function() {decoder.readUnsignedVarint32()});
-
- // Negative 32-bit varints encoded with non-1 bits in the high dword should
- // trigger assertions.
- decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]);
- assertThrows(function() {decoder.readUnsignedVarint32()});
-
- decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]);
+ decoder.reset();
assertThrows(function() {decoder.readUnsignedVarint32()});
});