Project import generated by Copybara

PiperOrigin-RevId: 300369497
pull/7269/head
Protobuf Team 5 years ago committed by Copybara-Service
parent a0cc0e83cb
commit 94b39efdf7
  1. 20
      js/experimental/runtime/kernel/lazy_accessor_test.js
  2. 18
      js/experimental/runtime/kernel/reader_test.js
  3. 9
      js/experimental/runtime/kernel/uint32_test_pairs.js

@ -883,6 +883,16 @@ describe('Fixed32 access', () => {
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', () => {
@ -1874,6 +1884,16 @@ describe('Uint32 access', () => {
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', () => {

@ -219,14 +219,16 @@ describe('readUint32 does', () => {
});
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);
}
});
}
}
});

@ -10,7 +10,8 @@ const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'
* 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.
* @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() {
const uint32Pairs = [
@ -34,6 +35,12 @@ function getUint32Pairs() {
intValue: Math.pow(2, 32) - 1,
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',
intValue: Math.pow(2, 32) - 1,

Loading…
Cancel
Save