Beispiel #1
0
/**
 * Tests the eas functionality
 */
static void test_xml_parse_document_2() {
	SOURCE(source, ""
		"<Parent>\n"
		"\t<Child>\n"
		"\t\tFirst content\n"
		"\t</Child>\n"
		"\t<This><Is>\n"
			"<A><Test>Content A</Test></A>\n"
			"<B><Test>Content B</Test></B>\n"
		"\t</Is></This>\n"
		"\t<Child>\n"
		"\t\tSecond content\n"
		"\t</Child>\n"
		"</Parent>\n"
	);
	struct xml_document* document = xml_parse_document(source, strlen(source));
	assert_that(document, "Could not parse document");

	struct xml_node* root = xml_document_root(document);
//	assert_that(string_equals(xml_node_name(root), "Parent"), "root node name must be `Parent'");
	assert_that(3 == xml_node_children(root), "root must have two children");

	struct xml_node* test_a = xml_easy_child(root, "This", "Is", "A", "Test", 0);
	assert_that(test_a, "Cannot find Parent/This/Is/A/Test");
//	assert_that(string_equals(xml_node_content(test_a), "Content A"), "Content of Parent/This/Is/A/Test must be `Content A'");

	struct xml_node* test_b = xml_easy_child(root, "This", "Is", "B", "Test", 0);
	assert_that(test_b, "Cannot find Parent/This/Is/B/Test");
//	assert_that(string_equals(xml_node_content(test_b), "Content B"), "Content of Parent/This/Is/B/Test must be `Content B'");

	struct xml_node* test_c = xml_easy_child(root, "This", "Is", "C", "Test", 0);
	assert_that(!test_c, "Must not find Parent/This/Is/C/Test because no such path exists");

	struct xml_node* must_be_null = xml_easy_child(root, "Child");
	assert_that(!must_be_null, "Parent/Child cannot be a valid expression, because there are two children named `Child' in `Parent'");

//	uint8_t* name_is = xml_easy_name(xml_easy_child(root, "This", "Is", 0));
//	assert_that(!strcmp(name_is, "Is"), "Name of Parent/This/Is must be `Is'");
//	free(name_is);

//	uint8_t* content_a = xml_easy_content(test_a);
//	assert_that(!strcmp(content_a, "Content A"), "Content of Parent/This/Is/A/Test must be `Content A'");
//	free(content_a);

	xml_document_free(document, true);
}
Beispiel #2
0
/**
 * Tests the xml_open_document functionality
 */
static void test_xml_parse_document_3() {
	#define FILE_NAME "test.xml"
	FILE* handle = fopen(FILE_NAME, "rb");
	assert_that(handle, "Cannot open " FILE_NAME);

	struct xml_document* document = xml_open_document(handle);
	assert_that(document, "Cannot parse " FILE_NAME);

	struct xml_node* element = xml_easy_child(
		xml_document_root(document), "Element", "With", 0
	);
	assert_that(element, "Cannot find Document/Element/With");
//	assert_that(string_equals(xml_node_content(element), "Child"), "Content of Document/Element/With must be `Child'");

	xml_document_free(document, true);
	#undef FILE_NAME
}
Beispiel #3
0
/**
 * Configuration helper
 */
static uint8_t* configuration_value(
			struct xml_node* configuration,
			uint8_t const* key
		) {

	if (!configuration) {
		return 0;
	}

	uint8_t* value = xml_easy_content(xml_easy_child(
		configuration, key, 0
	));
	if (!value) {
		return 0;
	}

	decode_html_entities_utf8(value, 0);
	return value;
}