add missing test code
authorLennart Poettering <lennart@poettering.net>
Wed, 20 Jan 2010 17:26:29 +0000 (18:26 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 20 Jan 2010 17:26:29 +0000 (18:26 +0100)
test-engine.c [new file with mode: 0644]
test2/Makefile [new file with mode: 0644]
test2/a.service [new file with mode: 0644]
test2/b.service [new file with mode: 0644]
test2/c.service [new file with mode: 0644]
test2/d.service [new file with mode: 0644]
test2/e.service [new file with mode: 0644]

diff --git a/test-engine.c b/test-engine.c
new file mode 100644 (file)
index 0000000..61882a9
--- /dev/null
@@ -0,0 +1,46 @@
+/*-*- Mode: C; c-basic-offset: 8 -*-*/
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "manager.h"
+
+int main(int argc, char *argv[]) {
+        Manager *m = NULL;
+        Name *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e;
+        Job *j;
+
+        assert_se(chdir("test2") == 0);
+
+        assert_se(m = manager_new());
+
+        printf("Loaded1:\n");
+        assert_se(manager_load_name(m, "a.service", &a) == 0);
+        assert_se(manager_load_name(m, "b.service", &b) == 0);
+        assert_se(manager_load_name(m, "c.service", &c) == 0);
+        manager_dump_names(m, stdout, "\t");
+
+        printf("Test1: (Trivial)\n");
+        assert_se(manager_add_job(m, JOB_START, c, JOB_REPLACE, false, &j) == 0);
+        manager_dump_jobs(m, stdout, "\t");
+
+        printf("Loaded2:\n");
+        manager_clear_jobs(m);
+        assert_se(manager_load_name(m, "d.service", &d) == 0);
+        assert_se(manager_load_name(m, "e.service", &e) == 0);
+        manager_dump_names(m, stdout, "\t");
+
+        printf("Test2: (Cyclic Order, Unfixable)\n");
+        assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, false, &j) == -ELOOP);
+        manager_dump_jobs(m, stdout, "\t");
+
+        printf("Test2: (Cyclic Order, Fixable)\n");
+        assert_se(manager_add_job(m, JOB_START, e, JOB_REPLACE, false, &j) == 0);
+        manager_dump_jobs(m, stdout, "\t");
+
+        manager_free(m);
+
+        return 0;
+}
diff --git a/test2/Makefile b/test2/Makefile
new file mode 100644 (file)
index 0000000..9aa46b4
--- /dev/null
@@ -0,0 +1,7 @@
+# Just a little hook script to easy building when in this directory
+
+all:
+       $(MAKE) -C ..
+
+clean:
+       $(MAKE) -C .. clean
diff --git a/test2/a.service b/test2/a.service
new file mode 100644 (file)
index 0000000..4ddb8b4
--- /dev/null
@@ -0,0 +1,4 @@
+[Meta]
+Description=A
+Requires=b.service
+Before=b.service
diff --git a/test2/b.service b/test2/b.service
new file mode 100644 (file)
index 0000000..b096e0d
--- /dev/null
@@ -0,0 +1,2 @@
+[Meta]
+Description=B
diff --git a/test2/c.service b/test2/c.service
new file mode 100644 (file)
index 0000000..8800ff7
--- /dev/null
@@ -0,0 +1,3 @@
+[Meta]
+Description=C
+Requires=a.service
diff --git a/test2/d.service b/test2/d.service
new file mode 100644 (file)
index 0000000..279c171
--- /dev/null
@@ -0,0 +1,5 @@
+[Meta]
+Description=D:Cyclic
+After=b.service
+Before=a.service
+Requires=a.service
diff --git a/test2/e.service b/test2/e.service
new file mode 100644 (file)
index 0000000..2e86e33
--- /dev/null
@@ -0,0 +1,5 @@
+[Meta]
+Description=E:Cyclic
+After=b.service
+Before=a.service
+Wants=a.service