libactd_includedir = $(includedir)/actd
libactd_include_HEADERS = include/unit_control.h
-bin_PROGRAMS = activationd_acceptance_checker
+bin_PROGRAMS = activationd_unit_tests
+activationd_unit_tests_SOURCES = tests/unit_tests.c
+activationd_unit_tests_CFLAGS = $(AM_CFLAGS)
+activationd_unit_tests_LDFLAGS = libactd.la
+activationd_unit_tests_DEPENDENCIES = libactd.la
+
+bin_PROGRAMS += activationd_acceptance_checker
activationd_acceptance_checker_SOURCES = \
tests/activationd_acceptance_tests.c \
--- /dev/null
+#include "unit_control.h"
+#include <stdio.h>
+
+static const char *async_result = NULL;
+
+int test_unit_start()
+{
+ return actd_start_unit("foo.bar");
+}
+
+int test_unit_stop()
+{
+ return actd_stop_unit("foo.bar");
+}
+
+int test_unit_restart()
+{
+ return actd_restart_unit("foo.bar");
+}
+
+void handler(GVariant *var, void *user_data, GError *err)
+{
+ g_variant_get(var, "(s)", &async_result);
+ g_main_loop_quit(user_data);
+}
+
+int test_async_action(int (*func)(const char *unit, actd_unit_cb cb, void *user_data))
+{
+ int ret;
+ GMainLoop *loop;
+
+ loop = g_main_loop_new(NULL, FALSE);
+
+ ret = actd_start_unit_async("foo.bar", handler, loop);
+ if (ret < 0)
+ return ret;
+
+ g_main_loop_run(loop);
+ g_main_loop_unref(loop);
+
+ ret = strcmp(async_result, "ok") == 0;
+ g_free(async_result);
+ async_result = NULL;
+
+ return ret;
+}
+
+int test_unit_start_async()
+{
+ return test_async_action(actd_start_unit_async);
+}
+
+int test_unit_stop_async()
+{
+ return test_async_action(actd_stop_unit_async);
+}
+
+int test_unit_restart_async()
+{
+ return test_async_action(actd_restart_unit_async);
+}
+
+int main()
+{
+ int i;
+ int ret;
+
+ struct {
+ const char *id;
+ int (*func)(void);
+ } tests[] = {
+ {"UnitStart", test_unit_start},
+ {"UnitStop", test_unit_stop},
+ {"UnitRestart", test_unit_restart},
+ {"UnitStartAsync", test_unit_start_async},
+ {"UnitStopAsync", test_unit_stop_async},
+ {"UnitRestartAsync", test_unit_restart_async},
+ {NULL, NULL},
+ };
+
+ for (i = 0; tests[i].id; ++i) {
+ ret = tests[i].func();
+ if (ret < 0)
+ printf("[FAILED] %s (ret = %d)\n", tests[i].id, ret);
+ else
+ printf("[OK] %s\n", tests[i].id);
+ }
+
+ return 0;
+}