1ffe3c632Sopenharmony_ci/** 2ffe3c632Sopenharmony_ci * @fileoverview Tests for reader.js. 3ffe3c632Sopenharmony_ci */ 4ffe3c632Sopenharmony_cigoog.module('protobuf.binary.ReaderTest'); 5ffe3c632Sopenharmony_ci 6ffe3c632Sopenharmony_cigoog.setTestOnly(); 7ffe3c632Sopenharmony_ci 8ffe3c632Sopenharmony_ci// Note to the reader: 9ffe3c632Sopenharmony_ci// Since the reader behavior changes with the checking level some of the 10ffe3c632Sopenharmony_ci// tests in this file have to know which checking level is enable to make 11ffe3c632Sopenharmony_ci// correct assertions. 12ffe3c632Sopenharmony_ciconst BufferDecoder = goog.require('protobuf.binary.BufferDecoder'); 13ffe3c632Sopenharmony_ciconst ByteString = goog.require('protobuf.ByteString'); 14ffe3c632Sopenharmony_ciconst reader = goog.require('protobuf.binary.reader'); 15ffe3c632Sopenharmony_ciconst {CHECK_CRITICAL_STATE} = goog.require('protobuf.internal.checks'); 16ffe3c632Sopenharmony_ciconst {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper'); 17ffe3c632Sopenharmony_ciconst {encode} = goog.require('protobuf.binary.textencoding'); 18ffe3c632Sopenharmony_ciconst {getBoolPairs} = goog.require('protobuf.binary.boolTestPairs'); 19ffe3c632Sopenharmony_ciconst {getDoublePairs} = goog.require('protobuf.binary.doubleTestPairs'); 20ffe3c632Sopenharmony_ciconst {getFixed32Pairs} = goog.require('protobuf.binary.fixed32TestPairs'); 21ffe3c632Sopenharmony_ciconst {getFloatPairs} = goog.require('protobuf.binary.floatTestPairs'); 22ffe3c632Sopenharmony_ciconst {getInt32Pairs} = goog.require('protobuf.binary.int32TestPairs'); 23ffe3c632Sopenharmony_ciconst {getInt64Pairs} = goog.require('protobuf.binary.int64TestPairs'); 24ffe3c632Sopenharmony_ciconst {getPackedBoolPairs} = goog.require('protobuf.binary.packedBoolTestPairs'); 25ffe3c632Sopenharmony_ciconst {getPackedDoublePairs} = goog.require('protobuf.binary.packedDoubleTestPairs'); 26ffe3c632Sopenharmony_ciconst {getPackedFixed32Pairs} = goog.require('protobuf.binary.packedFixed32TestPairs'); 27ffe3c632Sopenharmony_ciconst {getPackedFloatPairs} = goog.require('protobuf.binary.packedFloatTestPairs'); 28ffe3c632Sopenharmony_ciconst {getPackedInt32Pairs} = goog.require('protobuf.binary.packedInt32TestPairs'); 29ffe3c632Sopenharmony_ciconst {getPackedInt64Pairs} = goog.require('protobuf.binary.packedInt64TestPairs'); 30ffe3c632Sopenharmony_ciconst {getPackedSfixed32Pairs} = goog.require('protobuf.binary.packedSfixed32TestPairs'); 31ffe3c632Sopenharmony_ciconst {getPackedSfixed64Pairs} = goog.require('protobuf.binary.packedSfixed64TestPairs'); 32ffe3c632Sopenharmony_ciconst {getPackedSint32Pairs} = goog.require('protobuf.binary.packedSint32TestPairs'); 33ffe3c632Sopenharmony_ciconst {getPackedSint64Pairs} = goog.require('protobuf.binary.packedSint64TestPairs'); 34ffe3c632Sopenharmony_ciconst {getPackedUint32Pairs} = goog.require('protobuf.binary.packedUint32TestPairs'); 35ffe3c632Sopenharmony_ciconst {getSfixed32Pairs} = goog.require('protobuf.binary.sfixed32TestPairs'); 36ffe3c632Sopenharmony_ciconst {getSfixed64Pairs} = goog.require('protobuf.binary.sfixed64TestPairs'); 37ffe3c632Sopenharmony_ciconst {getSint32Pairs} = goog.require('protobuf.binary.sint32TestPairs'); 38ffe3c632Sopenharmony_ciconst {getSint64Pairs} = goog.require('protobuf.binary.sint64TestPairs'); 39ffe3c632Sopenharmony_ciconst {getUint32Pairs} = goog.require('protobuf.binary.uint32TestPairs'); 40ffe3c632Sopenharmony_ci 41ffe3c632Sopenharmony_ci/****************************************************************************** 42ffe3c632Sopenharmony_ci * Optional FUNCTIONS 43ffe3c632Sopenharmony_ci ******************************************************************************/ 44ffe3c632Sopenharmony_ci 45ffe3c632Sopenharmony_cidescribe('Read bool does', () => { 46ffe3c632Sopenharmony_ci for (const pair of getBoolPairs()) { 47ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 48ffe3c632Sopenharmony_ci if (pair.error && CHECK_CRITICAL_STATE) { 49ffe3c632Sopenharmony_ci expect(() => reader.readBool(pair.bufferDecoder, 0)).toThrow(); 50ffe3c632Sopenharmony_ci } else { 51ffe3c632Sopenharmony_ci const d = reader.readBool( 52ffe3c632Sopenharmony_ci pair.bufferDecoder, pair.bufferDecoder.startIndex()); 53ffe3c632Sopenharmony_ci expect(d).toEqual(pair.boolValue); 54ffe3c632Sopenharmony_ci } 55ffe3c632Sopenharmony_ci }); 56ffe3c632Sopenharmony_ci } 57ffe3c632Sopenharmony_ci}); 58ffe3c632Sopenharmony_ci 59ffe3c632Sopenharmony_cidescribe('readBytes does', () => { 60ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 61ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(); 62ffe3c632Sopenharmony_ci expect(() => reader.readBytes(bufferDecoder, 0)).toThrow(); 63ffe3c632Sopenharmony_ci }); 64ffe3c632Sopenharmony_ci 65ffe3c632Sopenharmony_ci it('read bytes by index', () => { 66ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(3, 1, 2, 3); 67ffe3c632Sopenharmony_ci const byteString = reader.readBytes(bufferDecoder, 0); 68ffe3c632Sopenharmony_ci expect(ByteString.fromArrayBuffer(new Uint8Array([1, 2, 3]).buffer)) 69ffe3c632Sopenharmony_ci .toEqual(byteString); 70ffe3c632Sopenharmony_ci }); 71ffe3c632Sopenharmony_ci}); 72ffe3c632Sopenharmony_ci 73ffe3c632Sopenharmony_cidescribe('readDouble does', () => { 74ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 75ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(); 76ffe3c632Sopenharmony_ci expect(() => reader.readDouble(bufferDecoder, 0)).toThrow(); 77ffe3c632Sopenharmony_ci }); 78ffe3c632Sopenharmony_ci 79ffe3c632Sopenharmony_ci for (const pair of getDoublePairs()) { 80ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 81ffe3c632Sopenharmony_ci const d = reader.readDouble(pair.bufferDecoder, 0); 82ffe3c632Sopenharmony_ci expect(d).toEqual(pair.doubleValue); 83ffe3c632Sopenharmony_ci }); 84ffe3c632Sopenharmony_ci } 85ffe3c632Sopenharmony_ci}); 86ffe3c632Sopenharmony_ci 87ffe3c632Sopenharmony_cidescribe('readFixed32 does', () => { 88ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 89ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(); 90ffe3c632Sopenharmony_ci expect(() => reader.readFixed32(bufferDecoder, 0)).toThrow(); 91ffe3c632Sopenharmony_ci }); 92ffe3c632Sopenharmony_ci 93ffe3c632Sopenharmony_ci for (const pair of getFixed32Pairs()) { 94ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 95ffe3c632Sopenharmony_ci const d = reader.readFixed32(pair.bufferDecoder, 0); 96ffe3c632Sopenharmony_ci expect(d).toEqual(pair.intValue); 97ffe3c632Sopenharmony_ci }); 98ffe3c632Sopenharmony_ci } 99ffe3c632Sopenharmony_ci}); 100ffe3c632Sopenharmony_ci 101ffe3c632Sopenharmony_cidescribe('readFloat does', () => { 102ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 103ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(); 104ffe3c632Sopenharmony_ci expect(() => reader.readFloat(bufferDecoder, 0)).toThrow(); 105ffe3c632Sopenharmony_ci }); 106ffe3c632Sopenharmony_ci 107ffe3c632Sopenharmony_ci for (const pair of getFloatPairs()) { 108ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 109ffe3c632Sopenharmony_ci const d = reader.readFloat(pair.bufferDecoder, 0); 110ffe3c632Sopenharmony_ci expect(d).toEqual(Math.fround(pair.floatValue)); 111ffe3c632Sopenharmony_ci }); 112ffe3c632Sopenharmony_ci } 113ffe3c632Sopenharmony_ci}); 114ffe3c632Sopenharmony_ci 115ffe3c632Sopenharmony_cidescribe('readInt32 does', () => { 116ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 117ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(0x80); 118ffe3c632Sopenharmony_ci expect(() => reader.readInt32(bufferDecoder, 0)).toThrow(); 119ffe3c632Sopenharmony_ci }); 120ffe3c632Sopenharmony_ci 121ffe3c632Sopenharmony_ci for (const pair of getInt32Pairs()) { 122ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 123ffe3c632Sopenharmony_ci if (pair.error && CHECK_CRITICAL_STATE) { 124ffe3c632Sopenharmony_ci expect(() => reader.readInt32(pair.bufferDecoder, 0)).toThrow(); 125ffe3c632Sopenharmony_ci } else { 126ffe3c632Sopenharmony_ci const d = reader.readInt32(pair.bufferDecoder, 0); 127ffe3c632Sopenharmony_ci expect(d).toEqual(pair.intValue); 128ffe3c632Sopenharmony_ci } 129ffe3c632Sopenharmony_ci }); 130ffe3c632Sopenharmony_ci } 131ffe3c632Sopenharmony_ci}); 132ffe3c632Sopenharmony_ci 133ffe3c632Sopenharmony_cidescribe('readSfixed32 does', () => { 134ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 135ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(0x80); 136ffe3c632Sopenharmony_ci expect(() => reader.readSfixed32(bufferDecoder, 0)).toThrow(); 137ffe3c632Sopenharmony_ci }); 138ffe3c632Sopenharmony_ci 139ffe3c632Sopenharmony_ci for (const pair of getSfixed32Pairs()) { 140ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 141ffe3c632Sopenharmony_ci const d = reader.readSfixed32(pair.bufferDecoder, 0); 142ffe3c632Sopenharmony_ci expect(d).toEqual(pair.intValue); 143ffe3c632Sopenharmony_ci }); 144ffe3c632Sopenharmony_ci } 145ffe3c632Sopenharmony_ci}); 146ffe3c632Sopenharmony_ci 147ffe3c632Sopenharmony_cidescribe('readSfixed64 does', () => { 148ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 149ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(0x80); 150ffe3c632Sopenharmony_ci expect(() => reader.readSfixed64(bufferDecoder, 0)).toThrow(); 151ffe3c632Sopenharmony_ci }); 152ffe3c632Sopenharmony_ci 153ffe3c632Sopenharmony_ci for (const pair of getSfixed64Pairs()) { 154ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 155ffe3c632Sopenharmony_ci const d = reader.readSfixed64(pair.bufferDecoder, 0); 156ffe3c632Sopenharmony_ci expect(d).toEqual(pair.longValue); 157ffe3c632Sopenharmony_ci }); 158ffe3c632Sopenharmony_ci } 159ffe3c632Sopenharmony_ci}); 160ffe3c632Sopenharmony_ci 161ffe3c632Sopenharmony_cidescribe('readSint32 does', () => { 162ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 163ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(0x80); 164ffe3c632Sopenharmony_ci expect(() => reader.readSint32(bufferDecoder, 0)).toThrow(); 165ffe3c632Sopenharmony_ci }); 166ffe3c632Sopenharmony_ci 167ffe3c632Sopenharmony_ci for (const pair of getSint32Pairs()) { 168ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 169ffe3c632Sopenharmony_ci if (pair.error && CHECK_CRITICAL_STATE) { 170ffe3c632Sopenharmony_ci expect(() => reader.readSint32(pair.bufferDecoder, 0)).toThrow(); 171ffe3c632Sopenharmony_ci } else { 172ffe3c632Sopenharmony_ci const d = reader.readSint32(pair.bufferDecoder, 0); 173ffe3c632Sopenharmony_ci expect(d).toEqual(pair.intValue); 174ffe3c632Sopenharmony_ci } 175ffe3c632Sopenharmony_ci }); 176ffe3c632Sopenharmony_ci } 177ffe3c632Sopenharmony_ci}); 178ffe3c632Sopenharmony_ci 179ffe3c632Sopenharmony_cidescribe('readInt64 does', () => { 180ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 181ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(0x80); 182ffe3c632Sopenharmony_ci expect(() => reader.readInt64(bufferDecoder, 0)).toThrow(); 183ffe3c632Sopenharmony_ci }); 184ffe3c632Sopenharmony_ci 185ffe3c632Sopenharmony_ci for (const pair of getInt64Pairs()) { 186ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 187ffe3c632Sopenharmony_ci if (pair.error && CHECK_CRITICAL_STATE) { 188ffe3c632Sopenharmony_ci expect(() => reader.readInt64(pair.bufferDecoder, 0)).toThrow(); 189ffe3c632Sopenharmony_ci } else { 190ffe3c632Sopenharmony_ci const d = reader.readInt64(pair.bufferDecoder, 0); 191ffe3c632Sopenharmony_ci expect(d).toEqual(pair.longValue); 192ffe3c632Sopenharmony_ci } 193ffe3c632Sopenharmony_ci }); 194ffe3c632Sopenharmony_ci } 195ffe3c632Sopenharmony_ci}); 196ffe3c632Sopenharmony_ci 197ffe3c632Sopenharmony_cidescribe('readSint64 does', () => { 198ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 199ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(0x80); 200ffe3c632Sopenharmony_ci expect(() => reader.readSint64(bufferDecoder, 0)).toThrow(); 201ffe3c632Sopenharmony_ci }); 202ffe3c632Sopenharmony_ci 203ffe3c632Sopenharmony_ci for (const pair of getSint64Pairs()) { 204ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 205ffe3c632Sopenharmony_ci if (pair.error && CHECK_CRITICAL_STATE) { 206ffe3c632Sopenharmony_ci expect(() => reader.readSint64(pair.bufferDecoder, 0)).toThrow(); 207ffe3c632Sopenharmony_ci } else { 208ffe3c632Sopenharmony_ci const d = reader.readSint64(pair.bufferDecoder, 0); 209ffe3c632Sopenharmony_ci expect(d).toEqual(pair.longValue); 210ffe3c632Sopenharmony_ci } 211ffe3c632Sopenharmony_ci }); 212ffe3c632Sopenharmony_ci } 213ffe3c632Sopenharmony_ci}); 214ffe3c632Sopenharmony_ci 215ffe3c632Sopenharmony_cidescribe('readUint32 does', () => { 216ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 217ffe3c632Sopenharmony_ci const bufferDecoder = createBufferDecoder(0x80); 218ffe3c632Sopenharmony_ci expect(() => reader.readUint32(bufferDecoder, 0)).toThrow(); 219ffe3c632Sopenharmony_ci }); 220ffe3c632Sopenharmony_ci 221ffe3c632Sopenharmony_ci for (const pair of getUint32Pairs()) { 222ffe3c632Sopenharmony_ci if (!pair.skip_reader) { 223ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 224ffe3c632Sopenharmony_ci if (pair.error && CHECK_CRITICAL_STATE) { 225ffe3c632Sopenharmony_ci expect(() => reader.readUint32(pair.bufferDecoder, 0)).toThrow(); 226ffe3c632Sopenharmony_ci } else { 227ffe3c632Sopenharmony_ci const d = reader.readUint32(pair.bufferDecoder, 0); 228ffe3c632Sopenharmony_ci expect(d).toEqual(pair.intValue); 229ffe3c632Sopenharmony_ci } 230ffe3c632Sopenharmony_ci }); 231ffe3c632Sopenharmony_ci } 232ffe3c632Sopenharmony_ci } 233ffe3c632Sopenharmony_ci}); 234ffe3c632Sopenharmony_ci 235ffe3c632Sopenharmony_ci/** 236ffe3c632Sopenharmony_ci * 237ffe3c632Sopenharmony_ci * @param {string} s 238ffe3c632Sopenharmony_ci * @return {!Uint8Array} 239ffe3c632Sopenharmony_ci */ 240ffe3c632Sopenharmony_cifunction encodeString(s) { 241ffe3c632Sopenharmony_ci if (typeof TextEncoder !== 'undefined') { 242ffe3c632Sopenharmony_ci const textEncoder = new TextEncoder('utf-8'); 243ffe3c632Sopenharmony_ci return textEncoder.encode(s); 244ffe3c632Sopenharmony_ci } else { 245ffe3c632Sopenharmony_ci return encode(s); 246ffe3c632Sopenharmony_ci } 247ffe3c632Sopenharmony_ci} 248ffe3c632Sopenharmony_ci 249ffe3c632Sopenharmony_ci/** @param {string} s */ 250ffe3c632Sopenharmony_cifunction expectEncodedStringToMatch(s) { 251ffe3c632Sopenharmony_ci const array = encodeString(s); 252ffe3c632Sopenharmony_ci const length = array.length; 253ffe3c632Sopenharmony_ci if (length > 127) { 254ffe3c632Sopenharmony_ci throw new Error('Test only works for strings shorter than 128'); 255ffe3c632Sopenharmony_ci } 256ffe3c632Sopenharmony_ci const encodedArray = new Uint8Array(length + 1); 257ffe3c632Sopenharmony_ci encodedArray[0] = length; 258ffe3c632Sopenharmony_ci encodedArray.set(array, 1); 259ffe3c632Sopenharmony_ci const bufferDecoder = BufferDecoder.fromArrayBuffer(encodedArray.buffer); 260ffe3c632Sopenharmony_ci expect(reader.readString(bufferDecoder, 0)).toEqual(s); 261ffe3c632Sopenharmony_ci} 262ffe3c632Sopenharmony_ci 263ffe3c632Sopenharmony_cidescribe('readString does', () => { 264ffe3c632Sopenharmony_ci it('return empty string for zero length string', () => { 265ffe3c632Sopenharmony_ci const s = reader.readString(createBufferDecoder(0x00), 0); 266ffe3c632Sopenharmony_ci expect(s).toEqual(''); 267ffe3c632Sopenharmony_ci }); 268ffe3c632Sopenharmony_ci 269ffe3c632Sopenharmony_ci it('decode random strings', () => { 270ffe3c632Sopenharmony_ci // 1 byte strings 271ffe3c632Sopenharmony_ci expectEncodedStringToMatch('hello'); 272ffe3c632Sopenharmony_ci expectEncodedStringToMatch('HELLO1!'); 273ffe3c632Sopenharmony_ci 274ffe3c632Sopenharmony_ci // 2 byte String 275ffe3c632Sopenharmony_ci expectEncodedStringToMatch('©'); 276ffe3c632Sopenharmony_ci 277ffe3c632Sopenharmony_ci // 3 byte string 278ffe3c632Sopenharmony_ci expectEncodedStringToMatch('❄'); 279ffe3c632Sopenharmony_ci 280ffe3c632Sopenharmony_ci // 4 byte string 281ffe3c632Sopenharmony_ci expectEncodedStringToMatch(''); 282ffe3c632Sopenharmony_ci }); 283ffe3c632Sopenharmony_ci 284ffe3c632Sopenharmony_ci it('decode 1 byte strings', () => { 285ffe3c632Sopenharmony_ci for (let i = 0; i < 0x80; i++) { 286ffe3c632Sopenharmony_ci const s = String.fromCharCode(i); 287ffe3c632Sopenharmony_ci expectEncodedStringToMatch(s); 288ffe3c632Sopenharmony_ci } 289ffe3c632Sopenharmony_ci }); 290ffe3c632Sopenharmony_ci 291ffe3c632Sopenharmony_ci it('decode 2 byte strings', () => { 292ffe3c632Sopenharmony_ci for (let i = 0xC0; i < 0x7FF; i++) { 293ffe3c632Sopenharmony_ci const s = String.fromCharCode(i); 294ffe3c632Sopenharmony_ci expectEncodedStringToMatch(s); 295ffe3c632Sopenharmony_ci } 296ffe3c632Sopenharmony_ci }); 297ffe3c632Sopenharmony_ci 298ffe3c632Sopenharmony_ci it('decode 3 byte strings', () => { 299ffe3c632Sopenharmony_ci for (let i = 0x7FF; i < 0x8FFF; i++) { 300ffe3c632Sopenharmony_ci const s = String.fromCharCode(i); 301ffe3c632Sopenharmony_ci expectEncodedStringToMatch(s); 302ffe3c632Sopenharmony_ci } 303ffe3c632Sopenharmony_ci }); 304ffe3c632Sopenharmony_ci 305ffe3c632Sopenharmony_ci it('throw exception on invalid bytes', () => { 306ffe3c632Sopenharmony_ci // This test will only succeed with the native TextDecoder since 307ffe3c632Sopenharmony_ci // our polyfill does not do any validation. IE10 and IE11 don't support 308ffe3c632Sopenharmony_ci // TextDecoder. 309ffe3c632Sopenharmony_ci // TODO: Remove this check once we no longer need to support IE 310ffe3c632Sopenharmony_ci if (typeof TextDecoder !== 'undefined') { 311ffe3c632Sopenharmony_ci expect( 312ffe3c632Sopenharmony_ci () => reader.readString( 313ffe3c632Sopenharmony_ci createBufferDecoder(0x01, /* invalid utf data point*/ 0xFF), 0)) 314ffe3c632Sopenharmony_ci .toThrow(); 315ffe3c632Sopenharmony_ci } 316ffe3c632Sopenharmony_ci }); 317ffe3c632Sopenharmony_ci 318ffe3c632Sopenharmony_ci it('throw exception if data is too short', () => { 319ffe3c632Sopenharmony_ci const array = createBufferDecoder(0x02, '?'.charCodeAt(0)); 320ffe3c632Sopenharmony_ci expect(() => reader.readString(array, 0)).toThrow(); 321ffe3c632Sopenharmony_ci }); 322ffe3c632Sopenharmony_ci}); 323ffe3c632Sopenharmony_ci 324ffe3c632Sopenharmony_ci/****************************************************************************** 325ffe3c632Sopenharmony_ci * REPEATED FUNCTIONS 326ffe3c632Sopenharmony_ci ******************************************************************************/ 327ffe3c632Sopenharmony_ci 328ffe3c632Sopenharmony_cidescribe('readPackedBool does', () => { 329ffe3c632Sopenharmony_ci for (const pair of getPackedBoolPairs()) { 330ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 331ffe3c632Sopenharmony_ci const d = reader.readPackedBool(pair.bufferDecoder, 0); 332ffe3c632Sopenharmony_ci expect(d).toEqual(pair.boolValues); 333ffe3c632Sopenharmony_ci }); 334ffe3c632Sopenharmony_ci } 335ffe3c632Sopenharmony_ci}); 336ffe3c632Sopenharmony_ci 337ffe3c632Sopenharmony_cidescribe('readPackedDouble does', () => { 338ffe3c632Sopenharmony_ci for (const pair of getPackedDoublePairs()) { 339ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 340ffe3c632Sopenharmony_ci const d = reader.readPackedDouble(pair.bufferDecoder, 0); 341ffe3c632Sopenharmony_ci expect(d).toEqual(pair.doubleValues); 342ffe3c632Sopenharmony_ci }); 343ffe3c632Sopenharmony_ci } 344ffe3c632Sopenharmony_ci}); 345ffe3c632Sopenharmony_ci 346ffe3c632Sopenharmony_cidescribe('readPackedFixed32 does', () => { 347ffe3c632Sopenharmony_ci for (const pair of getPackedFixed32Pairs()) { 348ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 349ffe3c632Sopenharmony_ci const d = reader.readPackedFixed32(pair.bufferDecoder, 0); 350ffe3c632Sopenharmony_ci expect(d).toEqual(pair.fixed32Values); 351ffe3c632Sopenharmony_ci }); 352ffe3c632Sopenharmony_ci } 353ffe3c632Sopenharmony_ci}); 354ffe3c632Sopenharmony_ci 355ffe3c632Sopenharmony_cidescribe('readPackedFloat does', () => { 356ffe3c632Sopenharmony_ci for (const pair of getPackedFloatPairs()) { 357ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 358ffe3c632Sopenharmony_ci const d = reader.readPackedFloat(pair.bufferDecoder, 0); 359ffe3c632Sopenharmony_ci expect(d).toEqual(pair.floatValues); 360ffe3c632Sopenharmony_ci }); 361ffe3c632Sopenharmony_ci } 362ffe3c632Sopenharmony_ci}); 363ffe3c632Sopenharmony_ci 364ffe3c632Sopenharmony_cidescribe('readPackedInt32 does', () => { 365ffe3c632Sopenharmony_ci for (const pair of getPackedInt32Pairs()) { 366ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 367ffe3c632Sopenharmony_ci const d = reader.readPackedInt32(pair.bufferDecoder, 0); 368ffe3c632Sopenharmony_ci expect(d).toEqual(pair.int32Values); 369ffe3c632Sopenharmony_ci }); 370ffe3c632Sopenharmony_ci } 371ffe3c632Sopenharmony_ci}); 372ffe3c632Sopenharmony_ci 373ffe3c632Sopenharmony_cidescribe('readPackedInt64 does', () => { 374ffe3c632Sopenharmony_ci for (const pair of getPackedInt64Pairs()) { 375ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 376ffe3c632Sopenharmony_ci const d = reader.readPackedInt64(pair.bufferDecoder, 0); 377ffe3c632Sopenharmony_ci expect(d).toEqual(pair.int64Values); 378ffe3c632Sopenharmony_ci }); 379ffe3c632Sopenharmony_ci } 380ffe3c632Sopenharmony_ci}); 381ffe3c632Sopenharmony_ci 382ffe3c632Sopenharmony_cidescribe('readPackedSfixed32 does', () => { 383ffe3c632Sopenharmony_ci for (const pair of getPackedSfixed32Pairs()) { 384ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 385ffe3c632Sopenharmony_ci const d = reader.readPackedSfixed32(pair.bufferDecoder, 0); 386ffe3c632Sopenharmony_ci expect(d).toEqual(pair.sfixed32Values); 387ffe3c632Sopenharmony_ci }); 388ffe3c632Sopenharmony_ci } 389ffe3c632Sopenharmony_ci}); 390ffe3c632Sopenharmony_ci 391ffe3c632Sopenharmony_cidescribe('readPackedSfixed64 does', () => { 392ffe3c632Sopenharmony_ci for (const pair of getPackedSfixed64Pairs()) { 393ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 394ffe3c632Sopenharmony_ci const d = reader.readPackedSfixed64(pair.bufferDecoder, 0); 395ffe3c632Sopenharmony_ci expect(d).toEqual(pair.sfixed64Values); 396ffe3c632Sopenharmony_ci }); 397ffe3c632Sopenharmony_ci } 398ffe3c632Sopenharmony_ci}); 399ffe3c632Sopenharmony_ci 400ffe3c632Sopenharmony_cidescribe('readPackedSint32 does', () => { 401ffe3c632Sopenharmony_ci for (const pair of getPackedSint32Pairs()) { 402ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 403ffe3c632Sopenharmony_ci const d = reader.readPackedSint32(pair.bufferDecoder, 0); 404ffe3c632Sopenharmony_ci expect(d).toEqual(pair.sint32Values); 405ffe3c632Sopenharmony_ci }); 406ffe3c632Sopenharmony_ci } 407ffe3c632Sopenharmony_ci}); 408ffe3c632Sopenharmony_ci 409ffe3c632Sopenharmony_cidescribe('readPackedSint64 does', () => { 410ffe3c632Sopenharmony_ci for (const pair of getPackedSint64Pairs()) { 411ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 412ffe3c632Sopenharmony_ci const d = reader.readPackedSint64(pair.bufferDecoder, 0); 413ffe3c632Sopenharmony_ci expect(d).toEqual(pair.sint64Values); 414ffe3c632Sopenharmony_ci }); 415ffe3c632Sopenharmony_ci } 416ffe3c632Sopenharmony_ci}); 417ffe3c632Sopenharmony_ci 418ffe3c632Sopenharmony_cidescribe('readPackedUint32 does', () => { 419ffe3c632Sopenharmony_ci for (const pair of getPackedUint32Pairs()) { 420ffe3c632Sopenharmony_ci it(`decode ${pair.name}`, () => { 421ffe3c632Sopenharmony_ci const d = reader.readPackedUint32(pair.bufferDecoder, 0); 422ffe3c632Sopenharmony_ci expect(d).toEqual(pair.uint32Values); 423ffe3c632Sopenharmony_ci }); 424ffe3c632Sopenharmony_ci } 425ffe3c632Sopenharmony_ci}); 426