summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2008-03-25 08:00:58 -0700
committerDan Nicholson <dbn.lists@gmail.com>2008-03-25 08:05:51 -0700
commit56b1141afef62b3f945704557c77b3035117630f (patch)
treee6e3c32328641b6186b33ae4c9678c9f6e450478 /test
parenta7f0e89d3d7bc2c6f028c9e272a4a4592e1f0285 (diff)
Function to construct an initd list from a directory of scripts
Added the initd_list_from_dir() function. This function takes a directory path, reads the scripts in the directory, and returns an allocated initd_list_t. A test case has been added to verify the operation.
Diffstat (limited to 'test')
-rw-r--r--test/.gitignore1
-rw-r--r--test/Makefile.am11
-rw-r--r--test/init.d/bar23
-rw-r--r--test/init.d/foo26
-rw-r--r--test/tparse-dir.c33
-rwxr-xr-xtest/tparse-dir.sh6
6 files changed, 97 insertions, 3 deletions
diff --git a/test/.gitignore b/test/.gitignore
index 71c3801..68c293b 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -4,3 +4,4 @@ tdep
tinitd
tinitd-list
tparse
+tparse-dir
diff --git a/test/Makefile.am b/test/Makefile.am
index 67d7a19..592c024 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,8 +1,11 @@
INCLUDES = -I$(top_srcdir)/lib
-EXTRA_DIST = test-script
-TESTS = tstr tstrarg tdep $(srcdir)/tparse.sh tinitd tinitd-list
-check_PROGRAMS = tstr tstrarg tdep tparse tinitd tinitd-list
+testscripts = test-script init.d/bar init.d/foo
+
+EXTRA_DIST = $(testscripts)
+TESTS = tstr tstrarg tdep $(srcdir)/tparse.sh $(srcdir)/tparse-dir.sh \
+ tinitd tinitd-list
+check_PROGRAMS = tstr tstrarg tdep tparse tparse-dir tinitd tinitd-list
tstr_SOURCES = tstr.c
tstr_LDADD = $(top_builddir)/lib/libinitd.la
@@ -12,6 +15,8 @@ tdep_SOURCES = tdep.c
tdep_LDADD = $(top_builddir)/lib/libinitd.la
tparse_SOURCES = tparse.c
tparse_LDADD = $(top_builddir)/lib/libinitd.la
+tparse_dir_SOURCES = tparse-dir.c
+tparse_dir_LDADD = $(top_builddir)/lib/libinitd.la
tinitd_SOURCES = tinitd.c
tinitd_LDADD = $(top_builddir)/lib/libinitd.la
tinitd_list_SOURCES = tinitd-list.c
diff --git a/test/init.d/bar b/test/init.d/bar
new file mode 100644
index 0000000..9825978
--- /dev/null
+++ b/test/init.d/bar
@@ -0,0 +1,23 @@
+#!/bin/sh
+# Begin $rc_base/init.d/bar
+
+### BEGIN INIT INFO
+# Provides : bar baz
+# Default-Start: 5
+# Default-Stop: 0 1 2 3 4 6
+# Required-Start: $network
+# Required-Stop: $network
+# Should-Start: dbus
+# Should-Stop: dbus
+# Short-Description: bar test service
+# Description: The bar service is used for testing out out
+# the initd-tools functions.
+### END INIT INFO
+
+# Do some other stuff
+case "$1" in
+start)
+ ;;
+stop)
+ ;;
+esac
diff --git a/test/init.d/foo b/test/init.d/foo
new file mode 100644
index 0000000..7a124b6
--- /dev/null
+++ b/test/init.d/foo
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Begin $rc_base/init.d/foo
+
+### BEGIN INIT INFO
+# Provides : foo
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Required-Start: $local_fs baz
+# Required-Stop: $local_fs baz
+# Should-Start:
+# Should-Stop:
+# Short-Description: test foo service
+# Description: The test service does cool
+# stuff when
+# you start it
+# X-Gado-Default-Start: S30
+# X-Gado-Default-Stop:
+### END INIT INFO
+
+# Do some other stuff
+case "$1" in
+start)
+ ;;
+stop)
+ ;;
+esac
diff --git a/test/tparse-dir.c b/test/tparse-dir.c
new file mode 100644
index 0000000..b399b93
--- /dev/null
+++ b/test/tparse-dir.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include "initd.h"
+
+static void print_list(const initd_list_t *list);
+
+int main(int argc, char *argv[])
+{
+ char *dir;
+ initd_list_t *test;
+
+ if (argc > 1)
+ dir = argv[1];
+ else
+ dir = ".";
+
+ test = initd_list_from_dir(dir);
+ if (test)
+ print_list(test);
+
+ return 0;
+}
+
+static void print_list(const initd_list_t *list)
+{
+ initd_t *ip;
+ int n;
+ for (ip = list->first; ip; ip = ip->next) {
+ printf("Service %s provides:", ip->name);
+ for (n = 0; n < ip->prov->nprov; n++)
+ printf(" %s", ip->prov->prov[n]);
+ printf("\n");
+ }
+}
diff --git a/test/tparse-dir.sh b/test/tparse-dir.sh
new file mode 100755
index 0000000..56b4c3f
--- /dev/null
+++ b/test/tparse-dir.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+: ${srcdir:=.}
+: ${builddir:=.}
+
+exec "$builddir/tparse-dir" "$srcdir/init.d"