Browse Source

Project import generated by Copybara

PiperOrigin-RevId: 300369497
Protobuf Team 5 years ago
parent
commit
94b39efdf7

+ 20 - 0
js/experimental/runtime/kernel/lazy_accessor_test.js

@@ -883,6 +883,16 @@ describe('Fixed32 access', () => {
       expect(accessor.getFixed32WithDefault(1)).toEqual(null);
       expect(accessor.getFixed32WithDefault(1)).toEqual(null);
     }
     }
   });
   });
+
+  it('throws in setter for negative value', () => {
+    if (CHECK_CRITICAL_TYPE) {
+      expect(() => LazyAccessor.createEmpty().setFixed32(1, -1)).toThrow();
+    } else {
+      const accessor = LazyAccessor.createEmpty();
+      accessor.setFixed32(1, -1);
+      expect(accessor.getFixed32WithDefault(1)).toEqual(-1);
+    }
+  });
 });
 });
 
 
 describe('Fixed64 access', () => {
 describe('Fixed64 access', () => {
@@ -1874,6 +1884,16 @@ describe('Uint32 access', () => {
       expect(accessor.getUint32WithDefault(1)).toEqual(null);
       expect(accessor.getUint32WithDefault(1)).toEqual(null);
     }
     }
   });
   });
+
+  it('throws in setter for negative value', () => {
+    if (CHECK_CRITICAL_TYPE) {
+      expect(() => LazyAccessor.createEmpty().setUint32(1, -1)).toThrow();
+    } else {
+      const accessor = LazyAccessor.createEmpty();
+      accessor.setUint32(1, -1);
+      expect(accessor.getUint32WithDefault(1)).toEqual(-1);
+    }
+  });
 });
 });
 
 
 describe('Uint64 access', () => {
 describe('Uint64 access', () => {

+ 10 - 8
js/experimental/runtime/kernel/reader_test.js

@@ -219,14 +219,16 @@ describe('readUint32 does', () => {
   });
   });
 
 
   for (const pair of getUint32Pairs()) {
   for (const pair of getUint32Pairs()) {
-    it(`decode ${pair.name}`, () => {
-      if (pair.error && CHECK_CRITICAL_STATE) {
-        expect(() => reader.readUint32(pair.bufferDecoder, 0)).toThrow();
-      } else {
-        const d = reader.readUint32(pair.bufferDecoder, 0);
-        expect(d).toEqual(pair.intValue);
-      }
-    });
+    if (!pair.skip_reader) {
+      it(`decode ${pair.name}`, () => {
+        if (pair.error && CHECK_CRITICAL_STATE) {
+          expect(() => reader.readUint32(pair.bufferDecoder, 0)).toThrow();
+        } else {
+          const d = reader.readUint32(pair.bufferDecoder, 0);
+          expect(d).toEqual(pair.intValue);
+        }
+      });
+    }
   }
   }
 });
 });
 
 

+ 8 - 1
js/experimental/runtime/kernel/uint32_test_pairs.js

@@ -10,7 +10,8 @@ const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'
  * An array of Pairs of float values and their bit representation.
  * An array of Pairs of float values and their bit representation.
  * This is used to test encoding and decoding from/to the protobuf wire format.
  * This is used to test encoding and decoding from/to the protobuf wire format.
  * @return {!Array<{name: string, intValue:number, bufferDecoder:
  * @return {!Array<{name: string, intValue:number, bufferDecoder:
- *     !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>}
+ *     !BufferDecoder, error: (boolean|undefined),
+ *    skip_reader: (boolean|undefined), skip_writer: (boolean|undefined)}>}
  */
  */
 function getUint32Pairs() {
 function getUint32Pairs() {
   const uint32Pairs = [
   const uint32Pairs = [
@@ -34,6 +35,12 @@ function getUint32Pairs() {
       intValue: Math.pow(2, 32) - 1,
       intValue: Math.pow(2, 32) - 1,
       bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
       bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
     },
     },
+    {
+      name: 'negative one',
+      intValue: -1,
+      bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
+      skip_reader: true,
+    },
     {
     {
       name: 'truncates more than 32 bits',
       name: 'truncates more than 32 bits',
       intValue: Math.pow(2, 32) - 1,
       intValue: Math.pow(2, 32) - 1,