tst_simple.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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: caseSenseMsg
  61. }
  62. MessageReserved {
  63. id: reservedMsg
  64. }
  65. PriorMessageUnderscoreField {
  66. id: underScoreMsg
  67. }
  68. LowerCaseMessageName {
  69. id: lowerCaseMsg
  70. }
  71. function test_simpleboolmessage() {
  72. boolMsg.testFieldBool = true;
  73. compare(boolMsg.testFieldBool, true, "SimpleBoolMessage == true")
  74. boolMsg.testFieldBool = false;
  75. compare(boolMsg.testFieldBool, false, "SimpleBoolMessage == false")
  76. }
  77. function test_simpleintmessage() {
  78. if (qVersion < 0x050E00) {
  79. skip("int32 type is not supported by Qt < 5.14")
  80. }
  81. compare(int32Msg.testFieldInt == 2147483647, true, "SimpleIntMessage.testFieldInt: 2147483647: " + int32Msg.testFieldInt)
  82. int32Msg.testFieldInt = 0;
  83. compare(int32Msg.testFieldInt == 0, true, "SimpleIntMessage == 0")
  84. int32Msg.testFieldInt = -128;
  85. compare(int32Msg.testFieldInt == -128, true, "SimpleIntMessage == -128")
  86. int32Msg.testFieldInt = 127;
  87. compare(int32Msg.testFieldInt == 127, true, "SimpleIntMessage == 127")
  88. int32Msg.testFieldInt = -256;
  89. compare(int32Msg.testFieldInt == -256, true, "SimpleIntMessage == -256")
  90. int32Msg.testFieldInt = 255;
  91. compare(int32Msg.testFieldInt == 255, true, "SimpleIntMessage == 255")
  92. int32Msg.testFieldInt = -32768;
  93. compare(int32Msg.testFieldInt == -32768, true, "SimpleIntMessage == -32768")
  94. int32Msg.testFieldInt = 32767;
  95. compare(int32Msg.testFieldInt == 32767, true, "SimpleIntMessage == 32767")
  96. int32Msg.testFieldInt = -65536;
  97. compare(int32Msg.testFieldInt == -65536, true, "SimpleIntMessage == -65536")
  98. int32Msg.testFieldInt = 65535;
  99. compare(int32Msg.testFieldInt == 65535, true, "SimpleIntMessage == 65535")
  100. int32Msg.testFieldInt = -2147483648;
  101. compare(int32Msg.testFieldInt == -2147483648, true, "SimpleIntMessage == -2147483648")
  102. int32Msg.testFieldInt = 2147483647;
  103. compare(int32Msg.testFieldInt == 2147483647, true, "SimpleIntMessage == 2147483647")
  104. }
  105. function test_simplesintmessage() {
  106. compare(sint32Msg.testFieldInt == 2147483647, true, "SimpleSIntMessage.testFieldInt: 2147483647: " + sint32Msg.testFieldInt)
  107. sint32Msg.testFieldInt = 0;
  108. compare(sint32Msg.testFieldInt, 0, "SimpleSIntMessage == 0")
  109. sint32Msg.testFieldInt = -128;
  110. compare(sint32Msg.testFieldInt, -128, "SimpleSIntMessage == -128")
  111. sint32Msg.testFieldInt = 127;
  112. compare(sint32Msg.testFieldInt, 127, "SimpleSIntMessage == 127")
  113. sint32Msg.testFieldInt = -256;
  114. compare(sint32Msg.testFieldInt, -256, "SimpleSIntMessage == -256")
  115. sint32Msg.testFieldInt = 255;
  116. compare(sint32Msg.testFieldInt, 255, "SimpleSIntMessage == 255")
  117. sint32Msg.testFieldInt = -32768;
  118. compare(sint32Msg.testFieldInt, -32768, "SimpleSIntMessage == -32768")
  119. sint32Msg.testFieldInt = 32767;
  120. compare(sint32Msg.testFieldInt, 32767, "SimpleSIntMessage == 32767")
  121. sint32Msg.testFieldInt = -65536;
  122. compare(sint32Msg.testFieldInt, -65536, "SimpleSIntMessage == -65536")
  123. sint32Msg.testFieldInt = 65535;
  124. compare(sint32Msg.testFieldInt, 65535, "SimpleSIntMessage == 65535")
  125. sint32Msg.testFieldInt = -2147483648;
  126. compare(sint32Msg.testFieldInt, -2147483648, "SimpleSIntMessage == -2147483648")
  127. sint32Msg.testFieldInt = 2147483647;
  128. compare(sint32Msg.testFieldInt, 2147483647, "SimpleSIntMessage == 2147483647")
  129. }
  130. function test_simpleuintmessage() {
  131. compare(uint32Msg.testFieldInt == 4294967295, true, "SimpleUIntMessage.testFieldInt: 4294967295: " + uint32Msg.testFieldInt)
  132. uint32Msg.testFieldInt = 0;
  133. compare(uint32Msg.testFieldInt == 0, true, "SimpleUIntMessage == 0")
  134. uint32Msg.testFieldInt = 127;
  135. compare(uint32Msg.testFieldInt == 127, true, "SimpleUIntMessage == 127")
  136. uint32Msg.testFieldInt = 255;
  137. compare(uint32Msg.testFieldInt == 255, true, "SimpleUIntMessage == 255")
  138. uint32Msg.testFieldInt = 32767;
  139. compare(uint32Msg.testFieldInt == 32767, true, "SimpleUIntMessage == 32767")
  140. uint32Msg.testFieldInt = 65535;
  141. compare(uint32Msg.testFieldInt == 65535, true, "SimpleUIntMessage == 65535")
  142. uint32Msg.testFieldInt = 2147483647;
  143. compare(uint32Msg.testFieldInt == 2147483647, true, "SimpleUIntMessage == 2147483647")
  144. uint32Msg.testFieldInt = 4294967295;
  145. compare(uint32Msg.testFieldInt == 4294967295, true, "SimpleUIntMessage == 4294967295")
  146. }
  147. function test_simplefixed32message() {
  148. if (qVersion < 0x050E00) {
  149. skip("fixed32 type is not supported by Qt < 5.14")
  150. }
  151. compare(fixed32Msg.testFieldFixedInt32 == 4294967295, true, "SimpleFixedInt32Message.testFieldInt: 4294967295: " + fixed32Msg.testFieldFixedInt32)
  152. fixed32Msg.testFieldFixedInt32 = 0;
  153. compare(fixed32Msg.testFieldFixedInt32 == 0, true, "SimpleFixedInt32Message == 0")
  154. fixed32Msg.testFieldFixedInt32 = 127;
  155. compare(fixed32Msg.testFieldFixedInt32 == 127, true, "SimpleFixedInt32Message == 127")
  156. fixed32Msg.testFieldFixedInt32 = 255;
  157. compare(fixed32Msg.testFieldFixedInt32 == 255, true, "SimpleFixedInt32Message == 255")
  158. fixed32Msg.testFieldFixedInt32 = 32767;
  159. compare(fixed32Msg.testFieldFixedInt32 == 32767, true, "SimpleFixedInt32Message == 32767")
  160. fixed32Msg.testFieldFixedInt32 = 65535;
  161. compare(fixed32Msg.testFieldFixedInt32 == 65535, true, "SimpleFixedInt32Message == 65535")
  162. fixed32Msg.testFieldFixedInt32 = 2147483647;
  163. compare(fixed32Msg.testFieldFixedInt32 == 2147483647, true, "SimpleFixedInt32Message == 2147483647")
  164. fixed32Msg.testFieldFixedInt32 = 4294967295;
  165. compare(fixed32Msg.testFieldFixedInt32 == 4294967295, true, "SimpleFixedInt32Message == 4294967295")
  166. }
  167. function test_simplesfixed32message() {
  168. if (qVersion < 0x050E00) {
  169. skip("sfixed32 type is not supported by Qt < 5.14")
  170. }
  171. compare(sfixed32Msg.testFieldFixedInt32 == 2147483647, true, "SimpleSFixedInt32Message.testFieldInt: 2147483647: " + sfixed32Msg.testFieldFixedInt32)
  172. sfixed32Msg.testFieldFixedInt32 = 0;
  173. compare(sfixed32Msg.testFieldFixedInt32 == 0, true, "SimpleSFixedInt32Message == 0")
  174. sfixed32Msg.testFieldFixedInt32 = -128;
  175. compare(sfixed32Msg.testFieldFixedInt32 == -128, true, "SimpleSFixedInt32Message == -128")
  176. sfixed32Msg.testFieldFixedInt32 = 127;
  177. compare(sfixed32Msg.testFieldFixedInt32 == 127, true, "SimpleSFixedInt32Message == 127")
  178. sfixed32Msg.testFieldFixedInt32 = -256;
  179. compare(sfixed32Msg.testFieldFixedInt32 == -256, true, "SimpleSFixedInt32Message == -256")
  180. sfixed32Msg.testFieldFixedInt32 = 255;
  181. compare(sfixed32Msg.testFieldFixedInt32 == 255, true, "SimpleSFixedInt32Message == 255")
  182. sfixed32Msg.testFieldFixedInt32 = -32768;
  183. compare(sfixed32Msg.testFieldFixedInt32 == -32768, true, "SimpleSFixedInt32Message == -32768")
  184. sfixed32Msg.testFieldFixedInt32 = 32767;
  185. compare(sfixed32Msg.testFieldFixedInt32 == 32767, true, "SimpleSFixedInt32Message == 32767")
  186. sfixed32Msg.testFieldFixedInt32 = -65536;
  187. compare(sfixed32Msg.testFieldFixedInt32 == -65536, true, "SimpleSFixedInt32Message == -65536")
  188. sfixed32Msg.testFieldFixedInt32 = 65535;
  189. compare(sfixed32Msg.testFieldFixedInt32 == 65535, true, "SimpleSFixedInt32Message == 65535")
  190. sfixed32Msg.testFieldFixedInt32 = -2147483648;
  191. compare(sfixed32Msg.testFieldFixedInt32 == -2147483648, true, "SimpleSFixedInt32Message == -2147483648")
  192. sfixed32Msg.testFieldFixedInt32 = 2147483647;
  193. compare(sfixed32Msg.testFieldFixedInt32 == 2147483647, true, "SimpleSFixedInt32Message == 2147483647")
  194. }
  195. function test_simplesstringmessage() {
  196. compare(stringMsg.testFieldString, "Test string", "SimpleStringMessage")
  197. }
  198. function test_reservedNames() {
  199. reservedMsg.idProto = 34;
  200. reservedMsg.importProto = 35;
  201. reservedMsg.propertyProto = 36;
  202. compare(reservedMsg.idProto, 34, "reservedMsg.idProto == 34")
  203. compare(reservedMsg.importProto, 35, "reservedMsg.importProto == 35")
  204. compare(reservedMsg.propertyProto, 36, "reservedMsg.propertyProto == 36")
  205. }
  206. function test_reservedEnums() {
  207. compare(MessageEnumReserved.Import, 0, "MessageEnumReserved.Import == 0")
  208. compare(MessageEnumReserved.Property, 1, "MessageEnumReserved.Property == 1")
  209. compare(MessageEnumReserved.Id, 2, "MessageEnumReserved.Id == 2")
  210. }
  211. function test_caseSense() {
  212. caseSenseMsg.testField = 34;
  213. compare(caseSenseMsg.testField == 34, true, "MessageUpperCase == 34")
  214. compare(MessageEnumReserved.EnumValue0 == 0, true, "MessageEnumReserved.EnumValue0 == 0")
  215. compare(MessageEnumReserved.EnumValue1 == 1, true, "MessageEnumReserved.EnumValue1 == 1")
  216. compare(MessageEnumReserved.EnumValue2 == 2, true, "MessageEnumReserved.EnumValue2 == 2")
  217. }
  218. function test_underScoreField() {
  219. underScoreMsg._underScoreMessageField = 123
  220. compare(underScoreMsg._underScoreMessageField == 123, true, "underScoreMsg._underScoreMessageField == 123")
  221. }
  222. function test_lowerCaseMessage() {
  223. lowerCaseMsg.testField = 34
  224. compare(lowerCaseMsg.testField == 34, true, "LowerCaseMessageName == 34")
  225. }
  226. }