Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
3cd2a977
Unverified
Commit
3cd2a977
authored
May 06, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
add test for get_ptr<binary_t*>
parent
1d6f7b0d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
44 deletions
+45
-44
test/src/unit-pointer_access.cpp
test/src/unit-pointer_access.cpp
+45
-44
No files found.
test/src/unit-pointer_access.cpp
View file @
3cd2a977
...
...
@@ -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
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -76,6 +60,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const object_t"
)
...
...
@@ -89,11 +74,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -104,6 +89,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
const
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to array_t"
)
...
...
@@ -117,11 +103,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -132,6 +118,8 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const array_t"
)
...
...
@@ -145,11 +133,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -160,6 +148,8 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
const
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to string_t"
)
...
...
@@ -173,11 +163,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -188,6 +178,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const string_t"
)
...
...
@@ -201,11 +192,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -216,6 +207,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
const
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to boolean_t"
)
...
...
@@ -229,11 +221,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -244,6 +236,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const boolean_t"
)
...
...
@@ -257,11 +250,11 @@ TEST_CASE("pointer access")
//CHECK(*p1 == value.get<test_type>());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -272,6 +265,8 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
const
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
binary_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to number_integer_t"
)
...
...
@@ -285,11 +280,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -300,6 +295,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_integer_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const number_integer_t"
)
...
...
@@ -313,11 +309,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -328,6 +324,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
const
json
::
number_integer_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to number_unsigned_t"
)
...
...
@@ -341,11 +338,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -356,6 +353,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_integer_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_unsigned_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const number_unsigned_t"
)
...
...
@@ -369,11 +367,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
value
.
get
<
test_type
>
());
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
...
...
@@ -384,6 +382,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
const
json
::
number_integer_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_unsigned_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_float_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to number_float_t"
)
...
...
@@ -397,11 +396,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
Approx
(
value
.
get
<
test_type
>
()));
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
Approx
(
value
.
get
<
test_type
>
()));
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
Approx
(
value
.
get
<
test_type
>
()));
// check if null pointers are returned correctly
...
...
@@ -412,6 +411,7 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
binary_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const number_float_t"
)
...
...
@@ -425,11 +425,11 @@ TEST_CASE("pointer access")
CHECK
(
*
p1
==
Approx
(
value
.
get
<
test_type
>
()));
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p
2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
*
p2
==
Approx
(
value
.
get
<
test_type
>
()));
const
test_type
*
const
p3
=
value
.
get_ptr
<
const
test_type
*
const
>
();
CHECK
(
p
1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
p
3
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
Approx
(
value
.
get
<
test_type
>
()));
// check if null pointers are returned correctly
...
...
@@ -440,5 +440,6 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
const
json
::
number_integer_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
number_float_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
binary_t
*>
()
==
nullptr
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment