From 619f9bfb6fa67df9d3c1b2f4b21a497494a5e0b3 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 20 Mar 2009 16:30:12 +0000 Subject: [PATCH] first round of tests, now with utf-8 --- src/drivers/ot/test/teston.c | 83 +++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/src/drivers/ot/test/teston.c b/src/drivers/ot/test/teston.c index 9379891..387becd 100644 --- a/src/drivers/ot/test/teston.c +++ b/src/drivers/ot/test/teston.c @@ -84,48 +84,39 @@ void cast_event(n_object* o, n_object* c) void start_tests(void) { k_log_out("Creating o11111 ------------------"); - char* o11111s = "UID: 11111-4141a\n" "\n" - "This: is one content\n"; - + "Cost: £111\n"; n_object* o11111 = n_object_new(o11111s); - - test_state(o11111, o11111s, "11111-4141a", "is one content"); - + test_state(o11111, o11111s, "11111-4141a", "£111"); k_log_out("Committing o11111"); - n_commit(o11111); k_log_out("Creating o22222 ------------------"); - char* o22222s = "UID: 22222-ef990\n" + "Permit: - UID: 11111-4141a\n" + " quiet\n" "\n" - "This: is two content\n"; - + "Cost: £222\n"; n_object* o22222 = n_object_new(o22222s); - - test_state(o22222, o22222s, "22222-ef990", "is two content"); + test_state(o22222, o22222s, "22222-ef990", "£222"); k_log_out("o11111 views o22222 ------------------"); - - n_object* o2 = n_view(o11111, "22222-ef990"); - + n_object* o2 = n_view(o11111, "22222-ef990"); /* creates Cast:/shell o2 and sends View event to o2 */ 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(o11111); /* ?? commit View (i.e. header change set) */ - n_commit(o22222); - - o2 = n_view(o11111, "22222-ef990"); + n_commit(o22222); /* merges with shell and sends Cast event to o1 */ + k_log_out("o11111 views o22222 ------------------"); + o2 = n_view(o11111, "22222-ef990"); /* quiet, so no View event to o2, satisfiable now so no Cast event to o1 */ 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"); + test_state(o2, o22222s, "22222-ef990", "£222"); k_log_out("o22222 views o33333 ------------------"); - - n_object* o3 = n_view(o22222, "33333-18bbc"); - + n_object* o3 = n_view(o22222, "33333-18bbc"); /* creats Cast:/shell o3 and sends View event to o3 */ k_assert(!o3, "Object 3 has not been created yet, but Object 2 can view it:\n%s", n_to_string(o3)); + n_commit(o22222); /* ?? commit View (i.e. header change set) */ } /* -------------------------------------------------------------------------- */ @@ -134,35 +125,57 @@ void view_event_1(n_object* o, n_object* v) { } -/* 2 -> 1 */ void cast_event_1(n_object* o, n_object* c) { + k_log_out("o11111 is cast o22222 ------------------"); + test_state(c, 0, "22222-ef990", "£222"); + k_assert(!strcmp(n_header(o, "View:1:UID"), "22222-ef990"), "o1 <-Cast- o2: o1 first View UID not o2" ); + k_assert(!strcmp(n_header(c, "Cast:1:UID"), "11111-4141a"), "o1 <-Cast- o2: o2 first Cast UID not o1" ); + k_assert(!strcmp(n_header(c, "Permit:1:UID"), "11111-4141a"), "o1 <-Cast- o2: o2 first Permit UID not o1" ); } /* -------------------------------------------------------------------------- */ -/* 1 -> 2 []; 1 -> 2 [*] */ void view_event_2(n_object* o, n_object* v) { + k_log_out("o22222 gets view from o11111 ------------------"); + test_state(v, 0, "11111-4141a", "£111"); + k_assert(!strcmp(n_header(v, "View:1:UID"), "22222-ef990"), "o1 -View-> o2: o1 first View UID not o2" ); + k_assert(!strcmp(n_header(o, "Cast:1:UID"), "11111-4141a"), "o1 -View-> o2: o2 first Cast UID not o1" ); + k_assert(!strcmp(n_header(o, "Permit:1:UID"), "11111-4141a"), "o1 -View-> o2: o2 first Permit UID not o1" ); } -/* 3 -> 2 */ void cast_event_2(n_object* o, n_object* c) { + k_log_out("o22222 is cast o33333 ------------------"); + test_state(c, 0, "33333-18bbc", "£333"); + k_assert(!strcmp(n_header(o, "View:1:UID"), "33333-18bbc"), "o2 <-Cast- o3: o2 first View UID not o3" ); + k_assert(!strcmp(n_header(c, "Cast:1:UID"), "22222-ef990"), "o2 <-Cast- o3: o3 first Cast UID not o2" ); + k_assert(!strcmp(n_header(c, "Permit:1:UID"), "22222-ef990"), "o2 <-Cast- o3: o3 first Permit UID not o2" ); } /* -------------------------------------------------------------------------- */ -/* 2 -> 3 [] */ void view_event_3(n_object* o, n_object* v) { - char* o33333s = - "UID: 33333-18bbc\n" - "\n" - "This: is three content\n"; - + k_log_out("o33333 gets view from o22222 ------------------"); + test_state(v, 0, "22222-ef990", "£222"); + k_assert(!strcmp(n_header(v, "View:1:UID"), "33333-18bbc"), "o2 -View-> o3: o2 first View UID not o3" ); + k_assert(!strcmp(n_header(o, "Cast:1:UID"), "22222-ef990"), "o2 -View-> o3: o3 first Cast UID not o2" ); + k_assert( !n_header(o, "Permit:1:UID"), "o2 -View-> o3: o3 has a Permit" ); + + k_log_out("Creating o33333 ------------------"); + char* o33333s = "UID: 33333-18bbc\n" + "Permit: - UID: 22222-ef990\n" + " quiet\n" + "\n" + "Cost: £333\n"; n_object* o33333 = n_object_new(o33333s); + test_state(o33333, o33333s, "33333-18bbc", "£333"); + k_assert(!strcmp(n_header(o33333, "Permit:1:UID"), "22222-ef990"), "o3 first Permit not o2" ); + k_assert(!strcmp(n_header(o33333, "Permit:1:quiet"), ""), "o3 first Permit not quiet" ); + k_log_out("Committing o33333"); n_commit(o33333); } @@ -178,8 +191,10 @@ void test_state(n_object* o, char* os, char* uid, char* cont) k_log_out("Checking %s", uid); + if(os){ 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"); @@ -190,11 +205,13 @@ void test_state(n_object* o, char* os, char* uid, char* cont) 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"); + c=k_hashtable_get(n_content(o), "Cost"); k_assert(c && !strcmp(c, cont), "Content was %s", c? c: "null"); + if(os){ c=n_to_string(o); k_assert(c && !strcmp(c, os), "To-string was\n%s", c? c: "null"); + } } /* -------------------------------------------------------------------------- */ -- 1.7.9.5