1c5f01b2fSopenharmony_ci// __ _____ _____ _____ 2c5f01b2fSopenharmony_ci// __| | __| | | | JSON for Modern C++ (supporting code) 3c5f01b2fSopenharmony_ci// | | |__ | | | | | | version 3.11.2 4c5f01b2fSopenharmony_ci// |_____|_____|_____|_|___| https://github.com/nlohmann/json 5c5f01b2fSopenharmony_ci// 6c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> 7c5f01b2fSopenharmony_ci// SPDX-License-Identifier: MIT 8c5f01b2fSopenharmony_ci 9c5f01b2fSopenharmony_ci#include "doctest_compatibility.h" 10c5f01b2fSopenharmony_ci 11c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp> 12c5f01b2fSopenharmony_ciusing nlohmann::json; 13c5f01b2fSopenharmony_ci 14c5f01b2fSopenharmony_ciTEST_CASE("pointer access") 15c5f01b2fSopenharmony_ci{ 16c5f01b2fSopenharmony_ci SECTION("pointer access to object_t") 17c5f01b2fSopenharmony_ci { 18c5f01b2fSopenharmony_ci using test_type = json::object_t; 19c5f01b2fSopenharmony_ci json value = {{"one", 1}, {"two", 2}}; 20c5f01b2fSopenharmony_ci 21c5f01b2fSopenharmony_ci // check if pointers are returned correctly 22c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 23c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 24c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 25c5f01b2fSopenharmony_ci 26c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 27c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 28c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 29c5f01b2fSopenharmony_ci 30c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 31c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 32c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 33c5f01b2fSopenharmony_ci 34c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 35c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::object_t*>() != nullptr); 36c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::array_t*>() == nullptr); 37c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::string_t*>() == nullptr); 38c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::boolean_t*>() == nullptr); 39c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_integer_t*>() == nullptr); 40c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr); 41c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_float_t*>() == nullptr); 42c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::binary_t*>() == nullptr); 43c5f01b2fSopenharmony_ci } 44c5f01b2fSopenharmony_ci 45c5f01b2fSopenharmony_ci SECTION("pointer access to const object_t") 46c5f01b2fSopenharmony_ci { 47c5f01b2fSopenharmony_ci using test_type = const json::object_t; 48c5f01b2fSopenharmony_ci const json value = {{"one", 1}, {"two", 2}}; 49c5f01b2fSopenharmony_ci 50c5f01b2fSopenharmony_ci // check if pointers are returned correctly 51c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 52c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 53c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 54c5f01b2fSopenharmony_ci 55c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 56c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 57c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 58c5f01b2fSopenharmony_ci 59c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 60c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 61c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 62c5f01b2fSopenharmony_ci 63c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 64c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::object_t*>() != nullptr); 65c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::array_t*>() == nullptr); 66c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::string_t*>() == nullptr); 67c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::boolean_t*>() == nullptr); 68c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr); 69c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr); 70c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_float_t*>() == nullptr); 71c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::binary_t*>() == nullptr); 72c5f01b2fSopenharmony_ci } 73c5f01b2fSopenharmony_ci 74c5f01b2fSopenharmony_ci SECTION("pointer access to array_t") 75c5f01b2fSopenharmony_ci { 76c5f01b2fSopenharmony_ci using test_type = json::array_t; 77c5f01b2fSopenharmony_ci json value = {1, 2, 3, 4}; 78c5f01b2fSopenharmony_ci 79c5f01b2fSopenharmony_ci // check if pointers are returned correctly 80c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 81c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 82c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 83c5f01b2fSopenharmony_ci 84c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 85c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 86c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 87c5f01b2fSopenharmony_ci 88c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 89c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 90c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 91c5f01b2fSopenharmony_ci 92c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 93c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::object_t*>() == nullptr); 94c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::array_t*>() != nullptr); 95c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::string_t*>() == nullptr); 96c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::boolean_t*>() == nullptr); 97c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_integer_t*>() == nullptr); 98c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr); 99c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_float_t*>() == nullptr); 100c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::binary_t*>() == nullptr); 101c5f01b2fSopenharmony_ci } 102c5f01b2fSopenharmony_ci 103c5f01b2fSopenharmony_ci SECTION("pointer access to const array_t") 104c5f01b2fSopenharmony_ci { 105c5f01b2fSopenharmony_ci using test_type = const json::array_t; 106c5f01b2fSopenharmony_ci const json value = {1, 2, 3, 4}; 107c5f01b2fSopenharmony_ci 108c5f01b2fSopenharmony_ci // check if pointers are returned correctly 109c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 110c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 111c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 112c5f01b2fSopenharmony_ci 113c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 114c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 115c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 116c5f01b2fSopenharmony_ci 117c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 118c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 119c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 120c5f01b2fSopenharmony_ci 121c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 122c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::object_t*>() == nullptr); 123c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::array_t*>() != nullptr); 124c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::string_t*>() == nullptr); 125c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::boolean_t*>() == nullptr); 126c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr); 127c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr); 128c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_float_t*>() == nullptr); 129c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::binary_t*>() == nullptr); 130c5f01b2fSopenharmony_ci } 131c5f01b2fSopenharmony_ci 132c5f01b2fSopenharmony_ci SECTION("pointer access to string_t") 133c5f01b2fSopenharmony_ci { 134c5f01b2fSopenharmony_ci using test_type = json::string_t; 135c5f01b2fSopenharmony_ci json value = "hello"; 136c5f01b2fSopenharmony_ci 137c5f01b2fSopenharmony_ci // check if pointers are returned correctly 138c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 139c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 140c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 141c5f01b2fSopenharmony_ci 142c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 143c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 144c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 145c5f01b2fSopenharmony_ci 146c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 147c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 148c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 149c5f01b2fSopenharmony_ci 150c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 151c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::object_t*>() == nullptr); 152c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::array_t*>() == nullptr); 153c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::string_t*>() != nullptr); 154c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::boolean_t*>() == nullptr); 155c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_integer_t*>() == nullptr); 156c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr); 157c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_float_t*>() == nullptr); 158c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::binary_t*>() == nullptr); 159c5f01b2fSopenharmony_ci } 160c5f01b2fSopenharmony_ci 161c5f01b2fSopenharmony_ci SECTION("pointer access to const string_t") 162c5f01b2fSopenharmony_ci { 163c5f01b2fSopenharmony_ci using test_type = const json::string_t; 164c5f01b2fSopenharmony_ci const json value = "hello"; 165c5f01b2fSopenharmony_ci 166c5f01b2fSopenharmony_ci // check if pointers are returned correctly 167c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 168c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 169c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 170c5f01b2fSopenharmony_ci 171c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 172c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 173c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 174c5f01b2fSopenharmony_ci 175c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 176c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 177c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 178c5f01b2fSopenharmony_ci 179c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 180c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::object_t*>() == nullptr); 181c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::array_t*>() == nullptr); 182c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::string_t*>() != nullptr); 183c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::boolean_t*>() == nullptr); 184c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr); 185c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr); 186c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_float_t*>() == nullptr); 187c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::binary_t*>() == nullptr); 188c5f01b2fSopenharmony_ci } 189c5f01b2fSopenharmony_ci 190c5f01b2fSopenharmony_ci SECTION("pointer access to boolean_t") 191c5f01b2fSopenharmony_ci { 192c5f01b2fSopenharmony_ci using test_type = json::boolean_t; 193c5f01b2fSopenharmony_ci json value = false; 194c5f01b2fSopenharmony_ci 195c5f01b2fSopenharmony_ci // check if pointers are returned correctly 196c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 197c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 198c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 199c5f01b2fSopenharmony_ci 200c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 201c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 202c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 203c5f01b2fSopenharmony_ci 204c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 205c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 206c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 207c5f01b2fSopenharmony_ci 208c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 209c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::object_t*>() == nullptr); 210c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::array_t*>() == nullptr); 211c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::string_t*>() == nullptr); 212c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::boolean_t*>() != nullptr); 213c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_integer_t*>() == nullptr); 214c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr); 215c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_float_t*>() == nullptr); 216c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::binary_t*>() == nullptr); 217c5f01b2fSopenharmony_ci } 218c5f01b2fSopenharmony_ci 219c5f01b2fSopenharmony_ci SECTION("pointer access to const boolean_t") 220c5f01b2fSopenharmony_ci { 221c5f01b2fSopenharmony_ci using test_type = const json::boolean_t; 222c5f01b2fSopenharmony_ci const json value = false; 223c5f01b2fSopenharmony_ci 224c5f01b2fSopenharmony_ci // check if pointers are returned correctly 225c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 226c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 227c5f01b2fSopenharmony_ci //CHECK(*p1 == value.get<test_type>()); 228c5f01b2fSopenharmony_ci 229c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 230c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 231c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 232c5f01b2fSopenharmony_ci 233c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 234c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 235c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 236c5f01b2fSopenharmony_ci 237c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 238c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::object_t*>() == nullptr); 239c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::array_t*>() == nullptr); 240c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::string_t*>() == nullptr); 241c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::boolean_t*>() != nullptr); 242c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr); 243c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr); 244c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_float_t*>() == nullptr); 245c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::binary_t*>() == nullptr); 246c5f01b2fSopenharmony_ci } 247c5f01b2fSopenharmony_ci 248c5f01b2fSopenharmony_ci SECTION("pointer access to number_integer_t") 249c5f01b2fSopenharmony_ci { 250c5f01b2fSopenharmony_ci using test_type = json::number_integer_t; 251c5f01b2fSopenharmony_ci json value = 23; 252c5f01b2fSopenharmony_ci 253c5f01b2fSopenharmony_ci // check if pointers are returned correctly 254c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 255c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 256c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 257c5f01b2fSopenharmony_ci 258c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 259c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 260c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 261c5f01b2fSopenharmony_ci 262c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 263c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 264c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 265c5f01b2fSopenharmony_ci 266c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 267c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::object_t*>() == nullptr); 268c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::array_t*>() == nullptr); 269c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::string_t*>() == nullptr); 270c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::boolean_t*>() == nullptr); 271c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_integer_t*>() != nullptr); 272c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr); 273c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_float_t*>() == nullptr); 274c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::binary_t*>() == nullptr); 275c5f01b2fSopenharmony_ci } 276c5f01b2fSopenharmony_ci 277c5f01b2fSopenharmony_ci SECTION("pointer access to const number_integer_t") 278c5f01b2fSopenharmony_ci { 279c5f01b2fSopenharmony_ci using test_type = const json::number_integer_t; 280c5f01b2fSopenharmony_ci const json value = 23; 281c5f01b2fSopenharmony_ci 282c5f01b2fSopenharmony_ci // check if pointers are returned correctly 283c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 284c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 285c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 286c5f01b2fSopenharmony_ci 287c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 288c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 289c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 290c5f01b2fSopenharmony_ci 291c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 292c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 293c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 294c5f01b2fSopenharmony_ci 295c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 296c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::object_t*>() == nullptr); 297c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::array_t*>() == nullptr); 298c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::string_t*>() == nullptr); 299c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::boolean_t*>() == nullptr); 300c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr); 301c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr); 302c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_float_t*>() == nullptr); 303c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::binary_t*>() == nullptr); 304c5f01b2fSopenharmony_ci } 305c5f01b2fSopenharmony_ci 306c5f01b2fSopenharmony_ci SECTION("pointer access to number_unsigned_t") 307c5f01b2fSopenharmony_ci { 308c5f01b2fSopenharmony_ci using test_type = json::number_unsigned_t; 309c5f01b2fSopenharmony_ci json value = 23u; 310c5f01b2fSopenharmony_ci 311c5f01b2fSopenharmony_ci // check if pointers are returned correctly 312c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 313c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 314c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 315c5f01b2fSopenharmony_ci 316c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 317c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 318c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 319c5f01b2fSopenharmony_ci 320c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 321c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 322c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 323c5f01b2fSopenharmony_ci 324c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 325c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::object_t*>() == nullptr); 326c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::array_t*>() == nullptr); 327c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::string_t*>() == nullptr); 328c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::boolean_t*>() == nullptr); 329c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_integer_t*>() != nullptr); 330c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_unsigned_t*>() != nullptr); 331c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_float_t*>() == nullptr); 332c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::binary_t*>() == nullptr); 333c5f01b2fSopenharmony_ci } 334c5f01b2fSopenharmony_ci 335c5f01b2fSopenharmony_ci SECTION("pointer access to const number_unsigned_t") 336c5f01b2fSopenharmony_ci { 337c5f01b2fSopenharmony_ci using test_type = const json::number_unsigned_t; 338c5f01b2fSopenharmony_ci const json value = 23u; 339c5f01b2fSopenharmony_ci 340c5f01b2fSopenharmony_ci // check if pointers are returned correctly 341c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 342c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 343c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 344c5f01b2fSopenharmony_ci 345c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 346c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 347c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 348c5f01b2fSopenharmony_ci 349c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 350c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 351c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 352c5f01b2fSopenharmony_ci 353c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 354c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::object_t*>() == nullptr); 355c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::array_t*>() == nullptr); 356c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::string_t*>() == nullptr); 357c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::boolean_t*>() == nullptr); 358c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr); 359c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_unsigned_t*>() != nullptr); 360c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_float_t*>() == nullptr); 361c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::binary_t*>() == nullptr); 362c5f01b2fSopenharmony_ci } 363c5f01b2fSopenharmony_ci 364c5f01b2fSopenharmony_ci SECTION("pointer access to number_float_t") 365c5f01b2fSopenharmony_ci { 366c5f01b2fSopenharmony_ci using test_type = json::number_float_t; 367c5f01b2fSopenharmony_ci json value = 42.23; 368c5f01b2fSopenharmony_ci 369c5f01b2fSopenharmony_ci // check if pointers are returned correctly 370c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 371c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 372c5f01b2fSopenharmony_ci CHECK(*p1 == Approx(value.get<test_type>())); 373c5f01b2fSopenharmony_ci 374c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 375c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 376c5f01b2fSopenharmony_ci CHECK(*p2 == Approx(value.get<test_type>())); 377c5f01b2fSopenharmony_ci 378c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 379c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 380c5f01b2fSopenharmony_ci CHECK(*p3 == Approx(value.get<test_type>())); 381c5f01b2fSopenharmony_ci 382c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 383c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::object_t*>() == nullptr); 384c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::array_t*>() == nullptr); 385c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::string_t*>() == nullptr); 386c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::boolean_t*>() == nullptr); 387c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_integer_t*>() == nullptr); 388c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr); 389c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::number_float_t*>() != nullptr); 390c5f01b2fSopenharmony_ci CHECK(value.get_ptr<json::binary_t*>() == nullptr); 391c5f01b2fSopenharmony_ci } 392c5f01b2fSopenharmony_ci 393c5f01b2fSopenharmony_ci SECTION("pointer access to const number_float_t") 394c5f01b2fSopenharmony_ci { 395c5f01b2fSopenharmony_ci using test_type = const json::number_float_t; 396c5f01b2fSopenharmony_ci const json value = 42.23; 397c5f01b2fSopenharmony_ci 398c5f01b2fSopenharmony_ci // check if pointers are returned correctly 399c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 400c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 401c5f01b2fSopenharmony_ci CHECK(*p1 == Approx(value.get<test_type>())); 402c5f01b2fSopenharmony_ci 403c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 404c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 405c5f01b2fSopenharmony_ci CHECK(*p2 == Approx(value.get<test_type>())); 406c5f01b2fSopenharmony_ci 407c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 408c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 409c5f01b2fSopenharmony_ci CHECK(*p3 == Approx(value.get<test_type>())); 410c5f01b2fSopenharmony_ci 411c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 412c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::object_t*>() == nullptr); 413c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::array_t*>() == nullptr); 414c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::string_t*>() == nullptr); 415c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::boolean_t*>() == nullptr); 416c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr); 417c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr); 418c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_float_t*>() != nullptr); 419c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::binary_t*>() == nullptr); 420c5f01b2fSopenharmony_ci } 421c5f01b2fSopenharmony_ci 422c5f01b2fSopenharmony_ci SECTION("pointer access to const binary_t") 423c5f01b2fSopenharmony_ci { 424c5f01b2fSopenharmony_ci using test_type = const json::binary_t; 425c5f01b2fSopenharmony_ci const json value = json::binary({1, 2, 3}); 426c5f01b2fSopenharmony_ci 427c5f01b2fSopenharmony_ci // check if pointers are returned correctly 428c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 429c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 430c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 431c5f01b2fSopenharmony_ci 432c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 433c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 434c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 435c5f01b2fSopenharmony_ci 436c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 437c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 438c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 439c5f01b2fSopenharmony_ci 440c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 441c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::object_t*>() == nullptr); 442c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::array_t*>() == nullptr); 443c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::string_t*>() == nullptr); 444c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::boolean_t*>() == nullptr); 445c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr); 446c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr); 447c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_float_t*>() == nullptr); 448c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::binary_t*>() != nullptr); 449c5f01b2fSopenharmony_ci } 450c5f01b2fSopenharmony_ci 451c5f01b2fSopenharmony_ci SECTION("pointer access to const binary_t") 452c5f01b2fSopenharmony_ci { 453c5f01b2fSopenharmony_ci using test_type = const json::binary_t; 454c5f01b2fSopenharmony_ci const json value = json::binary({}); 455c5f01b2fSopenharmony_ci 456c5f01b2fSopenharmony_ci // check if pointers are returned correctly 457c5f01b2fSopenharmony_ci test_type* p1 = value.get_ptr<test_type*>(); 458c5f01b2fSopenharmony_ci CHECK(p1 == value.get_ptr<test_type*>()); 459c5f01b2fSopenharmony_ci CHECK(*p1 == value.get<test_type>()); 460c5f01b2fSopenharmony_ci 461c5f01b2fSopenharmony_ci const test_type* p2 = value.get_ptr<const test_type*>(); 462c5f01b2fSopenharmony_ci CHECK(p2 == value.get_ptr<const test_type*>()); 463c5f01b2fSopenharmony_ci CHECK(*p2 == value.get<test_type>()); 464c5f01b2fSopenharmony_ci 465c5f01b2fSopenharmony_ci const test_type* const p3 = value.get_ptr<const test_type* const>(); 466c5f01b2fSopenharmony_ci CHECK(p3 == value.get_ptr<const test_type* const>()); 467c5f01b2fSopenharmony_ci CHECK(*p3 == value.get<test_type>()); 468c5f01b2fSopenharmony_ci 469c5f01b2fSopenharmony_ci // check if null pointers are returned correctly 470c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::object_t*>() == nullptr); 471c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::array_t*>() == nullptr); 472c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::string_t*>() == nullptr); 473c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::boolean_t*>() == nullptr); 474c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr); 475c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr); 476c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::number_float_t*>() == nullptr); 477c5f01b2fSopenharmony_ci CHECK(value.get_ptr<const json::binary_t*>() != nullptr); 478c5f01b2fSopenharmony_ci } 479c5f01b2fSopenharmony_ci} 480