#include #include #include "xml.h" #include "test/test.h" LILY_FILE_BEGIN(xml_suite) LILY_TEST("get xml attributes") { struct kai_tag_t *t = kai_parse_string( "" ); char *attr1 = kai_tag_get_attr(t, "attr1"); REQUIRE_NEQ(attr1, NULL, "%p"); CHECK_EQS(attr1, "hello"); char *attr2 = kai_tag_get_attr(t, "attr2"); REQUIRE_NEQ(attr2, NULL, "%p"); CHECK_EQS(attr2, "world"); char *attr3 = kai_tag_get_attr(t, "attr3"); CHECK_EQ(attr3, NULL, "%p"); kai_tag_destroy(t); } #include LILY_PUSH_TEST() LILY_TEST("convert xml attribute to long") { struct kai_tag_t *t = kai_parse_string( "" ); int n = kai_tag_attr_to_long(t, "attr1", 0, NULL); CHECK_EQ(n, 10, "%d"); int m = kai_tag_attr_to_long(t, "attr2", 14, NULL); CHECK_EQ(m, 14, "%d"); int flag = -1; int qq = kai_tag_attr_to_long(t, "qq", 0, &flag); CHECK_EQ(qq, 12, "%d"); CHECK_EQ(flag, 0, "%d"); int k = kai_tag_attr_to_long(t, "dne", 22, &flag); CHECK_EQ(k, 22, "%d"); CHECK_EQ(flag, 1, "%d"); kai_tag_destroy(t); } #include LILY_PUSH_TEST() #define LILY_FILE_END #include LILY_REGISTER_TESTS()