bool_test_pairs.js 2.2 KB

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