serializationtest.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of qtprotobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #include "serializationtest.h"
  26. #include "simpleintmessage.h"
  27. using namespace qtprotobuf::tests;
  28. SerializationTest::SerializationTest()
  29. {
  30. }
  31. TEST_F(SerializationTest, IntMessageSrializeTest)
  32. {
  33. SimpleIntMessage test;
  34. test.setTestFieldInt(15);
  35. QByteArray result = test.serialize();
  36. qDebug() << "Out result:" << result.toHex();
  37. ASSERT_EQ(result.size(), 2);
  38. ASSERT_EQ(result.at(0), 0x08);
  39. ASSERT_EQ(result.at(1), 0x0F);
  40. test.setTestFieldInt(300);
  41. result = test.serialize();
  42. qDebug() << "Out result:" << result.toHex();
  43. ASSERT_EQ(result.size(), 3);
  44. ASSERT_EQ(result.at(0), 0x08);
  45. ASSERT_EQ(result.at(1), '\xAC');
  46. ASSERT_EQ(result.at(2), 0x02);
  47. test.setTestFieldInt(65545);
  48. result = test.serialize();
  49. qDebug() << "Out result:" << result.toHex();
  50. ASSERT_EQ(result.size(), 4);
  51. ASSERT_EQ(result.at(0), 0x08);
  52. ASSERT_EQ(result.at(1), '\x89');
  53. ASSERT_EQ(result.at(2), '\x80');
  54. ASSERT_EQ(result.at(3), '\x04');
  55. test.setTestFieldInt(0);
  56. result = test.serialize();
  57. qDebug() << "Out result:" << result.toHex();
  58. test.setTestFieldInt(INT8_MAX + 1);
  59. result = test.serialize();
  60. qDebug() << "Out result:" << result.toHex();
  61. test.setTestFieldInt(INT16_MAX + 1);
  62. result = test.serialize();
  63. qDebug() << "Out result:" << result.toHex();
  64. test.setTestFieldInt(INT8_MAX);
  65. result = test.serialize();
  66. qDebug() << "Out result:" << result.toHex();
  67. test.setTestFieldInt(INT16_MAX);
  68. result = test.serialize();
  69. qDebug() << "Out result:" << result.toHex();
  70. test.setTestFieldInt(INT32_MAX);
  71. result = test.serialize();
  72. qDebug() << "Out result:" << result.toHex();
  73. test.setTestFieldInt(INT32_MIN);
  74. result = test.serialize();
  75. qDebug() << "Out result:" << result.toHex();
  76. }