• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Test data for bool encoding and decoding.
3 */
4goog.module('protobuf.binary.boolTestPairs');
5
6const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
7const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper');
8
9/**
10 * An array of Pairs of boolean values and their bit representation.
11 * This is used to test encoding and decoding from/to the protobuf wire format.
12 * @return {!Array<{name: string, boolValue: boolean, bufferDecoder:
13 *     !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>}
14 */
15function getBoolPairs() {
16  const boolPairs = [
17    {
18      name: 'true',
19      boolValue: true,
20      bufferDecoder: createBufferDecoder(0x01),
21    },
22    {
23      name: 'false',
24      boolValue: false,
25      bufferDecoder: createBufferDecoder(0x00),
26    },
27    {
28      name: 'two-byte true',
29      boolValue: true,
30      bufferDecoder: createBufferDecoder(0x80, 0x01),
31      skip_writer: true,
32    },
33    {
34      name: 'two-byte false',
35      boolValue: false,
36      bufferDecoder: createBufferDecoder(0x80, 0x00),
37      skip_writer: true,
38    },
39    {
40      name: 'minus one',
41      boolValue: true,
42      bufferDecoder: createBufferDecoder(
43          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01),
44      skip_writer: true,
45    },
46    {
47      name: 'max signed int 2^63 - 1',
48      boolValue: true,
49      bufferDecoder: createBufferDecoder(
50          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F),
51      skip_writer: true,
52    },
53    {
54      name: 'min signed int -2^63',
55      boolValue: true,
56      bufferDecoder: createBufferDecoder(
57          0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01),
58      skip_writer: true,
59    },
60    {
61      name: 'overflowed but valid varint',
62      boolValue: false,
63      bufferDecoder: createBufferDecoder(
64          0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02),
65      skip_writer: true,
66    },
67    {
68      name: 'errors out for 11 bytes',
69      boolValue: true,
70      bufferDecoder: createBufferDecoder(
71          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
72      error: true,
73      skip_writer: true,
74    },
75  ];
76  return [...boolPairs];
77}
78
79exports = {getBoolPairs};
80