unit-pointer_access.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /*
  2. __ _____ _____ _____
  3. __| | __| | | | JSON for Modern C++ (test suite)
  4. | | |__ | | | | | | version 3.7.3
  5. |_____|_____|_____|_|___| https://github.com/nlohmann/json
  6. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
  7. SPDX-License-Identifier: MIT
  8. Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
  9. Permission is hereby granted, free of charge, to any person obtaining a copy
  10. of this software and associated documentation files (the "Software"), to deal
  11. in the Software without restriction, including without limitation the rights
  12. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. copies of the Software, and to permit persons to whom the Software is
  14. furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in all
  16. copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. SOFTWARE.
  24. */
  25. #include "doctest_compatibility.h"
  26. #include <nlohmann/json.hpp>
  27. using nlohmann::json;
  28. TEST_CASE("pointer access")
  29. {
  30. SECTION("pointer access to object_t")
  31. {
  32. using test_type = json::object_t;
  33. json value = {{"one", 1}, {"two", 2}};
  34. // check if pointers are returned correctly
  35. test_type* p1 = value.get_ptr<test_type*>();
  36. CHECK(p1 == value.get_ptr<test_type*>());
  37. CHECK(*p1 == value.get<test_type>());
  38. const test_type* p2 = value.get_ptr<const test_type*>();
  39. CHECK(p2 == value.get_ptr<const test_type*>());
  40. CHECK(*p2 == value.get<test_type>());
  41. const test_type* const p3 = value.get_ptr<const test_type* const>();
  42. CHECK(p3 == value.get_ptr<const test_type* const>());
  43. CHECK(*p3 == value.get<test_type>());
  44. // check if null pointers are returned correctly
  45. CHECK(value.get_ptr<json::object_t*>() != nullptr);
  46. CHECK(value.get_ptr<json::array_t*>() == nullptr);
  47. CHECK(value.get_ptr<json::string_t*>() == nullptr);
  48. CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
  49. CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
  50. CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
  51. CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
  52. CHECK(value.get_ptr<json::binary_t*>() == nullptr);
  53. }
  54. SECTION("pointer access to const object_t")
  55. {
  56. using test_type = const json::object_t;
  57. const json value = {{"one", 1}, {"two", 2}};
  58. // check if pointers are returned correctly
  59. test_type* p1 = value.get_ptr<test_type*>();
  60. CHECK(p1 == value.get_ptr<test_type*>());
  61. CHECK(*p1 == value.get<test_type>());
  62. const test_type* p2 = value.get_ptr<const test_type*>();
  63. CHECK(p2 == value.get_ptr<const test_type*>());
  64. CHECK(*p2 == value.get<test_type>());
  65. const test_type* const p3 = value.get_ptr<const test_type* const>();
  66. CHECK(p3 == value.get_ptr<const test_type* const>());
  67. CHECK(*p3 == value.get<test_type>());
  68. // check if null pointers are returned correctly
  69. CHECK(value.get_ptr<const json::object_t*>() != nullptr);
  70. CHECK(value.get_ptr<const json::array_t*>() == nullptr);
  71. CHECK(value.get_ptr<const json::string_t*>() == nullptr);
  72. CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
  73. CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
  74. CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
  75. CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
  76. CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
  77. }
  78. SECTION("pointer access to array_t")
  79. {
  80. using test_type = json::array_t;
  81. json value = {1, 2, 3, 4};
  82. // check if pointers are returned correctly
  83. test_type* p1 = value.get_ptr<test_type*>();
  84. CHECK(p1 == value.get_ptr<test_type*>());
  85. CHECK(*p1 == value.get<test_type>());
  86. const test_type* p2 = value.get_ptr<const test_type*>();
  87. CHECK(p2 == value.get_ptr<const test_type*>());
  88. CHECK(*p2 == value.get<test_type>());
  89. const test_type* const p3 = value.get_ptr<const test_type* const>();
  90. CHECK(p3 == value.get_ptr<const test_type* const>());
  91. CHECK(*p3 == value.get<test_type>());
  92. // check if null pointers are returned correctly
  93. CHECK(value.get_ptr<json::object_t*>() == nullptr);
  94. CHECK(value.get_ptr<json::array_t*>() != nullptr);
  95. CHECK(value.get_ptr<json::string_t*>() == nullptr);
  96. CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
  97. CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
  98. CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
  99. CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
  100. CHECK(value.get_ptr<json::binary_t*>() == nullptr);
  101. }
  102. SECTION("pointer access to const array_t")
  103. {
  104. using test_type = const json::array_t;
  105. const json value = {1, 2, 3, 4};
  106. // check if pointers are returned correctly
  107. test_type* p1 = value.get_ptr<test_type*>();
  108. CHECK(p1 == value.get_ptr<test_type*>());
  109. CHECK(*p1 == value.get<test_type>());
  110. const test_type* p2 = value.get_ptr<const test_type*>();
  111. CHECK(p2 == value.get_ptr<const test_type*>());
  112. CHECK(*p2 == value.get<test_type>());
  113. const test_type* const p3 = value.get_ptr<const test_type* const>();
  114. CHECK(p3 == value.get_ptr<const test_type* const>());
  115. CHECK(*p3 == value.get<test_type>());
  116. // check if null pointers are returned correctly
  117. CHECK(value.get_ptr<const json::object_t*>() == nullptr);
  118. CHECK(value.get_ptr<const json::array_t*>() != nullptr);
  119. CHECK(value.get_ptr<const json::string_t*>() == nullptr);
  120. CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
  121. CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
  122. CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
  123. CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
  124. CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
  125. }
  126. SECTION("pointer access to string_t")
  127. {
  128. using test_type = json::string_t;
  129. json value = "hello";
  130. // check if pointers are returned correctly
  131. test_type* p1 = value.get_ptr<test_type*>();
  132. CHECK(p1 == value.get_ptr<test_type*>());
  133. CHECK(*p1 == value.get<test_type>());
  134. const test_type* p2 = value.get_ptr<const test_type*>();
  135. CHECK(p2 == value.get_ptr<const test_type*>());
  136. CHECK(*p2 == value.get<test_type>());
  137. const test_type* const p3 = value.get_ptr<const test_type* const>();
  138. CHECK(p3 == value.get_ptr<const test_type* const>());
  139. CHECK(*p3 == value.get<test_type>());
  140. // check if null pointers are returned correctly
  141. CHECK(value.get_ptr<json::object_t*>() == nullptr);
  142. CHECK(value.get_ptr<json::array_t*>() == nullptr);
  143. CHECK(value.get_ptr<json::string_t*>() != nullptr);
  144. CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
  145. CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
  146. CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
  147. CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
  148. CHECK(value.get_ptr<json::binary_t*>() == nullptr);
  149. }
  150. SECTION("pointer access to const string_t")
  151. {
  152. using test_type = const json::string_t;
  153. const json value = "hello";
  154. // check if pointers are returned correctly
  155. test_type* p1 = value.get_ptr<test_type*>();
  156. CHECK(p1 == value.get_ptr<test_type*>());
  157. CHECK(*p1 == value.get<test_type>());
  158. const test_type* p2 = value.get_ptr<const test_type*>();
  159. CHECK(p2 == value.get_ptr<const test_type*>());
  160. CHECK(*p2 == value.get<test_type>());
  161. const test_type* const p3 = value.get_ptr<const test_type* const>();
  162. CHECK(p3 == value.get_ptr<const test_type* const>());
  163. CHECK(*p3 == value.get<test_type>());
  164. // check if null pointers are returned correctly
  165. CHECK(value.get_ptr<const json::object_t*>() == nullptr);
  166. CHECK(value.get_ptr<const json::array_t*>() == nullptr);
  167. CHECK(value.get_ptr<const json::string_t*>() != nullptr);
  168. CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
  169. CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
  170. CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
  171. CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
  172. CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
  173. }
  174. SECTION("pointer access to boolean_t")
  175. {
  176. using test_type = json::boolean_t;
  177. json value = false;
  178. // check if pointers are returned correctly
  179. test_type* p1 = value.get_ptr<test_type*>();
  180. CHECK(p1 == value.get_ptr<test_type*>());
  181. CHECK(*p1 == value.get<test_type>());
  182. const test_type* p2 = value.get_ptr<const test_type*>();
  183. CHECK(p2 == value.get_ptr<const test_type*>());
  184. CHECK(*p2 == value.get<test_type>());
  185. const test_type* const p3 = value.get_ptr<const test_type* const>();
  186. CHECK(p3 == value.get_ptr<const test_type* const>());
  187. CHECK(*p3 == value.get<test_type>());
  188. // check if null pointers are returned correctly
  189. CHECK(value.get_ptr<json::object_t*>() == nullptr);
  190. CHECK(value.get_ptr<json::array_t*>() == nullptr);
  191. CHECK(value.get_ptr<json::string_t*>() == nullptr);
  192. CHECK(value.get_ptr<json::boolean_t*>() != nullptr);
  193. CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
  194. CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
  195. CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
  196. CHECK(value.get_ptr<json::binary_t*>() == nullptr);
  197. }
  198. SECTION("pointer access to const boolean_t")
  199. {
  200. using test_type = const json::boolean_t;
  201. const json value = false;
  202. // check if pointers are returned correctly
  203. test_type* p1 = value.get_ptr<test_type*>();
  204. CHECK(p1 == value.get_ptr<test_type*>());
  205. //CHECK(*p1 == value.get<test_type>());
  206. const test_type* p2 = value.get_ptr<const test_type*>();
  207. CHECK(p2 == value.get_ptr<const test_type*>());
  208. CHECK(*p2 == value.get<test_type>());
  209. const test_type* const p3 = value.get_ptr<const test_type* const>();
  210. CHECK(p3 == value.get_ptr<const test_type* const>());
  211. CHECK(*p3 == value.get<test_type>());
  212. // check if null pointers are returned correctly
  213. CHECK(value.get_ptr<const json::object_t*>() == nullptr);
  214. CHECK(value.get_ptr<const json::array_t*>() == nullptr);
  215. CHECK(value.get_ptr<const json::string_t*>() == nullptr);
  216. CHECK(value.get_ptr<const json::boolean_t*>() != nullptr);
  217. CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
  218. CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
  219. CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
  220. CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
  221. }
  222. SECTION("pointer access to number_integer_t")
  223. {
  224. using test_type = json::number_integer_t;
  225. json value = 23;
  226. // check if pointers are returned correctly
  227. test_type* p1 = value.get_ptr<test_type*>();
  228. CHECK(p1 == value.get_ptr<test_type*>());
  229. CHECK(*p1 == value.get<test_type>());
  230. const test_type* p2 = value.get_ptr<const test_type*>();
  231. CHECK(p2 == value.get_ptr<const test_type*>());
  232. CHECK(*p2 == value.get<test_type>());
  233. const test_type* const p3 = value.get_ptr<const test_type* const>();
  234. CHECK(p3 == value.get_ptr<const test_type* const>());
  235. CHECK(*p3 == value.get<test_type>());
  236. // check if null pointers are returned correctly
  237. CHECK(value.get_ptr<json::object_t*>() == nullptr);
  238. CHECK(value.get_ptr<json::array_t*>() == nullptr);
  239. CHECK(value.get_ptr<json::string_t*>() == nullptr);
  240. CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
  241. CHECK(value.get_ptr<json::number_integer_t*>() != nullptr);
  242. CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
  243. CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
  244. CHECK(value.get_ptr<json::binary_t*>() == nullptr);
  245. }
  246. SECTION("pointer access to const number_integer_t")
  247. {
  248. using test_type = const json::number_integer_t;
  249. const json value = 23;
  250. // check if pointers are returned correctly
  251. test_type* p1 = value.get_ptr<test_type*>();
  252. CHECK(p1 == value.get_ptr<test_type*>());
  253. CHECK(*p1 == value.get<test_type>());
  254. const test_type* p2 = value.get_ptr<const test_type*>();
  255. CHECK(p2 == value.get_ptr<const test_type*>());
  256. CHECK(*p2 == value.get<test_type>());
  257. const test_type* const p3 = value.get_ptr<const test_type* const>();
  258. CHECK(p3 == value.get_ptr<const test_type* const>());
  259. CHECK(*p3 == value.get<test_type>());
  260. // check if null pointers are returned correctly
  261. CHECK(value.get_ptr<const json::object_t*>() == nullptr);
  262. CHECK(value.get_ptr<const json::array_t*>() == nullptr);
  263. CHECK(value.get_ptr<const json::string_t*>() == nullptr);
  264. CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
  265. CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr);
  266. CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
  267. CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
  268. CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
  269. }
  270. SECTION("pointer access to number_unsigned_t")
  271. {
  272. using test_type = json::number_unsigned_t;
  273. json value = 23u;
  274. // check if pointers are returned correctly
  275. test_type* p1 = value.get_ptr<test_type*>();
  276. CHECK(p1 == value.get_ptr<test_type*>());
  277. CHECK(*p1 == value.get<test_type>());
  278. const test_type* p2 = value.get_ptr<const test_type*>();
  279. CHECK(p2 == value.get_ptr<const test_type*>());
  280. CHECK(*p2 == value.get<test_type>());
  281. const test_type* const p3 = value.get_ptr<const test_type* const>();
  282. CHECK(p3 == value.get_ptr<const test_type* const>());
  283. CHECK(*p3 == value.get<test_type>());
  284. // check if null pointers are returned correctly
  285. CHECK(value.get_ptr<json::object_t*>() == nullptr);
  286. CHECK(value.get_ptr<json::array_t*>() == nullptr);
  287. CHECK(value.get_ptr<json::string_t*>() == nullptr);
  288. CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
  289. CHECK(value.get_ptr<json::number_integer_t*>() != nullptr);
  290. CHECK(value.get_ptr<json::number_unsigned_t*>() != nullptr);
  291. CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
  292. CHECK(value.get_ptr<json::binary_t*>() == nullptr);
  293. }
  294. SECTION("pointer access to const number_unsigned_t")
  295. {
  296. using test_type = const json::number_unsigned_t;
  297. const json value = 23u;
  298. // check if pointers are returned correctly
  299. test_type* p1 = value.get_ptr<test_type*>();
  300. CHECK(p1 == value.get_ptr<test_type*>());
  301. CHECK(*p1 == value.get<test_type>());
  302. const test_type* p2 = value.get_ptr<const test_type*>();
  303. CHECK(p2 == value.get_ptr<const test_type*>());
  304. CHECK(*p2 == value.get<test_type>());
  305. const test_type* const p3 = value.get_ptr<const test_type* const>();
  306. CHECK(p3 == value.get_ptr<const test_type* const>());
  307. CHECK(*p3 == value.get<test_type>());
  308. // check if null pointers are returned correctly
  309. CHECK(value.get_ptr<const json::object_t*>() == nullptr);
  310. CHECK(value.get_ptr<const json::array_t*>() == nullptr);
  311. CHECK(value.get_ptr<const json::string_t*>() == nullptr);
  312. CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
  313. CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr);
  314. CHECK(value.get_ptr<const json::number_unsigned_t*>() != nullptr);
  315. CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
  316. CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
  317. }
  318. SECTION("pointer access to number_float_t")
  319. {
  320. using test_type = json::number_float_t;
  321. json value = 42.23;
  322. // check if pointers are returned correctly
  323. test_type* p1 = value.get_ptr<test_type*>();
  324. CHECK(p1 == value.get_ptr<test_type*>());
  325. CHECK(*p1 == Approx(value.get<test_type>()));
  326. const test_type* p2 = value.get_ptr<const test_type*>();
  327. CHECK(p2 == value.get_ptr<const test_type*>());
  328. CHECK(*p2 == Approx(value.get<test_type>()));
  329. const test_type* const p3 = value.get_ptr<const test_type* const>();
  330. CHECK(p3 == value.get_ptr<const test_type* const>());
  331. CHECK(*p3 == Approx(value.get<test_type>()));
  332. // check if null pointers are returned correctly
  333. CHECK(value.get_ptr<json::object_t*>() == nullptr);
  334. CHECK(value.get_ptr<json::array_t*>() == nullptr);
  335. CHECK(value.get_ptr<json::string_t*>() == nullptr);
  336. CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
  337. CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
  338. CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
  339. CHECK(value.get_ptr<json::number_float_t*>() != nullptr);
  340. CHECK(value.get_ptr<json::binary_t*>() == nullptr);
  341. }
  342. SECTION("pointer access to const number_float_t")
  343. {
  344. using test_type = const json::number_float_t;
  345. const json value = 42.23;
  346. // check if pointers are returned correctly
  347. test_type* p1 = value.get_ptr<test_type*>();
  348. CHECK(p1 == value.get_ptr<test_type*>());
  349. CHECK(*p1 == Approx(value.get<test_type>()));
  350. const test_type* p2 = value.get_ptr<const test_type*>();
  351. CHECK(p2 == value.get_ptr<const test_type*>());
  352. CHECK(*p2 == Approx(value.get<test_type>()));
  353. const test_type* const p3 = value.get_ptr<const test_type* const>();
  354. CHECK(p3 == value.get_ptr<const test_type* const>());
  355. CHECK(*p3 == Approx(value.get<test_type>()));
  356. // check if null pointers are returned correctly
  357. CHECK(value.get_ptr<const json::object_t*>() == nullptr);
  358. CHECK(value.get_ptr<const json::array_t*>() == nullptr);
  359. CHECK(value.get_ptr<const json::string_t*>() == nullptr);
  360. CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
  361. CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
  362. CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
  363. CHECK(value.get_ptr<const json::number_float_t*>() != nullptr);
  364. CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
  365. }
  366. SECTION("pointer access to const binary_t")
  367. {
  368. using test_type = const json::binary_t;
  369. const json value = json::binary({1, 2, 3});
  370. // check if pointers are returned correctly
  371. test_type* p1 = value.get_ptr<test_type*>();
  372. CHECK(p1 == value.get_ptr<test_type*>());
  373. CHECK(*p1 == value.get<test_type>());
  374. const test_type* p2 = value.get_ptr<const test_type*>();
  375. CHECK(p2 == value.get_ptr<const test_type*>());
  376. CHECK(*p2 == value.get<test_type>());
  377. const test_type* const p3 = value.get_ptr<const test_type* const>();
  378. CHECK(p3 == value.get_ptr<const test_type* const>());
  379. CHECK(*p3 == value.get<test_type>());
  380. // check if null pointers are returned correctly
  381. CHECK(value.get_ptr<const json::object_t*>() == nullptr);
  382. CHECK(value.get_ptr<const json::array_t*>() == nullptr);
  383. CHECK(value.get_ptr<const json::string_t*>() == nullptr);
  384. CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
  385. CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
  386. CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
  387. CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
  388. CHECK(value.get_ptr<const json::binary_t*>() != nullptr);
  389. }
  390. SECTION("pointer access to const binary_t")
  391. {
  392. using test_type = const json::binary_t;
  393. const json value = json::binary({});
  394. // check if pointers are returned correctly
  395. test_type* p1 = value.get_ptr<test_type*>();
  396. CHECK(p1 == value.get_ptr<test_type*>());
  397. CHECK(*p1 == value.get<test_type>());
  398. const test_type* p2 = value.get_ptr<const test_type*>();
  399. CHECK(p2 == value.get_ptr<const test_type*>());
  400. CHECK(*p2 == value.get<test_type>());
  401. const test_type* const p3 = value.get_ptr<const test_type* const>();
  402. CHECK(p3 == value.get_ptr<const test_type* const>());
  403. CHECK(*p3 == value.get<test_type>());
  404. // check if null pointers are returned correctly
  405. CHECK(value.get_ptr<const json::object_t*>() == nullptr);
  406. CHECK(value.get_ptr<const json::array_t*>() == nullptr);
  407. CHECK(value.get_ptr<const json::string_t*>() == nullptr);
  408. CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
  409. CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
  410. CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
  411. CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
  412. CHECK(value.get_ptr<const json::binary_t*>() != nullptr);
  413. }
  414. }