]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
forb: Add tests for forbrun
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 17 Feb 2011 13:55:50 +0000 (14:55 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 17 Feb 2011 13:55:50 +0000 (14:55 +0100)
src/forbrun/Makefile.omk
src/forbrun/tests/Makefile.omk
src/forbrun/tests/forb_shlib.c [deleted file]
src/forbrun/tests/forbrun.sh [new file with mode: 0755]
src/forbrun/tests/test_client.c [new file with mode: 0644]
src/forbrun/tests/test_obj.c [new file with mode: 0644]
src/forbrun/tests/test_obj.idl
src/forbrun/tests/wvtest.sh [new symlink]

index 46e14307fd3f0084062624bac05145cdf77ead99..a2bde3c852eb0b7d83c501eb93e09d6af28ca66b 100644 (file)
@@ -1,3 +1,5 @@
+SUBDIRS = tests
+
 bin_PROGRAMS = forbrun
 forbrun_SOURCES = forbrun.c
 
index 908480f5d49e6e362eda6aebaaf613ebee74ce13..2eaa706e492a0e7025a9100b09d2440ed882c06e 100644 (file)
@@ -1,6 +1,12 @@
-shared_LIBRARIES = forb_shlib_test
-forb_shlib_test_SOURCES = forb_shlib.c
-forb_shlib_test_SERVER_IDL = test_obj.idl
+wvtest_SCRIPTS = forbrun.sh
+
+shared_LIBRARIES = test_obj
+test_obj_SOURCES = test_obj.c
+test_obj_SERVER_IDL = test_obj.idl
+
+shared_LIBRARIES += test_client
+test_client_SOURCES = test_client.c
+test_client_CLIENT_IDL = test_obj.idl
 
 INCLUDES += -I.
 
diff --git a/src/forbrun/tests/forb_shlib.c b/src/forbrun/tests/forb_shlib.c
deleted file mode 100644 (file)
index 7ecb0dc..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <forb.h>
-#include "test_obj.h"
-#define WVTEST_CONFIGURED
-#include <wvtest.h>
-#include <forb/executor.h>
-#include <forb/object.h>
-#include <forb/iop.h>
-
-static CORBA_long add(test_obj obj, CORBA_long val, CORBA_Environment *ev)
-{
-       int to_add = (intptr_t)forb_object_instance_data(obj);
-       return val + to_add;
-}
-
-static CORBA_long add_indirect(test_obj obj, test_obj indirect_obj, CORBA_long val, CORBA_Environment *ev)
-{
-       return test_obj_add(indirect_obj, val, ev);
-}
-
-static const struct forb_test_obj_impl test_obj_impl = {
-       .add = add,
-       .add_indirect = add_indirect,
-};
-
-
-void *executor_thread(void *arg)
-{
-       forb_executor_t *executor = arg;
-       forb_executor_run(executor);
-       return NULL;
-}
-
-int forb_main(forb_orb orb, int argc, char *argv[])
-{
-       test_obj testobj;
-
-       testobj = forb_test_obj_new(orb, &test_obj_impl, (void*)1);
-       if (!testobj)
-               return -1;
-       forb_execute_object(testobj);
-       return 0;
-}
diff --git a/src/forbrun/tests/forbrun.sh b/src/forbrun/tests/forbrun.sh
new file mode 100755 (executable)
index 0000000..a7b4c90
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+. $(dirname $0)/wvtest.sh
+
+WVSTART "Without any parameters do nothing"
+WVPASS forbrun
+
+WVSTART "argv[0] in forb_main() contains the name of the library"
+WVFAIL sh -c 'forbrun libtest_obj.so 2> error'
+WVPASSEQ "$(cat error)" "Usage: libtest_obj.so <string>"
+
+WVSTART "Both server and client in a single process"
+WVPASS sh -c 'forbrun libtest_obj.so "Hello" -- libtest_client.so > output'
+WVPASSEQ "$(cat output)" "Hello"
+
+WVSTART "Server and client in separate processes"
+# Run server on background
+rm -f test.pid
+WVPASS sh -c 'forbrun --daemon=test.pid libtest_obj.so "Hello" > output'
+WVPASS test -f test.pid
+
+# Run client
+WVPASS forbrun libtest_client.so
+WVPASS kill $(cat test.pif)
+
+# Test whether the server was called
+WVPASSEQ "$(cat output)" "Hello"
+
diff --git a/src/forbrun/tests/test_client.c b/src/forbrun/tests/test_client.c
new file mode 100644 (file)
index 0000000..55fa01d
--- /dev/null
@@ -0,0 +1,11 @@
+#include <forb.h>
+#include "test_obj.h"
+#include <stdio.h>
+
+int forb_main(forb_orb orb, int argc, char *argv[])
+{
+       CORBA_Environment ev;
+       test_obj obj = forb_resolve_reference(orb, "mytestobj");
+       test_obj_printmsg(obj, &ev);
+       return 0;
+}
diff --git a/src/forbrun/tests/test_obj.c b/src/forbrun/tests/test_obj.c
new file mode 100644 (file)
index 0000000..18d2b65
--- /dev/null
@@ -0,0 +1,42 @@
+#include <forb.h>
+#include "test_obj.h"
+#include <forb/executor.h>
+#include <forb/object.h>
+#include <forb/iop.h>
+#include <stdio.h>
+
+static CORBA_long printmsg(test_obj obj, CORBA_Environment *ev)
+{
+       char *msg = forb_object_instance_data(obj);
+       return printf("%s\n", msg);
+}
+
+static const struct forb_test_obj_impl test_obj_impl = {
+       .printmsg = printmsg,
+};
+
+
+int forb_main(forb_orb orb, int argc, char *argv[])
+{
+       test_obj testobj;
+       int ret;
+
+       if (argc < 2) {
+               fprintf(stderr, "Usage: %s <string>\n", argv[0]);
+               return 1;
+       }
+
+       testobj = forb_test_obj_new(orb, &test_obj_impl, argv[1]);
+       if (!testobj)
+               return 1;
+
+       ret = forb_register_reference(testobj, "mytestobj");
+       if (ret) {
+               fprintf(stderr, "%s: forb_register_reference(\"mytestobj\") failed\n",
+                       argv[0]);
+               return 1;
+       }
+
+       forb_execute_object(testobj);
+       return 0;
+}
index 0edea5d185b306b4a7b1b6f4c1bd25495ead8986..77fb23029620665774d817a050ce1ff20cb29f2a 100644 (file)
@@ -1,6 +1,4 @@
 interface test_obj {
-       // Adds some number the value @a val
-       long add(in long val);
-       // Adds some number the value @a val by calling @a add method of indirect_obj
-       long add_indirect(in test_obj indirect_obj, in long val);
+       // Print message specified during object initialization
+       long printmsg();
 };
diff --git a/src/forbrun/tests/wvtest.sh b/src/forbrun/tests/wvtest.sh
new file mode 120000 (symlink)
index 0000000..45f4ebb
--- /dev/null
@@ -0,0 +1 @@
+../../../../wvtest/sh/wvtest.sh
\ No newline at end of file