test_SimpleTypes.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*
  2. * Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
  3. *
  4. * This file is part of Embedded Proto.
  5. *
  6. * Embedded Proto is open source software: you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as published
  8. * by the Free Software Foundation, version 3 of the license.
  9. *
  10. * Embedded Proto is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. * For commercial and closed source application please visit:
  19. * <https://EmbeddedProto.com/license/>.
  20. *
  21. * Embedded AMS B.V.
  22. * Info:
  23. * info at EmbeddedProto dot com
  24. *
  25. * Postal address:
  26. * Johan Huizingalaan 763a
  27. * 1066 VH, Amsterdam
  28. * the Netherlands
  29. */
  30. #include "gtest/gtest.h"
  31. #include <WireFormatter.h>
  32. #include <ReadBufferMock.h>
  33. #include <WriteBufferMock.h>
  34. #include <cstdint>
  35. #include <limits>
  36. // EAMS message definitions
  37. #include <simple_types.h>
  38. using ::testing::_;
  39. using ::testing::InSequence;
  40. using ::testing::Return;
  41. using ::testing::SetArgReferee;
  42. namespace test_EmbeddedAMS_SimpleTypes
  43. {
  44. TEST(SimpleTypes, zero)
  45. {
  46. InSequence s;
  47. // See if an empty message results in no data been pushed.
  48. ::Test_Simple_Types msg;
  49. Mocks::WriteBufferMock buffer;
  50. EXPECT_CALL(buffer, push(_)).Times(0);
  51. EXPECT_CALL(buffer, push(_,_)).Times(0);
  52. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.serialize(buffer));
  53. EXPECT_EQ(0, msg.serialized_size());
  54. }
  55. TEST(SimpleTypes, serialize_one)
  56. {
  57. InSequence s;
  58. // Using a protobuf message and the google protobuf implementation test is serialization is
  59. // correct.
  60. ::Test_Simple_Types msg;
  61. Mocks::WriteBufferMock buffer;
  62. msg.set_a_int32(1);
  63. msg.set_a_int64(1);
  64. msg.set_a_uint32(1);
  65. msg.set_a_uint64(1);
  66. msg.set_a_sint32(1);
  67. msg.set_a_sint64(1);
  68. msg.set_a_bool(true);
  69. msg.set_a_enum(Test_Enum::ONE);
  70. msg.set_a_fixed64(1);
  71. msg.set_a_sfixed64(1);
  72. msg.set_a_double(1.0);
  73. msg.set_a_fixed32(1);
  74. msg.set_a_sfixed32(1);
  75. msg.set_a_float(1.0F);
  76. uint8_t expected[] = {0x08, 0x01,
  77. 0x10, 0x01,
  78. 0x18, 0x01,
  79. 0x20, 0x01,
  80. 0x28, 0x02,
  81. 0x30, 0x02,
  82. 0x38, 0x01,
  83. 0x40, 0x01,
  84. 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85. 0x51, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  86. 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
  87. 0x65, 0x01, 0x00, 0x00, 0x00,
  88. 0x6d, 0x01, 0x00, 0x00, 0x00,
  89. 0x75, 0x00, 0x00, 0x80, 0x3f};
  90. for(auto e : expected) {
  91. EXPECT_CALL(buffer, push(e)).Times(1).WillOnce(Return(true));
  92. }
  93. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.serialize(buffer));
  94. EXPECT_EQ(58, msg.serialized_size());
  95. }
  96. TEST(SimpleTypes, serialize_max)
  97. {
  98. InSequence s;
  99. // Using a protobuf message and the google protobuf implementation test is serialization is
  100. // correct.
  101. ::Test_Simple_Types msg;
  102. Mocks::WriteBufferMock buffer;
  103. msg.set_a_int32(std::numeric_limits<int32_t>::max());
  104. msg.set_a_int64(std::numeric_limits<int64_t>::max());
  105. msg.set_a_uint32(std::numeric_limits<uint32_t>::max());
  106. msg.set_a_uint64(std::numeric_limits<uint64_t>::max());
  107. msg.set_a_sint32(std::numeric_limits<int32_t>::max());
  108. msg.set_a_sint64(std::numeric_limits<int64_t>::max());
  109. msg.set_a_bool(true);
  110. msg.set_a_enum(Test_Enum::TWOBILLION);
  111. msg.set_a_fixed64(std::numeric_limits<uint64_t>::max());
  112. msg.set_a_sfixed64(std::numeric_limits<int64_t>::max());
  113. msg.set_a_double(std::numeric_limits<double>::max());
  114. msg.set_a_fixed32(std::numeric_limits<uint32_t>::max());
  115. msg.set_a_sfixed32(std::numeric_limits<int32_t>::max());
  116. msg.set_a_float(std::numeric_limits<float>::max());
  117. uint8_t expected[] = {0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0x07,
  118. 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  119. 0x7F, 0x18, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F,
  120. 0x20, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01,
  121. 0x28, 0xFE, 0xFF, 0xFF, 0xFF, 0x0F,
  122. 0x30, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01,
  123. 0x38, 0x01,
  124. 0x40, 0x80, 0xA8, 0xD6, 0xB9, 0x07,
  125. 0x49, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  126. 0x51, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
  127. 0x59, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F,
  128. 0x65, 0xFF, 0xFF, 0xFF, 0xFF,
  129. 0x6D, 0xFF, 0xFF, 0xFF, 0x7F,
  130. 0x75, 0xFF, 0xFF, 0x7F, 0x7F};
  131. for(auto e : expected) {
  132. EXPECT_CALL(buffer, push(e)).Times(1).WillOnce(Return(true));
  133. }
  134. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.serialize(buffer));
  135. EXPECT_EQ(100, msg.serialized_size());
  136. }
  137. TEST(SimpleTypes, serialize_min)
  138. {
  139. InSequence s;
  140. // Using a protobuf message and the google protobuf implementation test is serialization is
  141. // correct.
  142. ::Test_Simple_Types msg;
  143. Mocks::WriteBufferMock buffer;
  144. msg.set_a_int32(std::numeric_limits<int32_t>::min());
  145. msg.set_a_int64(std::numeric_limits<int64_t>::min());
  146. msg.set_a_uint32(std::numeric_limits<uint32_t>::min());
  147. msg.set_a_uint64(std::numeric_limits<uint64_t>::min());
  148. msg.set_a_sint32(std::numeric_limits<int32_t>::min());
  149. msg.set_a_sint64(std::numeric_limits<int64_t>::min());
  150. msg.set_a_bool(false);
  151. msg.set_a_enum(Test_Enum::ZERO);
  152. msg.set_a_fixed64(std::numeric_limits<uint64_t>::min());
  153. msg.set_a_sfixed64(std::numeric_limits<int64_t>::min());
  154. msg.set_a_double(std::numeric_limits<double>::lowest());
  155. msg.set_a_fixed32(std::numeric_limits<uint32_t>::min());
  156. msg.set_a_sfixed32(std::numeric_limits<int32_t>::min());
  157. msg.set_a_float(std::numeric_limits<float>::lowest());
  158. uint8_t expected[] = {0x08, 0x80, 0x80, 0x80, 0x80, 0x08,
  159. 0x10, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01,
  160. 0x28, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F,
  161. 0x30, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01,
  162. 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  163. 0x59, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0xFF,
  164. 0x6D, 0x00, 0x00, 0x00, 0x80,
  165. 0x75, 0xFF, 0xFF, 0x7F, 0xFF};
  166. for(auto e : expected) {
  167. EXPECT_CALL(buffer, push(e)).Times(1).WillOnce(Return(true));
  168. }
  169. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.serialize(buffer));
  170. EXPECT_EQ(62, msg.serialized_size());
  171. }
  172. TEST(SimpleTypes, serialize_smalest_real)
  173. {
  174. InSequence s;
  175. // Using a protobuf message and the google protobuf implementation test is serialization is
  176. // correct.
  177. ::Test_Simple_Types msg;
  178. Mocks::WriteBufferMock buffer;
  179. msg.set_a_double(std::numeric_limits<double>::min());
  180. msg.set_a_float(std::numeric_limits<float>::min());
  181. uint8_t expected[] = {0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  182. 0x75, 0x00, 0x00, 0x80, 0x00 };
  183. for(auto e : expected) {
  184. EXPECT_CALL(buffer, push(e)).Times(1).WillOnce(Return(true));
  185. }
  186. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.serialize(buffer));
  187. EXPECT_EQ(14, msg.serialized_size());
  188. }
  189. TEST(SimpleTypes, serialize_fault_buffer_full_varint)
  190. {
  191. InSequence s;
  192. // Using a protobuf message and the google protobuf implementation test is serialization is
  193. // correct.
  194. ::Test_Simple_Types msg;
  195. Mocks::WriteBufferMock buffer;
  196. // Just set some large value.
  197. msg.set_a_uint32(std::numeric_limits<uint32_t>::max());
  198. // Allow for some bytes to be serialized
  199. EXPECT_CALL(buffer, push(_)).Times(1).WillOnce(Return(true));
  200. EXPECT_CALL(buffer, push(_)).Times(1).WillOnce(Return(true));
  201. // And then fail
  202. EXPECT_CALL(buffer, push(_)).Times(2).WillOnce(Return(false));
  203. EXPECT_EQ(::EmbeddedProto::Error::BUFFER_FULL, msg.serialize(buffer));
  204. }
  205. TEST(SimpleTypes, deserialize_zero)
  206. {
  207. InSequence s;
  208. Mocks::ReadBufferMock buffer;
  209. ::Test_Simple_Types msg;
  210. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(Return(false));
  211. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.deserialize(buffer));
  212. EXPECT_EQ(0, msg.get_a_int32());
  213. EXPECT_EQ(0, msg.get_a_int64());
  214. EXPECT_EQ(0U, msg.get_a_uint32());
  215. EXPECT_EQ(0U, msg.get_a_uint64());
  216. EXPECT_EQ(0, msg.get_a_sint32());
  217. EXPECT_EQ(0, msg.get_a_sint64());
  218. EXPECT_EQ(false, msg.get_a_bool());
  219. EXPECT_EQ(Test_Enum::ZERO, msg.get_a_enum());
  220. EXPECT_EQ(0U, msg.get_a_fixed64());
  221. EXPECT_EQ(0, msg.get_a_sfixed64());
  222. EXPECT_EQ(0.0, msg.get_a_double());
  223. EXPECT_EQ(0U, msg.get_a_fixed32());
  224. EXPECT_EQ(0, msg.get_a_sfixed32());
  225. EXPECT_EQ(0.0F, msg.get_a_float());
  226. }
  227. TEST(SimpleTypes, deserialize_one)
  228. {
  229. InSequence s;
  230. Mocks::ReadBufferMock buffer;
  231. ON_CALL(buffer, get_size()).WillByDefault(Return(58));
  232. ::Test_Simple_Types msg;
  233. uint8_t referee[] = { 0x08, 0x01,
  234. 0x10, 0x01,
  235. 0x18, 0x01,
  236. 0x20, 0x01,
  237. 0x28, 0x02,
  238. 0x30, 0x02,
  239. 0x38, 0x01,
  240. 0x40, 0x01,
  241. 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  242. 0x51, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  243. 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
  244. 0x65, 0x01, 0x00, 0x00, 0x00,
  245. 0x6d, 0x01, 0x00, 0x00, 0x00,
  246. 0x75, 0x00, 0x00, 0x80, 0x3f};
  247. for(auto r: referee) {
  248. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(r), Return(true)));
  249. }
  250. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(Return(false));
  251. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.deserialize(buffer));
  252. EXPECT_EQ(1, msg.get_a_int32());
  253. EXPECT_EQ(1, msg.get_a_int64());
  254. EXPECT_EQ(1U, msg.get_a_uint32());
  255. EXPECT_EQ(1U, msg.get_a_uint64());
  256. EXPECT_EQ(1, msg.get_a_sint32());
  257. EXPECT_EQ(1, msg.get_a_sint64());
  258. EXPECT_EQ(true, msg.get_a_bool());
  259. EXPECT_EQ(Test_Enum::ONE, msg.get_a_enum());
  260. EXPECT_EQ(1U, msg.get_a_fixed64());
  261. EXPECT_EQ(1, msg.get_a_sfixed64());
  262. EXPECT_EQ(1.0, msg.get_a_double());
  263. EXPECT_EQ(1U, msg.get_a_fixed32());
  264. EXPECT_EQ(1, msg.get_a_sfixed32());
  265. EXPECT_EQ(1.0F, msg.get_a_float());
  266. }
  267. TEST(SimpleTypes, deserialize_max)
  268. {
  269. InSequence s;
  270. Mocks::ReadBufferMock buffer;
  271. ON_CALL(buffer, get_size()).WillByDefault(Return(58));
  272. ::Test_Simple_Types msg;
  273. uint8_t referee[] = { 0x08, 0xFF, 0xFF, 0xFF, 0xFF,
  274. 0x07, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  275. 0x7F, 0x18, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F,
  276. 0x20, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01,
  277. 0x28, 0xFE, 0xFF, 0xFF, 0xFF, 0x0F,
  278. 0x30, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01,
  279. 0x38, 0x01,
  280. 0x40, 0x80, 0xA8, 0xD6, 0xB9, 0x07,
  281. 0x49, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  282. 0x51, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
  283. 0x59, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F,
  284. 0x65, 0xFF, 0xFF, 0xFF, 0xFF,
  285. 0x6D, 0xFF, 0xFF, 0xFF, 0x7F,
  286. 0x75, 0xFF, 0xFF, 0x7F, 0x7F};
  287. for(auto r: referee) {
  288. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(r), Return(true)));
  289. }
  290. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(Return(false));
  291. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.deserialize(buffer));
  292. EXPECT_EQ(std::numeric_limits<int32_t>::max(), msg.get_a_int32());
  293. EXPECT_EQ(std::numeric_limits<int64_t>::max(), msg.get_a_int64());
  294. EXPECT_EQ(std::numeric_limits<uint32_t>::max(), msg.get_a_uint32());
  295. EXPECT_EQ(std::numeric_limits<uint64_t>::max(), msg.get_a_uint64());
  296. EXPECT_EQ(std::numeric_limits<int32_t>::max(), msg.get_a_sint32());
  297. EXPECT_EQ(std::numeric_limits<int64_t>::max(), msg.get_a_sint64());
  298. EXPECT_EQ(true, msg.get_a_bool());
  299. EXPECT_EQ(Test_Enum::TWOBILLION, msg.get_a_enum());
  300. EXPECT_EQ(std::numeric_limits<uint64_t>::max(), msg.get_a_fixed64());
  301. EXPECT_EQ(std::numeric_limits<int64_t>::max(), msg.get_a_sfixed64());
  302. EXPECT_EQ(std::numeric_limits<double>::max(), msg.get_a_double());
  303. EXPECT_EQ(std::numeric_limits<uint32_t>::max(), msg.get_a_fixed32());
  304. EXPECT_EQ(std::numeric_limits<int32_t>::max(), msg.get_a_sfixed32());
  305. EXPECT_EQ(std::numeric_limits<float>::max(), msg.get_a_float());
  306. }
  307. TEST(SimpleTypes, deserialize_min)
  308. {
  309. InSequence s;
  310. Mocks::ReadBufferMock buffer;
  311. ON_CALL(buffer, get_size()).WillByDefault(Return(58));
  312. ::Test_Simple_Types msg;
  313. uint8_t referee[] = { 0x08, 0x80, 0x80, 0x80, 0x80, 0x08,
  314. 0x10, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01,
  315. 0x28, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F,
  316. 0x30, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01,
  317. 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  318. 0x59, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0xFF,
  319. 0x6D, 0x00, 0x00, 0x00, 0x80,
  320. 0x75, 0xFF, 0xFF, 0x7F, 0xFF};
  321. for(auto r: referee) {
  322. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(r), Return(true)));
  323. }
  324. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(Return(false));
  325. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.deserialize(buffer));
  326. EXPECT_EQ(std::numeric_limits<int32_t>::min(), msg.get_a_int32());
  327. EXPECT_EQ(std::numeric_limits<int64_t>::min(), msg.get_a_int64());
  328. EXPECT_EQ(std::numeric_limits<uint32_t>::min(), msg.get_a_uint32());
  329. EXPECT_EQ(std::numeric_limits<uint64_t>::min(), msg.get_a_uint64());
  330. EXPECT_EQ(std::numeric_limits<int32_t>::min(), msg.get_a_sint32());
  331. EXPECT_EQ(std::numeric_limits<int64_t>::min(), msg.get_a_sint64());
  332. EXPECT_EQ(false, msg.get_a_bool());
  333. EXPECT_EQ(Test_Enum::ZERO, msg.get_a_enum());
  334. EXPECT_EQ(std::numeric_limits<uint64_t>::min(), msg.get_a_fixed64());
  335. EXPECT_EQ(std::numeric_limits<int64_t>::min(), msg.get_a_sfixed64());
  336. EXPECT_EQ(std::numeric_limits<double>::lowest(), msg.get_a_double());
  337. EXPECT_EQ(std::numeric_limits<uint32_t>::min(), msg.get_a_fixed32());
  338. EXPECT_EQ(std::numeric_limits<int32_t>::min(), msg.get_a_sfixed32());
  339. EXPECT_EQ(std::numeric_limits<float>::lowest(), msg.get_a_float());
  340. }
  341. TEST(SimpleTypes, deserialize_smalest_real)
  342. {
  343. InSequence s;
  344. ::Test_Simple_Types msg;
  345. Mocks::ReadBufferMock buffer;
  346. uint8_t referee[] = {0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  347. 0x75, 0x00, 0x00, 0x80, 0x00 };
  348. for(auto r: referee) {
  349. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(r), Return(true)));
  350. }
  351. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(Return(false));
  352. EXPECT_EQ(::EmbeddedProto::Error::NO_ERRORS, msg.deserialize(buffer));
  353. EXPECT_EQ(std::numeric_limits<double>::min(), msg.get_a_double());
  354. EXPECT_EQ(std::numeric_limits<float>::min(), msg.get_a_float());
  355. }
  356. TEST(SimpleTypes, deserialize_fault_end_of_buffer_fixed)
  357. {
  358. InSequence s;
  359. Mocks::ReadBufferMock buffer;
  360. ON_CALL(buffer, get_size()).WillByDefault(Return(58));
  361. ::Test_Simple_Types msg;
  362. uint8_t referee[] = {0x49, 0xFF, 0xFF}; // End half way through a fixed size value.
  363. for(auto r: referee) {
  364. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(r), Return(true)));
  365. }
  366. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(Return(false));
  367. EXPECT_EQ(::EmbeddedProto::Error::END_OF_BUFFER, msg.deserialize(buffer));
  368. }
  369. TEST(SimpleTypes, deserialize_fault_end_of_buffer_bool)
  370. {
  371. InSequence s;
  372. Mocks::ReadBufferMock buffer;
  373. ON_CALL(buffer, get_size()).WillByDefault(Return(58));
  374. ::Test_Simple_Types msg;
  375. uint8_t referee[] = {0x38}; // Just the tag of a bool but no data
  376. for(auto r: referee) {
  377. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(r), Return(true)));
  378. }
  379. EXPECT_CALL(buffer, pop(_)).Times(1).WillOnce(Return(false));
  380. EXPECT_EQ(::EmbeddedProto::Error::END_OF_BUFFER, msg.deserialize(buffer));
  381. }
  382. } // End of namespace test_EmbeddedAMS_SimpleTypes