tst_simple.qml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. MessageUpperCase {
  60. id: idTest
  61. }
  62. function test_simpleboolmessage() {
  63. boolMsg.testFieldBool = true;
  64. compare(boolMsg.testFieldBool, true, "SimpleBoolMessage == true")
  65. boolMsg.testFieldBool = false;
  66. compare(boolMsg.testFieldBool, false, "SimpleBoolMessage == false")
  67. }
  68. function test_simpleintmessage() {
  69. compare(int32Msg.testFieldInt == 2147483647, true, "SimpleIntMessage.testFieldInt: 2147483647: " + int32Msg.testFieldInt)
  70. int32Msg.testFieldInt = 0;
  71. compare(int32Msg.testFieldInt == 0, true, "SimpleIntMessage == 0")
  72. int32Msg.testFieldInt = -128;
  73. compare(int32Msg.testFieldInt == -128, true, "SimpleIntMessage == -128")
  74. int32Msg.testFieldInt = 127;
  75. compare(int32Msg.testFieldInt == 127, true, "SimpleIntMessage == 127")
  76. int32Msg.testFieldInt = -256;
  77. compare(int32Msg.testFieldInt == -256, true, "SimpleIntMessage == -256")
  78. int32Msg.testFieldInt = 255;
  79. compare(int32Msg.testFieldInt == 255, true, "SimpleIntMessage == 255")
  80. int32Msg.testFieldInt = -32768;
  81. compare(int32Msg.testFieldInt == -32768, true, "SimpleIntMessage == -32768")
  82. int32Msg.testFieldInt = 32767;
  83. compare(int32Msg.testFieldInt == 32767, true, "SimpleIntMessage == 32767")
  84. int32Msg.testFieldInt = -65536;
  85. compare(int32Msg.testFieldInt == -65536, true, "SimpleIntMessage == -65536")
  86. int32Msg.testFieldInt = 65535;
  87. compare(int32Msg.testFieldInt == 65535, true, "SimpleIntMessage == 65535")
  88. int32Msg.testFieldInt = -2147483648;
  89. compare(int32Msg.testFieldInt == -2147483648, true, "SimpleIntMessage == -2147483648")
  90. int32Msg.testFieldInt = 2147483647;
  91. compare(int32Msg.testFieldInt == 2147483647, true, "SimpleIntMessage == 2147483647")
  92. }
  93. function test_simplesintmessage() {
  94. compare(sint32Msg.testFieldInt == 2147483647, true, "SimpleSIntMessage.testFieldInt: 2147483647: " + sint32Msg.testFieldInt)
  95. sint32Msg.testFieldInt = 0;
  96. compare(sint32Msg.testFieldInt, 0, "SimpleSIntMessage == 0")
  97. sint32Msg.testFieldInt = -128;
  98. compare(sint32Msg.testFieldInt, -128, "SimpleSIntMessage == -128")
  99. sint32Msg.testFieldInt = 127;
  100. compare(sint32Msg.testFieldInt, 127, "SimpleSIntMessage == 127")
  101. sint32Msg.testFieldInt = -256;
  102. compare(sint32Msg.testFieldInt, -256, "SimpleSIntMessage == -256")
  103. sint32Msg.testFieldInt = 255;
  104. compare(sint32Msg.testFieldInt, 255, "SimpleSIntMessage == 255")
  105. sint32Msg.testFieldInt = -32768;
  106. compare(sint32Msg.testFieldInt, -32768, "SimpleSIntMessage == -32768")
  107. sint32Msg.testFieldInt = 32767;
  108. compare(sint32Msg.testFieldInt, 32767, "SimpleSIntMessage == 32767")
  109. sint32Msg.testFieldInt = -65536;
  110. compare(sint32Msg.testFieldInt, -65536, "SimpleSIntMessage == -65536")
  111. sint32Msg.testFieldInt = 65535;
  112. compare(sint32Msg.testFieldInt, 65535, "SimpleSIntMessage == 65535")
  113. sint32Msg.testFieldInt = -2147483648;
  114. compare(sint32Msg.testFieldInt, -2147483648, "SimpleSIntMessage == -2147483648")
  115. sint32Msg.testFieldInt = 2147483647;
  116. compare(sint32Msg.testFieldInt, 2147483647, "SimpleSIntMessage == 2147483647")
  117. }
  118. function test_simpleuintmessage() {
  119. compare(uint32Msg.testFieldInt == 4294967295, true, "SimpleUIntMessage.testFieldInt: 4294967295: " + uint32Msg.testFieldInt)
  120. uint32Msg.testFieldInt = 0;
  121. compare(uint32Msg.testFieldInt == 0, true, "SimpleUIntMessage == 0")
  122. uint32Msg.testFieldInt = 127;
  123. compare(uint32Msg.testFieldInt == 127, true, "SimpleUIntMessage == 127")
  124. uint32Msg.testFieldInt = 255;
  125. compare(uint32Msg.testFieldInt == 255, true, "SimpleUIntMessage == 255")
  126. uint32Msg.testFieldInt = 32767;
  127. compare(uint32Msg.testFieldInt == 32767, true, "SimpleUIntMessage == 32767")
  128. uint32Msg.testFieldInt = 65535;
  129. compare(uint32Msg.testFieldInt == 65535, true, "SimpleUIntMessage == 65535")
  130. uint32Msg.testFieldInt = 2147483647;
  131. compare(uint32Msg.testFieldInt == 2147483647, true, "SimpleUIntMessage == 2147483647")
  132. uint32Msg.testFieldInt = 4294967295;
  133. compare(uint32Msg.testFieldInt == 4294967295, true, "SimpleUIntMessage == 4294967295")
  134. }
  135. function test_simplefixed32message() {
  136. compare(fixed32Msg.testFieldFixedInt32 == 4294967295, true, "SimpleFixedInt32Message.testFieldInt: 4294967295: " + fixed32Msg.testFieldFixedInt32)
  137. fixed32Msg.testFieldFixedInt32 = 0;
  138. compare(fixed32Msg.testFieldFixedInt32 == 0, true, "SimpleFixedInt32Message == 0")
  139. fixed32Msg.testFieldFixedInt32 = 127;
  140. compare(fixed32Msg.testFieldFixedInt32 == 127, true, "SimpleFixedInt32Message == 127")
  141. fixed32Msg.testFieldFixedInt32 = 255;
  142. compare(fixed32Msg.testFieldFixedInt32 == 255, true, "SimpleFixedInt32Message == 255")
  143. fixed32Msg.testFieldFixedInt32 = 32767;
  144. compare(fixed32Msg.testFieldFixedInt32 == 32767, true, "SimpleFixedInt32Message == 32767")
  145. fixed32Msg.testFieldFixedInt32 = 65535;
  146. compare(fixed32Msg.testFieldFixedInt32 == 65535, true, "SimpleFixedInt32Message == 65535")
  147. fixed32Msg.testFieldFixedInt32 = 2147483647;
  148. compare(fixed32Msg.testFieldFixedInt32 == 2147483647, true, "SimpleFixedInt32Message == 2147483647")
  149. fixed32Msg.testFieldFixedInt32 = 4294967295;
  150. compare(fixed32Msg.testFieldFixedInt32 == 4294967295, true, "SimpleFixedInt32Message == 4294967295")
  151. }
  152. function test_simplesfixed32message() {
  153. compare(sfixed32Msg.testFieldFixedInt32 == 2147483647, true, "SimpleSFixedInt32Message.testFieldInt: 2147483647: " + sfixed32Msg.testFieldFixedInt32)
  154. sfixed32Msg.testFieldFixedInt32 = 0;
  155. compare(sfixed32Msg.testFieldFixedInt32 == 0, true, "SimpleSFixedInt32Message == 0")
  156. sfixed32Msg.testFieldFixedInt32 = -128;
  157. compare(sfixed32Msg.testFieldFixedInt32 == -128, true, "SimpleSFixedInt32Message == -128")
  158. sfixed32Msg.testFieldFixedInt32 = 127;
  159. compare(sfixed32Msg.testFieldFixedInt32 == 127, true, "SimpleSFixedInt32Message == 127")
  160. sfixed32Msg.testFieldFixedInt32 = -256;
  161. compare(sfixed32Msg.testFieldFixedInt32 == -256, true, "SimpleSFixedInt32Message == -256")
  162. sfixed32Msg.testFieldFixedInt32 = 255;
  163. compare(sfixed32Msg.testFieldFixedInt32 == 255, true, "SimpleSFixedInt32Message == 255")
  164. sfixed32Msg.testFieldFixedInt32 = -32768;
  165. compare(sfixed32Msg.testFieldFixedInt32 == -32768, true, "SimpleSFixedInt32Message == -32768")
  166. sfixed32Msg.testFieldFixedInt32 = 32767;
  167. compare(sfixed32Msg.testFieldFixedInt32 == 32767, true, "SimpleSFixedInt32Message == 32767")
  168. sfixed32Msg.testFieldFixedInt32 = -65536;
  169. compare(sfixed32Msg.testFieldFixedInt32 == -65536, true, "SimpleSFixedInt32Message == -65536")
  170. sfixed32Msg.testFieldFixedInt32 = 65535;
  171. compare(sfixed32Msg.testFieldFixedInt32 == 65535, true, "SimpleSFixedInt32Message == 65535")
  172. sfixed32Msg.testFieldFixedInt32 = -2147483648;
  173. compare(sfixed32Msg.testFieldFixedInt32 == -2147483648, true, "SimpleSFixedInt32Message == -2147483648")
  174. sfixed32Msg.testFieldFixedInt32 = 2147483647;
  175. compare(sfixed32Msg.testFieldFixedInt32 == 2147483647, true, "SimpleSFixedInt32Message == 2147483647")
  176. }
  177. function test_simplesstringmessage() {
  178. compare(stringMsg.testFieldString, "Test string", "SimpleStringMessage")
  179. }
  180. }