#include "gtest/gtest.h"
#include "conf_io/conf_xml.h"
TEST(Xml, basic0) {
value_t v;
str_t str;
conf_node_t* node = NULL;
conf_doc_t* doc = conf_doc_load_xml("");
ASSERT_EQ(conf_doc_get(doc, "hello.name", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "abc");
node = conf_node_find_child(doc->root, "hello");
ASSERT_EQ(node != NULL, true);
ASSERT_STREQ(conf_node_get_name(node), "hello");
str_init(&str, 100);
conf_doc_save_xml(doc, &str);
ASSERT_STREQ(str.str, "\n");
str_reset(&str);
conf_doc_destroy(doc);
}
TEST(Xml, basic1) {
value_t v;
str_t str;
conf_node_t* node = NULL;
conf_doc_t* doc = conf_doc_load_xml("");
ASSERT_EQ(conf_doc_get(doc, "hello.name", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "abc");
ASSERT_EQ(conf_doc_get(doc, "hello.world.name", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "cde");
ASSERT_EQ(conf_doc_get(doc, "hello.world.value", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "123");
node = conf_node_find_child(doc->root, "hello");
ASSERT_EQ(node != NULL, true);
ASSERT_STREQ(conf_node_get_name(node), "hello");
str_init(&str, 100);
conf_doc_save_xml(doc, &str);
ASSERT_STREQ(str.str, "\n \n\n");
str_reset(&str);
conf_doc_destroy(doc);
}
TEST(Xml, basic2) {
value_t v;
str_t str;
conf_node_t* node = NULL;
conf_doc_t* doc = conf_doc_load_xml(
"");
ASSERT_EQ(conf_doc_get(doc, "hello.name", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "abc");
ASSERT_EQ(conf_doc_get(doc, "hello.world.name", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "cde");
ASSERT_EQ(conf_doc_get(doc, "hello.world.value", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "123");
ASSERT_EQ(conf_doc_get(doc, "hello.foo.name", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "oo");
ASSERT_EQ(conf_doc_get(doc, "hello.foo.value", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "456");
node = conf_node_find_child(doc->root, "hello");
ASSERT_EQ(node != NULL, true);
ASSERT_STREQ(conf_node_get_name(node), "hello");
str_init(&str, 100);
conf_doc_save_xml(doc, &str);
ASSERT_STREQ(str.str,
"\n \n \n\n");
str_reset(&str);
conf_doc_destroy(doc);
}
TEST(Xml, basic3) {
value_t v;
str_t str;
conf_doc_t* doc = conf_doc_load_xml(
"");
ASSERT_EQ(conf_doc_get(doc, "awtk.name", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "ttt");
str_init(&str, 100);
conf_doc_save_xml(doc, &str);
ASSERT_STREQ(str.str,
"\n \n \n\n\n");
str_reset(&str);
conf_doc_destroy(doc);
}
TEST(Xml, basic4) {
value_t v;
str_t str;
conf_node_t* node = NULL;
conf_doc_t* doc = conf_doc_load_xml("");
ASSERT_EQ(conf_doc_get(doc, "hello.name", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "<>&\"");
node = conf_node_find_child(doc->root, "hello");
ASSERT_EQ(node != NULL, true);
ASSERT_STREQ(conf_node_get_name(node), "hello");
str_init(&str, 100);
conf_doc_save_xml(doc, &str);
ASSERT_STREQ(str.str, "\n");
str_reset(&str);
conf_doc_destroy(doc);
}
TEST(Xml, basic5) {
str_t str;
conf_doc_t* doc = conf_doc_load_xml("");
str_init(&str, 100);
conf_doc_save_xml(doc, &str);
ASSERT_STREQ(str.str, "\n \n\n");
str_reset(&str);
conf_doc_destroy(doc);
}
TEST(Xml, text0) {
str_t str;
conf_doc_t* doc = conf_doc_load_xml("123");
ASSERT_STREQ(conf_doc_get_str(doc, "group_box." CONF_XML_TEXT, NULL), "123");
str_init(&str, 100);
conf_doc_save_xml(doc, &str);
ASSERT_STREQ(str.str, "123\n");
str_reset(&str);
conf_doc_destroy(doc);
}
TEST(Xml, text1) {
str_t str;
conf_doc_t* doc = conf_doc_load_xml("123<abc");
ASSERT_STREQ(conf_doc_get_str(doc, "group_box." CONF_XML_TEXT, NULL), "123123<abc\n");
str_reset(&str);
conf_doc_destroy(doc);
}