2 /* -------------------------------------------------------------------------- */
5 #include <notification.h>
7 /* -------------------------------------------------------------------------- */
9 static int handles_object(char* uid);
10 static void view_event(n_object* o, n_object* v);
11 static void cast_event(n_object* o, n_object* c);
12 static void sync_object(n_object* o);
14 static void start_tests(void);
15 static void view_event_1(n_object* o, n_object* v);
16 static void view_event_2(n_object* o, n_object* v);
17 static void view_event_3(n_object* o, n_object* v);
18 static void cast_event_1(n_object* o, n_object* c);
19 static void cast_event_2(n_object* o, n_object* c);
20 static void cast_event_3(n_object* o, n_object* c);
22 static void test_state(n_object* o, char* os, char* uid, char* cont);
24 /* -------------------------------------------------------------------------- */
26 EXPORT int teston_module_loaded(void)
28 n_register_driver("teston", handles_object, view_event, cast_event, sync_object);
30 k_log_out("Test ON Driver initialised");
37 EXPORT int teston_module_event(void* data)
39 n_dispatch((n_event*)data);
43 EXPORT int teston_module_tick(void)
48 /* -------------------------------------------------------------------------- */
50 int handles_object(char* uid)
55 void sync_object(n_object* o)
59 /* -------------------------------------------------------------------------- */
61 void view_event(n_object* o, n_object* v)
63 if(n_uid_is(o, "11111-4141a")) view_event_1(o,v);
64 if(n_uid_is(o, "22222-ef990")) view_event_2(o,v);
65 if(n_uid_is(o, "33333-18bbc")) view_event_3(o,v);
66 k_assert(0, "No match to UID in view_event");
69 void cast_event(n_object* o, n_object* c)
71 if(n_uid_is(o, "11111-4141a")) cast_event_1(o,c);
72 if(n_uid_is(o, "22222-ef990")) cast_event_2(o,c);
73 if(n_uid_is(o, "33333-18bbc")) cast_event_3(o,c);
74 k_assert(0, "No match to UID in cast_event");
77 /* -------------------------------------------------------------------------- */
80 - object.create .update .commit .rollback (auto inc version #?)
81 - object.view - may return empty so wait for ..
82 - viewstate(object) - state asked for /or/ object is subscribing
84 void start_tests(void)
86 k_log_out("Creating o11111 ------------------");
88 char* o11111s = "UID: 11111-4141a\n"
90 "This: is one content\n";
92 n_object* o11111 = n_object_new(o11111s);
94 test_state(o11111, o11111s, "11111-4141a", "is one content");
96 k_log_out("Committing o11111");
100 k_log_out("Creating o22222 ------------------");
102 char* o22222s = "UID: 22222-ef990\n"
104 "This: is two content\n";
106 n_object* o22222 = n_object_new(o22222s);
108 test_state(o22222, o22222s, "22222-ef990", "is two content");
110 k_log_out("o11111 views o22222 ------------------");
112 n_object* o2 = n_view(o11111, "22222-ef990");
114 k_assert(!o2, "Object 2 has not been committed yet, but Object 1 can view it:\n%s\n", n_to_string(o2));
118 o2 = n_view(o11111, "22222-ef990");
120 k_assert(o2!=0, "Object 2 has been committed, but can't be viewed by Object 1");
122 test_state(o2, o22222s, "22222-ef990", "is two content");
124 k_log_out("o22222 views o33333 ------------------");
126 n_object* o3 = n_view(o22222, "33333-18bbc");
128 k_assert(!o3, "Object 3 has not been created yet, but Object 2 can view it:\n%s", n_to_string(o3));
131 /* -------------------------------------------------------------------------- */
133 void view_event_1(n_object* o, n_object* v)
138 void cast_event_1(n_object* o, n_object* c)
142 /* -------------------------------------------------------------------------- */
144 /* 1 -> 2 []; 1 -> 2 [*] */
145 void view_event_2(n_object* o, n_object* v)
150 void cast_event_2(n_object* o, n_object* c)
154 /* -------------------------------------------------------------------------- */
157 void view_event_3(n_object* o, n_object* v)
162 "This: is three content\n";
164 n_object* o33333 = n_object_new(o33333s);
169 void cast_event_3(n_object* o, n_object* c)
173 /* -------------------------------------------------------------------------- */
175 void test_state(n_object* o, char* os, char* uid, char* cont)
179 k_log_out("Checking %s", uid);
182 k_assert(c && !strcmp(c, os), "To-string was\n%s", c? c: "null");
185 k_assert(c && !strcmp(c, uid), "UID was %s in n_uid", c? c: "null");
187 c=n_header(o, "UID");
188 k_assert(c && !strcmp(c, uid), "UID was %s in n_header", c? c: "null");
190 c=k_hashtable_get(n_headers(o), "UID");
191 k_assert(c && !strcmp(c, uid), "UID was %s in hash get", c? c: "null");
193 c=k_hashtable_get(n_content(o), "This");
194 k_assert(c && !strcmp(c, cont), "Content was %s", c? c: "null");
197 k_assert(c && !strcmp(c, os), "To-string was\n%s", c? c: "null");
200 /* -------------------------------------------------------------------------- */