mirror of
https://github.com/zlgopen/awtk.git
synced 2025-05-08 19:44:45 +08:00
improve conf json
This commit is contained in:
parent
18abdd25e1
commit
2182c46dfc
@ -104,12 +104,12 @@ if OS_NAME == 'Darwin':
|
||||
sdl_path = "/opt/homebrew/Cellar/sdl2/"
|
||||
if not os.path.exists(sdl_path) :
|
||||
# Compatible with old systems
|
||||
sdl_path = '/usr/local/Cellar/sdl2/'
|
||||
sdl_path = '/usr/local/Cellar/sdl2'
|
||||
sdl_versions = os.listdir(sdl_path)
|
||||
if len(sdl_versions)==0:
|
||||
print("Can not find the SDL version")
|
||||
exit(-1)
|
||||
sdl_lib = sdl_path + sdl_versions[0] + "/lib"
|
||||
sdl_lib = sdl_path+ sdl_versions[0]+"/lib"
|
||||
|
||||
TOOLS_NAME = ''
|
||||
OS_FLAGS = '-Wall -Wno-unused-function -fPIC -DWITHOUT_GLAD=1 '
|
||||
|
@ -1,5 +1,8 @@
|
||||
# 最新动态
|
||||
|
||||
2024/11/21
|
||||
* 完善conf_json(感谢兆坤提供补丁)
|
||||
|
||||
2024/11/19
|
||||
* 增加函数 str_append_format_padding
|
||||
* 增加 atomic_compare_exchange(感谢兆坤提供补丁)
|
||||
|
@ -55,6 +55,7 @@ static ret_t conf_json_parse_name(json_parser_t* parser) {
|
||||
}
|
||||
|
||||
str_set_with_len(s, parser->data + parser->cursor, i - parser->cursor);
|
||||
str_unescape(s);
|
||||
parser->cursor = i + 1;
|
||||
node = conf_doc_create_node(parser->doc, s->str);
|
||||
return_value_if_fail(node != NULL, RET_OOM);
|
||||
@ -447,9 +448,11 @@ static ret_t conf_json_save_node(conf_node_t* node, str_t* str, uint32_t level,
|
||||
|
||||
if (indent > 0) {
|
||||
return_value_if_fail(conf_json_write_indent(str, level, indent) == RET_OK, RET_OOM);
|
||||
return_value_if_fail(str_append_more(str, "\"", name, "\" : ", NULL) == RET_OK, RET_OOM);
|
||||
return_value_if_fail(str_append_json_str(str, name) == RET_OK, RET_OOM);
|
||||
return_value_if_fail(str_append(str, " : ") == RET_OK, RET_OOM);
|
||||
} else {
|
||||
return_value_if_fail(str_append_more(str, "\"", name, "\":", NULL) == RET_OK, RET_OOM);
|
||||
return_value_if_fail(str_append_json_str(str, name) == RET_OK, RET_OOM);
|
||||
return_value_if_fail(str_append(str, ":") == RET_OK, RET_OOM);
|
||||
}
|
||||
|
||||
return conf_json_save_node_value(node, str, level, indent);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "tkc/named_value.h"
|
||||
#include "conf_io/conf_json.h"
|
||||
#include "tkc/object_default.h"
|
||||
|
||||
TEST(ConfJson, arr) {
|
||||
value_t v;
|
||||
@ -402,6 +403,9 @@ TEST(Json, save_as) {
|
||||
ASSERT_NE(conf, (tk_object_t*)NULL);
|
||||
ASSERT_EQ(tk_object_set_prop_int(conf, "value", 123), RET_OK);
|
||||
ASSERT_EQ(tk_object_get_prop_int(conf, "value", 0), 123);
|
||||
ASSERT_EQ(tk_object_set_prop_str(conf, "config\\awtk", "430bf786fb5f536c84ee0846f11f12aa"),
|
||||
RET_OK);
|
||||
ASSERT_STREQ(tk_object_get_prop_str(conf, "config\\awtk"), "430bf786fb5f536c84ee0846f11f12aa");
|
||||
wbuffer_init_extendable(&wb);
|
||||
data_writer_wbuffer_build_url(&wb, url);
|
||||
|
||||
@ -413,10 +417,37 @@ TEST(Json, save_as) {
|
||||
ASSERT_NE(conf, (tk_object_t*)NULL);
|
||||
|
||||
ASSERT_EQ(tk_object_get_prop_int(conf, "value", 0), 123);
|
||||
ASSERT_STREQ(tk_object_get_prop_str(conf, "config\\awtk"), "430bf786fb5f536c84ee0846f11f12aa");
|
||||
wbuffer_deinit(&wb);
|
||||
TK_OBJECT_UNREF(conf);
|
||||
}
|
||||
|
||||
TEST(Json, object_from_json) {
|
||||
char url[MAX_PATH + 1] = {0};
|
||||
tk_object_t* conf = NULL;
|
||||
tk_object_t* obj = object_default_create_ex(FALSE);
|
||||
str_t str_json;
|
||||
|
||||
str_init(&str_json, 0);
|
||||
|
||||
tk_object_set_prop_str(obj, "config\\awtk.json", "430bf786fb5f536c84ee0846f11f12aa");
|
||||
object_to_json(obj, &str_json);
|
||||
|
||||
data_reader_mem_build_url(str_json.str, str_json.size, url);
|
||||
conf = conf_json_load(url, FALSE);
|
||||
|
||||
TK_OBJECT_UNREF(obj);
|
||||
obj = object_default_create_ex(FALSE);
|
||||
tk_object_copy_props(obj, conf, TRUE);
|
||||
|
||||
ASSERT_STREQ(tk_object_get_prop_str(obj, "config\\awtk.json"),
|
||||
"430bf786fb5f536c84ee0846f11f12aa");
|
||||
|
||||
str_reset(&str_json);
|
||||
TK_OBJECT_UNREF(obj);
|
||||
TK_OBJECT_UNREF(conf);
|
||||
}
|
||||
|
||||
TEST(ConfJson, find) {
|
||||
value_t v;
|
||||
const char* data = "{\"tom\": {\"name\":{\"first\":\"bill\", \"last\":\"tom\"}, \"age\":100}} ";
|
||||
@ -810,6 +841,5 @@ TEST(Json, format) {
|
||||
ASSERT_STREQ((char*)(wb.data), "{\n \"age\" : \"123\"\n}");
|
||||
TK_OBJECT_UNREF(conf);
|
||||
|
||||
|
||||
wbuffer_deinit(&wb);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user