mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
improve conf obj
This commit is contained in:
parent
ae85d1549a
commit
d9a0d794fb
@ -1,6 +1,7 @@
|
||||
# 最新动态
|
||||
2022/08/15
|
||||
* 完善conf_xml。
|
||||
* 完善conf\_xml。
|
||||
* 完善conf\_obj\_create\_sub\_object
|
||||
|
||||
2022/08/13
|
||||
* 修复bitmap高效lcd旋转的时候显示不正常的问题(感谢智明提供补丁)
|
||||
|
@ -472,12 +472,20 @@ tk_object_t* conf_sub_obj_create(tk_object_t* conf, const char* path) {
|
||||
tk_object_t* obj = NULL;
|
||||
conf_sub_obj_t* o = NULL;
|
||||
conf_node_t* root = NULL;
|
||||
conf_obj_t* conf_obj = CONF_OBJ(conf);
|
||||
return_value_if_fail(conf_obj != NULL && path != NULL, NULL);
|
||||
return_value_if_fail(conf_obj->doc != NULL && conf_obj->doc->root != NULL, NULL);
|
||||
conf_obj_t* conf_obj = NULL;
|
||||
return_value_if_fail(conf != NULL && path != NULL, NULL);
|
||||
|
||||
root = conf_doc_find_node(conf_obj->doc, conf_obj->doc->root, path, FALSE);
|
||||
return_value_if_fail(root != NULL, NULL);
|
||||
if (conf->vt == &s_conf_sub_obj_vtable) {
|
||||
conf_sub_obj_t* sub = CONF_SUB_OBJ(conf);
|
||||
conf_obj = sub->conf;
|
||||
return_value_if_fail(conf_obj->doc != NULL && conf_obj->doc->root != NULL, NULL);
|
||||
root = conf_doc_find_node(conf_obj->doc, sub->root, path, FALSE);
|
||||
return_value_if_fail(root != NULL, NULL);
|
||||
} else {
|
||||
conf_obj = CONF_OBJ(conf);
|
||||
root = conf_doc_find_node(conf_obj->doc, conf_obj->doc->root, path, FALSE);
|
||||
return_value_if_fail(root != NULL, NULL);
|
||||
}
|
||||
|
||||
obj = tk_object_create(&s_conf_sub_obj_vtable);
|
||||
o = CONF_SUB_OBJ(obj);
|
||||
@ -486,7 +494,7 @@ tk_object_t* conf_sub_obj_create(tk_object_t* conf, const char* path) {
|
||||
o->conf = conf_obj;
|
||||
o->root = root;
|
||||
o->real_root = conf_obj->doc->root;
|
||||
TK_OBJECT_REF(conf);
|
||||
TK_OBJECT_REF(o->conf);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -593,3 +593,23 @@ TEST(Json, append_array) {
|
||||
|
||||
conf_doc_destroy(doc);
|
||||
}
|
||||
|
||||
TEST(Json, subobject2) {
|
||||
tk_object_t* conf = conf_json_create();
|
||||
ASSERT_NE(conf, (tk_object_t*)NULL);
|
||||
ASSERT_EQ(tk_object_set_prop_str(conf, "awtk.name", "awtk"), RET_OK);
|
||||
ASSERT_EQ(tk_object_set_prop_int(conf, "awtk.value", 123), RET_OK);
|
||||
ASSERT_EQ(tk_object_set_prop_int(conf, "awtk.detail.age", 123), RET_OK);
|
||||
ASSERT_EQ(tk_object_set_prop_int(conf, "awtk.detail.salary", 1000), RET_OK);
|
||||
ASSERT_EQ(tk_object_set_prop_str(conf, "awtk.detail.desc", "hello"), RET_OK);
|
||||
tk_object_t* awtk = conf_obj_create_sub_object(conf, "awtk");
|
||||
ASSERT_NE(awtk, (tk_object_t*)NULL);
|
||||
|
||||
tk_object_t* detail = conf_obj_create_sub_object(awtk, "detail");
|
||||
ASSERT_NE(detail, (tk_object_t*)NULL);
|
||||
ASSERT_EQ(tk_object_get_prop_int(detail, "age", 0), 123);
|
||||
|
||||
TK_OBJECT_UNREF(detail);
|
||||
TK_OBJECT_UNREF(awtk);
|
||||
TK_OBJECT_UNREF(conf);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user