2 /* -------------------------------------------------------------------------- */
5 #include <notification.h>
7 /* -------------------------------------------------------------------------- */
9 static int handles_resource(char* name);
10 static void sync_resource(ni_resource* res);
12 static void start_tests(void);
13 static void running_tests(ni_event* evt);
15 static void test_state(n_object* o, char* os, char* uid, char* cont);
17 /* -------------------------------------------------------------------------- */
19 EXPORT int teston_module_loaded(void)
21 ni_register_driver("teston", handles_resource, sync_resource);
23 k_log_out("Test ON Driver initialised");
30 EXPORT int teston_module_event(void* data)
40 EXPORT int teston_module_tick(void)
45 /* -------------------------------------------------------------------------- */
47 int handles_resource(char* name)
52 void sync_resource(ni_resource* res)
56 /* -------------------------------------------------------------------------- */
59 - object.create .update .commit .rollback (auto inc version #?)
60 - object.see - may return empty so wait for ..
61 - seestate(object) - state asked for /or/ object is subscribing
63 void start_tests(void)
65 k_log_out("Creating o11111");
67 char* o11111s = "UID: 11111-4141a\n"
69 "This: is one content\n";
71 n_object* o11111 = n_object_new(o11111s);
73 test_state(o11111, o11111s, "11111-4141a", "is one content");
75 k_log_out("Committing o11111");
79 k_log_out("Creating o22222");
81 char* o22222s = "UID: 22222-ef990\n"
83 "This: is two content\n";
85 n_object* o22222 = n_object_new(o22222s);
87 test_state(o22222, o22222s, "22222-ef990", "is two content");
89 n_object* o2 = n_see(o11111, "22222-ef990");
91 k_assert(!o2, "Object 2 has not been committed yet, but Object 1 can see it:\n%s\n", n_to_string(o2));
95 o2 = n_see(o11111, "22222-ef990");
97 k_assert(o2!=0, "Object 2 has been committed, but can't be seen by Object 1");
99 test_state(o2, o22222s, "22222-ef990", "is two content");
101 n_object* o3 = n_see(o22222, "33333-18bbc");
103 k_assert(!o3, "Object 3 has not been created yet, but Object 2 can see it:\n%s", n_to_string(o3));
106 void running_tests(ni_event* evt)
111 "This: is three content\n";
113 n_object* o33333 = n_object_new(o33333s);
119 /* -------------------------------------------------------------------------- */
121 void test_state(n_object* o, char* os, char* uid, char* cont)
125 k_log_out("Checking %s", uid);
128 k_assert(c && !strcmp(c, os), "To-string was\n%s", c? c: "null");
131 k_assert(c && !strcmp(c, uid), "UID was %s in n_uid", c? c: "null");
133 c=n_header(o, "UID");
134 k_assert(c && !strcmp(c, uid), "UID was %s in n_header", c? c: "null");
136 c=k_hashtable_get(n_headers(o), "UID");
137 k_assert(c && !strcmp(c, uid), "UID was %s in hash get", c? c: "null");
139 c=k_hashtable_get(n_content(o), "This");
140 k_assert(c && !strcmp(c, cont), "Content was %s", c? c: "null");
143 k_assert(c && !strcmp(c, os), "To-string was\n%s", c? c: "null");
146 /* -------------------------------------------------------------------------- */