From 3cd2a977ae9fd65e6313f2712a184d6c841debd8 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 6 May 2020 22:13:55 +0200 Subject: [PATCH] :white_check_mark: add test for get_ptr --- test/src/unit-pointer_access.cpp | 89 ++++++++++++++++---------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/test/src/unit-pointer_access.cpp b/test/src/unit-pointer_access.cpp index 778bef7ba..95fdb7805 100644 --- a/test/src/unit-pointer_access.cpp +++ b/test/src/unit-pointer_access.cpp @@ -34,22 +34,6 @@ using nlohmann::json; TEST_CASE("pointer access") { - // create a JSON value with different types - json json_types = - { - {"boolean", true}, - { - "number", { - {"integer", 42}, - {"unsigned", 42u}, - {"floating-point", 17.23} - } - }, - {"string", "Hello, world!"}, - {"array", {1, 2, 3, 4, 5}}, - {"null", nullptr} - }; - SECTION("pointer access to object_t") { using test_type = json::object_t; @@ -61,11 +45,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -76,6 +60,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to const object_t") @@ -89,11 +74,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -104,6 +89,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to array_t") @@ -117,11 +103,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -132,6 +118,8 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + } SECTION("pointer access to const array_t") @@ -145,11 +133,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -160,6 +148,8 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + } SECTION("pointer access to string_t") @@ -173,11 +163,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -188,6 +178,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to const string_t") @@ -201,11 +192,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -216,6 +207,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to boolean_t") @@ -229,11 +221,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -244,6 +236,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to const boolean_t") @@ -257,11 +250,11 @@ TEST_CASE("pointer access") //CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -272,6 +265,8 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to number_integer_t") @@ -285,11 +280,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -300,6 +295,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() != nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to const number_integer_t") @@ -313,11 +309,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -328,6 +324,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() != nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to number_unsigned_t") @@ -341,11 +338,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -356,6 +353,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() != nullptr); CHECK(value.get_ptr() != nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to const number_unsigned_t") @@ -369,11 +367,11 @@ TEST_CASE("pointer access") CHECK(*p1 == value.get()); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == value.get()); // check if null pointers are returned correctly @@ -384,6 +382,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() != nullptr); CHECK(value.get_ptr() != nullptr); CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to number_float_t") @@ -397,11 +396,11 @@ TEST_CASE("pointer access") CHECK(*p1 == Approx(value.get())); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == Approx(value.get())); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == Approx(value.get())); // check if null pointers are returned correctly @@ -412,6 +411,7 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() != nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to const number_float_t") @@ -425,11 +425,11 @@ TEST_CASE("pointer access") CHECK(*p1 == Approx(value.get())); const test_type* p2 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p2 == value.get_ptr()); CHECK(*p2 == Approx(value.get())); const test_type* const p3 = value.get_ptr(); - CHECK(p1 == value.get_ptr()); + CHECK(p3 == value.get_ptr()); CHECK(*p3 == Approx(value.get())); // check if null pointers are returned correctly @@ -440,5 +440,6 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() != nullptr); + CHECK(value.get_ptr() == nullptr); } }