7 #include "../src/ceptr.h"
8 #include "../src/process.h"
15 code =
_t_parse(G_sem,0,
"(IF (PARAM_REF:/2/3) (PARAM_REF:/2/1) (PARAM_REF:/2/2))");
17 T *signature = __p_make_signature(
"result",SIGNATURE_PASSTHRU,NULL_STRUCTURE,
18 "condition",SIGNATURE_PROCESS,BOOLEAN,
19 "true_branch",SIGNATURE_ANY,NULL_STRUCTURE,
20 "false_branch",SIGNATURE_ANY,NULL_STRUCTURE,
24 spec_is_str_equal(t2s(signature),
"(PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:result)) (SIGNATURE_PASSTHRU)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:condition)) (SIGNATURE_PROCESS:BOOLEAN)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:true_branch)) (SIGNATURE_ANY)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:false_branch)) (SIGNATURE_ANY)))");
26 Process p =
_d_define_process(G_sem,code,
"myif",
"a duplicate of the sys if process with params in different order",signature,NULL,TEST_CONTEXT);
28 T *params =
_t_parse(G_sem,0,
"(PARAMS (TEST_INT_SYMBOL:123) (TEST_INT_SYMBOL:321) (BOOLEAN:1))");
33 spec_is_str_equal(t2s(r),
"(RUN_TREE (process:IF (PARAM_REF:/2/3) (PARAM_REF:/2/1) (PARAM_REF:/2/2)) (PARAMS (TEST_INT_SYMBOL:123) (TEST_INT_SYMBOL:321) (BOOLEAN:1)))");
35 spec_is_equal(
_p_reduce(G_sem,r),noReductionErr);
37 spec_is_str_equal(t2s(
_t_child(r,1)),
"(TEST_INT_SYMBOL:123)");
41 params =
_t_parse(G_sem,0,
"(PARAMS (TEST_INT_SYMBOL:123) (TEST_INT_SYMBOL:321))");
46 spec_is_str_equal(t2s(r),
"(RUN_TREE (process:ADD_INT (TEST_INT_SYMBOL:123) (TEST_INT_SYMBOL:321)) (PARAMS))");
54 void testProcessGet() {
58 T *t = _t_newi(0,TEST_INT_SYMBOL,314);
61 T *n = _t_newr(0,GET);
62 _t_new(n,WHICH_XADDR,&x,
sizeof(
Xaddr));
63 T *run_tree = __p_build_run_tree(n,0);
65 Qe *e = _p_addrt2q(q,run_tree);
68 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (TEST_INT_SYMBOL:314) (PARAMS))");
70 _a_get_instances(&r->
instances,TEST_INT_SYMBOL,t);
71 spec_is_str_equal(t2s(t),
"(ITERATION_DATA (TEST_INT_SYMBOL:314))");
77 void testProcessDel() {
81 T *t = _t_newi(0,TEST_INT_SYMBOL,314);
84 T *n = _t_newr(0,DEL);
85 _t_new(n,WHICH_XADDR,&x,
sizeof(
Xaddr));
86 T *run_tree = __p_build_run_tree(n,0);
88 Qe *e = _p_addrt2q(q,run_tree);
91 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (TEST_INT_SYMBOL:314) (PARAMS))");
93 _a_get_instances(&r->
instances,TEST_INT_SYMBOL,t);
94 spec_is_str_equal(t2s(t),
"(ITERATION_DATA)");
100 void testProcessNew() {
104 T *n = _t_newr(0,NEW);
105 _t_news(n,NEW_TYPE,TEST_INT_SYMBOL);
106 _t_new_str(n,TEST_STR_SYMBOL,
"fish");
107 T *run_tree = __p_build_run_tree(n,0);
109 Qe *e = _p_addrt2q(q,run_tree);
112 spec_is_equal(r->
q->
completed->context->
err,structureMismatchReductionErr);
115 _t_news(n,NEW_TYPE,TEST_INT_SYMBOL);
116 _t_newi(n,TEST_INT_SYMBOL2,314);
117 run_tree = __p_build_run_tree(n,0);
119 e = _p_addrt2q(q,run_tree);
122 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (WHICH_XADDR:TEST_INT_SYMBOL.1) (PARAMS))");
124 spec_is_str_equal(t2s(i),
"(TEST_INT_SYMBOL:314)");
129 void testProcessDefine() {
132 T *p =
_t_parse(r->
sem,0,
"(DEF_SYMBOL (SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:\"age\")) (SYMBOL_STRUCTURE:INTEGER)))");
134 spec_is_str_equal(t2s(p),
"(RESULT_SYMBOL:age)");
136 spec_is_str_equal(t2s(d),
"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:age)) (SYMBOL_STRUCTURE:INTEGER))");
139 p =
_t_parse(r->
sem,0,
"(DEF_STRUCTURE (STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:\"age_pair\")) (STRUCTURE_SEQUENCE (STRUCTURE_SYMBOL:age) (STRUCTURE_SYMBOL:age)))");
141 spec_is_str_equal(t2s(p),
"(RESULT_STRUCTURE:age_pair)");
143 spec_is_str_equal(t2s(d),
"(STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:age_pair)) (STRUCTURE_SEQUENCE (STRUCTURE_SYMBOL:age) (STRUCTURE_SYMBOL:age)))");
146 p =
_t_parse(r->
sem,0,
"(DEF_PROCESS (PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:\"power\")) (PROCESS_INTENTION:\"takes the mathematical power of the two params\") (NOOP) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:\"result\")) (SIGNATURE_SYMBOL:NULL_SYMBOL)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:\"val\")) (SIGNATURE_STRUCTURE:INTEGER)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:\"exponent\")) (SIGNATURE_STRUCTURE:INTEGER))) (PROCESS_LINK (PROCESS_OF_STRUCTURE:INTEGER) (PROCESS_TYPE (OPERATOR))))");
148 spec_is_str_equal(t2s(p),
"(RESULT_PROCESS:power)");
150 spec_is_str_equal(t2s(d),
"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:power)) (PROCESS_INTENTION:takes the mathematical power of the two params) (process:NOOP) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:result)) (SIGNATURE_SYMBOL:NULL_SYMBOL)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:val)) (SIGNATURE_STRUCTURE:INTEGER)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:exponent)) (SIGNATURE_STRUCTURE:INTEGER))) (PROCESS_LINK (PROCESS_OF_STRUCTURE:INTEGER) (PROCESS_TYPE (OPERATOR))))");
153 p =
_t_parse(r->
sem,0,
"(DEF_RECEPTOR (RECEPTOR_DEFINITION (RECEPTOR_LABEL (ENGLISH_LABEL:\"streamscapes\")) (DEFINITIONS (STRUCTURES) (SYMBOLS) (PROCESSES) (RECEPTORS) (PROTOCOLS) (SCAPES)))");
155 spec_is_str_equal(t2s(p),
"(RESULT_RECEPTOR:streamscapes)");
157 spec_is_str_equal(t2s(d),
"(RECEPTOR_DEFINITION (RECEPTOR_LABEL (ENGLISH_LABEL:streamscapes)) (DEFINITIONS (STRUCTURES) (SYMBOLS) (PROCESSES) (RECEPTORS) (PROTOCOLS) (SCAPES)))");
165 p =
_t_parse(r->
sem,0,
"(DEF_PROTOCOL (PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:\"do\")) (PROTOCOL_SEMANTICS (ROLE:agent) (GOAL:process) (USAGE:data)) (act (EXPECT (ROLE:agent) (SOURCE (ROLE:agent)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:data) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (SLOT (GOAL:process) (SLOT_IS_VALUE_OF:ACTION))))))");
167 spec_is_str_equal(t2s(p),
"(RESULT_PROTOCOL:do)");
169 spec_is_str_equal(t2s(d),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:do)) (PROTOCOL_SEMANTICS (ROLE:agent) (GOAL:process) (USAGE:data)) (act (EXPECT (ROLE:agent) (SOURCE (ROLE:agent)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:data) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (SLOT (GOAL:process) (SLOT_IS_VALUE_OF:ACTION)))))");
175 void testProcessDo() {
176 T *code =
_t_parse(G_sem,0,
"(DO (SCOPE (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:2)))");
178 spec_is_str_equal(t2s(code),
"(TEST_INT_SYMBOL:2)");
182 void testProcessTranscode() {
187 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_INT_SYMBOL)) (TRANSCODE_ITEMS (TEST_INT_SYMBOL2:314)))");
189 spec_is_str_equal(t2s(n),
"(TEST_INT_SYMBOL:314)");
193 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_STR_SYMBOL)) (TRANSCODE_ITEMS (TEST_INT_SYMBOL2:314)))");
195 spec_is_str_equal(t2s(n),
"(TEST_STR_SYMBOL:314)");
199 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_STR_SYMBOL)) (TRANSCODE_ITEMS (TEST_FLOAT_SYMBOL:3.14159)))");
201 spec_is_str_equal(t2s(n),
"(TEST_STR_SYMBOL:3.141590)");
205 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_STR_SYMBOL)) (TRANSCODE_ITEMS (ASCII_CHAR:'x')))");
207 spec_is_str_equal(t2s(n),
"(TEST_STR_SYMBOL:x)");
211 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_INT_SYMBOL)) (TRANSCODE_ITEMS (TEST_STR_SYMBOL:\"314\")))");
213 spec_is_str_equal(t2s(n),
"(TEST_INT_SYMBOL:314)");
218 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINES)) (TRANSCODE_ITEMS (TEST_INTEGERS (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:2) (TEST_INT_SYMBOL:314))))");
220 spec_is_str_equal(t2s(n),
"(LINES (LINE:1) (LINE:2) (LINE:314))");
222 debug_disable(D_TRANSCODE);
225 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINE)) (TRANSCODE_ITEMS (CONTENT_TYPE (MEDIA_TYPE_IDENT:TEXT_MEDIA_TYPE) (MEDIA_SUBTYPE_IDENT:CEPTR_TEXT_MEDIA_SUBTYPE))))");
227 T *run_tree = __p_build_run_tree(n,0);
229 Qe *e = _p_addrt2q(q,run_tree);
231 spec_is_str_equal(t2s(
_t_child(run_tree,1)),
"(LINE:Content-Type: text/ceptr)");
234 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINE)) (TRANSCODE_ITEMS (TODAY (YEAR:2015) (MONTH:1) (DAY:30))))");
237 run_tree = __p_build_run_tree(n,0);
239 e = _p_addrt2q(q,run_tree);
241 debug_disable(D_REDUCE+D_REDUCEV);
242 spec_is_str_equal(t2s(
_t_child(run_tree,1)),
"(US_SHORT_DATE:1/30/2015)");
244 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINES)) (TRANSCODE_ITEMS (HTTP_HEADERS (CONTENT_TYPE (MEDIA_TYPE_IDENT:TEXT_MEDIA_TYPE) (MEDIA_SUBTYPE_IDENT:CEPTR_TEXT_MEDIA_SUBTYPE)) (CONTENT_TYPE (MEDIA_TYPE_IDENT:TEXT_MEDIA_TYPE) (MEDIA_SUBTYPE_IDENT:HTML_TEXT_MEDIA_SUBTYPE)))))");
245 run_tree = __p_build_run_tree(n,0);
247 _p_addrt2q(q,run_tree);
249 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (LINES (LINE:Content-Type: text/ceptr) (LINE:Content-Type: text/html)) (PARAMS))");
251 n =
_t_parse(G_sem,0,
"(ascii_chars_2_http_req (TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:ASCII_CHARS)) (TRANSCODE_ITEMS (TEST_STR_SYMBOL:\"GET /path/to/file.ext?name=joe&age=30 HTTP/0.9\n\"))))");
253 run_tree = __p_build_run_tree(n,0);
255 _p_addrt2q(q,run_tree);
257 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (HTTP_REQUEST (HTTP_REQUEST_METHOD:GET) (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext))) (HTTP_REQUEST_PATH_QUERY (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:name) (PARAM_VALUE:joe)) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:age) (PARAM_VALUE:30)))) (HTTP_REQUEST_VERSION (VERSION_MAJOR:0) (VERSION_MINOR:9))) (PARAMS))");
262 n =
_t_parse(G_sem,0,
"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:HTTP_REQUEST)) (TRANSCODE_ITEMS (TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:ASCII_CHARS)) (TRANSCODE_ITEMS (TEST_STR_SYMBOL:\"GET /path/to/file.ext?name=joe&age=30 HTTP/0.9\n\")))))");
264 run_tree = __p_build_run_tree(n,0);
266 _p_addrt2q(q,run_tree);
268 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (HTTP_REQUEST (HTTP_REQUEST_METHOD:GET) (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext))) (HTTP_REQUEST_PATH_QUERY (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:name) (PARAM_VALUE:joe)) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:age) (PARAM_VALUE:30)))) (HTTP_REQUEST_VERSION (VERSION_MAJOR:0) (VERSION_MINOR:9))) (PARAMS))");
270 debug_disable(D_TRANSCODE);
271 debug_disable(D_REDUCE+D_REDUCEV);
272 debug_disable(D_STEP);
277 void testProcessDissolve() {
284 n =
_t_parse(G_sem,0,
"(LINES (LINE:\"fish\") (DISSOLVE (LINES (LINE:\"cat\") (LINE:\"dog\"))) (CONCAT_STR (RESULT_SYMBOL:LINE) (TEST_STR_SYMBOL:\"sh\") (TEST_STR_SYMBOL:\"oe\")))");
287 T *run_tree = __p_build_run_tree(n,0);
289 Qe *e = _p_addrt2q(q,run_tree);
291 spec_is_str_equal(t2s(
_t_child(run_tree,1)),
"(LINES (LINE:fish) (LINE:cat) (LINE:dog) (LINE:shoe))");
304 void testProcessSemtrex() {
308 T *pattern =
_sl(n,TICK);
309 T *t = __r_make_tick();
312 spec_is_str_equal(t2s(n),
"(BOOLEAN:1)");
316 pattern =
_sl(n,TICK);
317 _t_newi(n,TEST_INT_SYMBOL,1);
319 spec_is_str_equal(t2s(n),
"(BOOLEAN:0)");
323 pattern = _t_newr(n,SEMTREX_WALK);
324 T *g = _t_news(pattern,SEMTREX_GROUP,TEST_CHAR_SYMBOL);
328 _t_newi(n,BOOLEAN,1);
330 spec_is_str_equal(t2s(n),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:TEST_CHAR_SYMBOL) (SEMTREX_MATCH_PATH:/3) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
335 void testProcessFill() {
337 T *n =
_t_parse(G_sem,0,
"(FILL (SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (TEST_INT_SYMBOL:1) (SLOT (USAGE:REQUEST_TYPE)))) (SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (TEST_INT_SYMBOL:32))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:ADD_INT)))))");
341 spec_is_str_equal(t2s(n),
"(process:ADD_INT (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:32))");
346 void testProcessFillMatch() {
350 T *p1 = _t_newr(n,TEST_ANYTHING_SYMBOL);
351 T *s = _t_newr(p1,SLOT);
352 _t_news(s,USAGE,TEST_INT_SYMBOL2);
353 T *p2 = _t_newi(n,SEMTREX_MATCH,1);
354 _t_news(p2,SEMTREX_MATCH,TEST_INT_SYMBOL2);
355 int path[] = {TREE_PATH_TERMINATOR};
356 _t_new(p2,SEMTREX_MATCH_PATH,path,2*
sizeof(
int));
357 _t_newi(p2,SEMTREX_MATCH_SIBLINGS_COUNT,1);
358 T *p3 = _t_newi(n,TEST_INT_SYMBOL2,314);
368 spec_is_str_equal(t2s(
_t_child(t,1)),
"(TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL2:314))");
373 void testProcessFillMatchFull() {
377 T *p1 = _t_newr(n,TEST_ANYTHING_SYMBOL);
378 T *s = _t_newr(p1,SLOT);
379 _t_news(s,USAGE,NULL_SYMBOL);
380 T *p2 = _t_newi(n,SEMTREX_MATCH,1);
381 _t_news(p2,SEMTREX_MATCH,NULL_SYMBOL);
382 int path[] = {TREE_PATH_TERMINATOR};
383 _t_new(p2,SEMTREX_MATCH_PATH,path,2*
sizeof(
int));
384 _t_newi(p2,SEMTREX_MATCH_SIBLINGS_COUNT,1);
385 T *p3 = _t_newi(n,TEST_INT_SYMBOL,314);
391 spec_is_str_equal(t2s(
_t_child(t,1)),
"(TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL:314))");
401 T *p1 = _t_newi(n,BOOLEAN,1);
402 T *p2 = _t_newi(n,TEST_INT_SYMBOL,99);
403 T *p3 = _t_newi(n,TEST_INT_SYMBOL,100);
406 spec_is_str_equal(t2s(n),
"(TEST_INT_SYMBOL:99)");
411 void testProcessCond(){
413 T *n =
_t_parse(G_sem,0,
"(COND (CONDITIONS (COND_PAIR (BOOLEAN:0) (ASCII_CHAR:'x')) (COND_ELSE (ASCII_CHAR:'y'))))");
418 spec_is_str_equal(t2s(
_t_child(t,1)),
"(ASCII_CHAR:'y')");
423 n =
_t_parse(G_sem,0,
"(COND (CONDITIONS (COND_PAIR (BOOLEAN:0) (ASCII_CHAR:'x')) (COND_PAIR (BOOLEAN:1) (ASCII_CHAR:'y')) (COND_ELSE (ASCII_CHAR:'z'))))");
428 spec_is_str_equal(t2s(
_t_child(t,1)),
"(ASCII_CHAR:'y')");
433 void testProcessSym() {
435 _t_news(n,EQUALITY_TEST_SYMBOL,TEST_INT_SYMBOL);
436 _t_news(n,TEST_SYMBOL_SYMBOL,TEST_INT_SYMBOL);
438 spec_is_str_equal(t2s(n),
"(BOOLEAN:1)");
441 _t_news(n,EQUALITY_TEST_SYMBOL,TEST_INT_SYMBOL);
442 _t_news(n,TEST_SYMBOL_SYMBOL,TEST_STR_SYMBOL);
444 spec_is_str_equal(t2s(n),
"(BOOLEAN:0)");
453 _t_newi(n,TEST_INT_SYMBOL,99);
454 _t_newi(n,TEST_INT_SYMBOL,100);
456 spec_is_str_equal(t2s(n),
"(TEST_INT_SYMBOL:199)");
473 _t_newi(n,TEST_INT_SYMBOL,100);
474 _t_newi(n,TEST_INT_SYMBOL,98);
476 spec_is_str_equal(t2s(n),
"(TEST_INT_SYMBOL:2)");
481 _t_newi(n,TEST_INT_SYMBOL,100);
482 _t_newi(n,TEST_INT_SYMBOL,98);
484 spec_is_str_equal(t2s(n),
"(TEST_INT_SYMBOL:9800)");
489 _t_newi(n,TEST_INT_SYMBOL,100);
490 _t_newi(n,TEST_INT_SYMBOL,48);
492 spec_is_str_equal(t2s(n),
"(TEST_INT_SYMBOL:2)");
497 _t_newi(n,TEST_INT_SYMBOL,100);
498 _t_newi(n,TEST_INT_SYMBOL,0);
504 _t_newi(n,TEST_INT_SYMBOL,100);
505 _t_newi(n,TEST_INT_SYMBOL,2);
507 spec_is_str_equal(t2s(n),
"(TEST_INT_SYMBOL:0)");
512 _t_newi(n,TEST_INT_SYMBOL,100);
513 _t_newi(n,TEST_INT_SYMBOL,0);
519 _t_newi(n,TEST_INT_SYMBOL,100);
520 _t_newi(n,TEST_INT_SYMBOL,2);
522 spec_is_str_equal(t2s(n),
"(BOOLEAN:0)");
526 _t_newi(n,TEST_INT_SYMBOL,100);
527 _t_newi(n,TEST_INT_SYMBOL,100);
529 spec_is_str_equal(t2s(n),
"(BOOLEAN:1)");
534 _t_newi(n,TEST_INT_SYMBOL,2);
535 _t_newi(n,TEST_INT_SYMBOL,100);
537 spec_is_str_equal(t2s(n),
"(BOOLEAN:1)");
541 _t_newi(n,TEST_INT_SYMBOL,100);
542 _t_newi(n,TEST_INT_SYMBOL,100);
544 spec_is_str_equal(t2s(n),
"(BOOLEAN:0)");
549 _t_newi(n,TEST_INT_SYMBOL,2);
550 _t_newi(n,TEST_INT_SYMBOL,100);
552 spec_is_str_equal(t2s(n),
"(BOOLEAN:0)");
556 _t_newi(n,TEST_INT_SYMBOL,101);
557 _t_newi(n,TEST_INT_SYMBOL,100);
559 spec_is_str_equal(t2s(n),
"(BOOLEAN:1)");
564 void testProcessPath() {
565 T *p =
_t_parse(G_sem,0,
"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION))");
567 spec_is_str_equal(t2s(p),
"(CONTINUE_LOCATION:/4/1)");
569 p =
_t_parse(G_sem,0,
"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:2))");
571 spec_is_str_equal(t2s(p),
"(CONTINUE_LOCATION:/4)");
573 p =
_t_parse(G_sem,0,
"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:3))");
575 spec_is_str_equal(t2s(p),
"(CONTINUE_LOCATION:/)");
577 p =
_t_parse(G_sem,0,
"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:10))");
579 spec_is_str_equal(t2s(p),
"(CONTINUE_LOCATION:/)");
582 void testProcessString() {
590 _t_news(n,RESULT_SYMBOL,TEST_NAME_SYMBOL);
591 _t_new_str(n,TEST_STR_SYMBOL,
"Fred");
592 _t_new_str(n,TEST_STR_SYMBOL,
" ");
593 _t_new_str(n,TEST_STR_SYMBOL,
"Smith");
596 spec_is_str_equal(t2s(n),
"(TEST_NAME_SYMBOL:Fred Smith)");
601 _t_new_str(n,TEST_STR_SYMBOL,
"fish");
603 spec_is_str_equal(t2s(n),
"(ASCII_CHARS (ASCII_CHAR:'f') (ASCII_CHAR:'i') (ASCII_CHAR:'s') (ASCII_CHAR:'h'))");
608 _t_news(n,RESULT_SYMBOL,TEST_NAME_SYMBOL);
610 _t_new(n,ASCII_CHAR,&xx,
sizeof(
char));
611 _t_new_str(n,TEST_STR_SYMBOL,
"red");
613 _t_new(n,ASCII_CHAR,&xx,
sizeof(
char));
614 _t_new_str(n,TEST_STR_SYMBOL,
"Smith");
616 spec_is_str_equal(t2s(n),
"(TEST_NAME_SYMBOL:Fred Smith)");
621 _t_newi(n,TEST_INT_SYMBOL,314);
623 _t_news(n,RESULT_SYMBOL,TEST_INT_SYMBOL);
625 _t_news(n,RESULT_SYMBOL,TEST_NAME_SYMBOL);
627 _t_news(n,RESULT_SYMBOL,TEST_NAME_SYMBOL);
628 _t_newi(n,TEST_INT_SYMBOL,314);
637 void testProcessRespond() {
640 T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
644 T *s =
__r_make_signal(f,t,DEFAULT_ASPECT,TESTING,signal_contents,0,defaultRequestUntil(),0);
647 T *n = _t_newr(run_tree,RESPOND);
648 _t_news(n,CARRIER,TESTING);
650 T *response_contents = _t_newi(n,TEST_INT_SYMBOL,271);
664 spec_is_str_equal(t2s(n),
"(SIGNAL_UUID)");
665 spec_is_str_equal(_td(r,r->pending_signals),
"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:4)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (IN_RESPONSE_TO_UUID)) (BODY:{(TEST_INT_SYMBOL:271)}))))");
667 int p[] = {1,SignalMessageIdx,MessageHeadIdx,HeadOptionalsIdx,TREE_PATH_TERMINATOR};
668 T *u2 =
_t_get(r->pending_signals,p);
676 extern int G_next_process_id;
678 void testProcessSay() {
679 T *p = _t_newr(0,SAY);
682 __r_make_addr(p,TO_ADDRESS,to);
683 _t_news(p,ASPECT_IDENT,DEFAULT_ASPECT);
684 _t_news(p,CARRIER,TESTING);
685 _t_newi(p,TEST_INT_SYMBOL,314);
689 T *run_tree = __p_build_run_tree(p,0);
693 G_next_process_id = 0;
695 T *ps = r->pending_signals;
696 Qe *e =_p_addrt2q(q,run_tree);
706 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (SIGNAL_UUID) (PARAMS))");
707 spec_is_str_equal(t2s(ps),
"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING)) (BODY:{(TEST_INT_SYMBOL:314)}))))");
711 void testProcessRequest() {
712 T *p = _t_newr(0,REQUEST);
715 __r_make_addr(p,TO_ADDRESS,to);
716 _t_news(p,ASPECT_IDENT,DEFAULT_ASPECT);
717 _t_news(p,CARRIER,TESTING);
718 _t_newi(p,TEST_INT_SYMBOL,314);
719 _t_news(p,RESPONSE_CARRIER,TESTING);
720 T *ec = _t_newr(p,END_CONDITIONS);
723 T *code =_t_rclone(p);
726 T *run_tree = __p_build_run_tree(code,0);
728 spec_is_str_equal(_td(r,run_tree),
"(RUN_TREE (process:REQUEST (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (TEST_INT_SYMBOL:314) (RESPONSE_CARRIER:TESTING) (END_CONDITIONS (COUNT:1))) (PARAMS))");
731 G_next_process_id = 0;
733 T *ps = r->pending_signals;
734 Qe *e =_p_addrt2q(q,run_tree);
742 spec_is_ptr_equal(q->
blocked,e);
743 spec_is_equal(c->
state,Block);
744 spec_is_str_equal(_td(r,r->pending_responses),
"(PENDING_RESPONSES (PENDING_RESPONSE (SIGNAL_UUID) (CARRIER:TESTING) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1)) (END_CONDITIONS (COUNT:1))))");
747 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (SIGNAL_UUID) (PARAMS))");
748 spec_is_str_equal(t2s(ps),
"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (END_CONDITIONS (COUNT:1))) (BODY:{(TEST_INT_SYMBOL:314)}))))");
753 T *s =
__r_make_signal(r->
addr,r->
addr,DEFAULT_ASPECT,TESTING,_t_new_str(0,TEST_STR_SYMBOL,
"one fish"),
_t_surface(
_t_child(run_tree,1)),0,0);
755 spec_is_str_equal(_td(r,r->pending_responses),
"(PENDING_RESPONSES)");
781 debug_disable(D_SIGNALS);
789 T *_testProcessAddSay(
T *parent,
int id,
T *message) {
790 T *say = _t_newr(parent,SAY);
792 __r_make_addr(say,TO_ADDRESS,to);
793 _t_news(say,ASPECT_IDENT,DEFAULT_ASPECT);
794 _t_news(say,CARRIER,TESTING);
814 void testProcessConverse() {
815 T *p = _t_newr(0,CONVERSE);
816 T *scope = _t_newr(p,SCOPE);
817 _t_newi(p,BOOLEAN,1);
818 _testProcessAddSay(scope,100,_t_newi(0,TEST_INT_SYMBOL,31415));
819 T *code = _testProcessAddSay(0,99,p);
821 T *run_tree = __p_build_run_tree(code,0);
824 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (process:SAY (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (process:CONVERSE (SCOPE (process:SAY (TO_ADDRESS (RECEPTOR_ADDR:100)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (TEST_INT_SYMBOL:31415))) (BOOLEAN:1))) (PARAMS))");
829 G_next_process_id = 0;
831 T *cons = r->conversations;
832 T *ps = r->pending_signals;
833 Qe *e =_p_addrt2q(q,run_tree);
840 debug_disable(D_STEP);
841 spec_is_str_equal(t2s(cons),
"(CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1/4))))");
844 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (process:SAY (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (SIGNAL_UUID)) (PARAMS))");
845 spec_is_ptr_equal(q->
blocked,e);
848 spec_is_str_equal(t2s(ps),
"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:100)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (CONVERSATION_IDENT (CONVERSATION_UUID))) (BODY:{(TEST_INT_SYMBOL:31415)}))))");
851 code = _t_newr(0,COMPLETE);
852 _t_newi(code,TEST_INT_SYMBOL,123);
855 T *run_tree2 = __p_build_run_tree(code,0);
857 Qe *e2 =_p_addrt2q(q,run_tree2);
859 spec_is_ptr_equal(q->
blocked,NULL);
860 spec_is_ptr_equal(q->
active,NULL);
862 spec_is_ptr_equal(q->
completed->next,e2);
865 spec_is_str_equal(t2s(cons),
"(CONVERSATIONS)");
867 spec_is_str_equal(t2s(run_tree2),
"(RUN_TREE (CONVERSATION_IDENT (CONVERSATION_UUID)) (PARAMS))");
871 spec_is_str_equal(t2s(ps),
"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:100)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (CONVERSATION_IDENT (CONVERSATION_UUID))) (BODY:{(TEST_INT_SYMBOL:31415)}))) (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING)) (BODY:{(TEST_INT_SYMBOL:123)}))))");
875 p = _t_newr(0,CONVERSE);
876 scope = _t_newr(p,SCOPE);
877 T *complete = _t_newr(scope,COMPLETE);
878 _t_newi(complete,TEST_INT_SYMBOL,321);
879 _t_newi(scope,TEST_INT_SYMBOL,123);
881 run_tree = __p_build_run_tree(p,0);
884 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (process:CONVERSE (SCOPE (process:COMPLETE (TEST_INT_SYMBOL:321)) (TEST_INT_SYMBOL:123))) (PARAMS))");
885 e =_p_addrt2q(q,run_tree);
888 debug_disable(D_STEP);
889 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (TEST_INT_SYMBOL:321) (PARAMS))");
893 code = _testProcessAddSay(0,100,_t_new_str(0,TEST_STR_SYMBOL,
"What I said!"));
894 T *signature = __p_make_signature(
"result",SIGNATURE_SYMBOL,NULL_SYMBOL,NULL);
897 p = _t_newr(0,CONVERSE);
898 scope = _t_newr(p,SCOPE);
899 _t_newr(scope,sayer);
900 complete = _t_newr(scope,COMPLETE);
901 _t_newi(complete,TEST_INT_SYMBOL,321);
903 run_tree = __p_build_run_tree(p,0);
906 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (process:CONVERSE (SCOPE (process:sayer) (process:COMPLETE (TEST_INT_SYMBOL:321)))) (PARAMS))");
907 e =_p_addrt2q(q,run_tree);
910 debug_disable(D_STEP);
912 spec_is_str_equal(t2s(
_t_child(ps,
_t_children(ps))),
"(SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:100)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (CONVERSATION_IDENT (CONVERSATION_UUID))) (BODY:{(TEST_STR_SYMBOL:What I said!)})))");
915 p = _t_newr(0,CONVERSE);
916 scope = _t_newr(p,SCOPE);
917 T *p2 = _t_newr(scope,CONVERSE);
918 p2 = _t_newr(p2,SCOPE);
921 run_tree = __p_build_run_tree(p,0);
923 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (process:CONVERSE (SCOPE (process:CONVERSE (SCOPE (process:sayer))))) (PARAMS))");
925 e =_p_addrt2q(q,run_tree);
928 debug_disable(D_STEP);
931 T *head =
_t_getv(last_sig,SignalMessageIdx,MessageHeadIdx,TREE_PATH_TERMINATOR);
932 T *s_cid =
__t_find(head,CONVERSATION_IDENT,HeadOptionalsIdx);
933 T *cid =
_t_getv(r->conversations,1,ConversationConversationsIdx,1,ConversationIdentIdx,TREE_PATH_TERMINATOR);
934 spec_is_true(__uuid_equal(__cid_getUUID(cid),__cid_getUUID(s_cid)));
939 void testProcessConverseListen() {
941 T *code =
_t_parse(G_sem,0,
"(NEW (NEW_TYPE:TEST_INT_SYMBOL) (PARAM_REF:/2/1))");
943 T *signature = __p_make_signature(
"result",SIGNATURE_PASSTHRU,NULL_STRUCTURE,
944 "int",SIGNATURE_SYMBOL,TEST_INT_SYMBOL,
948 code =
_t_parse(G_sem,0,
"(CONVERSE (SCOPE (LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TEST_INT_SYMBOL) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_INT_SYMBOL))) (ACTION:new_int (TEST_INT_SYMBOL:314)))) (BOOLEAN:1))");
950 T *run_tree = __p_build_run_tree(code,0);
953 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (process:CONVERSE (SCOPE (process:LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TEST_INT_SYMBOL) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_INT_SYMBOL))) (ACTION:new_int (TEST_INT_SYMBOL:314)))) (BOOLEAN:1)) (PARAMS))");
958 G_next_process_id = 0;
960 T *cons = r->conversations;
961 T *ps = r->pending_signals;
962 Qe *e =_p_addrt2q(q,run_tree);
966 spec_is_ptr_equal(q->
blocked,e);
968 T *ex = __r_get_expectations(r,DEFAULT_ASPECT);
969 spec_is_str_equal(t2s(ex),
"(EXPECTATIONS (EXPECTATION (CARRIER:TEST_INT_SYMBOL) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_INT_SYMBOL))) (ACTION:new_int (TEST_INT_SYMBOL:314)) (PARAMS (SLOT (USAGE:NULL_SYMBOL))) (END_CONDITIONS (UNLIMITED)) (CONVERSATION_IDENT (CONVERSATION_UUID))))");
971 T *t = _t_newi(0,TEST_INT_SYMBOL,314);
979 T *cid =
_t_clone(
_t_getv(cons,1,ConversationIdentIdx,TREE_PATH_TERMINATOR));
983 debug_disable(D_LISTEN+D_SIGNALS);
984 spec_is_str_equal(t2s(r->
instances),
"(INSTANCE_STORE (INSTANCES (SYMBOL_INSTANCES:TEST_INT_SYMBOL (TEST_INT_SYMBOL:314))))");
988 __r_cleanup_conversation(r,__cid_getUUID(cid));
989 spec_is_str_equal(t2s(ex),
"(EXPECTATIONS)");
994 void testProcessThisScope() {
996 T *scope = _t_newr(code,SCOPE);
997 _t_newr(scope,THIS_SCOPE);
1001 T *run_tree = __p_build_run_tree(code,0);
1004 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (process:CONVERSE (SCOPE (process:THIS_SCOPE))) (PARAMS))");
1007 G_next_process_id = 0;
1009 T *cons = r->conversations;
1010 Qe *e =_p_addrt2q(q,run_tree);
1015 debug_disable(D_STEP);
1016 spec_is_str_equal(t2s(cons),
"(CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1))))");
1019 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (CONVERSATION_IDENT (CONVERSATION_UUID)) (PARAMS))");
1024 void testProcessQuote() {
1030 T *a = _t_newr(n,ADD_INT);
1031 _t_newi(a,TEST_INT_SYMBOL,99);
1032 _t_newi(a,TEST_INT_SYMBOL,100);
1034 T *c = _t_rclone(n);
1038 spec_is_str_equal(t2s(t),
"(RUN_TREE (process:ADD_INT (TEST_INT_SYMBOL:99) (TEST_INT_SYMBOL:100)))");
1044 void testProcessStream() {
1049 char buffer[500] =
"line1\nabc\nGET /path/to/file.ext HTTP/0.9\n";
1050 stream = fmemopen(buffer, 500,
"r+");
1055 Stream *st = _st_new_unix_stream(stream,1);
1058 spec_is_str_equal(t2s(n),
"(BOOLEAN:1)");
1064 _t_news(n,RESULT_SYMBOL,TEST_STR_SYMBOL);
1066 T *run_tree = __p_build_run_tree(n,0);
1068 Qe *e = _p_addrt2q(q,run_tree);
1075 spec_is_ptr_equal(q->
blocked,e);
1076 spec_is_equal(c->
state,Block);
1080 while(!(st->flags&StreamHasData) && st->flags&StreamAlive ) {sleepms(1);};
1084 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (TEST_STR_SYMBOL:line1) (PARAMS))");
1089 _t_news(n,RESULT_SYMBOL,ASCII_CHARS);
1091 run_tree = __p_build_run_tree(n,0);
1093 e = _p_addrt2q(q,run_tree);
1095 while(!(st->flags&StreamHasData) && st->flags&StreamAlive ) {sleepms(1);};
1097 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (ASCII_CHARS (ASCII_CHAR:'a') (ASCII_CHAR:'b') (ASCII_CHAR:'c')) (PARAMS))");
1102 _t_news(n,RESULT_SYMBOL,HTTP_REQUEST);
1104 run_tree = __p_build_run_tree(n,0);
1106 e = _p_addrt2q(q,run_tree);
1108 while(!(st->flags&StreamHasData) && st->flags&StreamAlive ) {sleepms(1);};
1110 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (HTTP_REQUEST (HTTP_REQUEST_METHOD:GET) (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext))) (HTTP_REQUEST_VERSION (VERSION_MAJOR:0) (VERSION_MINOR:9))) (PARAMS))");
1113 fseek(stream,strlen(buffer),SEEK_SET);
1116 _t_new_str(n,TEST_STR_SYMBOL,
"fish\n");
1117 _t_new_str(n,LINE,
"cow");
1118 T *lns = _t_newr(n,LINES);
1119 _t_new_str(lns,LINE,
"thing1");
1120 _t_new_str(lns,LINE,
"thing2");
1121 _t_newi(n,TEST_INT_SYMBOL,314);
1123 run_tree = __p_build_run_tree(n,0);
1125 e = _p_addrt2q(q,run_tree);
1129 char *expected_result =
"line1\nabc\nGET /path/to/file.ext HTTP/0.9\nfish\ncow\nthing1\nthing2\n(TEST_INT_SYMBOL:314)";
1131 spec_is_str_equal(buffer,expected_result);
1137 stream = fmemopen(buffer, strlen (buffer),
"r");
1138 st = _st_new_unix_stream(stream,0);
1142 _t_new_str(n,TEST_STR_SYMBOL,
"fish\n");
1144 run_tree = __p_build_run_tree(n,0);
1146 e = _p_addrt2q(q,run_tree);
1150 spec_is_equal(e->context->
err,unixErrnoReductionErr);
1153 spec_is_str_equal(buffer,expected_result);
1161 spec_is_str_equal(t2s(n),
"(BOOLEAN:0)");
1166 debug_disable(D_STREAM+D_SOCKET+D_SIGNALS);
1170 void testProcessStreamClose() {
1175 char buffer[500] =
"line1\nabc\n";
1176 stream = fmemopen(buffer, 500,
"r+");
1179 Stream *st = _st_new_unix_stream(stream,
true);
1184 spec_is_str_equal(t2s(n),
"(BOOLEAN:1)");
1186 debug_disable(D_STREAM+D_SOCKET+D_SIGNALS);
1192 void testProcessInitiate(){
1196 __sem_get_by_label(G_sem,
"time",&time,CLOCK_CONTEXT);
1199 T *p = _t_news(n,PNAME,time);
1200 T *i = _t_news(n,WHICH_INTERACTION,tell_time);
1201 T *bindings = _t_newr(n,PROTOCOL_BINDINGS);
1202 T *res = _t_newr(bindings,RESOLUTION);
1203 T *w = _t_newr(res,WHICH_RECEPTOR);
1204 _t_news(w,ROLE,TIME_TELLER);
1205 __r_make_addr(w,ACTUAL_RECEPTOR,r->
addr);
1206 res = _t_newr(bindings,RESOLUTION);
1207 w = _t_newr(res,WHICH_RECEPTOR);
1208 _t_news(w,ROLE,TIME_HEARER);
1210 __r_make_addr(w,ACTUAL_RECEPTOR,clock_addr);
1211 res = _t_newr(bindings,RESOLUTION);
1212 w = _t_newr(res,WHICH_PROCESS);
1213 _t_news(w,GOAL,RESPONSE_HANDLER);
1215 _t_newi(noop,TEST_INT_SYMBOL,314);
1217 _t_news(w,ACTUAL_PROCESS,NOOP);
1219 T *run_tree = __p_build_run_tree(n,0);
1221 Qe *e = _p_addrt2q(q,run_tree);
1223 spec_is_str_equal(_td(r,r->pending_signals),
"(PENDING_SIGNALS)");
1226 debug_disable(D_REDUCE+D_STEP+D_REDUCEV);
1228 spec_is_str_equal(t2s(run_tree),
"");
1236 void testProcessReduce() {
1240 _t_newi(n,BOOLEAN,1);
1241 T *n1 = _t_newr(n,IF);
1242 T *n2 = _t_newr(n1,IF);
1243 _t_newi(n2,BOOLEAN,0);
1244 _t_newi(n2,BOOLEAN,1);
1245 _t_newi(n2,BOOLEAN,0);
1246 _t_newi(n1,TEST_INT_SYMBOL,98);
1247 _t_newi(n1,TEST_INT_SYMBOL,99);
1248 _t_newi(n,TEST_INT_SYMBOL,100);
1250 T *c = _t_rclone(n);
1255 spec_is_equal(context->
id,99);
1264 spec_is_equal(rt_cur_child(c),0);
1266 spec_is_equal(
_p_step(&q,&context),Descend);
1267 spec_is_equal(rt_cur_child(c),0);
1270 spec_is_equal(
_p_step(&q,&context),Eval);
1272 spec_is_equal(rt_cur_child(c),1);
1275 spec_is_equal(
_p_step(&q,&context),Ascend);
1278 spec_is_equal(
_p_step(&q,&context),Eval);
1280 spec_is_equal(rt_cur_child(
_t_child(c,1)),RUN_TREE_EVALUATED);
1283 spec_is_equal(
_p_step(&q,&context),Descend);
1286 spec_is_equal(
_p_step(&q,&context),Eval);
1287 spec_is_equal(rt_cur_child(c),2);
1299 spec_is_str_equal(t2s(c),
"(TEST_INT_SYMBOL:99)");
1305 void testProcessParameter() {
1308 T *n =
_t_parse(G_sem,0,
"(TEST_ANYTHING_SYMBOL (DISSOLVE (PARAMETER (PARAMETER_REFERENCE (PARAM_PATH:/2/1)) (PARAMETER_RESULT (RESULT_VALUE)))) (PARAMETER (PARAMETER_REFERENCE (PARAM_PATH:/2/2)) (PARAMETER_RESULT (RESULT_SYMBOL:TEST_SYMBOL_SYMBOL))) (PARAMETER (PARAMETER_REFERENCE (PARAM_PATH:/2/1)) (PARAMETER_RESULT (RESULT_LABEL:ENGLISH_LABEL))))");
1310 T *p1 = _t_newi(0,TEST_INT_SYMBOL,314);
1311 T *p2 = _t_new_str(0,TEST_STR_SYMBOL,
"314");
1312 T *run_tree = __p_build_run_tree(n,2,p1,p2);
1317 Qe *e = _p_addrt2q(q,run_tree);
1320 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL:314) (TEST_SYMBOL_SYMBOL:TEST_STR_SYMBOL) (ENGLISH_LABEL:TEST_INT_SYMBOL)) (PARAMS (TEST_INT_SYMBOL:314) (TEST_STR_SYMBOL:314)))");
1325 void testProcessRefs() {
1329 int pt1[] = {2,1,TREE_PATH_TERMINATOR};
1330 int pt2[] = {SignalMessageIdx,MessageBodyIdx,0,TREE_PATH_TERMINATOR};
1332 T *n = _t_newr(0,NOOP);
1333 T *t = _t_newr(n,TEST_ANYTHING_SYMBOL);
1334 _t_new(t,PARAM_REF,pt1,
sizeof(
int)*4);
1335 _t_new(t,SIGNAL_REF,pt2,
sizeof(
int)*4);
1336 t = _t_newi(0,TEST_INT_SYMBOL,314);
1337 T *run_tree = __p_build_run_tree(n,1,t);
1342 T *signal =
__r_make_signal(fm,to,DEFAULT_ASPECT,TESTING,_t_new_str(0,TEST_STR_SYMBOL,
"foo"),0,0,0);
1347 Qe *e = _p_addrt2q(q,run_tree);
1350 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL:314) (TEST_STR_SYMBOL:foo)) (PARAMS (TEST_INT_SYMBOL:314)))");
1367 T *code =
_t_parse(G_sem,0,
"(IF (EQ_INT (MOD_INT (PARAM_REF:/2/1) (TEST_INT_SYMBOL:2)) (TEST_INT_SYMBOL:0)) (PARAM_REF:/2/2) (PARAM_REF:/2/3))");
1369 T *signature = __p_make_signature(
"result",SIGNATURE_PASSTHRU,NULL_STRUCTURE,
1370 "val",SIGNATURE_STRUCTURE,INTEGER,
1371 "true_branch",SIGNATURE_ANY,NULL_STRUCTURE,
1372 "false_branch",SIGNATURE_ANY,NULL_STRUCTURE,
1375 G_ifeven =
_d_define_process(G_sem,code,
"if even",
"return 2nd child if even, third if not",signature,NULL,TEST_CONTEXT);
1392 _t_newi(code,TEST_INT_SYMBOL,2);
1393 _t_newi(code,TEST_INT_SYMBOL,0);
1395 T *signature = __p_make_signature(
"result",SIGNATURE_SYMBOL,NULL_SYMBOL,
1396 "val",SIGNATURE_STRUCTURE,INTEGER,
1399 return _d_define_process(G_sem,code,
"divByZero",
"create a divide by zero error",signature,NULL,TEST_CONTEXT);
1407 T *processes = __sem_get_defs(G_sem,SEM_TYPE_PROCESS,TEST_CONTEXT);
1410 int p[] = {if_even.id,ProcessDefCodeIdx,TREE_PATH_TERMINATOR};
1412 spec_is_str_equal(t2s(
_t_get(processes,p)),
"(process:IF (process:EQ_INT (process:MOD_INT (PARAM_REF:/2/1) (TEST_INT_SYMBOL:2)) (TEST_INT_SYMBOL:0)) (PARAM_REF:/2/2) (PARAM_REF:/2/3))");
1417 _t_newi(n,TEST_INT_SYMBOL,99);
1418 _t_newi(n,TEST_INT_SYMBOL,123);
1419 _t_newi(n,TEST_INT_SYMBOL,124);
1423 spec_is_equal(
_p_reduce(G_sem,t),noReductionErr);
1424 spec_is_str_equal(t2s(
_t_child(t,1)),
"(TEST_INT_SYMBOL:124)");
1430 void testProcessSignatureMatching() {
1435 T *x = _t_new(n,TEST_STR_SYMBOL,
"test",5);
1436 _t_newi(n,TEST_INT_SYMBOL,123);
1437 _t_newi(n,TEST_INT_SYMBOL,124);
1441 T *c = _t_rclone(n);
1443 spec_is_equal(
_p_reduce(G_sem,t),signatureMismatchReductionErr);
1450 spec_is_equal(
_p_reduce(G_sem,t),tooFewParamsReductionErr);
1456 __t_morph(x,TEST_INT_SYMBOL,&v,
sizeof(
int),0);
1461 spec_is_equal(
_p_reduce(G_sem,t),tooManyParamsReductionErr);
1468 spec_is_equal(
__p_check_signature(G_sem,send_request,n,NULL),missingSemanticMapReductionErr);
1471 spec_is_equal(
__p_check_signature(G_sem,send_request,n,sm),mismatchSemanticMapReductionErr);
1478 REPLACEMENT_VALUE,ACTUAL_SYMBOL,PING,NULL_SYMBOL,NULL_SYMBOL,
1480 USAGE,RESPONSE_TYPE,
1481 REPLACEMENT_VALUE,ACTUAL_SYMBOL,PING,NULL_SYMBOL,NULL_SYMBOL,
1483 GOAL,REQUEST_HANDLER,
1484 REPLACEMENT_VALUE,ACTUAL_PROCESS,NOOP,NULL_SYMBOL,NULL_SYMBOL,
1486 GOAL,RESPONSE_HANDLER,
1487 REPLACEMENT_VALUE,ACTUAL_PROCESS,NOOP,NULL_SYMBOL,
1488 NULL_SYMBOL,NULL_SYMBOL,NULL_SYMBOL
1490 spec_is_str_equal(t2s(sm),
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))))");
1492 spec_is_equal(
__p_check_signature(G_sem,send_request,n,sm),mismatchSemanticMapReductionErr);
1497 REPLACEMENT_VALUE,ACTUAL_RECEPTOR,FROM_ADDRESS,RECEPTOR_ADDR,3,NULL_SYMBOL,NULL_SYMBOL);
1499 spec_is_str_equal(t2s(sm),
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (ROLE:RECOGNIZER) (REPLACEMENT_VALUE (ACTUAL_RECEPTOR (FROM_ADDRESS (RECEPTOR_ADDR:3))))))");
1501 spec_is_equal(
__p_check_signature(G_sem,send_request,n,sm),mismatchSemanticMapReductionErr);
1508 REPLACEMENT_VALUE,ACTUAL_RECEPTOR,FROM_ADDRESS,RECEPTOR_ADDR,3,NULL_SYMBOL,NULL_SYMBOL);
1513 REPLACEMENT_VALUE,ASPECT_IDENT,DEFAULT_ASPECT,NULL_SYMBOL,NULL_SYMBOL,NULL_SYMBOL);
1515 _t_parse(G_sem,sm,
"(SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL)))");
1517 spec_is_str_equal(t2s(sm),
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (ACTUAL_RECEPTOR (FROM_ADDRESS (RECEPTOR_ADDR:3))))) (SEMANTIC_LINK (USAGE:CHANNEL) (REPLACEMENT_VALUE (ASPECT_IDENT:DEFAULT_ASPECT))) (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL))))");
1530 void testProcessError() {
1532 T *n =
_t_parse(G_sem,0,
"(NOOP (DIV_INT (TEST_INT_SYMBOL:100) (TEST_INT_SYMBOL:0)))");
1533 T *c = _t_rclone(n);
1535 T *ps = _t_newr(t,PARAMS);
1538 int pt[] = {RunTreeErrorParamsIdx,1,TREE_PATH_TERMINATOR};
1539 __t_new(t,PARAM_REF,pt,
sizeof(
int)*4,
true);
1542 spec_is_equal(e,noReductionErr);
1543 spec_is_str_equal(t2s(
_t_child(t,1)),
"(ZERO_DIVIDE_ERR (ERROR_LOCATION:/1/1))");
1548 void testProcessRaise() {
1550 _t_news(n,REDUCTION_ERROR_SYMBOL,ZERO_DIVIDE_ERR);
1557 _t_news(n,REDUCTION_ERROR_SYMBOL,NOT_A_PROCESS_ERR);
1558 T *c = _t_rclone(n);
1560 T *ps = _t_newr(t,PARAMS);
1563 int pt[] = {RunTreeErrorParamsIdx,1,TREE_PATH_TERMINATOR};
1564 __t_new(t,PARAM_REF,pt,
sizeof(
int)*4,
true);
1567 spec_is_equal(e,noReductionErr);
1568 spec_is_str_equal(t2s(
_t_child(t,1)),
"(NOT_A_PROCESS_ERR (ERROR_LOCATION:/1))");
1573 void testProcessIterate() {
1576 char *output_data = NULL;
1578 output = open_memstream(&output_data,&size);
1581 Stream *st = _st_new_unix_stream(output,0);
1582 T *code =
_t_parse(G_sem,0,
"(ITERATE (PARAMS) (TEST_INT_SYMBOL:3) (STREAM_WRITE % (LINE:\"testing\")))",
_t_new_cptr(0,EDGE_STREAM,st));
1584 T *t = __p_build_run_tree(code,0);
1586 spec_is_equal(e,noReductionErr);
1587 spec_is_str_equal(output_data,
"testing\ntesting\ntesting\n");
1595 code =
_t_parse(G_sem,0,
"(ITERATE (PARAMS (TEST_INT_SYMBOL:314)) (LT_INT (PARAM_REF:/1/1/1) (TEST_INT_SYMBOL:3)) (STREAM_WRITE % (LINE:\"testing\")))",
_t_new_cptr(0,EDGE_STREAM,st));
1597 t = __p_build_run_tree(code,0);
1599 spec_is_equal(e,noReductionErr);
1600 spec_is_str_equal(output_data,
"testing\ntesting\ntesting\n");
1608 void testProcessIterateOnSymbol() {
1611 char *output_data = NULL;
1613 output = open_memstream(&output_data,&size);
1616 Stream *st = _st_new_unix_stream(output,0);
1617 T *code =
_t_parse(G_sem,0,
"(ITERATE (PARAMS) (ITERATE_ON_SYMBOL:TEST_STR_SYMBOL) (STREAM_WRITE % (PARAM_REF:/1/1/1/1)))",
_t_new_cptr(0,EDGE_STREAM,st));
1618 T *run_tree = __p_build_run_tree(code,0);
1624 T *t = _t_new_str(0,TEST_STR_SYMBOL,
"thing1 ");
1626 t = _t_new_str(0,TEST_STR_SYMBOL,
"thing2 ");
1630 Qe *e = _p_addrt2q(q,run_tree);
1634 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (REDUCTION_ERROR_SYMBOL:NULL_SYMBOL) (PARAMS))");
1636 spec_is_str_equal(output_data,
"thing1 thing2 ");
1643 void testProcessListen() {
1647 T *n =
_t_parse(G_sem,0,
"(LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TICK) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TICK))) (ACTION:NOOP (TEST_INT_SYMBOL:314)))");
1649 spec_is_str_equal(t2s(n),
"(REDUCTION_ERROR_SYMBOL:NULL_SYMBOL)");
1652 T *ex = __r_get_expectations(r,DEFAULT_ASPECT);
1653 spec_is_str_equal(t2s(ex),
"(EXPECTATIONS (EXPECTATION (CARRIER:TICK) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TICK))) (ACTION:NOOP (TEST_INT_SYMBOL:314)) (PARAMS (SLOT (USAGE:NULL_SYMBOL))) (END_CONDITIONS (UNLIMITED))))");
1655 _r_remove_expectation(r,
_t_child(ex,1));
1658 n =
_t_parse(G_sem,0,
"(LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL))))");
1660 G_next_process_id = 0;
1661 T *run_tree = __p_build_run_tree(n,0);
1664 Qe *e = _p_addrt2q(q,run_tree);
1669 spec_is_ptr_equal(q->
blocked,e);
1670 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (process:LISTEN) (PARAMS))");
1672 spec_is_str_equal(t2s(__r_get_expectations(r,DEFAULT_ASPECT)),
"(EXPECTATIONS (EXPECTATION (CARRIER:TESTING) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL))) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1)) (PARAMS (SLOT (USAGE:NULL_SYMBOL))) (END_CONDITIONS (COUNT:1))))");
1680 spec_is_str_equal(t2s(__r_get_expectations(r,DEFAULT_ASPECT)),
"(EXPECTATIONS)");
1684 spec_is_str_equal(t2s(run_tree),
"(RUN_TREE (PARAMS (TEST_STR_SYMBOL:fishy!)) (PARAMS))");
1685 debug_disable(D_LISTEN);
1689 void testProcessSelfAddr() {
1693 _t_news(n,RESULT_SYMBOL,TO_ADDRESS);
1695 spec_is_str_equal(t2s(n),
"(TO_ADDRESS (RECEPTOR_ADDR:3))");
1700 void testProcessGetLabel() {
1702 T *n =
_t_parse(G_sem,0,
"(GET_LABEL (LABEL_SYMBOL:CONTENT_TYPE) (LABEL_TYPE:HTTP_HEADER_LABEL) (RESULT_SYMBOL:LINE))");
1704 spec_is_str_equal(t2s(n),
"(LINE:Content-Type)");
1716 T *d = _t_newr(n,divz);
1717 _t_newi(d,TEST_INT_SYMBOL,124);
1719 T *c = _t_rclone(n);
1721 T *ps = _t_newr(t,PARAMS);
1724 int pt[] = {4,1,TREE_PATH_TERMINATOR};
1725 __t_new(t,PARAM_REF,pt,
sizeof(
int)*4,1);
1728 spec_is_equal(
_p_reduce(G_sem,t),noReductionErr);
1729 spec_is_str_equal(t2s(
_t_child(t,1)),
"(ZERO_DIVIDE_ERR (ERROR_LOCATION:/1/1))");
1752 __t_newi(l2,TEST_INT_SYMBOL,123,1);
1753 __t_newi(l2,TEST_INT_SYMBOL,124,1);
1760 spec_is_ptr_equal(q->
active,NULL);
1764 spec_is_ptr_equal(q->
active->prev,NULL);
1771 spec_is_long_equal(q->
active->accounts.elapsed_time,0);
1772 spec_is_long_equal(q->
active->next->accounts.elapsed_time,0);
1779 raise_error(
"ERROR; return code from pthread_create() is %d\n", rc);
1782 rc = pthread_join(thread, &status);
1784 raise_error(
"ERROR; return code from pthread_join() is %d\n", rc);
1786 spec_is_long_equal((
long)status,noReductionErr);
1793 spec_is_true((et1 = q->
completed->accounts.elapsed_time)>0);
1795 spec_is_true((et2 = q->
completed->next->accounts.elapsed_time)>0);
1798 spec_is_str_equal(t2s(
_t_child(t1,1)),
"(TEST_INT_SYMBOL:124)");
1799 spec_is_str_equal(t2s(
_t_child(t2,1)),
"(TEST_INT_SYMBOL:123)");
1807 sprintf(buf,
"(RECEPTOR_ELAPSED_TIME:%ld)",et1+et2);
1808 spec_is_str_equal(t2s(
_t_child(
_t_child(r->
root,ReceptorInstanceStateIdx),ReceptorElapsedTimeIdx)),buf);
1815 void testRunTreeTemplate() {
1818 T *sm =
_t_parse(G_sem,0,
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL))) (SEMANTIC_LINK (USAGE:CHANNEL) (REPLACEMENT_VALUE (ASPECT_IDENT:DEFAULT_ASPECT))) (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (PING))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (PING))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (TO_ADDRESS (RECEPTOR_ADDR:3)))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (NOOP))))");
1822 spec_is_str_equal(t2s(r),
"(RUN_TREE (process:NOOP (process:REQUEST (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:backnforth) (PING) (CARRIER:backnforth))) (PARAMS))");
1827 void testProcessContinue() {
1831 T *n =
_t_parse(G_sem,0,
"(NOOP (IF (BOOLEAN:0) (CONTINUE (CONTINUE_LOCATION:/1) (CONTINUE_VALUE (TEST_STR_SYMBOL:\"fish\"))) (TEST_INT_SYMBOL:413)))");
1832 T *c = _t_rclone(n);
1836 spec_is_str_equal(t2s(
_t_child(t,1)),
"(TEST_STR_SYMBOL:fish)");
1841 void testProcessWakeup() {
1844 T *p =
_t_parse(G_sem,0,
"(NOOP (REQUEST (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (TEST_INT_SYMBOL:314) (RESPONSE_CARRIER:TESTING) (END_CONDITIONS (COUNT:1))))");
1846 T *code =_t_rclone(p);
1847 T *run_tree = __p_build_run_tree(code,0);
1849 spec_is_str_equal(_td(r,run_tree),
"(RUN_TREE (process:NOOP (process:REQUEST (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (TEST_INT_SYMBOL:314) (RESPONSE_CARRIER:TESTING) (END_CONDITIONS (COUNT:1)))) (PARAMS))");
1852 G_next_process_id = 0;
1854 Qe *e =_p_addrt2q(q,run_tree);
1860 spec_is_ptr_equal(q->
blocked,e);
1861 spec_is_equal(c->
state,Block);
1862 spec_is_str_equal(_td(r,r->pending_responses),
"(PENDING_RESPONSES (PENDING_RESPONSE (SIGNAL_UUID) (CARRIER:TESTING) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1/1)) (END_CONDITIONS (COUNT:1))))");
1863 T *wakeup =
_t_getv(r->pending_responses,1,PendingResponseWakeupIdx,TREE_PATH_TERMINATOR);
1865 _p_wakeup(q,wakeup,NULL,divideByZeroReductionErr);
1867 spec_is_ptr_equal(q->
blocked,NULL);
1868 spec_is_ptr_equal(q->
active,e);
1869 spec_is_equal(c->
state,divideByZeroReductionErr);
1874 run_tree = __p_build_run_tree(code,0);
1876 e =_p_addrt2q(q,run_tree);
1879 wakeup =
_t_getv(r->pending_responses,2,PendingResponseWakeupIdx,TREE_PATH_TERMINATOR);
1880 _p_wakeup(q,wakeup,_t_newi(0,TEST_INT_SYMBOL,314),noReductionErr);
1881 spec_is_ptr_equal(q->
blocked,NULL);
1882 spec_is_ptr_equal(q->
active,e);
1883 spec_is_equal(c->
state,Eval);
1885 spec_is_str_equal(_td(r,run_tree),
"(RUN_TREE (TEST_INT_SYMBOL:314) (PARAMS))");
1891 void testProcess() {
1893 testProcessParameter();
1898 testProcessDefine();
1900 testProcessTranscode();
1901 testProcessDissolve();
1902 testProcessSemtrex();
1904 testProcessFillMatch();
1905 testProcessFillMatchFull();
1911 testProcessString();
1912 testProcessRespond();
1914 testProcessRequest();
1915 testProcessConverse();
1916 testProcessConverseListen();
1917 testProcessThisScope();
1919 testProcessStream();
1920 testProcessStreamClose();
1921 testProcessInitiate();
1922 testProcessReduce();
1925 testProcessSignatureMatching();
1928 testProcessIterate();
1929 testProcessIterateOnSymbol();
1930 testProcessListen();
1931 testProcessSelfAddr();
1932 testProcessGetLabel();
1935 testRunTreeTemplate();
1936 testProcessContinue();
1937 testProcessWakeup();
T * _t_new_root(Symbol symbol)
Receptor * r
back-pointer to receptor in which this Q is running (for defs and more)
void testProcessIntMath()
Error _p_step(Q *q, R **contextP)
Process _d_define_process(SemTable *sem, T *code, char *name, char *intention, T *signature, T *link, Context c)
T * __t_newi(T *parent, Symbol symbol, int surface, bool is_run_node)
T * _t_detach_by_idx(T *t, int i)
void _p_wakeup(Q *q, T *wakeup, T *with, Error err)
void * _p_reduceq_thread(void *arg)
void _r_free(Receptor *r)
int state
process state machine state
void _defIfEven()
[defIfEven]
T * __t_new(T *parent, Symbol symbol, void *surface, size_t size, bool is_run_node)
T * _t_child(T *t, int i)
T * makeASCIITree(char *c)
int err
process error value
Context context
the context this receptor's definition creates
ReceptorAddress addr
the address by which to get messages to this receptor instance
Error __p_check_signature(SemTable *sem, Process p, T *code, T *sem_map)
void _st_kill(Stream *st)
Instances instances
the instances store
void testProcessReduceDefinedProcess()
[defDivZero]
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
Qe * active
active processes
int id
the process id this context exists in
Error __p_reduce_sys_proc(R *context, Symbol s, T *code, Q *q)
int contexts_count
number of active processes
Process _defDivZero()
[defIfEven]
void _st_free(Stream *st)
Symbol _d_define_symbol(SemTable *sem, Structure s, char *label, Context c)
T * node_pointer
pointer to the tree node to execute next
T * __r_make_signal(ReceptorAddress from, ReceptorAddress to, Aspect aspect, Symbol carrier, T *signal_contents, UUIDt *in_response_to, T *until, T *cid)
T * __t_find(T *t, SemanticID sym, int start_child)
T * root
RECEPTOR_INSTANCE semantic tree.
void testProcessErrorTrickleUp()
Qe * blocked
blocked processes
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
Error _p_reduce(SemTable *sem, T *rt)
T * _r_get_instance(Receptor *r, Xaddr x)
#define _sl(t, s)
macro to add a single symbol literal to semtrex tree
Qe * completed
completed processes (pending cleanup)
T * _t_parse(SemTable *sem, T *parent, char *s,...)
T * run_tree
pointer to the root of the run_tree
R * __p_make_context(T *run_tree, R *caller, int process_id, T *sem_map)
void __t_morph(T *t, Symbol s, void *surface, size_t size, int allocate)
Error _r_deliver(Receptor *r, T *signal)
void _t_detach_by_ptr(T *t, T *c)
T * _t_build(SemTable *sem, T *parent,...)
T * _p_make_run_tree(SemTable *sem, Process p, T *params, T *sem_map)
T * _t_new_cptr(T *parent, Symbol symbol, void *s)
Xaddr _r_new_instance(Receptor *r, T *t)