Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
46174879
J
json
项目概览
畅游知识海洋
/
json
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
json
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
46174879
编写于
8月 10, 2016
作者:
N
Niels
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean up
上级
5db41313
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
193 addition
and
25 deletion
+193
-25
.travis.yml
.travis.yml
+1
-19
README.md
README.md
+7
-1
test/src/unit-pointer_access.cpp
test/src/unit-pointer_access.cpp
+185
-5
未找到文件。
.travis.yml
浏览文件 @
46174879
...
...
@@ -41,25 +41,7 @@ matrix:
after_success
:
-
valgrind --error-exitcode=1 --leak-check=full test/json_unit
# Coveralls
#- os: linux
# compiler: gcc
# addons:
# apt:
# sources: ['ubuntu-toolchain-r-test']
# packages: ['g++-4.9', 'valgrind', 'python-pip', 'python-yaml']
# before_script:
# - pip install --user git+git://github.com/eddyxu/cpp-coveralls.git
# after_success:
# - make clean
# - touch src/json.hpp
# - make json_unit CXXFLAGS="-fprofile-arcs -ftest-coverage -std=c++11 -lstdc++" CXX=$COMPILER
# - test/json_unit "*"
# - coveralls --build-root test --exclude src/catch.hpp --exclude src/unit-algorithms.cpp --exclude src/unit-allocator.cpp --exclude src/unit-capacity.cpp --exclude src/unit-class_const_iterator.cpp --exclude src/unit-class_iterator.cpp --exclude src/unit-class_lexer.cpp --exclude src/unit-class_parser.cpp --exclude src/unit-comparison.cpp --exclude src/unit-concepts.cpp --exclude src/unit-constructor1.cpp --exclude src/unit-constructor2.cpp --exclude src/unit-convenience.cpp --exclude src/unit-conversions.cpp --exclude src/unit-deserialization.cpp --exclude src/unit-element_access1.cpp --exclude src/unit-element_access2.cpp --exclude src/unit-inspection.cpp --exclude src/unit-iterator_wrapper.cpp --exclude src/unit-iterators1.cpp --exclude src/unit-iterators2.cpp --exclude src/unit-json_patch.cpp --exclude src/unit-json_pointer.cpp --exclude src/unit-modifiers.cpp --exclude src/unit-pointer_access.cpp --exclude src/unit-readme.cpp --exclude src/unit-reference_access.cpp --exclude src/unit-regression.cpp --exclude src/unit-serialization.cpp --exclude src/unit-testsuites.cpp --exclude src/unit-unicode.cpp --include ../src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9'
# env:
# - COMPILER=g++-4.9
# - SPECIAL=coveralls
# Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/)
-
os
:
linux
compiler
:
gcc
...
...
README.md
浏览文件 @
46174879
...
...
@@ -416,7 +416,13 @@ The following compilers are currently used in continuous integration at [Travis]
| GCC 4.9.3 | Ubuntu 14.04.4 LTS | g++-4.9 (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3 |
| GCC 5.3.0 | Ubuntu 14.04.4 LTS | g++-5 (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204 |
| GCC 6.1.1 | Ubuntu 14.04.4 LTS | g++-6 (Ubuntu 6.1.1-3ubuntu11~14.04.1) 6.1.1 20160511 |
| Clang 3.6.0 | Ubuntu 14.04.4 LTS | clang version 3.6.0 (tags/RELEASE_360/final) |
| Clang 3.6.1 | Ubuntu 14.04.4 LTS | clang version 3.6.1 (tags/RELEASE_361/final) |
| Clang 3.6.2 | Ubuntu 14.04.4 LTS | clang version 3.6.2 (tags/RELEASE_362/final) |
| Clang 3.7.0 | Ubuntu 14.04.4 LTS | clang version 3.7.0 (tags/RELEASE_370/final) |
| Clang 3.7.1 | Ubuntu 14.04.4 LTS | clang version 3.7.1 (tags/RELEASE_371/final) |
| Clang 3.8.0 | Ubuntu 14.04.4 LTS | clang version 3.8.0 (tags/RELEASE_380/final) |
| Clang 3.8.1 | Ubuntu 14.04.4 LTS | clang version 3.8.1 (tags/RELEASE_381/final) |
| Clang Xcode 6.1 | Darwin Kernel Version 13.4.0 (OSX 10.9.5) | Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) |
| Clang Xcode 6.2 | Darwin Kernel Version 13.4.0 (OSX 10.9.5) | Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn) |
| Clang Xcode 6.3 | Darwin Kernel Version 14.3.0 (OSX 10.10.3) | Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn) |
...
...
@@ -504,7 +510,7 @@ To compile and run the tests, you need to execute
$
make check
===============================================================================
All tests passed
(
89050
12
assertions
in
32
test
cases
)
All tests passed
(
89050
99
assertions
in
32
test
cases
)
```
For more information, have a look at the file
[
.travis.yml
](
https://github.com/nlohmann/json/blob/master/.travis.yml
)
.
test/src/unit-pointer_access.cpp
浏览文件 @
46174879
...
...
@@ -79,18 +79,30 @@ TEST_CASE("pointer access")
SECTION
(
"pointer access to const object_t"
)
{
using
test_type
=
json
::
object_t
;
using
test_type
=
const
json
::
object_t
;
const
json
value
=
{{
"one"
,
1
},
{
"two"
,
2
}};
// this should not compile
// test_type* p1 = value.get_ptr<test_type*>();
// check if pointers are returned correctly
test_type
*
p1
=
value
.
get_ptr
<
test_type
*>
();
CHECK
(
p1
==
value
.
get_ptr
<
test_type
*>
());
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p1
==
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
(
p2
==
p3
);
CHECK
(
p1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
CHECK
(
value
.
get_ptr
<
const
json
::
object_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
array_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
string_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
boolean_t
*>
()
==
nullptr
);
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
);
}
SECTION
(
"pointer access to array_t"
)
...
...
@@ -121,6 +133,34 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const array_t"
)
{
using
test_type
=
const
json
::
array_t
;
const
json
value
=
{
1
,
2
,
3
,
4
};
// check if pointers are returned correctly
test_type
*
p1
=
value
.
get_ptr
<
test_type
*>
();
CHECK
(
p1
==
value
.
get_ptr
<
test_type
*>
());
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p1
==
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
(
p1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
CHECK
(
value
.
get_ptr
<
const
json
::
object_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
array_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
string_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
boolean_t
*>
()
==
nullptr
);
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
);
}
SECTION
(
"pointer access to string_t"
)
{
using
test_type
=
json
::
string_t
;
...
...
@@ -149,6 +189,34 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const string_t"
)
{
using
test_type
=
const
json
::
string_t
;
const
json
value
=
"hello"
;
// check if pointers are returned correctly
test_type
*
p1
=
value
.
get_ptr
<
test_type
*>
();
CHECK
(
p1
==
value
.
get_ptr
<
test_type
*>
());
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p1
==
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
(
p1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
CHECK
(
value
.
get_ptr
<
const
json
::
object_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
array_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
string_t
*>
()
!=
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
boolean_t
*>
()
==
nullptr
);
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
);
}
SECTION
(
"pointer access to boolean_t"
)
{
using
test_type
=
json
::
boolean_t
;
...
...
@@ -177,6 +245,34 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const boolean_t"
)
{
using
test_type
=
const
json
::
boolean_t
;
const
json
value
=
false
;
// check if pointers are returned correctly
test_type
*
p1
=
value
.
get_ptr
<
test_type
*>
();
CHECK
(
p1
==
value
.
get_ptr
<
test_type
*>
());
//CHECK(*p1 == value.get<test_type>());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p1
==
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
(
p1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
//CHECK(*p3 == value.get<test_type>());
// check if null pointers are returned correctly
CHECK
(
value
.
get_ptr
<
const
json
::
object_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
array_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
string_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
boolean_t
*>
()
!=
nullptr
);
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
);
}
SECTION
(
"pointer access to number_integer_t"
)
{
using
test_type
=
json
::
number_integer_t
;
...
...
@@ -205,6 +301,34 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const number_integer_t"
)
{
using
test_type
=
const
json
::
number_integer_t
;
const
json
value
=
23
;
// check if pointers are returned correctly
test_type
*
p1
=
value
.
get_ptr
<
test_type
*>
();
CHECK
(
p1
==
value
.
get_ptr
<
test_type
*>
());
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p1
==
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
(
p1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
CHECK
(
value
.
get_ptr
<
const
json
::
object_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
array_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
string_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
boolean_t
*>
()
==
nullptr
);
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
);
}
SECTION
(
"pointer access to number_unsigned_t"
)
{
using
test_type
=
json
::
number_unsigned_t
;
...
...
@@ -233,6 +357,34 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
==
nullptr
);
}
SECTION
(
"pointer access to const number_unsigned_t"
)
{
using
test_type
=
const
json
::
number_unsigned_t
;
const
json
value
=
23u
;
// check if pointers are returned correctly
test_type
*
p1
=
value
.
get_ptr
<
test_type
*>
();
CHECK
(
p1
==
value
.
get_ptr
<
test_type
*>
());
CHECK
(
*
p1
==
value
.
get
<
test_type
>
());
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p1
==
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
(
p1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
value
.
get
<
test_type
>
());
// check if null pointers are returned correctly
CHECK
(
value
.
get_ptr
<
const
json
::
object_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
array_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
string_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
boolean_t
*>
()
==
nullptr
);
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
);
}
SECTION
(
"pointer access to number_float_t"
)
{
using
test_type
=
json
::
number_float_t
;
...
...
@@ -260,4 +412,32 @@ TEST_CASE("pointer access")
CHECK
(
value
.
get_ptr
<
json
::
number_unsigned_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
json
::
number_float_t
*>
()
!=
nullptr
);
}
SECTION
(
"pointer access to const number_float_t"
)
{
using
test_type
=
const
json
::
number_float_t
;
const
json
value
=
42.23
;
// check if pointers are returned correctly
test_type
*
p1
=
value
.
get_ptr
<
test_type
*>
();
CHECK
(
p1
==
value
.
get_ptr
<
test_type
*>
());
CHECK
(
*
p1
==
Approx
(
value
.
get
<
test_type
>
()));
const
test_type
*
p2
=
value
.
get_ptr
<
const
test_type
*>
();
CHECK
(
p1
==
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
(
p1
==
value
.
get_ptr
<
const
test_type
*
const
>
());
CHECK
(
*
p3
==
Approx
(
value
.
get
<
test_type
>
()));
// check if null pointers are returned correctly
CHECK
(
value
.
get_ptr
<
const
json
::
object_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
array_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
string_t
*>
()
==
nullptr
);
CHECK
(
value
.
get_ptr
<
const
json
::
boolean_t
*>
()
==
nullptr
);
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
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录