uint32_test_pairs.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @fileoverview Test data for int32 encoding and decoding.
  3. */
  4. goog.module('protobuf.binary.uint32TestPairs');
  5. const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
  6. const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper');
  7. /**
  8. * An array of Pairs of float 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, intValue:number, bufferDecoder:
  11. * !BufferDecoder, error: (boolean|undefined),
  12. * skip_reader: (boolean|undefined), skip_writer: (boolean|undefined)}>}
  13. */
  14. function getUint32Pairs() {
  15. const uint32Pairs = [
  16. {
  17. name: 'zero',
  18. intValue: 0,
  19. bufferDecoder: createBufferDecoder(0x00),
  20. },
  21. {
  22. name: 'one ',
  23. intValue: 1,
  24. bufferDecoder: createBufferDecoder(0x01),
  25. },
  26. {
  27. name: 'max signed int 2^31 - 1',
  28. intValue: Math.pow(2, 31) - 1,
  29. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x07),
  30. },
  31. {
  32. name: 'max unsigned int 2^32 - 1',
  33. intValue: Math.pow(2, 32) - 1,
  34. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
  35. },
  36. {
  37. name: 'negative one',
  38. intValue: -1,
  39. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x0F),
  40. skip_reader: true,
  41. },
  42. {
  43. name: 'truncates more than 32 bits',
  44. intValue: Math.pow(2, 32) - 1,
  45. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01),
  46. skip_writer: true,
  47. },
  48. {
  49. name: 'truncates more than 32 bits (bit 33 set)',
  50. intValue: Math.pow(2, 28) - 1,
  51. bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0x10),
  52. skip_writer: true,
  53. },
  54. {
  55. name: 'errors out for 11 bytes',
  56. intValue: Math.pow(2, 32) - 1,
  57. bufferDecoder: createBufferDecoder(
  58. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
  59. error: true,
  60. skip_writer: true,
  61. },
  62. ];
  63. return [...uint32Pairs];
  64. }
  65. exports = {getUint32Pairs};