+++ /dev/null
-
-/* -------------------------------------------------------------------------- */
-
-#include <kernelapi.h>
-#include <ni.h>
-
-/* -------------------------------------------------------------------------- */
-
-static int handles_resource(char* name);
-static void sync_resource(ni_resource* res);
-
-static void start_tests(void);
-static void running_tests(ni_event* evt);
-
-static void test_state(n_object* o, char* os, char* uid, char* cont);
-
-/* -------------------------------------------------------------------------- */
-
-EXPORT int testni_module_loaded(void)
-{
- ni_register_driver("testni", handles_resource, sync_resource);
-
- k_log_out("Test NI Driver initialised");
-
- start_tests();
-
- return 1;
-}
-
-EXPORT int testni_module_event(void* data)
-{
- ni_event* evt=data;
-
- running_tests(evt);
-
- ni_event_delete(evt);
- return 1;
-}
-
-EXPORT int testni_module_tick(void)
-{
- return 1;
-}
-
-/* -------------------------------------------------------------------------- */
-
-int handles_resource(char* name)
-{
- return 1;
-}
-
-void sync_resource(ni_resource* res)
-{
-}
-
-/* -------------------------------------------------------------------------- */
-
-/*
- - 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
- */
-void start_tests(void)
-{
- k_log_out("Creating o11111");
-
- char* o11111s = "UID: 11111-4141a\n"
- "\n"
- "This: is one content\n";
-
- n_object* o11111 = n_object_new(o11111s);
-
- test_state(o11111, o11111s, "11111-4141a", "is one content");
-
- k_log_out("Committing o11111");
-
- n_commit(o11111);
-
- k_log_out("Creating o22222");
-
- char* o22222s = "UID: 22222-ef990\n"
- "\n"
- "This: is two content\n";
-
- n_object* o22222 = n_object_new(o22222s);
-
- test_state(o22222, o22222s, "22222-ef990", "is two content");
-
- n_object* o2 = n_see(o11111, "22222-ef990");
-
- k_assert(!o2, "Object 2 has not been committed yet, but Object 1 can see it:\n%s\n", n_to_string(o2));
-
- n_commit(o22222);
-
- o2 = n_see(o11111, "22222-ef990");
-
- k_assert(o2!=0, "Object 2 has been committed, but can't be seen by Object 1");
-
- test_state(o2, o22222s, "22222-ef990", "is two content");
-
- n_object* o3 = n_see(o22222, "33333-18bbc");
-
- k_assert(!o3, "Object 3 has not been created yet, but Object 2 can see it:\n%s", n_to_string(o3));
-}
-
-void running_tests(ni_event* evt)
-{
- char* o33333s =
- "UID: 33333-18bbc\n"
- "\n"
- "This: is three content\n";
-
- n_object* o33333 = n_object_new(o33333s);
-
- n_commit(o33333);
-
-}
-
-/* -------------------------------------------------------------------------- */
-
-void test_state(n_object* o, char* os, char* uid, char* cont)
-{
- char* c;
-
- k_log_out("Checking %s", uid);
-
- c=n_to_string(o);
- k_assert(c && !strcmp(c, os), "To-string was\n%s", c? c: "null");
-
- c=n_uid(o);
- k_assert(c && !strcmp(c, uid), "UID was %s in n_uid", c? c: "null");
-
- c=n_header(o, "UID");
- k_assert(c && !strcmp(c, uid), "UID was %s in n_header", c? c: "null");
-
- c=k_hashtable_get(n_headers(o), "UID");
- k_assert(c && !strcmp(c, uid), "UID was %s in hash get", c? c: "null");
-
- c=k_hashtable_get(n_content(o), "This");
- k_assert(c && !strcmp(c, cont), "Content was %s", c? c: "null");
-
- c=n_to_string(o);
- k_assert(c && !strcmp(c, os), "To-string was\n%s", c? c: "null");
-}
-
-/* -------------------------------------------------------------------------- */
-
-
-