summaryrefslogtreecommitdiffstats
path: root/framework/src/audit/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/audit/src/test')
-rw-r--r--framework/src/audit/src/test/Makefile.am26
-rw-r--r--framework/src/audit/src/test/ilist_test.c69
-rw-r--r--framework/src/audit/src/test/slist_test.c98
3 files changed, 193 insertions, 0 deletions
diff --git a/framework/src/audit/src/test/Makefile.am b/framework/src/audit/src/test/Makefile.am
new file mode 100644
index 00000000..b6f44edb
--- /dev/null
+++ b/framework/src/audit/src/test/Makefile.am
@@ -0,0 +1,26 @@
+# Copyright 2008,2014,2015 Red Hat Inc., Durham, North Carolina.
+# All Rights Reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Authors:
+# Steve Grubb <sgrubb@redhat.com>
+#
+
+AM_CPPFLAGS = -I${top_srcdir} -I${top_srcdir}/lib -I${top_srcdir}/src
+check_PROGRAMS = ilist_test slist_test
+TESTS = $(check_PROGRAMS)
+ilist_test_LDADD = ${top_builddir}/src/ausearch-int.o
+slist_test_LDADD = ${top_builddir}/src/ausearch-string.o
diff --git a/framework/src/audit/src/test/ilist_test.c b/framework/src/audit/src/test/ilist_test.c
new file mode 100644
index 00000000..85787126
--- /dev/null
+++ b/framework/src/audit/src/test/ilist_test.c
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include "ausearch-int.h"
+
+int main(void)
+{
+ int i = 0;
+ ilist e;
+ int_node *node;
+
+ ilist_create(&e);
+
+ // This first test checks to see if list is
+ // created in a numeric order
+ ilist_add_if_uniq(&e, 6, 0);
+ ilist_add_if_uniq(&e, 5, 0);
+ ilist_add_if_uniq(&e, 7, 0);
+ ilist_add_if_uniq(&e, 1, 0);
+ ilist_add_if_uniq(&e, 8, 0);
+ ilist_add_if_uniq(&e, 2, 0);
+ ilist_add_if_uniq(&e, 9, 0);
+ ilist_add_if_uniq(&e, 0, 0);
+ ilist_add_if_uniq(&e, 4, 0);
+ ilist_add_if_uniq(&e, 3, 0);
+
+ ilist_first(&e);
+ do {
+ node = ilist_get_cur(&e);
+ if (i != node->num) {
+ printf("Test failed - i:%d != num:%d\n", i, node->num);
+ return 1;
+ }
+ i++;
+ } while ((node = ilist_next(&e)));
+
+ ilist_clear(&e);
+ puts("starting sort test");
+
+ // Now test to see if the sort function works
+ // Fill the list exactly backwards
+ ilist_add_if_uniq(&e, 3, 0);
+ ilist_add_if_uniq(&e, 3, 0);
+ ilist_add_if_uniq(&e, 4, 0);
+ ilist_add_if_uniq(&e, 3, 0);
+ ilist_add_if_uniq(&e, 4, 0);
+ ilist_add_if_uniq(&e, 2, 0);
+ ilist_add_if_uniq(&e, 4, 0);
+ ilist_add_if_uniq(&e, 2, 0);
+ ilist_add_if_uniq(&e, 4, 0);
+ ilist_add_if_uniq(&e, 1, 0);
+
+ ilist_sort_by_hits(&e);
+
+ i = 0;
+ ilist_first(&e);
+ do {
+ node = ilist_get_cur(&e);
+ if (node->hits != (4-i)) {
+ printf("Sort test failed - i:%d != ihits:%d\n", i, node->hits);
+ return 1;
+ }
+ i++;
+ } while ((node = ilist_next(&e)));
+
+ ilist_clear(&e);
+
+ printf("ilist tests passed\n");
+ return 0;
+}
+
diff --git a/framework/src/audit/src/test/slist_test.c b/framework/src/audit/src/test/slist_test.c
new file mode 100644
index 00000000..e0336149
--- /dev/null
+++ b/framework/src/audit/src/test/slist_test.c
@@ -0,0 +1,98 @@
+#include <stdio.h>
+#include <string.h>
+#include "ausearch-string.h"
+
+slist s;
+
+int print_list(void)
+{
+ int cnt = 0;
+ slist_first(&s);
+ do {
+ snode *cur = slist_get_cur(&s);
+ if (cur) {
+ cnt++;
+ printf("%s\n", cur->str);
+ }
+ } while (slist_next(&s));
+ return cnt;
+}
+
+int main(void)
+{
+ snode n, *node;
+ int rc, i = 0;
+
+ slist_create(&s);
+
+ // This first test checks to see if list is
+ // created in a numeric order
+ slist_add_if_uniq(&s, "test1");
+ slist_add_if_uniq(&s, "test2");
+ slist_first(&s);
+ slist_add_if_uniq(&s, "test3");
+ puts("should be 3");
+ rc = print_list();
+ if (s.cnt != 3 || rc !=3) {
+ puts("test count is wrong");
+ return 1;
+ }
+
+ n.str = strdup("test4");
+ n.key = NULL;
+ n.hits = 1;
+ slist_append(&s, &n);
+ puts("should add a #4");
+ rc = print_list();
+ if (s.cnt != 4 || rc != 4) {
+ puts("test count is wrong");
+ return 1;
+ }
+
+ slist_add_if_uniq(&s, "test2");
+ puts("should be same");
+ rc = print_list();
+ if (s.cnt != 4 || rc != 4) {
+ puts("test count is wrong");
+ return 1;
+ }
+
+ slist_clear(&s);
+ puts("should be empty");
+ rc = print_list();
+ if (s.cnt != 0 || rc != 0) {
+ puts("test count is wrong");
+ return 1;
+ }
+ puts("starting sort test");
+
+ // Now test to see if the sort function works
+ // Fill the list exactly backwards
+ slist_add_if_uniq(&s, "test3");
+ slist_add_if_uniq(&s, "test3");
+ slist_add_if_uniq(&s, "test4");
+ slist_add_if_uniq(&s, "test3");
+ slist_add_if_uniq(&s, "test4");
+ slist_add_if_uniq(&s, "test2");
+ slist_add_if_uniq(&s, "test4");
+ slist_add_if_uniq(&s, "test2");
+ slist_add_if_uniq(&s, "test4");
+ slist_add_if_uniq(&s, "test1");
+
+ slist_sort_by_hits(&s);
+ slist_first(&s);
+ do {
+ node = slist_get_cur(&s);
+ if (node->hits != (4-i)) {
+ printf("Sort test failed - i:%d != hits:%d\n", i, node->hits);
+ return 1;
+ }
+ i++;
+ } while ((node = slist_next(&s)));
+ puts("sort test passes");
+
+ slist_clear(&s);
+
+ return 0;
+}
+