Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
949c0833
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,发现更多精彩内容 >>
提交
949c0833
编写于
4月 27, 2017
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move 'hooks' parameter into buffers (parse/print)
上级
c4c217f2
变更
11
展开全部
显示空白变更内容
内联
并排
Showing
11 changed file
with
122 addition
and
98 deletion
+122
-98
cJSON.c
cJSON.c
+69
-63
tests/parse_array.c
tests/parse_array.c
+6
-4
tests/parse_number.c
tests/parse_number.c
+1
-1
tests/parse_object.c
tests/parse_object.c
+6
-4
tests/parse_string.c
tests/parse_string.c
+6
-4
tests/parse_value.c
tests/parse_value.c
+4
-2
tests/print_array.c
tests/print_array.c
+9
-6
tests/print_number.c
tests/print_number.c
+3
-2
tests/print_object.c
tests/print_object.c
+9
-6
tests/print_string.c
tests/print_string.c
+3
-2
tests/print_value.c
tests/print_value.c
+6
-4
未找到文件。
cJSON.c
浏览文件 @
949c0833
此差异已折叠。
点击以展开。
tests/parse_array.c
浏览文件 @
949c0833
...
...
@@ -44,21 +44,23 @@ static void assert_is_array(cJSON *array_item)
static
void
assert_not_array
(
const
char
*
json
)
{
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
};
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
buffer
.
content
=
(
const
unsigned
char
*
)
json
;
buffer
.
length
=
strlen
(
json
)
+
sizeof
(
""
);
buffer
.
hooks
=
global_hooks
;
TEST_ASSERT_FALSE
(
parse_array
(
item
,
&
buffer
,
&
global_hooks
));
TEST_ASSERT_FALSE
(
parse_array
(
item
,
&
buffer
));
assert_is_invalid
(
item
);
}
static
void
assert_parse_array
(
const
char
*
json
)
{
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
};
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
buffer
.
content
=
(
const
unsigned
char
*
)
json
;
buffer
.
length
=
strlen
(
json
)
+
sizeof
(
""
);
buffer
.
hooks
=
global_hooks
;
TEST_ASSERT_TRUE
(
parse_array
(
item
,
&
buffer
,
&
global_hooks
));
TEST_ASSERT_TRUE
(
parse_array
(
item
,
&
buffer
));
assert_is_array
(
item
);
}
...
...
tests/parse_number.c
浏览文件 @
949c0833
...
...
@@ -45,7 +45,7 @@ static void assert_is_number(cJSON *number_item)
static
void
assert_parse_number
(
const
char
*
string
,
int
integer
,
double
real
)
{
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
};
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
buffer
.
content
=
(
const
unsigned
char
*
)
string
;
buffer
.
length
=
strlen
(
string
)
+
sizeof
(
""
);
...
...
tests/parse_object.c
浏览文件 @
949c0833
...
...
@@ -52,22 +52,24 @@ static void assert_is_child(cJSON *child_item, const char *name, int type)
static
void
assert_not_object
(
const
char
*
json
)
{
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
};
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
parsebuffer
.
content
=
(
const
unsigned
char
*
)
json
;
parsebuffer
.
length
=
strlen
(
json
)
+
sizeof
(
""
);
parsebuffer
.
hooks
=
global_hooks
;
TEST_ASSERT_FALSE
(
parse_object
(
item
,
&
parsebuffer
,
&
global_hooks
));
TEST_ASSERT_FALSE
(
parse_object
(
item
,
&
parsebuffer
));
assert_is_invalid
(
item
);
reset
(
item
);
}
static
void
assert_parse_object
(
const
char
*
json
)
{
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
};
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
parsebuffer
.
content
=
(
const
unsigned
char
*
)
json
;
parsebuffer
.
length
=
strlen
(
json
)
+
sizeof
(
""
);
parsebuffer
.
hooks
=
global_hooks
;
TEST_ASSERT_TRUE
(
parse_object
(
item
,
&
parsebuffer
,
&
global_hooks
));
TEST_ASSERT_TRUE
(
parse_object
(
item
,
&
parsebuffer
));
assert_is_object
(
item
);
}
...
...
tests/parse_string.c
浏览文件 @
949c0833
...
...
@@ -45,11 +45,12 @@ static void assert_is_string(cJSON *string_item)
static
void
assert_parse_string
(
const
char
*
string
,
const
char
*
expected
)
{
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
};
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
buffer
.
content
=
(
const
unsigned
char
*
)
string
;
buffer
.
length
=
strlen
(
string
)
+
sizeof
(
""
);
buffer
.
hooks
=
global_hooks
;
TEST_ASSERT_TRUE_MESSAGE
(
parse_string
(
item
,
&
buffer
,
&
global_hooks
),
"Couldn't parse string."
);
TEST_ASSERT_TRUE_MESSAGE
(
parse_string
(
item
,
&
buffer
),
"Couldn't parse string."
);
assert_is_string
(
item
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
expected
,
item
->
valuestring
,
"The parsed result isn't as expected."
);
global_hooks
.
deallocate
(
item
->
valuestring
);
...
...
@@ -58,11 +59,12 @@ static void assert_parse_string(const char *string, const char *expected)
static
void
assert_not_parse_string
(
const
char
*
const
string
)
{
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
};
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
buffer
.
content
=
(
const
unsigned
char
*
)
string
;
buffer
.
length
=
strlen
(
string
)
+
sizeof
(
""
);
buffer
.
hooks
=
global_hooks
;
TEST_ASSERT_FALSE_MESSAGE
(
parse_string
(
item
,
&
buffer
,
&
global_hooks
),
"Malformed string should not be accepted."
);
TEST_ASSERT_FALSE_MESSAGE
(
parse_string
(
item
,
&
buffer
),
"Malformed string should not be accepted."
);
assert_is_invalid
(
item
);
}
...
...
tests/parse_value.c
浏览文件 @
949c0833
...
...
@@ -43,10 +43,12 @@ static void assert_is_value(cJSON *value_item, int type)
static
void
assert_parse_value
(
const
char
*
string
,
int
type
)
{
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
};
parse_buffer
buffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
buffer
.
content
=
(
const
unsigned
char
*
)
string
;
buffer
.
length
=
strlen
(
string
)
+
sizeof
(
""
);
TEST_ASSERT_TRUE
(
parse_value
(
item
,
&
buffer
,
&
global_hooks
));
buffer
.
hooks
=
global_hooks
;
TEST_ASSERT_TRUE
(
parse_value
(
item
,
&
buffer
));
assert_is_value
(
item
,
type
);
}
...
...
tests/print_array.c
浏览文件 @
949c0833
...
...
@@ -31,34 +31,37 @@ static void assert_print_array(const char * const expected, const char * const i
cJSON
item
[
1
];
printbuffer
formatted_buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
};
printbuffer
unformatted_buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
};
printbuffer
formatted_buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
printbuffer
unformatted_buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
};
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
parsebuffer
.
content
=
(
const
unsigned
char
*
)
input
;
parsebuffer
.
length
=
strlen
(
input
)
+
sizeof
(
""
);
parsebuffer
.
hooks
=
global_hooks
;
/* buffer for formatted printing */
formatted_buffer
.
buffer
=
printed_formatted
;
formatted_buffer
.
length
=
sizeof
(
printed_formatted
);
formatted_buffer
.
offset
=
0
;
formatted_buffer
.
noalloc
=
true
;
formatted_buffer
.
hooks
=
global_hooks
;
/* buffer for unformatted printing */
unformatted_buffer
.
buffer
=
printed_unformatted
;
unformatted_buffer
.
length
=
sizeof
(
printed_unformatted
);
unformatted_buffer
.
offset
=
0
;
unformatted_buffer
.
noalloc
=
true
;
unformatted_buffer
.
hooks
=
global_hooks
;
memset
(
item
,
0
,
sizeof
(
item
));
TEST_ASSERT_TRUE_MESSAGE
(
parse_array
(
item
,
&
parsebuffer
,
&
global_hooks
),
"Failed to parse array."
);
TEST_ASSERT_TRUE_MESSAGE
(
parse_array
(
item
,
&
parsebuffer
),
"Failed to parse array."
);
unformatted_buffer
.
format
=
false
;
TEST_ASSERT_TRUE_MESSAGE
(
print_array
(
item
,
&
unformatted_buffer
,
&
global_hooks
),
"Failed to print unformatted string."
);
TEST_ASSERT_TRUE_MESSAGE
(
print_array
(
item
,
&
unformatted_buffer
),
"Failed to print unformatted string."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
input
,
printed_unformatted
,
"Unformatted array is not correct."
);
formatted_buffer
.
format
=
true
;
TEST_ASSERT_TRUE_MESSAGE
(
print_array
(
item
,
&
formatted_buffer
,
&
global_hooks
),
"Failed to print formatted string."
);
TEST_ASSERT_TRUE_MESSAGE
(
print_array
(
item
,
&
formatted_buffer
),
"Failed to print formatted string."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
expected
,
printed_formatted
,
"Formatted array is not correct."
);
reset
(
item
);
...
...
tests/print_number.c
浏览文件 @
949c0833
...
...
@@ -28,16 +28,17 @@ static void assert_print_number(const char *expected, double input)
{
unsigned
char
printed
[
1024
];
cJSON
item
[
1
];
printbuffer
buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
};
printbuffer
buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
buffer
.
buffer
=
printed
;
buffer
.
length
=
sizeof
(
printed
);
buffer
.
offset
=
0
;
buffer
.
noalloc
=
true
;
buffer
.
hooks
=
global_hooks
;
memset
(
item
,
0
,
sizeof
(
item
));
cJSON_SetNumberValue
(
item
,
input
);
TEST_ASSERT_TRUE_MESSAGE
(
print_number
(
item
,
&
buffer
,
&
global_hooks
),
"Failed to print number."
);
TEST_ASSERT_TRUE_MESSAGE
(
print_number
(
item
,
&
buffer
),
"Failed to print number."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
expected
,
buffer
.
buffer
,
"Printed number is not as expected."
);
}
...
...
tests/print_object.c
浏览文件 @
949c0833
...
...
@@ -31,35 +31,38 @@ static void assert_print_object(const char * const expected, const char * const
cJSON
item
[
1
];
printbuffer
formatted_buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
};
printbuffer
unformatted_buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
};
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
};
printbuffer
formatted_buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
printbuffer
unformatted_buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
/* buffer for parsing */
parsebuffer
.
content
=
(
const
unsigned
char
*
)
input
;
parsebuffer
.
length
=
strlen
(
input
)
+
sizeof
(
""
);
parsebuffer
.
hooks
=
global_hooks
;
/* buffer for formatted printing */
formatted_buffer
.
buffer
=
printed_formatted
;
formatted_buffer
.
length
=
sizeof
(
printed_formatted
);
formatted_buffer
.
offset
=
0
;
formatted_buffer
.
noalloc
=
true
;
formatted_buffer
.
hooks
=
global_hooks
;
/* buffer for unformatted printing */
unformatted_buffer
.
buffer
=
printed_unformatted
;
unformatted_buffer
.
length
=
sizeof
(
printed_unformatted
);
unformatted_buffer
.
offset
=
0
;
unformatted_buffer
.
noalloc
=
true
;
unformatted_buffer
.
hooks
=
global_hooks
;
memset
(
item
,
0
,
sizeof
(
item
));
TEST_ASSERT_TRUE_MESSAGE
(
parse_object
(
item
,
&
parsebuffer
,
&
global_hooks
),
"Failed to parse object."
);
TEST_ASSERT_TRUE_MESSAGE
(
parse_object
(
item
,
&
parsebuffer
),
"Failed to parse object."
);
unformatted_buffer
.
format
=
false
;
TEST_ASSERT_TRUE_MESSAGE
(
print_object
(
item
,
&
unformatted_buffer
,
&
global_hooks
),
"Failed to print unformatted string."
);
TEST_ASSERT_TRUE_MESSAGE
(
print_object
(
item
,
&
unformatted_buffer
),
"Failed to print unformatted string."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
input
,
printed_unformatted
,
"Unformatted object is not correct."
);
formatted_buffer
.
format
=
true
;
TEST_ASSERT_TRUE_MESSAGE
(
print_object
(
item
,
&
formatted_buffer
,
&
global_hooks
),
"Failed to print formatted string."
);
TEST_ASSERT_TRUE_MESSAGE
(
print_object
(
item
,
&
formatted_buffer
),
"Failed to print formatted string."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
expected
,
printed_formatted
,
"Formatted ojbect is not correct."
);
reset
(
item
);
...
...
tests/print_string.c
浏览文件 @
949c0833
...
...
@@ -27,13 +27,14 @@
static
void
assert_print_string
(
const
char
*
expected
,
const
char
*
input
)
{
unsigned
char
printed
[
1024
];
printbuffer
buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
};
printbuffer
buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
buffer
.
buffer
=
printed
;
buffer
.
length
=
sizeof
(
printed
);
buffer
.
offset
=
0
;
buffer
.
noalloc
=
true
;
buffer
.
hooks
=
global_hooks
;
TEST_ASSERT_TRUE_MESSAGE
(
print_string_ptr
((
const
unsigned
char
*
)
input
,
&
buffer
,
&
global_hooks
),
"Failed to print string."
);
TEST_ASSERT_TRUE_MESSAGE
(
print_string_ptr
((
const
unsigned
char
*
)
input
,
&
buffer
),
"Failed to print string."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
expected
,
printed
,
"The printed string isn't as expected."
);
}
...
...
tests/print_value.c
浏览文件 @
949c0833
...
...
@@ -32,21 +32,23 @@ static void assert_print_value(const char *input)
{
unsigned
char
printed
[
1024
];
cJSON
item
[
1
];
printbuffer
buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
};
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
};
printbuffer
buffer
=
{
0
,
0
,
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
parse_buffer
parsebuffer
=
{
0
,
0
,
0
,
0
,
{
0
,
0
,
0
}
};
buffer
.
buffer
=
printed
;
buffer
.
length
=
sizeof
(
printed
);
buffer
.
offset
=
0
;
buffer
.
noalloc
=
true
;
buffer
.
hooks
=
global_hooks
;
parsebuffer
.
content
=
(
const
unsigned
char
*
)
input
;
parsebuffer
.
length
=
strlen
(
input
)
+
sizeof
(
""
);
parsebuffer
.
hooks
=
global_hooks
;
memset
(
item
,
0
,
sizeof
(
item
));
TEST_ASSERT_TRUE_MESSAGE
(
parse_value
(
item
,
&
parsebuffer
,
&
global_hooks
),
"Failed to parse value."
);
TEST_ASSERT_TRUE_MESSAGE
(
parse_value
(
item
,
&
parsebuffer
),
"Failed to parse value."
);
TEST_ASSERT_TRUE_MESSAGE
(
print_value
(
item
,
&
buffer
,
&
global_hooks
),
"Failed to print value."
);
TEST_ASSERT_TRUE_MESSAGE
(
print_value
(
item
,
&
buffer
),
"Failed to print value."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
input
,
buffer
.
buffer
,
"Printed value is not as expected."
);
reset
(
item
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录