tst_simple.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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.3
  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_1initialization() {
  72. compare(int32Msg.testFieldInt, 2147483647, "SimpleIntMessage initialization")
  73. compare(sint32Msg.testFieldInt, 2147483647, "SimpleSIntMessage initialization")
  74. compare(uint32Msg.testFieldInt, 4294967295, "SimpleUIntMessage initialization")
  75. compare(fixed32Msg.testFieldFixedInt32, 4294967295, "SimpleFixedInt32Message initialization")
  76. compare(sfixed32Msg.testFieldFixedInt32, 2147483647, "SimpleSFixedInt32Message initialization")
  77. }
  78. function test_simpleboolmessage() {
  79. boolMsg.testFieldBool = true;
  80. compare(boolMsg.testFieldBool, true, "SimpleBoolMessage == true")
  81. boolMsg.testFieldBool = false;
  82. compare(boolMsg.testFieldBool, false, "SimpleBoolMessage == false")
  83. }
  84. function test_simpleintmessage() {
  85. int32Msg.testFieldInt = 0;
  86. compare(int32Msg.testFieldInt, 0, "SimpleIntMessage == 0")
  87. int32Msg.testFieldInt = -128;
  88. compare(int32Msg.testFieldInt, -128, "SimpleIntMessage == -128")
  89. int32Msg.testFieldInt = 127;
  90. compare(int32Msg.testFieldInt, 127, "SimpleIntMessage == 127")
  91. int32Msg.testFieldInt = -256;
  92. compare(int32Msg.testFieldInt, -256, "SimpleIntMessage == -256")
  93. int32Msg.testFieldInt = 255;
  94. compare(int32Msg.testFieldInt, 255, "SimpleIntMessage == 255")
  95. int32Msg.testFieldInt = -32768;
  96. compare(int32Msg.testFieldInt, -32768, "SimpleIntMessage == -32768")
  97. int32Msg.testFieldInt = 32767;
  98. compare(int32Msg.testFieldInt, 32767, "SimpleIntMessage == 32767")
  99. int32Msg.testFieldInt = -65536;
  100. compare(int32Msg.testFieldInt, -65536, "SimpleIntMessage == -65536")
  101. int32Msg.testFieldInt = 65535;
  102. compare(int32Msg.testFieldInt, 65535, "SimpleIntMessage == 65535")
  103. int32Msg.testFieldInt = -2147483648;
  104. compare(int32Msg.testFieldInt, -2147483648, "SimpleIntMessage == -2147483648")
  105. int32Msg.testFieldInt = 2147483647;
  106. compare(int32Msg.testFieldInt, 2147483647, "SimpleIntMessage == 2147483647")
  107. }
  108. function test_simplesintmessage() {
  109. sint32Msg.testFieldInt = 0;
  110. compare(sint32Msg.testFieldInt, 0, "SimpleSIntMessage == 0")
  111. sint32Msg.testFieldInt = -128;
  112. compare(sint32Msg.testFieldInt, -128, "SimpleSIntMessage == -128")
  113. sint32Msg.testFieldInt = 127;
  114. compare(sint32Msg.testFieldInt, 127, "SimpleSIntMessage == 127")
  115. sint32Msg.testFieldInt = -256;
  116. compare(sint32Msg.testFieldInt, -256, "SimpleSIntMessage == -256")
  117. sint32Msg.testFieldInt = 255;
  118. compare(sint32Msg.testFieldInt, 255, "SimpleSIntMessage == 255")
  119. sint32Msg.testFieldInt = -32768;
  120. compare(sint32Msg.testFieldInt, -32768, "SimpleSIntMessage == -32768")
  121. sint32Msg.testFieldInt = 32767;
  122. compare(sint32Msg.testFieldInt, 32767, "SimpleSIntMessage == 32767")
  123. sint32Msg.testFieldInt = -65536;
  124. compare(sint32Msg.testFieldInt, -65536, "SimpleSIntMessage == -65536")
  125. sint32Msg.testFieldInt = 65535;
  126. compare(sint32Msg.testFieldInt, 65535, "SimpleSIntMessage == 65535")
  127. sint32Msg.testFieldInt = -2147483648;
  128. compare(sint32Msg.testFieldInt, -2147483648, "SimpleSIntMessage == -2147483648")
  129. sint32Msg.testFieldInt = 2147483647;
  130. compare(sint32Msg.testFieldInt, 2147483647, "SimpleSIntMessage == 2147483647")
  131. }
  132. function test_simpleuintmessage() {
  133. uint32Msg.testFieldInt = 0;
  134. compare(uint32Msg.testFieldInt, 0, "SimpleUIntMessage == 0")
  135. uint32Msg.testFieldInt = 127;
  136. compare(uint32Msg.testFieldInt, 127, "SimpleUIntMessage == 127")
  137. uint32Msg.testFieldInt = 255;
  138. compare(uint32Msg.testFieldInt, 255, "SimpleUIntMessage == 255")
  139. uint32Msg.testFieldInt = 32767;
  140. compare(uint32Msg.testFieldInt, 32767, "SimpleUIntMessage == 32767")
  141. uint32Msg.testFieldInt = 65535;
  142. compare(uint32Msg.testFieldInt, 65535, "SimpleUIntMessage == 65535")
  143. uint32Msg.testFieldInt = 2147483647;
  144. compare(uint32Msg.testFieldInt, 2147483647, "SimpleUIntMessage == 2147483647")
  145. uint32Msg.testFieldInt = 4294967295;
  146. compare(uint32Msg.testFieldInt, 4294967295, "SimpleUIntMessage == 4294967295")
  147. }
  148. function test_simplefixed32message() {
  149. fixed32Msg.testFieldFixedInt32 = 0;
  150. compare(fixed32Msg.testFieldFixedInt32, 0, "SimpleFixedInt32Message == 0")
  151. fixed32Msg.testFieldFixedInt32 = 127;
  152. compare(fixed32Msg.testFieldFixedInt32, 127, "SimpleFixedInt32Message == 127")
  153. fixed32Msg.testFieldFixedInt32 = 255;
  154. compare(fixed32Msg.testFieldFixedInt32, 255, "SimpleFixedInt32Message == 255")
  155. fixed32Msg.testFieldFixedInt32 = 32767;
  156. compare(fixed32Msg.testFieldFixedInt32, 32767, "SimpleFixedInt32Message == 32767")
  157. fixed32Msg.testFieldFixedInt32 = 65535;
  158. compare(fixed32Msg.testFieldFixedInt32, 65535, "SimpleFixedInt32Message == 65535")
  159. fixed32Msg.testFieldFixedInt32 = 2147483647;
  160. compare(fixed32Msg.testFieldFixedInt32, 2147483647, "SimpleFixedInt32Message == 2147483647")
  161. fixed32Msg.testFieldFixedInt32 = 4294967295;
  162. compare(fixed32Msg.testFieldFixedInt32, 4294967295, "SimpleFixedInt32Message == 4294967295")
  163. }
  164. function test_simplesfixed32message() {
  165. sfixed32Msg.testFieldFixedInt32 = 0;
  166. compare(sfixed32Msg.testFieldFixedInt32, 0, "SimpleSFixedInt32Message == 0")
  167. sfixed32Msg.testFieldFixedInt32 = -128;
  168. compare(sfixed32Msg.testFieldFixedInt32, -128, "SimpleSFixedInt32Message == -128")
  169. sfixed32Msg.testFieldFixedInt32 = 127;
  170. compare(sfixed32Msg.testFieldFixedInt32, 127, "SimpleSFixedInt32Message == 127")
  171. sfixed32Msg.testFieldFixedInt32 = -256;
  172. compare(sfixed32Msg.testFieldFixedInt32, -256, "SimpleSFixedInt32Message == -256")
  173. sfixed32Msg.testFieldFixedInt32 = 255;
  174. compare(sfixed32Msg.testFieldFixedInt32, 255, "SimpleSFixedInt32Message == 255")
  175. sfixed32Msg.testFieldFixedInt32 = -32768;
  176. compare(sfixed32Msg.testFieldFixedInt32, -32768, "SimpleSFixedInt32Message == -32768")
  177. sfixed32Msg.testFieldFixedInt32 = 32767;
  178. compare(sfixed32Msg.testFieldFixedInt32, 32767, "SimpleSFixedInt32Message == 32767")
  179. sfixed32Msg.testFieldFixedInt32 = -65536;
  180. compare(sfixed32Msg.testFieldFixedInt32, -65536, "SimpleSFixedInt32Message == -65536")
  181. sfixed32Msg.testFieldFixedInt32 = 65535;
  182. compare(sfixed32Msg.testFieldFixedInt32, 65535, "SimpleSFixedInt32Message == 65535")
  183. sfixed32Msg.testFieldFixedInt32 = -2147483648;
  184. compare(sfixed32Msg.testFieldFixedInt32, -2147483648, "SimpleSFixedInt32Message == -2147483648")
  185. sfixed32Msg.testFieldFixedInt32 = 2147483647;
  186. compare(sfixed32Msg.testFieldFixedInt32, 2147483647, "SimpleSFixedInt32Message == 2147483647")
  187. }
  188. function test_simplesstringmessage() {
  189. compare(stringMsg.testFieldString, "Test string", "SimpleStringMessage")
  190. }
  191. function test_reservedNames() {
  192. reservedMsg.id_proto = 34;
  193. reservedMsg.import_proto = 35;
  194. reservedMsg.property_proto = 36;
  195. compare(reservedMsg.id_proto, 34, "reservedMsg.id_proto == 34")
  196. compare(reservedMsg.import_proto, 35, "reservedMsg.import_proto == 35")
  197. compare(reservedMsg.property_proto, 36, "reservedMsg.property_proto == 36")
  198. }
  199. function test_reservedEnums() {
  200. compare(MessageEnumReserved.Import, 0, "MessageEnumReserved.Import == 0")
  201. compare(MessageEnumReserved.Property, 1, "MessageEnumReserved.Property == 1")
  202. compare(MessageEnumReserved.Id, 2, "MessageEnumReserved.Id == 2")
  203. }
  204. function test_caseSense() {
  205. caseSenseMsg.testField = 34;
  206. compare(caseSenseMsg.testField, 34, "MessageUpperCase == 34")
  207. compare(MessageEnumReserved.EnumValue0 == 0, true, "MessageEnumReserved.EnumValue0 == 0")
  208. compare(MessageEnumReserved.EnumValue1 == 1, true, "MessageEnumReserved.EnumValue1 == 1")
  209. compare(MessageEnumReserved.EnumValue2 == 2, true, "MessageEnumReserved.EnumValue2 == 2")
  210. }
  211. function test_underScoreField() {
  212. underScoreMsg.underScoreMessageField = 123
  213. compare(underScoreMsg.underScoreMessageField, 123, "underScoreMsg.underScoreMessageField == 123")
  214. }
  215. function test_lowerCaseMessage() {
  216. lowerCaseMsg.testField = 34
  217. compare(lowerCaseMsg.testField, 34, "LowerCaseMessageName == 34")
  218. }
  219. function test_int32ImplicitConversion() {
  220. int32Msg.testFieldInt = 0
  221. compare(int32Msg.testFieldInt ? true : false, false, "Invalid implicit conversion: " + int32Msg.testFieldInt + " should be false")
  222. int32Msg.testFieldInt = 1
  223. compare(int32Msg.testFieldInt ? true : false, true, "Invalid implicit conversion: " + int32Msg.testFieldInt + " should be true")
  224. }
  225. function test_int32LocaleStringConversion() {
  226. compare(int32Msg.testFieldInt.toLocaleString(Qt.locale()), Number(int32Msg.testFieldInt).toLocaleString(Qt.locale()),
  227. "Locale number string is not match " + int32Msg.testFieldInt.toLocaleString(Qt.locale()) + " != " + Number(int32Msg.testFieldInt).toLocaleString(Qt.locale()))
  228. }
  229. function test_fixed32ImplicitConversion() {
  230. fixed32Msg.testFieldFixedInt32 = 0
  231. compare(fixed32Msg.testFieldFixedInt32 ? true : false, false, "Invalid implicit conversion: " + fixed32Msg.testFieldInt + " should be false")
  232. fixed32Msg.testFieldFixedInt32 = 1
  233. compare(fixed32Msg.testFieldFixedInt32 ? true : false, true, "Invalid implicit conversion: " + fixed32Msg.testFieldInt + " should be true")
  234. }
  235. function test_fixed32LocaleStringConversion() {
  236. compare(fixed32Msg.testFieldFixedInt32.toLocaleString(Qt.locale()), Number(fixed32Msg.testFieldFixedInt32).toLocaleString(Qt.locale()),
  237. "Locale number string is not match " + fixed32Msg.testFieldFixedInt32.toLocaleString(Qt.locale()) + " != " + Number(fixed32Msg.testFieldFixedInt32).toLocaleString(Qt.locale()))
  238. }
  239. function test_sint32ImplicitConversion() {
  240. sint32Msg.testFieldInt = 0
  241. compare(sint32Msg.testFieldInt ? true : false, false, "Invalid implicit conversion: " + sint32Msg.testFieldInt + " should be false")
  242. sint32Msg.testFieldInt = 1
  243. compare(sint32Msg.testFieldInt ? true : false, true, "Invalid implicit conversion: " + sint32Msg.testFieldInt + " should be true")
  244. }
  245. function test_sint32LocaleStringConversion() {
  246. compare(sint32Msg.testFieldInt.toLocaleString(Qt.locale()), Number(sint32Msg.testFieldInt).toLocaleString(Qt.locale()),
  247. "Locale number string is not match " + sint32Msg.testFieldInt.toLocaleString(Qt.locale()) + " != " + Number(sint32Msg.testFieldInt).toLocaleString(Qt.locale()))
  248. }
  249. function test_sfixed32ImplicitConversion() {
  250. sfixed32Msg.testFieldFixedInt32 = 0
  251. compare(sfixed32Msg.testFieldFixedInt32 ? true : false, false, "Invalid implicit conversion: " + sfixed32Msg.testFieldInt + " should be false")
  252. sfixed32Msg.testFieldFixedInt32 = 1
  253. compare(sfixed32Msg.testFieldFixedInt32 ? true : false, true, "Invalid implicit conversion: " + sfixed32Msg.testFieldInt + " should be true")
  254. }
  255. function test_sfixed32LocaleStringConversion() {
  256. compare(sfixed32Msg.testFieldFixedInt32.toLocaleString(Qt.locale()), Number(sfixed32Msg.testFieldFixedInt32).toLocaleString(Qt.locale()),
  257. "Locale number string is not match " + sfixed32Msg.testFieldFixedInt32.toLocaleString(Qt.locale()) + " != " + Number(sfixed32Msg.testFieldFixedInt32).toLocaleString(Qt.locale()))
  258. }
  259. }