#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); CHECK_EQ(n, 10, "%d"); int m = kai_tag_attr_to_long(t, "attr2", 14); CHECK_EQ(m, 14, "%d"); kai_tag_destroy(t); } #include LILY_PUSH_TEST() LILY_TEST("duplicate xml attributes") { struct kai_tag_t *t = kai_parse_string( "" ); char *a = kai_tag_attr_to_dup(t, "attr1"); char *b = kai_tag_attr_to_dup(t, "attr1"); char *c = kai_tag_attr_to_dup(t, "dne"); kai_tag_destroy(t); REQUIRE_NEQ(a, NULL, "%p"); REQUIRE_NEQ(b, NULL, "%p"); CHECK_EQ(c, NULL, "%p"); CHECK_EQS(a, "hello"); CHECK_EQS(b, "hello"); CHECK_NEQ(a, b, "%p"); free(a); free(b); } #include LILY_PUSH_TEST() #define LILY_FILE_END #include LILY_REGISTER_TESTS()