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)
k_log_out("Test NI Driver initialised");
+ start_tests();
+
return 1;
}
EXPORT int testni_module_event(void* data)
{
- k_log_out("Test NI got event: %p", data);
ni_event* evt=data;
+
+ running_tests(evt);
+
ni_event_delete(evt);
return 1;
}
/* -------------------------------------------------------------------------- */
-
+/*
+ - 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");
+}
+
+/* -------------------------------------------------------------------------- */
+
/* -------------------------------------------------------------------------- */
+typedef struct n_object{
+ k_hashtable* headers;
+ k_hashtable* content;
+} n_object;
+
+PUBLIC n_object* n_object_new(char* s);
+PUBLIC void n_commit(n_object* o);
+PUBLIC n_object* n_see(n_object* o, char* uid);
+PUBLIC char* n_to_string(n_object* o);
+PUBLIC char* n_uid(n_object* o);
+PUBLIC char* n_header(n_object* o, char* name);
+PUBLIC k_hashtable* n_headers(n_object* o);
+PUBLIC k_hashtable* n_content(n_object* o);
+
+/* -------------------------------------------------------------------------- */
+
PUBLIC char* ni_hostname(void);
PUBLIC void ni_hostname_set(char* name);
char* protocol,
char* connection,
k_channel* chan);
-EXPORT void ni_request(ni_event* evt,
+PUBLIC void ni_request(ni_event* evt,
char* to,
char* method,
k_channel* chan);
/* -}{---- ------------------------------------------------------------------ */
+EXPORT n_object* n_object_new(char* s)
+{
+ return 0;
+}
+
+EXPORT void n_commit(n_object* o)
+{
+}
+
+EXPORT n_object* n_see(n_object* o, char* uid)
+{
+ return 0;
+}
+
+EXPORT char* n_to_string(n_object* o)
+{
+ return 0;
+}
+
+EXPORT char* n_uid(n_object* o)
+{
+ return 0;
+}
+
+EXPORT char* n_header(n_object* o, char* name)
+{
+ return 0;
+}
+
+EXPORT k_hashtable* n_headers(n_object* o)
+{
+ return 0;
+}
+
+EXPORT k_hashtable* n_content(n_object* o)
+{
+ return 0;
+}
+
+/* -}{---- ------------------------------------------------------------------ */
+
#define TMPBUFSIZE 4096
static char tmpbuf[TMPBUFSIZE];
static char* hostname;
{
ni_driver* d=ni_driver_new(name, handles_resource, sync_resource);
if(!strcmp(name, "np")) npdriver=d;
- else moddriver=d;
+ else moddriver=d;
}
/* -}{---- ------------------------------------------------------------------ */
va_list ap;
va_start(ap, format);
if(LOG_TO_STD){
- VPRINTFERR(format,ap);
+ VPRINTFERR(format, ap);
PRINTFERR("\n");
FFLUSH(stderr);
}
va_end(ap);
}
+EXPORT void k_assert(int t, char* format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ if(!t){
+ if(LOG_TO_STD){
+ VPRINTFERR(format, ap);
+ PRINTFERR("\n");
+ FFLUSH(stderr);
+ }
+ else{
+ vsnprintf(logbuf, LOGBUFSIZE,format,ap);
+ *(logbuf+LOGBUFSIZE-2)='\n';
+ *(logbuf+LOGBUFSIZE-1)=0;
+ write_to_logfile_cern_style(logbuf,1);
+ }
+ k_log_err("Terminating Cilux");
+ k_log_err("---------------------");
+ EXIT(-1);
+ }
+ va_end(ap);
+}
+
EXPORT void k_fatal(char* format, ...)
{
va_list ap;
va_start(ap, format);
- k_log_out(format, ap);
+ if(LOG_TO_STD){
+ VPRINTFERR(format, ap);
+ PRINTFERR("\n");
+ FFLUSH(stderr);
+ }
+ else{
+ vsnprintf(logbuf, LOGBUFSIZE,format,ap);
+ *(logbuf+LOGBUFSIZE-2)='\n';
+ *(logbuf+LOGBUFSIZE-1)=0;
+ write_to_logfile_cern_style(logbuf,1);
+ }
va_end(ap);
- k_log_out("Terminating Cilux");
- k_log_out("---------------------");
+ k_log_err("Terminating Cilux");
+ k_log_err("---------------------");
EXIT(1);
}