X-Git-Url: http://ftp.carnet.hr/pub/carnet-debian/scm?a=blobdiff_plain;f=src%2Ftests%2Ftest_os_xml.c;h=55e307ea39d9374a745e87ad9f74d36e66ca408c;hb=946517cefb8751a43a89bda4220221f065f4e5d1;hp=1c6fa9468004bb624f1e7883bfe94293901bb68f;hpb=789cbc8e52da68eba3517b920ef22e000cf3c9fd;p=ossec-hids.git
diff --git a/src/tests/test_os_xml.c b/src/tests/test_os_xml.c
index 1c6fa94..55e307e 100644
--- a/src/tests/test_os_xml.c
+++ b/src/tests/test_os_xml.c
@@ -17,6 +17,7 @@
Suite *test_suite(void);
+
static void create_xml_file(const char *str, char file_name[], size_t length)
{
strncpy(file_name, "/tmp/tmp_file-XXXXXX", length);
@@ -26,21 +27,19 @@ static void create_xml_file(const char *str, char file_name[], size_t length)
close(fd);
}
-static void nodecat(XML_NODE node, OS_XML *xml, char *buffer) {
+static void nodecat(XML_NODE node, OS_XML *xml, char *buffer)
+{
int i = 0;
/* write node */
- while(node[i])
- {
+ while (node[i]) {
strncat(buffer, "<", 1);
ck_assert_ptr_ne(node[i]->element, NULL);
strncat(buffer, node[i]->element, strlen(node[i]->element));
/* write attributes */
- if(node[i]->attributes)
- {
+ if (node[i]->attributes) {
ck_assert_ptr_ne(node[i]->values, NULL);
int j = 0;
- while(node[i]->attributes[j])
- {
+ while (node[i]->attributes[j]) {
strncat(buffer, " ", 1);
ck_assert_ptr_ne(node[i]->values[j], NULL);
strncat(buffer, node[i]->attributes[j], strlen(node[i]->attributes[j]));
@@ -51,9 +50,7 @@ static void nodecat(XML_NODE node, OS_XML *xml, char *buffer) {
j++;
}
ck_assert_ptr_eq(node[i]->values[j], NULL);
- }
- else
- {
+ } else {
ck_assert_ptr_eq(node[i]->values, NULL);
}
strncat(buffer, ">", 1);
@@ -62,8 +59,7 @@ static void nodecat(XML_NODE node, OS_XML *xml, char *buffer) {
/* write children */
XML_NODE child = OS_GetElementsbyNode(xml, node[i]);
- if(child != NULL)
- {
+ if (child != NULL) {
nodecat(child, xml, buffer);
OS_ClearNode(child);
}
@@ -79,8 +75,7 @@ static void nodecat(XML_NODE node, OS_XML *xml, char *buffer) {
static void assert_os_xml_eq_str(OS_XML *xml, const char *xml_str)
{
XML_NODE node = OS_GetElementsbyNode(xml, NULL);
- if(node == NULL)
- {
+ if (node == NULL) {
ck_assert_str_eq(xml_str, "");
return;
}
@@ -119,58 +114,58 @@ END_TEST
START_TEST(test_multiplenodes)
{
assert_os_xml_eq(
- ""
- ""
- "",
- ""
- ""
- "");
+ ""
+ ""
+ "",
+ ""
+ ""
+ "");
}
END_TEST
START_TEST(test_children)
{
assert_os_xml_eq(
- ""
- ""
- ""
- ""
- ""
- ""
- ""
- ""
- ""
- ""
- "",
- ""
- ""
- ""
- ""
- ""
- ""
- ""
- ""
- ""
- ""
- "");
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ "",
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ "");
}
END_TEST
START_TEST(test_multiplecontent)
{
assert_os_xml_eq(
- ""
- "value1"
- ""
- "",
- "");
+ ""
+ "value1"
+ ""
+ "",
+ "");
assert_os_xml_eq(
- ""
- "value1"
- ""
- "value2"
- "",
- "value2");
+ ""
+ "value1"
+ ""
+ "value2"
+ "",
+ "value2");
}
END_TEST
@@ -178,82 +173,82 @@ END_TEST
START_TEST(test_attributes)
{
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
}
END_TEST
START_TEST(test_variables)
{
assert_os_xml_eq(
- "value1"
- "value2"
- "$var2"
- "blah$var2"
- "blah$var2$var1 blah",
- "value2"
- "blahvalue2"
- "blahvalue2value1 blah");
+ "value1"
+ "value2"
+ "$var2"
+ "blah$var2"
+ "blah$var2$var1 blah",
+ "value2"
+ "blahvalue2"
+ "blahvalue2value1 blah");
}
END_TEST
START_TEST(test_comments)
{
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
assert_os_xml_eq(
- "",
- "");
+ "",
+ "");
}
END_TEST
START_TEST(test_specialchars)
{
assert_os_xml_eq(
- "value1"
- "\\",
- "\\");
+ "value1"
+ "\\",
+ "\\");
}
END_TEST
@@ -442,7 +437,7 @@ START_TEST(test_invalidvariable2)
}
END_TEST
-START_TEST(test_unknownvariable)
+START_TEST(test_unknownvariable1)
{
char xml_file_name[256];
create_xml_file("content$var", xml_file_name, 256);
@@ -457,6 +452,13 @@ START_TEST(test_unknownvariable)
}
END_TEST
+START_TEST(test_unknownvariable2)
+{
+ assert_os_xml_eq("$var",
+ "$var");
+}
+END_TEST
+
START_TEST(test_infiniteattribute2)
{
char xml_file_name[256];
@@ -623,7 +625,7 @@ START_TEST(test_osgetonecontentforelement)
}
END_TEST
-static void assert_ox_xml_write_eq(const char *xml_str_old, const char *xml_str_new,const char **xml_path, const char *oldval, const char *newval)
+static void assert_ox_xml_write_eq(const char *xml_str_old, const char *xml_str_new, const char **xml_path, const char *oldval, const char *newval)
{
char xml_in_file_name[256];
create_xml_file(xml_str_old, xml_in_file_name, 256);
@@ -646,24 +648,24 @@ START_TEST(test_oswritexml_success)
{
const char *xml_path[] = { "root", "child", NULL };
assert_ox_xml_write_eq(
- "test",
- "test_new",
- xml_path, "test", "test_new");
+ "test",
+ "test_new",
+ xml_path, "test", "test_new");
assert_ox_xml_write_eq(
- "test",
- "test",
- xml_path, "test", "test");
+ "test",
+ "test",
+ xml_path, "test", "test");
assert_ox_xml_write_eq(
- "",
- "test",
- xml_path, "test", "test");
+ "",
+ "test",
+ xml_path, "test", "test");
assert_ox_xml_write_eq(
- "",
- "\n test",
- xml_path, NULL, "test");
+ "",
+ "\n test",
+ xml_path, NULL, "test");
}
END_TEST
@@ -731,13 +733,15 @@ START_TEST(test_osgetcontents)
ck_assert_ptr_eq(OS_GetContents(&xml, NULL), NULL);
int i = 0;
- while(content1[i])
+ while (content1[i]) {
free(content1[i++]);
+ }
free(content1);
i = 0;
- while(content2[i])
+ while (content2[i]) {
free(content2[i++]);
+ }
free(content2);
OS_ClearXML(&xml);
unlink(xml_file_name);
@@ -758,8 +762,9 @@ START_TEST(test_osgetelementcontent)
ck_assert_ptr_eq(content[1], NULL);
int i = 0;
- while(content[i])
+ while (content[i]) {
free(content[i++]);
+ }
free(content);
OS_ClearXML(&xml);
unlink(xml_file_name);
@@ -786,12 +791,14 @@ START_TEST(test_osgetelements)
ck_assert_ptr_eq(OS_GetElements(&xml, xml_path2), NULL);
int i = 0;
- while(content1[i])
+ while (content1[i]) {
free(content1[i++]);
+ }
free(content1);
i = 0;
- while(content2[i])
+ while (content2[i]) {
free(content2[i++]);
+ }
free(content2);
OS_ClearXML(&xml);
unlink(xml_file_name);
@@ -813,8 +820,9 @@ START_TEST(test_osgetattributes)
ck_assert_ptr_eq(content[2], NULL);
int i = 0;
- while(content[i])
+ while (content[i]) {
free(content[i++]);
+ }
free(content);
OS_ClearXML(&xml);
unlink(xml_file_name);
@@ -933,7 +941,8 @@ Suite *test_suite(void)
tcase_add_test(tc_core, test_invalidvariablename);
tcase_add_test(tc_core, test_invalidvariable);
tcase_add_test(tc_core, test_invalidvariable2);
- tcase_add_test(tc_core, test_unknownvariable);
+ tcase_add_test(tc_core, test_unknownvariable1);
+ tcase_add_test(tc_core, test_unknownvariable2);
tcase_add_test(tc_core, test_infiniteattribute2);
tcase_add_test(tc_core, test_invalidattributestart);
tcase_add_test(tc_core, test_invalidattributeclosing);