Skip to content

Commit 3d34125

Browse files
Protobuf Teamcopybara-github
authored andcommitted
Project import generated by Copybara
PiperOrigin-RevId: 300369497
1 parent 6678d3a commit 3d34125

3 files changed

Lines changed: 38 additions & 9 deletions

File tree

experimental/runtime/kernel/lazy_accessor_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,16 @@ describe('Fixed32 access', () => {
883883
expect(accessor.getFixed32WithDefault(1)).toEqual(null);
884884
}
885885
});
886+
887+
it('throws in setter for negative value', () => {
888+
if (CHECK_CRITICAL_TYPE) {
889+
expect(() => LazyAccessor.createEmpty().setFixed32(1, -1)).toThrow();
890+
} else {
891+
const accessor = LazyAccessor.createEmpty();
892+
accessor.setFixed32(1, -1);
893+
expect(accessor.getFixed32WithDefault(1)).toEqual(-1);
894+
}
895+
});
886896
});
887897

888898
describe('Fixed64 access', () => {
@@ -1874,6 +1884,16 @@ describe('Uint32 access', () => {
18741884
expect(accessor.getUint32WithDefault(1)).toEqual(null);
18751885
}
18761886
});
1887+
1888+
it('throws in setter for negative value', () => {
1889+
if (CHECK_CRITICAL_TYPE) {
1890+
expect(() => LazyAccessor.createEmpty().setUint32(1, -1)).toThrow();
1891+
} else {
1892+
const accessor = LazyAccessor.createEmpty();
1893+
accessor.setUint32(1, -1);
1894+
expect(accessor.getUint32WithDefault(1)).toEqual(-1);
1895+
}
1896+
});
18771897
});
18781898

18791899
describe('Uint64 access', () => {

experimental/runtime/kernel/reader_test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,16 @@ describe('readUint32 does', () => {
219219
});
220220

221221
for (const pair of getUint32Pairs()) {
222-
it(`decode ${pair.name}`, () => {
223-
if (pair.error && CHECK_CRITICAL_STATE) {
224-
expect(() => reader.readUint32(pair.bufferDecoder, 0)).toThrow();
225-
} else {
226-
const d = reader.readUint32(pair.bufferDecoder, 0);
227-
expect(d).toEqual(pair.intValue);
228-
}
229-
});
222+
if (!pair.skip_reader) {
223+
it(`decode ${pair.name}`, () => {
224+
if (pair.error && CHECK_CRITICAL_STATE) {
225+
expect(() => reader.readUint32(pair.bufferDecoder, 0)).toThrow();
226+
} else {
227+
const d = reader.readUint32(pair.bufferDecoder, 0);
228+
expect(d).toEqual(pair.intValue);
229+
}
230+
});
231+
}
230232
}
231233
});
232234

experimental/runtime/kernel/uint32_test_pairs.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'
1010
* An array of Pairs of float values and their bit representation.
1111
* This is used to test encoding and decoding from/to the protobuf wire format.
1212
* @return {!Array<{name: string, intValue:number, bufferDecoder:
13-
* !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>}
13+
* !BufferDecoder, error: (boolean|undefined),
14+
* skip_reader: (boolean|undefined), skip_writer: (boolean|undefined)}>}
1415
*/
1516
function getUint32Pairs() {
1617
const uint32Pairs = [
@@ -34,6 +35,12 @@ function getUint32Pairs() {
3435
intValue: Math.pow(2, 32) - 1,
3536
bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
3637
},
38+
{
39+
name: 'negative one',
40+
intValue: -1,
41+
bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
42+
skip_reader: true,
43+
},
3744
{
3845
name: 'truncates more than 32 bits',
3946
intValue: Math.pow(2, 32) - 1,

0 commit comments

Comments
 (0)