tst_simple.qml 8.7 KB

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