Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
43754e78
T
Third Party CJSON
项目概览
OpenHarmony
/
Third Party CJSON
大约 1 年 前同步成功
通知
6
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party CJSON
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
43754e78
编写于
12月 31, 2017
作者:
M
Max Bruckner
提交者:
GitHub
12月 31, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #215 from DaveGamble/new-documentation
New documentation
上级
a1a1e60c
1e953636
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
542 addition
and
186 deletion
+542
-186
README.md
README.md
+283
-186
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-0
tests/readme_examples.c
tests/readme_examples.c
+258
-0
未找到文件。
README.md
浏览文件 @
43754e78
此差异已折叠。
点击以展开。
tests/CMakeLists.txt
浏览文件 @
43754e78
...
...
@@ -56,6 +56,7 @@ if(ENABLE_CJSON_TEST)
parse_with_opts
compare_tests
cjson_add
readme_examples
)
option
(
ENABLE_VALGRIND OFF
"Enable the valgrind memory checker for the tests."
)
...
...
tests/readme_examples.c
0 → 100644
浏览文件 @
43754e78
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "unity/examples/unity_config.h"
#include "unity/src/unity.h"
#include "common.h"
static
const
char
*
json
=
"{
\n
\
\t\"
name
\"
:
\t\"
Awesome 4K
\"
,
\n
\
\t\"
resolutions
\"
:
\t
[{
\n
\
\t\t\t\"
width
\"
:
\t
1280,
\n
\
\t\t\t\"
height
\"
:
\t
720
\n
\
\t\t
}, {
\n
\
\t\t\t\"
width
\"
:
\t
1920,
\n
\
\t\t\t\"
height
\"
:
\t
1080
\n
\
\t\t
}, {
\n
\
\t\t\t\"
width
\"
:
\t
3840,
\n
\
\t\t\t\"
height
\"
:
\t
2160
\n
\
\t\t
}]
\n
\
}"
;
static
char
*
create_monitor
(
void
)
{
const
unsigned
int
resolution_numbers
[
3
][
2
]
=
{
{
1280
,
720
},
{
1920
,
1080
},
{
3840
,
2160
}
};
char
*
string
=
NULL
;
cJSON
*
name
=
NULL
;
cJSON
*
resolutions
=
NULL
;
cJSON
*
resolution
=
NULL
;
cJSON
*
width
=
NULL
;
cJSON
*
height
=
NULL
;
size_t
index
=
0
;
cJSON
*
monitor
=
cJSON_CreateObject
();
if
(
monitor
==
NULL
)
{
goto
end
;
}
name
=
cJSON_CreateString
(
"Awesome 4K"
);
if
(
name
==
NULL
)
{
goto
end
;
}
/* after creation was successful, immediately add it to the monitor,
* thereby transfering ownership of the pointer to it */
cJSON_AddItemToObject
(
monitor
,
"name"
,
name
);
resolutions
=
cJSON_CreateArray
();
if
(
resolutions
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
monitor
,
"resolutions"
,
resolutions
);
for
(
index
=
0
;
index
<
(
sizeof
(
resolution_numbers
)
/
(
2
*
sizeof
(
int
)));
++
index
)
{
resolution
=
cJSON_CreateObject
();
if
(
resolution
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToArray
(
resolutions
,
resolution
);
width
=
cJSON_CreateNumber
(
resolution_numbers
[
index
][
0
]);
if
(
width
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
resolution
,
"width"
,
width
);
height
=
cJSON_CreateNumber
(
resolution_numbers
[
index
][
1
]);
if
(
height
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
resolution
,
"height"
,
height
);
}
string
=
cJSON_Print
(
monitor
);
if
(
string
==
NULL
)
{
fprintf
(
stderr
,
"Failed to print monitor.
\n
"
);
}
end:
cJSON_Delete
(
monitor
);
return
string
;
}
static
char
*
create_monitor_with_helpers
(
void
)
{
const
unsigned
int
resolution_numbers
[
3
][
2
]
=
{
{
1280
,
720
},
{
1920
,
1080
},
{
3840
,
2160
}
};
char
*
string
=
NULL
;
cJSON
*
resolutions
=
NULL
;
size_t
index
=
0
;
cJSON
*
monitor
=
cJSON_CreateObject
();
if
(
cJSON_AddStringToObject
(
monitor
,
"name"
,
"Awesome 4K"
)
==
NULL
)
{
goto
end
;
}
resolutions
=
cJSON_AddArrayToObject
(
monitor
,
"resolutions"
);
if
(
resolutions
==
NULL
)
{
goto
end
;
}
for
(
index
=
0
;
index
<
(
sizeof
(
resolution_numbers
)
/
(
2
*
sizeof
(
int
)));
++
index
)
{
cJSON
*
resolution
=
cJSON_CreateObject
();
if
(
cJSON_AddNumberToObject
(
resolution
,
"width"
,
resolution_numbers
[
index
][
0
])
==
NULL
)
{
goto
end
;
}
if
(
cJSON_AddNumberToObject
(
resolution
,
"height"
,
resolution_numbers
[
index
][
1
])
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToArray
(
resolutions
,
resolution
);
}
string
=
cJSON_Print
(
monitor
);
if
(
string
==
NULL
)
{
fprintf
(
stderr
,
"Failed to print monitor.
\n
"
);
}
end:
cJSON_Delete
(
monitor
);
return
string
;
}
/* return 1 if the monitor supports full hd, 0 otherwise */
static
int
supports_full_hd
(
const
char
*
const
monitor
)
{
const
cJSON
*
resolution
=
NULL
;
const
cJSON
*
resolutions
=
NULL
;
const
cJSON
*
name
=
NULL
;
int
status
=
0
;
cJSON
*
monitor_json
=
cJSON_Parse
(
monitor
);
if
(
monitor_json
==
NULL
)
{
const
char
*
error_ptr
=
cJSON_GetErrorPtr
();
if
(
error_ptr
!=
NULL
)
{
fprintf
(
stderr
,
"Error before: %s
\n
"
,
error_ptr
);
}
status
=
0
;
goto
end
;
}
name
=
cJSON_GetObjectItemCaseSensitive
(
monitor_json
,
"name"
);
if
(
cJSON_IsString
(
name
)
&&
(
name
->
valuestring
!=
NULL
))
{
printf
(
"Checking monitor
\"
%s
\"\n
"
,
name
->
valuestring
);
}
resolutions
=
cJSON_GetObjectItemCaseSensitive
(
monitor_json
,
"resolutions"
);
cJSON_ArrayForEach
(
resolution
,
resolutions
)
{
cJSON
*
width
=
cJSON_GetObjectItemCaseSensitive
(
resolution
,
"width"
);
cJSON
*
height
=
cJSON_GetObjectItemCaseSensitive
(
resolution
,
"height"
);
if
(
!
cJSON_IsNumber
(
width
)
||
!
cJSON_IsNumber
(
height
))
{
status
=
0
;
goto
end
;
}
if
((
width
->
valuedouble
==
1920
)
&&
(
height
->
valuedouble
==
1080
))
{
status
=
1
;
goto
end
;
}
}
end:
cJSON_Delete
(
monitor_json
);
return
status
;
}
static
void
create_monitor_should_create_a_monitor
(
void
)
{
char
*
monitor
=
create_monitor
();
TEST_ASSERT_EQUAL_STRING
(
monitor
,
json
);
free
(
monitor
);
}
static
void
create_monitor_with_helpers_should_create_a_monitor
(
void
)
{
char
*
monitor
=
create_monitor_with_helpers
();
TEST_ASSERT_EQUAL_STRING
(
json
,
monitor
);
free
(
monitor
);
}
static
void
supports_full_hd_should_check_for_full_hd_support
(
void
)
{
static
const
char
*
monitor_without_hd
=
"{
\n
\
\t\t\"
name
\"
:
\"
lame monitor
\"
,
\n
\
\t\t\"
resolutions
\"
:
\t
[{
\n
\
\t\t\t\"
width
\"
:
\t
640,
\n
\
\t\t\t\"
height
\"
:
\t
480
\n
\
\t\t
}]
\n
\
}"
;
TEST_ASSERT
(
supports_full_hd
(
json
));
TEST_ASSERT_FALSE
(
supports_full_hd
(
monitor_without_hd
));
}
int
main
(
void
)
{
UNITY_BEGIN
();
RUN_TEST
(
create_monitor_should_create_a_monitor
);
RUN_TEST
(
create_monitor_with_helpers_should_create_a_monitor
);
RUN_TEST
(
supports_full_hd_should_check_for_full_hd_support
);
return
UNITY_END
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录