7 #include "../src/semtrex.h"
8 #include "../src/receptor.h"
11 void testDefValidate() {
12 T *symbols = __sem_get_defs(G_sem,SEM_TYPE_SYMBOL,TEST_CONTEXT);
13 T *structures = __sem_get_defs(G_sem,SEM_TYPE_STRUCTURE,TEST_CONTEXT);
15 Symbol bad_symbol = {1,SEM_TYPE_SYMBOL,99};
16 Structure bad_structure = {2,SEM_TYPE_STRUCTURE,22};
25 T *d = __r_make_definitions();
26 int ctx = _sem_new_context(G_sem,d);
27 T *defs = __sem_get_defs(G_sem,SEM_TYPE_SYMBOL,ctx);
30 T *def = _sem_get_def(G_sem,ss);
32 spec_is_equal(_d_get_def_addr(def),1);
33 spec_is_true(is_symbol(ss));
35 spec_is_ptr_equal(
_t_child(defs,ss.id),def);
39 spec_is_str_equal(t2s(defs),
"(SYMBOLS (SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:shoe size)) (SYMBOL_STRUCTURE:INTEGER)))");
43 spec_is_equal(ss.id,2);
44 spec_is_str_equal(t2s(
_t_child(defs,ss.id)),
"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:street number)) (SYMBOL_STRUCTURE:NULL_STRUCTURE))");
45 __d_set_symbol_structure(defs,ss,INTEGER);
46 spec_is_str_equal(t2s(
_t_child(defs,ss.id)),
"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:street number)) (SYMBOL_STRUCTURE:INTEGER))");
47 spec_is_equal(_d_get_def_addr(
_t_child(defs,ss.id)),ss.id);
49 _sem_free_context(G_sem,ctx);
56 T *defs = __sem_get_defs(G_sem,SEM_TYPE_STRUCTURE,TEST_CONTEXT);
60 spec_is_str_equal(t2s(_sem_get_def(G_sem,st)),
"(STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:boolean pair)) (STRUCTURE_SEQUENCE (STRUCTURE_SYMBOL:BOOLEAN) (STRUCTURE_SYMBOL:BOOLEAN)))");
67 T *symbols = __sem_get_defs(G_sem,SEM_TYPE_SYMBOL,SYS_CONTEXT);
70 spec_is_structure_equal(0,
__d_get_symbol_structure(symbols,STRUCTURE_DEFINITION),TUPLE_OF_STRUCTURE_LABEL_AND_STRUCTURE_DEF);
74 symbols = __sem_get_defs(G_sem,SEM_TYPE_SYMBOL,TEST_CONTEXT);
93 T *symbols = __sem_get_defs(G_sem,SEM_TYPE_SYMBOL,TEST_CONTEXT);
94 T *structures = __sem_get_defs(G_sem,SEM_TYPE_STRUCTURE,TEST_CONTEXT);
107 float ll[] = {2.0,90.3};
126 T *defs = __sem_get_defs(G_sem,SEM_TYPE_PROCESS,TEST_CONTEXT);
128 T *signature = __p_make_signature(
"result",SIGNATURE_SYMBOL,NULL_SYMBOL,
129 "val",SIGNATURE_STRUCTURE,INTEGER,
130 "exponent",SIGNATURE_STRUCTURE,INTEGER,
133 PROCESS_OF_STRUCTURE,INTEGER,PROCESS_TYPE,OPERATOR,
134 NULL_SYMBOL,NULL_SYMBOL
136 Process p =
_d_define_process(G_sem,code,
"power",
"takes the mathematical power of the two params",signature,link,TEST_CONTEXT);
138 spec_is_true(is_process(p));
139 spec_is_true(!is_symbol(p));
143 spec_is_str_equal(t2s(s),
"(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))))");
149 T *defs = __sem_get_defs(G_sem,SEM_TYPE_PROCESS,TEST_CONTEXT);
151 T *t = _t_newr(code,SLOT);
152 _t_news(t,GOAL,RESPONSE_HANDLER);
153 t = _t_newr(code,SLOT);
154 _t_news(t,USAGE,REQUEST_TYPE);
155 _t_news(t,SLOT_IS_VALUE_OF,TEST_INT_SYMBOL);
156 T *signature = __p_make_signature(
"result",SIGNATURE_SYMBOL,NULL_SYMBOL,NULL);
158 T *def = _sem_get_def(G_sem,p);
160 T *sig =
_t_child(def,ProcessDefSignatureIdx);
161 spec_is_str_equal(t2s(
_t_child(sig,2)),
"(TEMPLATE_SIGNATURE (EXPECTED_SLOT (GOAL:RESPONSE_HANDLER)) (EXPECTED_SLOT (USAGE:REQUEST_TYPE) (SLOT_IS_VALUE_OF:TEST_INT_SYMBOL)))");
173 Symbol SY(r,house_loc,latlong);
178 __t_dump(r->
sem,stx,0,buf);
179 spec_is_str_equal(buf,
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:house_loc) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:lat)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:lon))))");
181 T *t =
_t_parse(G_sem,0,
"(house_loc (lat:22.2) (lon:43.9))");
184 t =
_t_parse(G_sem,0,
"(house_loc (lat:22.2) (lat:43.9))");
190 spec_is_str_equal(t2s(stx),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_LINE) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_VERSION) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:VERSION_MAJOR)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:VERSION_MINOR)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_METHOD)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH_SEGMENTS) (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH_SEGMENT)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH_FILE) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:FILE_NAME)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:FILE_EXTENSION)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH_QUERY) (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH_QUERY_PARAMS) (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_PATH_QUERY_PARAM) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PARAM_KEY)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PARAM_VALUE)))))))))))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_HEADERS) (SEMTREX_ZERO_OR_MORE (SEMTREX_OR (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_HEADER) (SEMTREX_OR (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_HOST)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_USER_AGENT)))) (SEMTREX_OR (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_GENERAL_HEADER) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HEADER_KEY)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HEADER_VALUE)))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_ENTITY_HEADER) (SEMTREX_OR (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:CONTENT_TYPE) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:MEDIA_TYPE_IDENT)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:MEDIA_SUBTYPE_IDENT)) (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:MEDIA_PARAM) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PARAM_KEY)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PARAM_VALUE))))))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:CONTENT_ENCODING)))))))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_BODY) (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_ANY)))))");
191 spec_is_str_equal(
_dump_semtrex(G_sem,stx,buf),
"/HTTP_REQUEST/(HTTP_REQUEST_LINE/(HTTP_REQUEST_VERSION/(VERSION_MAJOR,VERSION_MINOR),HTTP_REQUEST_METHOD,HTTP_REQUEST_PATH/(HTTP_REQUEST_PATH_SEGMENTS/HTTP_REQUEST_PATH_SEGMENT*,HTTP_REQUEST_PATH_FILE/(FILE_NAME,FILE_EXTENSION),HTTP_REQUEST_PATH_QUERY/HTTP_REQUEST_PATH_QUERY_PARAMS/HTTP_REQUEST_PATH_QUERY_PARAM/(PARAM_KEY,PARAM_VALUE)**)),HTTP_REQUEST_HEADERS/HTTP_REQUEST_HEADER/(HTTP_REQUEST_HOST|HTTP_REQUEST_USER_AGENT)|(HTTP_GENERAL_HEADER/(HEADER_KEY,HEADER_VALUE)|HTTP_ENTITY_HEADER/(CONTENT_TYPE/(MEDIA_TYPE_IDENT,MEDIA_SUBTYPE_IDENT,MEDIA_PARAM/(PARAM_KEY,PARAM_VALUE)*)|CONTENT_ENCODING))*,HTTP_REQUEST_BODY/.*)");
194 spec_is_true(
_t_match(stx,G_http_req_example));
195 debug_disable(D_STX_MATCH+D_STX_BUILD);
201 spec_is_str_equal(t2s(stx),
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHARS) (SEMTREX_ONE_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:ASCII_CHAR))))");
202 spec_is_str_equal(
_dump_semtrex(r->
sem,stx,buf),
"/ASCII_CHARS/ASCII_CHAR+");
209 void testDefSysDefs() {
210 SemanticID vmhr = {SYS_CONTEXT,SEM_TYPE_RECEPTOR,0};
211 spec_is_sem_equal(vmhr,SYS_RECEPTOR);
213 spec_is_equal(G_sem->contexts,_NUM_DEFAULT_CONTEXTS);
214 spec_is_equal(
_t_children(G_sem->stores[0].definitions),6);
215 spec_is_equal(
_t_children(
_t_child(G_sem->stores[0].definitions,SEM_TYPE_STRUCTURE)),NUM_SYS_STRUCTURES-1);
216 spec_is_equal(
_t_children(
_t_child(G_sem->stores[0].definitions,SEM_TYPE_SYMBOL)),NUM_SYS_SYMBOLS-1);
218 dump2json(G_sem,__sem_context(G_sem,SYS_CONTEXT)->definitions,
"sysdefs");
221 spec_is_str_equal(t2s(_sem_get_def(G_sem,STRUCTURE_DEF)),
"(STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:STRUCTURE_DEF)) (STRUCTURE_OR (STRUCTURE_SYMBOL:STRUCTURE_SYMBOL) (STRUCTURE_SYMBOL:STRUCTURE_SEQUENCE) (STRUCTURE_SYMBOL:STRUCTURE_OR) (STRUCTURE_SYMBOL:STRUCTURE_ZERO_OR_MORE) (STRUCTURE_SYMBOL:STRUCTURE_ONE_OR_MORE) (STRUCTURE_SYMBOL:STRUCTURE_ZERO_OR_ONE) (STRUCTURE_SYMBOL:STRUCTURE_STRUCTURE) (STRUCTURE_SYMBOL:STRUCTURE_ANYTHING)))");
223 spec_is_str_equal(t2s(_sem_get_def(G_sem,CSTRING)),
"(STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:CSTRING)) (STRUCTURE_SYMBOL:NULL_SYMBOL))");
226 spec_is_str_equal(t2s(_sem_get_def(G_sem,IF)),
"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:IF)) (PROCESS_INTENTION:if) (process:NULL_PROCESS) (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:then)) (SIGNATURE_ANY)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:else)) (SIGNATURE_ANY) (SIGNATURE_OPTIONAL))))");
229 spec_is_str_equal(t2s(_sem_get_def(G_sem,LT_INT)),
"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:LT_INT)) (PROCESS_INTENTION:test less than) (process:NULL_PROCESS) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:result)) (SIGNATURE_SYMBOL:BOOLEAN)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:int1)) (SIGNATURE_STRUCTURE:INTEGER)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:int2)) (SIGNATURE_STRUCTURE:INTEGER))) (PROCESS_LINK (PROCESS_OF_STRUCTURE:INTEGER) (PROCESS_TYPE (OPERATOR))))");
232 spec_is_str_equal(t2s(_sem_get_def(G_sem,respond_with_yup)),
"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:respond_with_yup)) (PROCESS_INTENTION:respond with yup) (process:RESPOND (SIGNAL_REF:/2/1/4) (YUP)) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:response id)) (SIGNATURE_SYMBOL:SIGNAL_UUID))))");
235 spec_is_str_equal(t2s(_sem_get_def(G_sem,ALIVE)),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:ALIVE)) (PROTOCOL_SEMANTICS (ROLE:SERVER) (ROLE:CLIENT) (GOAL:HANDLER)) (alive (EXPECT (ROLE:SERVER) (SOURCE (ROLE:CLIENT)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PING))) (ACTION:respond_with_yup)) (EXPECT (ROLE:CLIENT) (SOURCE (ROLE:SERVER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:YUP))) (SLOT (GOAL:HANDLER) (SLOT_IS_VALUE_OF:ACTION)))))");
238 spec_is_str_equal(t2s(_sem_get_def(G_sem,CONTENT_TYPE)),
"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:CONTENT_TYPE) (HTTP_HEADER_LABEL:Content-Type)) (SYMBOL_STRUCTURE:MEDIA_TYPE))");
242 void testDefReceptor() {
243 T *d = __r_make_definitions();
247 defs = _sem_get_defs(G_sem,s);
248 spec_is_str_equal(t2s(defs),
"(RECEPTORS (RECEPTOR_DEFINITION (RECEPTOR_LABEL (ENGLISH_LABEL:streamscapes)) (DEFINITIONS (STRUCTURES) (SYMBOLS) (PROCESSES) (RECEPTORS) (PROTOCOLS) (SCAPES))))");
250 T *d2 = __sem_get_defs(G_sem,SEM_TYPE_RECEPTOR, _d_get_receptor_context(G_sem,s));
252 spec_is_ptr_equal(d2,
_t_child(d,SEM_TYPE_RECEPTOR));
256 spec_is_str_equal(n,
"streamscapes");
T * _t_new_root(Symbol symbol)
char * _sem_get_name(SemTable *sem, SemanticID s)
Process _d_define_process(SemTable *sem, T *code, char *name, char *intention, T *signature, T *link, Context c)
void testGetSymbolStructure()
SemanticID _d_define_receptor(SemTable *sem, char *label, T *definitions, Context c)
void testDefProcessTemplate()
void _r_free(Receptor *r)
T * _t_child(T *t, int i)
T * _d_build_def_semtrex(SemTable *sem, Symbol s, T *parent)
size_t _d_get_symbol_size(SemTable *sem, Symbol s, void *surface)
int _t_match(T *semtrex, T *t)
Structure __d_get_symbol_structure(T *symbols, Symbol s)
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
size_t _d_get_structure_size(SemTable *sem, Structure s, void *surface)
Symbol _d_define_symbol(SemTable *sem, Structure s, char *label, Context c)
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
T * _t_parse(SemTable *sem, T *parent, char *s,...)
char * _dump_semtrex(SemTable *sem, T *s, char *buf)
Structure _d_define_structure_v(SemTable *sem, char *label, Context c, int num_params,...)
T * _t_build(SemTable *sem, T *parent,...)