int64_test_pairs.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @fileoverview Test data for int64 encoding and decoding.
  3. */
  4. goog.module('protobuf.binary.int64TestPairs');
  5. const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
  6. const Int64 = goog.require('protobuf.Int64');
  7. const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper');
  8. /**
  9. * An array of Pairs of float values and their bit representation.
  10. * This is used to test encoding and decoding from/to the protobuf wire format.
  11. * @return {!Array<{name: string, longValue: !Int64, bufferDecoder:
  12. * !BufferDecoder, error: ?boolean, skip_writer: ?boolean}>}
  13. */
  14. function getInt64Pairs() {
  15. const int64Pairs = [
  16. {
  17. name: 'zero',
  18. longValue: Int64.fromInt(0),
  19. bufferDecoder: createBufferDecoder(0x00),
  20. },
  21. {
  22. name: 'one ',
  23. longValue: Int64.fromInt(1),
  24. bufferDecoder: createBufferDecoder(0x01),
  25. },
  26. {
  27. name: 'minus one',
  28. longValue: Int64.fromInt(-1),
  29. bufferDecoder: createBufferDecoder(
  30. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01),
  31. },
  32. {
  33. name: 'max signed int 2^63 - 1',
  34. longValue: Int64.fromBits(0xFFFFFFFF, 0x7FFFFFFF),
  35. bufferDecoder: createBufferDecoder(
  36. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F),
  37. },
  38. {
  39. name: 'value min signed int -2^63 (64 bit)',
  40. longValue: Int64.fromBits(0xFFFFFFFF, 0xFFFFFFFF),
  41. bufferDecoder: createBufferDecoder(
  42. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01),
  43. },
  44. {
  45. name: 'errors out for 11 bytes',
  46. longValue: Int64.fromInt(-1),
  47. bufferDecoder: createBufferDecoder(
  48. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF),
  49. error: true,
  50. skip_writer: true,
  51. },
  52. ];
  53. return [...int64Pairs];
  54. }
  55. exports = {getInt64Pairs};