more test and api stuff
[cilux] / src / drivers / ot / test / teston.c
index 583f3b3..9379891 100644 (file)
@@ -6,11 +6,18 @@
 
 /* -------------------------------------------------------------------------- */
 
-static int  handles_resource(char* name);
-static void sync_resource(ni_resource* res);
+static int  handles_object(char* uid);
+static void view_event(n_object* o, n_object* v);
+static void cast_event(n_object* o, n_object* c);
+static void sync_object(n_object* o);
 
 static void start_tests(void);
-static void running_tests(ni_event* evt);
+static void view_event_1(n_object* o, n_object* v);
+static void view_event_2(n_object* o, n_object* v);
+static void view_event_3(n_object* o, n_object* v);
+static void cast_event_1(n_object* o, n_object* c);
+static void cast_event_2(n_object* o, n_object* c);
+static void cast_event_3(n_object* o, n_object* c);
 
 static void test_state(n_object* o, char* os, char* uid, char* cont);
 
@@ -18,7 +25,7 @@ static void test_state(n_object* o, char* os, char* uid, char* cont);
 
 EXPORT int teston_module_loaded(void)
 {
-    ni_register_driver("teston", handles_resource, sync_resource);
+    n_register_driver("teston", handles_object, view_event, cast_event, sync_object);
 
     k_log_out("Test ON Driver initialised");
 
@@ -29,11 +36,7 @@ EXPORT int teston_module_loaded(void)
 
 EXPORT int teston_module_event(void* data)
 {
-    ni_event* evt=data;
-
-    running_tests(evt);
-
-    ni_event_delete(evt);
+    n_dispatch((n_event*)data);
     return 1;
 }
 
@@ -44,25 +47,43 @@ EXPORT int teston_module_tick(void)
 
 /* -------------------------------------------------------------------------- */
 
-int handles_resource(char* name)
+int handles_object(char* uid)
 {
     return 1;
 }
 
-void sync_resource(ni_resource* res)
+void sync_object(n_object* o)
+{
+}
+
+/* -------------------------------------------------------------------------- */
+
+void view_event(n_object* o, n_object* v)
+{
+    if(n_uid_is(o, "11111-4141a")) view_event_1(o,v);
+    if(n_uid_is(o, "22222-ef990")) view_event_2(o,v);
+    if(n_uid_is(o, "33333-18bbc")) view_event_3(o,v);
+    k_assert(0, "No match to UID in view_event");
+}
+
+void cast_event(n_object* o, n_object* c)
 {
+    if(n_uid_is(o, "11111-4141a")) cast_event_1(o,c);
+    if(n_uid_is(o, "22222-ef990")) cast_event_2(o,c);
+    if(n_uid_is(o, "33333-18bbc")) cast_event_3(o,c);
+    k_assert(0, "No match to UID in cast_event");
 }
 
 /* -------------------------------------------------------------------------- */
 
 /*
  - object.create .update .commit .rollback (auto inc version #?)
- - object.see - may return empty so wait for ..
- - seestate(object) - state asked for /or/ object is subscribing
+ - object.view - may return empty so wait for ..
+ - viewstate(object) - state asked for /or/ object is subscribing
  */
 void start_tests(void)
 {
-    k_log_out("Creating o11111");
+    k_log_out("Creating o11111 ------------------");
 
     char* o11111s = "UID: 11111-4141a\n"
                     "\n"
@@ -76,7 +97,7 @@ void start_tests(void)
 
     n_commit(o11111);
 
-    k_log_out("Creating o22222");
+    k_log_out("Creating o22222 ------------------");
 
     char* o22222s = "UID: 22222-ef990\n"
                     "\n"
@@ -86,24 +107,54 @@ void start_tests(void)
 
     test_state(o22222, o22222s, "22222-ef990", "is two content");
 
-    n_object* o2 = n_see(o11111, "22222-ef990");
+    k_log_out("o11111 views o22222 ------------------");
 
-    k_assert(!o2, "Object 2 has not been committed yet, but Object 1 can see it:\n%s\n", n_to_string(o2));
+    n_object* o2 = n_view(o11111, "22222-ef990");
+
+    k_assert(!o2, "Object 2 has not been committed yet, but Object 1 can view it:\n%s\n", n_to_string(o2));
 
     n_commit(o22222);
 
-    o2 = n_see(o11111, "22222-ef990");
+    o2 = n_view(o11111, "22222-ef990");
 
-    k_assert(o2!=0, "Object 2 has been committed, but can't be seen by Object 1");
+    k_assert(o2!=0, "Object 2 has been committed, but can't be viewed by Object 1");
 
     test_state(o2, o22222s, "22222-ef990", "is two content");
 
-    n_object* o3 = n_see(o22222, "33333-18bbc");
+    k_log_out("o22222 views o33333 ------------------");
+
+    n_object* o3 = n_view(o22222, "33333-18bbc");
+
+    k_assert(!o3, "Object 3 has not been created yet, but Object 2 can view it:\n%s", n_to_string(o3));
+}
+
+/* -------------------------------------------------------------------------- */
+
+void view_event_1(n_object* o, n_object* v)
+{
+}
+
+/* 2 -> 1 */
+void cast_event_1(n_object* o, n_object* c)
+{
+}
+
+/* -------------------------------------------------------------------------- */
+
+/* 1 -> 2 []; 1 -> 2 [*] */
+void view_event_2(n_object* o, n_object* v)
+{
+}
 
-    k_assert(!o3, "Object 3 has not been created yet, but Object 2 can see it:\n%s", n_to_string(o3));
+/* 3 -> 2 */
+void cast_event_2(n_object* o, n_object* c)
+{
 }
 
-void running_tests(ni_event* evt)
+/* -------------------------------------------------------------------------- */
+
+/* 2 -> 3 [] */
+void view_event_3(n_object* o, n_object* v)
 {
     char* o33333s = 
             "UID: 33333-18bbc\n"
@@ -113,7 +164,10 @@ void running_tests(ni_event* evt)
     n_object* o33333 = n_object_new(o33333s);
 
     n_commit(o33333);
+}
 
+void cast_event_3(n_object* o, n_object* c)
+{
 }
 
 /* -------------------------------------------------------------------------- */