tst_simple.qml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. import QtQuick 2.12
  26. import QtTest 1.0
  27. import QtProtobuf 0.1
  28. import qtprotobufnamespace.tests 1.0
  29. TestCase {
  30. name: "Simple values assignment"
  31. SimpleBoolMessage {
  32. id: boolMsg
  33. testFieldBool: false
  34. }
  35. SimpleIntMessage {
  36. id: int32Msg
  37. testFieldInt: 2147483647
  38. }
  39. SimpleSIntMessage {
  40. id: sint32Msg
  41. testFieldInt: 2147483647
  42. }
  43. SimpleUIntMessage {
  44. id: uint32Msg
  45. testFieldInt: 4294967295
  46. }
  47. SimpleFixedInt32Message {
  48. id: fixed32Msg
  49. testFieldFixedInt32: 4294967295
  50. }
  51. SimpleSFixedInt32Message {
  52. id: sfixed32Msg
  53. testFieldFixedInt32: 2147483647
  54. }
  55. SimpleStringMessage {
  56. id: stringMsg
  57. testFieldString: "Test string"
  58. }
  59. function test_simpleboolmessage() {
  60. boolMsg.testFieldBool = true;
  61. compare(boolMsg.testFieldBool, true, "SimpleBoolMessage == true")
  62. boolMsg.testFieldBool = false;
  63. compare(boolMsg.testFieldBool, false, "SimpleBoolMessage == false")
  64. }
  65. function test_simpleintmessage() {
  66. compare(int32Msg.testFieldInt == 2147483647, true, "SimpleIntMessage.testFieldInt: 2147483647: " + int32Msg.testFieldInt)
  67. int32Msg.testFieldInt = 0;
  68. compare(int32Msg.testFieldInt == 0, true, "SimpleIntMessage == 0")
  69. int32Msg.testFieldInt = -128;
  70. compare(int32Msg.testFieldInt == -128, true, "SimpleIntMessage == -128")
  71. int32Msg.testFieldInt = 127;
  72. compare(int32Msg.testFieldInt == 127, true, "SimpleIntMessage == 127")
  73. int32Msg.testFieldInt = -256;
  74. compare(int32Msg.testFieldInt == -256, true, "SimpleIntMessage == -256")
  75. int32Msg.testFieldInt = 255;
  76. compare(int32Msg.testFieldInt == 255, true, "SimpleIntMessage == 255")
  77. int32Msg.testFieldInt = -32768;
  78. compare(int32Msg.testFieldInt == -32768, true, "SimpleIntMessage == -32768")
  79. int32Msg.testFieldInt = 32767;
  80. compare(int32Msg.testFieldInt == 32767, true, "SimpleIntMessage == 32767")
  81. int32Msg.testFieldInt = -65536;
  82. compare(int32Msg.testFieldInt == -65536, true, "SimpleIntMessage == -65536")
  83. int32Msg.testFieldInt = 65535;
  84. compare(int32Msg.testFieldInt == 65535, true, "SimpleIntMessage == 65535")
  85. int32Msg.testFieldInt = -2147483648;
  86. compare(int32Msg.testFieldInt == -2147483648, true, "SimpleIntMessage == -2147483648")
  87. int32Msg.testFieldInt = 2147483647;
  88. compare(int32Msg.testFieldInt == 2147483647, true, "SimpleIntMessage == 2147483647")
  89. }
  90. function test_simplesintmessage() {
  91. compare(sint32Msg.testFieldInt == 2147483647, true, "SimpleSIntMessage.testFieldInt: 2147483647: " + sint32Msg.testFieldInt)
  92. sint32Msg.testFieldInt = 0;
  93. compare(sint32Msg.testFieldInt, 0, "SimpleSIntMessage == 0")
  94. sint32Msg.testFieldInt = -128;
  95. compare(sint32Msg.testFieldInt, -128, "SimpleSIntMessage == -128")
  96. sint32Msg.testFieldInt = 127;
  97. compare(sint32Msg.testFieldInt, 127, "SimpleSIntMessage == 127")
  98. sint32Msg.testFieldInt = -256;
  99. compare(sint32Msg.testFieldInt, -256, "SimpleSIntMessage == -256")
  100. sint32Msg.testFieldInt = 255;
  101. compare(sint32Msg.testFieldInt, 255, "SimpleSIntMessage == 255")
  102. sint32Msg.testFieldInt = -32768;
  103. compare(sint32Msg.testFieldInt, -32768, "SimpleSIntMessage == -32768")
  104. sint32Msg.testFieldInt = 32767;
  105. compare(sint32Msg.testFieldInt, 32767, "SimpleSIntMessage == 32767")
  106. sint32Msg.testFieldInt = -65536;
  107. compare(sint32Msg.testFieldInt, -65536, "SimpleSIntMessage == -65536")
  108. sint32Msg.testFieldInt = 65535;
  109. compare(sint32Msg.testFieldInt, 65535, "SimpleSIntMessage == 65535")
  110. sint32Msg.testFieldInt = -2147483648;
  111. compare(sint32Msg.testFieldInt, -2147483648, "SimpleSIntMessage == -2147483648")
  112. sint32Msg.testFieldInt = 2147483647;
  113. compare(sint32Msg.testFieldInt, 2147483647, "SimpleSIntMessage == 2147483647")
  114. }
  115. function test_simpleuintmessage() {
  116. compare(uint32Msg.testFieldInt == 4294967295, true, "SimpleUIntMessage.testFieldInt: 4294967295: " + uint32Msg.testFieldInt)
  117. uint32Msg.testFieldInt = 0;
  118. compare(uint32Msg.testFieldInt == 0, true, "SimpleUIntMessage == 0")
  119. uint32Msg.testFieldInt = 127;
  120. compare(uint32Msg.testFieldInt == 127, true, "SimpleUIntMessage == 127")
  121. uint32Msg.testFieldInt = 255;
  122. compare(uint32Msg.testFieldInt == 255, true, "SimpleUIntMessage == 255")
  123. uint32Msg.testFieldInt = 32767;
  124. compare(uint32Msg.testFieldInt == 32767, true, "SimpleUIntMessage == 32767")
  125. uint32Msg.testFieldInt = 65535;
  126. compare(uint32Msg.testFieldInt == 65535, true, "SimpleUIntMessage == 65535")
  127. uint32Msg.testFieldInt = 2147483647;
  128. compare(uint32Msg.testFieldInt == 2147483647, true, "SimpleUIntMessage == 2147483647")
  129. uint32Msg.testFieldInt = 4294967295;
  130. compare(uint32Msg.testFieldInt == 4294967295, true, "SimpleUIntMessage == 4294967295")
  131. }
  132. function test_simplefixed32message() {
  133. compare(fixed32Msg.testFieldFixedInt32 == 4294967295, true, "SimpleFixedInt32Message.testFieldInt: 4294967295: " + fixed32Msg.testFieldFixedInt32)
  134. fixed32Msg.testFieldFixedInt32 = 0;
  135. compare(fixed32Msg.testFieldFixedInt32 == 0, true, "SimpleFixedInt32Message == 0")
  136. fixed32Msg.testFieldFixedInt32 = 127;
  137. compare(fixed32Msg.testFieldFixedInt32 == 127, true, "SimpleFixedInt32Message == 127")
  138. fixed32Msg.testFieldFixedInt32 = 255;
  139. compare(fixed32Msg.testFieldFixedInt32 == 255, true, "SimpleFixedInt32Message == 255")
  140. fixed32Msg.testFieldFixedInt32 = 32767;
  141. compare(fixed32Msg.testFieldFixedInt32 == 32767, true, "SimpleFixedInt32Message == 32767")
  142. fixed32Msg.testFieldFixedInt32 = 65535;
  143. compare(fixed32Msg.testFieldFixedInt32 == 65535, true, "SimpleFixedInt32Message == 65535")
  144. fixed32Msg.testFieldFixedInt32 = 2147483647;
  145. compare(fixed32Msg.testFieldFixedInt32 == 2147483647, true, "SimpleFixedInt32Message == 2147483647")
  146. fixed32Msg.testFieldFixedInt32 = 4294967295;
  147. compare(fixed32Msg.testFieldFixedInt32 == 4294967295, true, "SimpleFixedInt32Message == 4294967295")
  148. }
  149. function test_simplesfixed32message() {
  150. compare(sfixed32Msg.testFieldFixedInt32 == 2147483647, true, "SimpleSFixedInt32Message.testFieldInt: 2147483647: " + sfixed32Msg.testFieldFixedInt32)
  151. sfixed32Msg.testFieldFixedInt32 = 0;
  152. compare(sfixed32Msg.testFieldFixedInt32 == 0, true, "SimpleSFixedInt32Message == 0")
  153. sfixed32Msg.testFieldFixedInt32 = -128;
  154. compare(sfixed32Msg.testFieldFixedInt32 == -128, true, "SimpleSFixedInt32Message == -128")
  155. sfixed32Msg.testFieldFixedInt32 = 127;
  156. compare(sfixed32Msg.testFieldFixedInt32 == 127, true, "SimpleSFixedInt32Message == 127")
  157. sfixed32Msg.testFieldFixedInt32 = -256;
  158. compare(sfixed32Msg.testFieldFixedInt32 == -256, true, "SimpleSFixedInt32Message == -256")
  159. sfixed32Msg.testFieldFixedInt32 = 255;
  160. compare(sfixed32Msg.testFieldFixedInt32 == 255, true, "SimpleSFixedInt32Message == 255")
  161. sfixed32Msg.testFieldFixedInt32 = -32768;
  162. compare(sfixed32Msg.testFieldFixedInt32 == -32768, true, "SimpleSFixedInt32Message == -32768")
  163. sfixed32Msg.testFieldFixedInt32 = 32767;
  164. compare(sfixed32Msg.testFieldFixedInt32 == 32767, true, "SimpleSFixedInt32Message == 32767")
  165. sfixed32Msg.testFieldFixedInt32 = -65536;
  166. compare(sfixed32Msg.testFieldFixedInt32 == -65536, true, "SimpleSFixedInt32Message == -65536")
  167. sfixed32Msg.testFieldFixedInt32 = 65535;
  168. compare(sfixed32Msg.testFieldFixedInt32 == 65535, true, "SimpleSFixedInt32Message == 65535")
  169. sfixed32Msg.testFieldFixedInt32 = -2147483648;
  170. compare(sfixed32Msg.testFieldFixedInt32 == -2147483648, true, "SimpleSFixedInt32Message == -2147483648")
  171. sfixed32Msg.testFieldFixedInt32 = 2147483647;
  172. compare(sfixed32Msg.testFieldFixedInt32 == 2147483647, true, "SimpleSFixedInt32Message == 2147483647")
  173. }
  174. function test_simplesstringmessage() {
  175. compare(stringMsg.testFieldString, "Test string", "SimpleStringMessage")
  176. }
  177. }