tst_simple.qml 11 KB

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