7 #include "../src/ceptr.h"
8 #include "../src/receptor.h"
11 void testCreateTreeNodes() {
15 T *t, *t1, *t2, *t3, *t4, *t5;
17 t = _t_new(0,TEST_STR_SYMBOL,
"hello",6);
18 spec_is_long_equal(
_t_size(t),(
long)6);
20 spec_is_str_equal((
char *)
_t_surface(t),
"hello");
22 spec_is_ptr_equal(
_t_root(t),t);
23 spec_is_ptr_equal(
_t_child(t,1),NULL);
24 spec_is_true(semeq(
_t_symbol(t),TEST_STR_SYMBOL));
26 t1 = _t_new(t,TEST_STR_SYMBOL,
"t1",3);
30 spec_is_ptr_equal(
_t_root(t1),t);
32 t2 = _t_new(t,TEST_STR_SYMBOL,
"t2",3);
36 spec_is_ptr_equal(
_t_root(t2),t);
40 t3 = _t_newi(t,s99,101);
55 t5 = _t_newr(t4,TEST_ANYTHING_SYMBOL2);
57 spec_is_long_equal(
_t_size(t5),(
long)0);
58 spec_is_symbol_equal(0,
_t_symbol(t5),TEST_ANYTHING_SYMBOL2);
69 T *tf = _t_new(0,TEST_FLOAT_SYMBOL,&f,
sizeof(
float));
71 spec_is_str_equal(t2s(tf),
"(TEST_FLOAT_SYMBOL:3.141500)");
86 spec_is_true(!(tr->context.flags & TFLAG_ALLOCATED));
88 spec_is_str_equal(t2s(t),
"(TEST_ANYTHING_SYMBOL (TEST_RECEPTOR:{(RECEPTOR_INSTANCE (INSTANCE_OF:TEST_RECEPTOR) (CONTEXT_NUM:3) (PARENT_CONTEXT_NUM:0) (RECEPTOR_STATE (FLUX (DEFAULT_ASPECT (EXPECTATIONS) (SIGNALS))) (PENDING_SIGNALS) (PENDING_RESPONSES) (CONVERSATIONS) (RECEPTOR_ELAPSED_TIME:0)))}))");
99 spec_is_true(ts->context.flags &= TFLAG_SURFACE_IS_SCAPE);
101 spec_is_str_equal(t2s(ts),
"(TEST_ALPHABETIZE_SCAPE_SYMBOL:key TEST_INT_SYMBOL,data TEST_STR_SYMBOL)");
110 char buffer[] =
"line1\nline2\n";
111 stream = fmemopen(buffer, strlen (buffer),
"r+");
113 Stream *s = _st_new_unix_stream(stream,0);
116 spec_is_true(ts->context.flags & TFLAG_SURFACE_IS_CPTR);
117 spec_is_true(ts->context.flags & TFLAG_REFERENCE);
121 spec_is_str_equal(x,
"(EDGE_STREAM");
131 void testTreeOrthogonal() {
133 T *t2 = _t_newi(0,TEST_INT_SYMBOL2,99);
134 T *o =
_t_newt(t,TEST_TREE_SYMBOL,t2);
136 spec_is_str_equal(t2s(t),
"(TEST_ANYTHING_SYMBOL (TEST_TREE_SYMBOL:{(TEST_INT_SYMBOL2:99)}))");
139 spec_is_str_equal(t2s(tc),
"(TEST_ANYTHING_SYMBOL (TEST_TREE_SYMBOL:{(TEST_INT_SYMBOL2:99)}))");
145 void testTreeRealloc() {
147 T *t = _t_new(0,TEST_STR_SYMBOL,
"t",2);
154 ts[i] = _t_new(t,TEST_STR_SYMBOL,tname,3);
156 spec_is_str_equal((
char *)
_t_surface(ts[11]),
"tl");
164 int p0[] = {TREE_PATH_TERMINATOR};
165 int p1[] = {1,TREE_PATH_TERMINATOR};
166 int p2[] = {2,TREE_PATH_TERMINATOR};
167 int p3[] = {3,TREE_PATH_TERMINATOR};
168 int p33[] = {3,3,TREE_PATH_TERMINATOR};
169 int p331[] = {3,3,1,TREE_PATH_TERMINATOR};
170 int p3312[] = {3,3,1,2,TREE_PATH_TERMINATOR};
171 int p33122[] = {3,3,1,2,2,TREE_PATH_TERMINATOR};
172 int p311[] = {3,1,1,TREE_PATH_TERMINATOR};
174 spec_is_ptr_equal(
_t_get(t,p0),t);
178 spec_is_symbol_equal(0,
_t_symbol(
_t_get(t,p33)),HTTP_REQUEST_PATH_QUERY);
179 spec_is_symbol_equal(0,
_t_symbol(
_t_get(t,p331)),HTTP_REQUEST_PATH_QUERY_PARAMS);
180 spec_is_symbol_equal(0,
_t_symbol(
_t_get(t,p3312)),HTTP_REQUEST_PATH_QUERY_PARAM);
182 spec_is_symbol_equal(0,
_t_symbol(
_t_get(t,p311)),HTTP_REQUEST_PATH_SEGMENT);
184 spec_is_str_equal(t2s(
_t_getv(t,3,3,1,2,TREE_PATH_TERMINATOR)),
"(HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:page) (PARAM_VALUE:2))");
188 spec_is_ptr_equal(
_t_get(t,p311),NULL);
198 int p1[] = {3,1,1,TREE_PATH_TERMINATOR};
199 int p2[] = {3,1,2,TREE_PATH_TERMINATOR};
200 int p3[] = {3,3,1,2,2,TREE_PATH_TERMINATOR};
207 T *tt =
_t_newt(0,TEST_TREE_SYMBOL,t);
208 int po[] = {0,TREE_PATH_TERMINATOR};
209 int po1[] = {0,3,1,1,TREE_PATH_TERMINATOR};
213 spec_is_ptr_equal(x,t);
223 int p0[] = {TREE_PATH_TERMINATOR};
224 int p1[] = {1,TREE_PATH_TERMINATOR};
225 int p2[] = {3,1,TREE_PATH_TERMINATOR};
226 int p3[] = {3,1,1,TREE_PATH_TERMINATOR};
230 spec_is_path_equal(path,p0);
233 spec_is_path_equal(path,p1);
236 spec_is_path_equal(path,p3);
239 spec_is_path_equal(path,p2);
248 int p0[] = {TREE_PATH_TERMINATOR};
249 int p1[] = {1,TREE_PATH_TERMINATOR};
250 int p2[] = {2,TREE_PATH_TERMINATOR};
251 int p3[] = {2,1,1,TREE_PATH_TERMINATOR};
252 int p4[] = {3,0,TREE_PATH_TERMINATOR};
253 int p5[] = {3,0,2,1,1,TREE_PATH_TERMINATOR};
269 int p0[] = {TREE_PATH_TERMINATOR};
270 int p1[] = {1,TREE_PATH_TERMINATOR};
271 int p2[] = {3,0,TREE_PATH_TERMINATOR};
272 int p3[] = {2,1,1,TREE_PATH_TERMINATOR};
273 int p5[] = {3,0,2,1,1,TREE_PATH_TERMINATOR};
286 int p5[] = {3,0,2,1,1,TREE_PATH_TERMINATOR};
289 spec_is_path_equal(pp,p5);
296 int p5[] = {3,0,2,1,1,TREE_PATH_TERMINATOR};
304 T *x,*t =
_t_parse(G_sem,0,
"(Root (A) (B (C (D) (E))) (F))");
310 spec_is_str_equal(t2s(x),
"(A)");
311 int p1[] = {1,TREE_PATH_TERMINATOR};
312 spec_is_path_equal(path,p1);
313 spec_is_equal(len,2*
sizeof(
int));
316 spec_is_str_equal(t2s(x),
"(D)");
317 int p2[] = {2,1,1,TREE_PATH_TERMINATOR};
318 spec_is_path_equal(path,p2);
319 spec_is_equal(len,4*
sizeof(
int));
322 spec_is_str_equal(t2s(x),
"(E)");
323 int p3[] = {2,1,2,TREE_PATH_TERMINATOR};
324 spec_is_path_equal(path,p3);
327 spec_is_str_equal(t2s(x),
"(C (D) (E))");
328 int p4[] = {2,1,TREE_PATH_TERMINATOR};
329 spec_is_path_equal(path,p4);
332 spec_is_str_equal(t2s(x),
"(B (C (D) (E)))");
333 int p5[] = {2,TREE_PATH_TERMINATOR};
334 spec_is_path_equal(path,p5);
337 spec_is_str_equal(t2s(x),
"(F)");
338 int p6[] = {3,TREE_PATH_TERMINATOR};
339 spec_is_path_equal(path,p6);
342 spec_is_str_equal(t2s(x),
"(Root (A) (B (C (D) (E))) (F))");
343 int p7[] = {TREE_PATH_TERMINATOR};
344 spec_is_path_equal(path,p7);
347 spec_is_ptr_equal(x,NULL);
375 __t_dump(G_sem,c,0,buf1);
376 __t_dump(G_sem,t,0,buf2);
378 spec_is_str_equal(buf1,buf2);
393 T *t_version = _t_newr(0,HTTP_REQUEST_VERSION);
394 _t_newi(t_version,VERSION_MAJOR,1);
395 _t_newi(t_version,VERSION_MINOR,1);
398 int p[] = {1,TREE_PATH_TERMINATOR};
399 spec_is_str_equal(t2s(
_t_get(t,p)),
"(HTTP_REQUEST_VERSION (VERSION_MAJOR:1) (VERSION_MINOR:1))");
403 t =
_t_build(G_sem,0,SEMANTIC_MAP,SEMANTIC_LINK,USAGE,REQUEST_TYPE,REPLACEMENT_VALUE,ACTUAL_SYMBOL,PING,NULL_SYMBOL,NULL_SYMBOL,NULL_SYMBOL);
405 T *t2 =
_t_build(G_sem,0,TEST_ANYTHING_SYMBOL,TEST_INT_SYMBOL,1,TEST_INT_SYMBOL,2,TEST_INT_SYMBOL,1,TEST_INT_SYMBOL,3,NULL_SYMBOL,NULL_SYMBOL);
409 spec_is_str_equal(t2s(t),
"(TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:2) (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:3))");
414 t2 = _t_newi(0,TEST_INT_SYMBOL,314);
416 spec_is_str_equal(t2s(t),
"(TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:314) (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:3))");
430 T *t_version = _t_newr(0,HTTP_REQUEST_VERSION);
431 _t_newi(t_version,VERSION_MAJOR,1);
432 _t_newi(t_version,VERSION_MINOR,2);
434 spec_is_str_equal(t2s(
_t_child(t,1)),
"(HTTP_REQUEST_VERSION (VERSION_MAJOR:1) (VERSION_MINOR:1))");
437 spec_is_str_equal(t2s(s),
"(HTTP_REQUEST_VERSION (VERSION_MAJOR:1) (VERSION_MINOR:1))");
439 spec_is_str_equal(t2s(
_t_child(t,1)),
"(HTTP_REQUEST_VERSION (VERSION_MAJOR:1) (VERSION_MINOR:2))");
449 int p[] = {3,1,2,TREE_PATH_TERMINATOR};
450 T *c = _t_new(0,HTTP_REQUEST_PATH_SEGMENT,
"a",2);
453 p[2] = TREE_PATH_TERMINATOR;
455 __t_dump(G_sem,c,0,buf);
456 spec_is_str_equal(buf,
"(HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:groups) (HTTP_REQUEST_PATH_SEGMENT:a) (HTTP_REQUEST_PATH_SEGMENT:5))");
463 p[1] = TREE_PATH_TERMINATOR;
466 spec_is_str_equal(t2s(t),
"(ASCII_CHARS (ASCII_CHAR:'x'))");
472 T *x = _t_newi(0,TEST_INT_SYMBOL,123);
473 T *z = _t_new(0,TEST_STR_SYMBOL,
"fish",5);
476 spec_is_str_equal(t2s(x),
"(TEST_STR_SYMBOL:fish)");
485 T *x = _t_new(0,TEST_STR_SYMBOL,
"fish",5);
488 __t_morph(x,TEST_INT_SYMBOL,&i,
sizeof(
int),0);
489 spec_is_str_equal(t2s(x),
"(TEST_INT_SYMBOL:789)");
499 int p1[] = {1,TREE_PATH_TERMINATOR};
507 spec_is_ptr_equal(
_t_parent(t_version),NULL);
520 t->contents.symbol.id++;
522 t->contents.symbol.id--;
525 int p[] = {1,2,TREE_PATH_TERMINATOR};
527 int orig_version = *(
int *)&v->contents.surface;
528 *(
int *)&v->contents.surface = orig_version + 1;
530 *(
int *)&v->contents.surface = orig_version;
542 spec_is_long_equal(
sizeof(
UUIDt),16);
543 UUIDt u = __uuid_gen();
546 clock_gettime(CLOCK_MONOTONIC, &c);
547 uint64_t t = ((c.tv_sec * (1000000)) + (c.tv_nsec / 1000));
550 spec_is_long_equal(u.time,t);
557 char buf[2000] = {0};
558 char buf1[2000] = {0};
560 __t_dump(G_sem,t,0,buf);
567 t1 = _t_unserialize(G_sem,&surface,&l,0);
568 __t_dump(G_sem,t1,0,buf1);
570 spec_is_str_equal(buf1,buf);
581 char buf[5000] = {0};
588 wjson(G_sem,t,
"httpreq",0);
589 char *stxs =
"/%<HTTP_REQUEST_PATH_SEGMENTS:HTTP_REQUEST_PATH_SEGMENTS,HTTP_REQUEST_PATH_FILE>";
592 wjson(G_sem,stx,
"httpreq",1);
596 wjson(G_sem,r,
"httpreq",2);
605 void testProcessHTML() {
606 T *t = parseHTML(
"<html><body><div id=\"314\" class=\"contents\">Hello world<img src=\"test.png\"/></div></body></html>");
607 spec_is_str_equal(t2s(t),
"(HTML_HTML (HTML_ATTRIBUTES) (HTML_CONTENT (HTML_BODY (HTML_ATTRIBUTES) (HTML_CONTENT (HTML_DIV (HTML_ATTRIBUTES (HTML_ATTRIBUTE (PARAM_KEY:id) (PARAM_VALUE:314)) (HTML_ATTRIBUTE (PARAM_KEY:class) (PARAM_VALUE:contents))) (HTML_CONTENT (HTML_TEXT:Hello world) (HTML_IMG (HTML_ATTRIBUTES (HTML_ATTRIBUTE (PARAM_KEY:src) (PARAM_VALUE:test.png))) (HTML_CONTENT))))))))");
615 T *t =
_t_build(G_sem,0,TEST_ANYTHING_SYMBOL,ACTION,IF,TEST_ANYTHING_SYMBOL,TEST_STR_SYMBOL,
"fish",NULL_SYMBOL,TEST_INT_SYMBOL,3141,SIGNAL_REF,SignalMessageIdx,MessageHeadIdx,HeadCarrierIdx,TREE_PATH_TERMINATOR,NULL_SYMBOL);
616 spec_is_str_equal(t2s(t),
"(TEST_ANYTHING_SYMBOL (ACTION:IF) (TEST_ANYTHING_SYMBOL (TEST_STR_SYMBOL:fish)) (TEST_INT_SYMBOL:3141) (SIGNAL_REF:/2/1/4))");
620 t =
_t_build(G_sem,0,SYMBOL_DEFINITION,SYMBOL_LABEL,ENGLISH_LABEL,
"shoe size",NULL_SYMBOL,SYMBOL_STRUCTURE,INTEGER,NULL_SYMBOL);
621 spec_is_str_equal(t2s(t),
"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:shoe size)) (SYMBOL_STRUCTURE:INTEGER))");
623 t =
_t_build(G_sem,0,TODAY,YEAR,2015,MONTH,1,DAY,30,NULL_SYMBOL);
624 spec_is_str_equal(t2s(t),
"(TODAY (YEAR:2015) (MONTH:1) (DAY:30))");
627 t =
_t_build(G_sem,0,PATTERN,SEMTREX_SYMBOL_LITERAL,SEMTREX_SYMBOL,PING,NULL_SYMBOL);
628 spec_is_str_equal(t2s(t),
"(PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PING)))");
632 t =
_t_build(G_sem,0,RESPOND,SIGNAL_REF,SignalMessageIdx,MessageHeadIdx,HeadCarrierIdx,TREE_PATH_TERMINATOR,YUP,NULL_SYMBOL);
633 spec_is_str_equal(t2s(t),
"(process:RESPOND (SIGNAL_REF:/2/1/4) (YUP))");
637 t =
_t_build(G_sem,0,TEST_FLOAT_SYMBOL,3.14);
638 spec_is_str_equal(t2s(t),
"(TEST_FLOAT_SYMBOL:3.140000)");
642 t =
_t_build(G_sem,0,ASCII_CHAR,
'x');
643 spec_is_str_equal(t2s(t),
"(ASCII_CHAR:'x')");
648 t =
_t_build2(G_sem,0,STX_OP,PROTOCOL_DEFINITION,STX_OP,PROTOCOL_LABEL,STX_OP,ENGLISH_LABEL,
"RECOGNIZE",STX_CP,STX_CP,STX_OP,PROTOCOL_SEMANTICS,STX_CP,STX_OP,INCLUSION,STX_OP,PNAME,REQUESTING,STX_CP,STX_OP,LINKAGE,STX_OP,WHICH_ROLE,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,ROLE,RECOGNIZER,STX_CP,STX_CP,STX_CP,STX_OP,LINKAGE,STX_OP,WHICH_ROLE,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,ROLE,RECOGNIZEE,STX_CP,STX_CP,STX_CP,STX_OP,LINKAGE,STX_OP,WHICH_GOAL,STX_OP,GOAL,RESPONSE_HANDLER,STX_CP,STX_OP,GOAL,RECOGNITION,STX_CP,STX_CP,STX_CP,STX_OP,RESOLUTION,STX_OP,WHICH_SYMBOL,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_OP,ACTUAL_SYMBOL,are_you,STX_CP,STX_CP,STX_CP,STX_OP,RESOLUTION,STX_OP,WHICH_SYMBOL,STX_OP,USAGE,RESPONSE_TYPE,STX_CP,STX_OP,ACTUAL_SYMBOL,i_am,STX_CP,STX_CP,STX_CP,STX_OP,RESOLUTION,STX_OP,WHICH_PROCESS,STX_OP,GOAL,REQUEST_HANDLER,STX_CP,STX_OP,ACTUAL_PROCESS,fill_i_am,STX_CP,STX_CP,STX_CP,STX_CP,STX_CP);
649 spec_is_str_equal(t2s(t),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:RECOGNIZE)) (PROTOCOL_SEMANTICS) (INCLUSION (PNAME:REQUESTING) (LINKAGE (WHICH_ROLE (ROLE:REQUESTER) (ROLE:RECOGNIZER))) (LINKAGE (WHICH_ROLE (ROLE:RESPONDER) (ROLE:RECOGNIZEE))) (LINKAGE (WHICH_GOAL (GOAL:RESPONSE_HANDLER) (GOAL:RECOGNITION))) (RESOLUTION (WHICH_SYMBOL (USAGE:REQUEST_TYPE) (ACTUAL_SYMBOL:are_you))) (RESOLUTION (WHICH_SYMBOL (USAGE:RESPONSE_TYPE) (ACTUAL_SYMBOL:i_am))) (RESOLUTION (WHICH_PROCESS (GOAL:REQUEST_HANDLER) (ACTUAL_PROCESS:fill_i_am)))))");
653 t =
_t_build2(G_sem,0,STX_OP,ASCII_CHAR,
'x',STX_CP);
654 spec_is_str_equal(t2s(t),
"(ASCII_CHAR:'x')");
665 T *
template =
_t_parse(G_sem,0,
"(PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:REQUEST_TYPE) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL))))");
666 T *sem_map =
_t_parse(G_sem,0,
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))))");
667 _t_fill_template(
template,sem_map);
668 spec_is_str_equal(t2s(
template),
"(PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PING)))");
673 template =
_t_build(G_sem,0,REQUEST,SLOT,ROLE,RESPONDER,SLOT_IS_VALUE_OF,TO_ADDRESS,NULL_SYMBOL,SLOT,USAGE,REQUEST_TYPE,NULL_SYMBOL,SLOT,USAGE,REQUEST_TYPE,NULL_SYMBOL,NULL_SYMBOL);
674 spec_is_str_equal(t2s(
template),
"(process:REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:REQUEST_TYPE)) (SLOT (USAGE:REQUEST_TYPE)))");
675 sem_map =
_t_parse(G_sem,0,
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (ACTUAL_RECEPTOR (RECEPTOR_ADDR:3)))))");
676 _t_fill_template(
template,sem_map);
677 spec_is_str_equal(t2s(
template),
"(process:REQUEST (TO_ADDRESS (RECEPTOR_ADDR:3)) (PING) (PING))");
682 template =
_t_parse(G_sem,0,
"(PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:REQUEST_TYPE))))");
683 sem_map =
_t_parse(G_sem,0,
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (SEMTREX_SYMBOL:PING))))");
684 _t_fill_template(
template,sem_map);
685 spec_is_str_equal(t2s(
template),
"(PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PING)))");
691 template =
_t_parse(G_sem,0,
"(SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (TEST_INT_SYMBOL:1) (SLOT (USAGE:REQUEST_TYPE))))");
692 sem_map =
_t_parse(G_sem,0,
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (TEST_INT_SYMBOL:32))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:ADD_INT))))");
693 _t_fill_template(
template,sem_map);
694 spec_is_str_equal(t2s(
template),
"(process:ADD_INT (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:32))");
700 template =
_t_parse(G_sem,0,
"(SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (TEST_INT_SYMBOL:1) (SLOT (USAGE:REQUEST_TYPE)) (TEST_INT_SYMBOL:2)))");
701 sem_map =
_t_parse(G_sem,0,
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (NULL_SYMBOL))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:ADD_INT))))");
702 _t_fill_template(
template,sem_map);
703 spec_is_str_equal(t2s(
template),
"(process:ADD_INT (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:2))");
712 void testTreeStreamWrite() {
713 char buffer[500] =
"x";
715 stream = fmemopen(buffer, 500,
"r+");
716 Stream *st = _st_new_unix_stream(stream,1);
717 T *t = _t_new_str(0,TEST_STR_SYMBOL,
"fish\n");
718 spec_is_equal(
_t_write(G_sem,t,st),5);
719 spec_is_str_equal(buffer,
"fish\n");
722 t = _t_new_str(0,LINE,
"cow");
723 spec_is_equal(
_t_write(G_sem,t,st),4);
724 spec_is_str_equal(buffer,
"fish\ncow\n");
728 _t_new_str(t,LINE,
"thing1");
729 _t_new_str(t,LINE,
"thing2");
733 t = _t_newi(0,TEST_INT_SYMBOL,314);
737 char *expected_result =
"fish\ncow\nthing1\nthing2\n(TEST_INT_SYMBOL:314)";
738 spec_is_str_equal(buffer,expected_result);
743 void testTreeInt64() {
744 T *t = _t_newi64(0,TEST_INT64_SYMBOL,5000000001);
745 spec_is_str_equal(t2s(t),
"(TEST_INT64_SYMBOL:5000000001)");
749 void testTreeFindBySymbol() {
755 T *match = _t_newr(0,PATTERN);
756 _sl(match,TEST_INT_SYMBOL);
757 UUIDt cuuid = __uuid_gen();
758 T *cid = __cid_new(0,&cuuid,0);
760 T *t = __r_build_expectation(TEST_INT_SYMBOL,match,
_t_newp(0,ACTION,NOOP),0,0,NULL,cid);
762 spec_is_ptr_equal(
__t_find(t,CONVERSATION_IDENT,ExpectationOptionalsIdx),cid);
763 spec_is_ptr_equal(
__t_find(t,SEMANTIC_MAP,ExpectationOptionalsIdx),NULL);
768 void testTreeParse() {
769 char *s =
"( ) \n\t TEST_LABEL:1 1.2 .334 /) 'c'%\"string\" /1/2/3)";
770 T *t = __t_tokenize(s);
771 spec_is_str_equal(t2s(t),
"(P_TOKENS (P_OP) (P_CP) (P_LABEL:TEST_LABEL) (P_COLON) (P_VAL_I:1) (P_VAL_F:1.200000) (P_VAL_F:0.334000) (P_VAL_PATH:/) (P_CP) (P_VAL_C:'c') (P_INTERPOLATE) (P_VAL_S:string) (P_VAL_PATH:/1/2/3) (P_CP))");
773 s =
"(DO (SCOPE (TEST_INT_SYMBOL:1) (TEST_CHAR_SYMBOL:'x')% (TEST_STR_SYMBOL:\"fish\") (PARAM_REF:/1/2/3) (CARRIER:backnforth)))";
774 t =
_t_parse(G_sem,0,s,_t_newc(0,ASCII_CHAR,
'y'));
775 spec_is_str_equal(t2s(t),
"(process:DO (SCOPE (TEST_INT_SYMBOL:1) (TEST_CHAR_SYMBOL:'x') (ASCII_CHAR:'y') (TEST_STR_SYMBOL:fish) (PARAM_REF:/1/2/3) (CARRIER:backnforth)))");
778 s =
"(SIGNATURE_SYMBOL:NULL_SYMBOL)";
780 spec_is_str_equal(t2s(t),s);
785 spec_is_str_equal(t2s(t),s);
790 testCreateTreeNodes();
794 testTreeOrthogonal();
819 testTreeStreamWrite();
821 testTreeFindBySymbol();
T * _t_new_root(Symbol symbol)
Scape * _s_new(Symbol key_source, Symbol data_source)
T * _t_next_sibling(T *t)
T * _t_new_scape(T *parent, Symbol symbol, Scape *s)
void _t_morph(T *dst, T *src)
T * _t_build2(SemTable *sem, T *parent,...)
void testTreeMorphLowLevel()
void testTreePathGetPath()
int _t_write(SemTable *sem, T *t, Stream *stream)
T * _t_path_walk(T *t, int **pathP, int *lenP)
int _t_hash_equal(TreeHash h1, TreeHash h2)
T * _t_detach_by_idx(T *t, int i)
int _t_path_depth(int *p)
T * _t_new_receptor(T *parent, Symbol symbol, Receptor *r)
TreeHash _t_hash(SemTable *sem, T *t)
void _t_serialize(SemTable *sem, T *t, void **surfaceP, size_t *lengthP)
T * _t_child(T *t, int i)
T * _t_newp(T *parent, Symbol symbol, Process surface)
T * _t_swap(T *t, int i, T *r)
void _t_pathcpy(int *dst_p, int *src_p)
void _t_insert_at(T *t, int *path, T *i)
void testTreeNewReceptor()
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
T * _t_newt(T *parent, Symbol symbol, T *surface)
void _t_replace_node(T *t, T *r)
void _st_free(Stream *st)
int _t_matchr(T *semtrex, T *t, T **rP)
void * _t_get_surface(T *t, int *p)
T * __t_find(T *t, SemanticID sym, int start_child)
void testTreePathGetSurface()
T * _makeTestHTTPRequestTree()
[makeTestHTTPRequestTree]
void testTreePathSprint()
#define _sl(t, s)
macro to add a single symbol literal to semtrex tree
T * parseSemtrex(SemTable *sem, char *stx)
T * _t_parse(SemTable *sem, T *parent, char *s,...)
int _t_path_equal(int *p1, int *p2)
char * _t2json(SemTable *sem, T *t, int level, char *buf)
void __t_morph(T *t, Symbol s, void *surface, size_t size, int allocate)
void _t_replace(T *t, int i, T *r)
void _t_detach_by_ptr(T *t, T *c)
T * _t_build(SemTable *sem, T *parent,...)
T * _t_new_cptr(T *parent, Symbol symbol, void *s)
char * _t_sprint_path(int *fp, char *buf)