7 #include "../src/ceptr.h"
8 #include "../src/receptor.h"
37 for(i=0;i<h.m->levels;i++) {
40 L *l = _GET_LEVEL(h,i);
42 printf(
"%d(%d):",i,l->nodes);
43 for(j=0;j<l->nodes;j++) {
45 N *n = _GET_NODE(h,l,j);
46 if (!(n->flags & TFLAG_DELETED))
47 printf(
"%s:%d, ",(
char *)
_m_surface(hh),n->parenti);
57 char *s = (
char *)data;
60 sprintf(s,(
char *)
"%d.%d, ",h.a.l,h.a.i);
62 void testCreateTreeNodesM(){
64 H h,h1,h11,h2,h21,h22,h3;
67 h = _m_new(null_H,TEST_STR_SYMBOL,
"hello",6);
68 spec_is_equal(h.a.l,0);
69 spec_is_equal(h.a.i,0);
70 spec_is_equal(h.m->levels,1);
71 spec_is_long_equal(
_m_size(h),(
size_t)6);
73 spec_is_str_equal((
char *)
_m_surface(h),
"hello");
74 spec_is_maddr_equal(
_m_parent(h),null_H.a);
75 spec_is_maddr_equal(
_m_child(h,1),null_H.a);
76 spec_is_maddr_equal(
_m_child(h,NULL_ADDR),null_H.a);
77 spec_is_true(semeq(
_m_symbol(h),TEST_STR_SYMBOL));
80 h1 = _m_new(h,TEST_STR_SYMBOL,
"t1",3);
81 spec_is_equal(h.m->levels,2);
82 spec_is_str_equal((
char *)
_m_surface(h1),
"t1");
85 spec_is_maddr_equal(
_m_child(h,1),h1.a);
86 spec_is_maddr_equal(
_m_child(h,NULL_ADDR),h1.a);
87 spec_is_maddr_equal(
_m_child(h1,NULL_ADDR),null_H.a);
90 h2 = _m_new(h,TEST_STR_SYMBOL,
"t2",3);
91 spec_is_equal(h.m->levels,2);
92 spec_is_str_equal((
char *)
_m_surface(h2),
"t2");
95 spec_is_maddr_equal(
_m_child(h,2),h2.a);
96 spec_is_maddr_equal(
_m_child(h,NULL_ADDR),h2.a);
100 h21 = _m_new(h2,TEST_STR_SYMBOL,
"t21",4);
101 spec_is_equal(h21.a.l,2);
102 spec_is_equal(h21.a.i,0);
103 spec_is_equal(h.m->levels,3);
104 spec_is_str_equal((
char *)
_m_surface(h21),
"t21");
105 spec_is_maddr_equal(
_m_parent(h21),h2.a);
107 spec_is_maddr_equal(
_m_child(h2,1),h21.a);
108 spec_is_maddr_equal(
_m_child(h2,NULL_ADDR),h21.a);
111 spec_is_maddr_equal(
_m_child(h1,NULL_ADDR),null_H.a);
112 h11 = _m_new(h1,TEST_STR_SYMBOL,
"t11",4);
113 spec_is_equal(h11.a.l,2);
114 spec_is_equal(h11.a.i,1);
115 spec_is_equal(h.m->levels,3);
116 spec_is_str_equal((
char *)
_m_surface(h11),
"t11");
117 spec_is_maddr_equal(
_m_parent(h11),h1.a);
119 spec_is_maddr_equal(
_m_child(h1,1),h11.a);
120 spec_is_maddr_equal(
_m_child(h1,NULL_ADDR),h11.a);
124 h22 = _m_new(h2,TEST_STR_SYMBOL,
"t22",4);
125 spec_is_equal(h22.a.l,2);
126 spec_is_equal(h22.a.i,2);
127 spec_is_equal(h.m->levels,3);
128 spec_is_str_equal((
char *)
_m_surface(h22),
"t22");
129 spec_is_maddr_equal(
_m_parent(h22),h2.a);
131 spec_is_maddr_equal(
_m_child(h2,2),h22.a);
132 spec_is_maddr_equal(
_m_child(h2,NULL_ADDR),h22.a);
153 H h12 = _m_new(null_H,TEST_TREE_SYMBOL,
"t12",4);
154 spec_is_str_equal((
char *)
_m_surface(h12),
"t12");
155 _m_new(h12,TEST_STR_SYMBOL,
"t121",5);
156 H h221 = _m_new(h22,TEST_STR_SYMBOL,
"t221",5);
157 spec_is_equal(h221.a.l,3);
158 spec_is_equal(h221.a.i,0);
159 spec_is_equal(GET_LEVEL(h221)->nodes,1);
166 spec_is_str_equal(buf,
"0.0, 1.0, 2.1, 1.1, 2.0, 2.2, 3.0, 1.2, ");
169 spec_is_equal(h12.a.l,2);
170 spec_is_equal(h12.a.i,3);
173 spec_is_maddr_equal(
_m_child(h1,2),h12.a);
175 spec_is_equal(h22.a.l,2);
176 spec_is_equal(h22.a.i,2);
178 spec_is_equal(GET_LEVEL(h221)->nodes,2);
179 spec_is_str_equal((
char *)
_m_surface(h221),
"t221");
182 spec_is_str_equal((
char *)
_m_surface(h221),
"t221");
188 spec_is_str_equal(xx,
"t121");
189 spec_is_equal(h121.a.l,3);
190 spec_is_equal(h121.a.i,1);
199 spec_is_str_equal(buf,
"1.1, 2.0, 2.2, 3.0, ");
203 spec_is_maddr_equal(
_m_parent(h2),null_H.a);
207 spec_is_true(h2.m != h.m);
215 void testMTreeOrthogonal() {
216 H h = _m_new(null_H,TEST_STR_SYMBOL,
"hello",6);
217 H h1 =
_m_newi(null_H,TEST_INT_SYMBOL,314);
218 _m_newt(h,TEST_TREE_SYMBOL,h1);
221 spec_is_str_equal(t2s(t),
"(TEST_STR_SYMBOL:hello (TEST_TREE_SYMBOL:{(TEST_INT_SYMBOL:314)}))");
230 spec_is_str_equal(t2s(t),
"(TEST_STR_SYMBOL:hello (TEST_TREE_SYMBOL:{(TEST_INT_SYMBOL:314)}))");
237 void testMTreeReceptor() {
239 T *t = _t_newi(0,TEST_INT_SYMBOL,0);
248 spec_is_str_equal(t2s(t2),
"(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)))})");
263 spec_is_str_equal(buf,
"0.0, 1.0, 2.0, 2.1, 1.1, 1.2, 2.2, 3.0, 3.1, 2.3, 3.2, 3.3, 2.4, 3.4, 4.0, 5.0, 5.1, 4.1, 5.2, 5.3, ");
270 spec_is_str_equal(buf,
"1.2, 2.2, 3.0, 3.1, 2.3, 3.2, 3.3, 2.4, 3.4, 4.0, 5.0, 5.1, 4.1, 5.2, 5.3, ");
282 spec_is_symbol_equal(0,
_m_symbol(h),HTTP_REQUEST_LINE);
285 spec_is_symbol_equal(0,
_m_symbol(hh),HTTP_REQUEST_VERSION);
288 spec_is_str_equal((
char *)
_m_surface(hh),
"page");
293 char buf[2000] = {0};
294 char buf1[2000] = {0};
296 __t_dump(G_sem,t,0,buf);
297 __t_dump(G_sem,t1,0,buf1);
299 spec_is_str_equal(buf1,buf);
307 T *n = _t_newr(0,ADD_INT);
308 _t_newi(n,TEST_INT_SYMBOL,99);
309 _t_newi(n,TEST_INT_SYMBOL,100);
319 spec_is_str_equal(t2s(t),
"(RUN_TREE (process:ADD_INT (TEST_INT_SYMBOL:99) (TEST_INT_SYMBOL:100)))");
322 debug_disable(D_REDUCE+D_REDUCEV);
323 spec_is_str_equal(t2s(t),
"(RUN_TREE (TEST_INT_SYMBOL:199))");
331 void testMTreeSerialize() {
337 spec_is_equal(s->magic,h.m->magic);
338 spec_is_equal(s->total_size,929);
339 spec_is_equal(s->levels,h.m->levels);
340 spec_is_equal(s->level_offsets[0],0);
342 spec_is_equal(s->level_offsets[1], (
int)SERIALIZED_LEVEL_SIZE(l));
347 char buf[2000] = {0};
348 char buf1[2000] = {0};
350 __t_dump(G_sem,t,0,buf);
351 __t_dump(G_sem,t1,0,buf1);
353 spec_is_str_equal(buf1,buf);
355 writeFile(
"web/test.cmt",s,s->total_size);
358 h =
_m_new_from_t(__sem_get_defs(G_sem,SEM_TYPE_STRUCTURE,INTERNET_CONTEXT));
360 writeFile(
"web/httpstructures.cmt",s,s->total_size);
363 h =
_m_new_from_t(__sem_get_defs(G_sem,SEM_TYPE_SYMBOL,INTERNET_CONTEXT));
365 writeFile(
"web/httpsymbols.cmt",s,s->total_size);
368 h =
_m_new_from_t(__sem_get_defs(G_sem,SEM_TYPE_STRUCTURE,SYS_CONTEXT));
370 writeFile(
"web/sysstructures.cmt",s,s->total_size);
373 h =
_m_new_from_t(__sem_get_defs(G_sem,SEM_TYPE_SYMBOL,SYS_CONTEXT));
375 writeFile(
"web/syssymbols.cmt",s,s->total_size);
384 _m_newi(h1,TEST_INT_SYMBOL,314);
385 _m_newi(h1,TEST_INT_SYMBOL,1000);
386 H h2 = _m_newt(null_H,TEST_TREE_SYMBOL,h1);
387 h = _m_newt(null_H,TEST_TREE_SYMBOL,h2);
393 spec_is_str_equal(t2s(t),
"(TEST_TREE_SYMBOL:{(TEST_TREE_SYMBOL:{(process:ADD_INT (TEST_INT_SYMBOL:314) (TEST_INT_SYMBOL:1000))})})");
403 testCreateTreeNodesM();
404 testMTreeOrthogonal();
408 testMTreeSerialize();
T * _t_new_root(Symbol symbol)
void _m_walk(H h, void(*walkfn)(H, N *, void *, MwalkState *, Maddr), void *user_data)
T * _t_new_receptor(T *parent, Symbol symbol, Receptor *r)
Maddr _m_child(H h, Mindex c)
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
SState * state(StateType type, int *statesP, int level)
H _m_newi(H parent, Symbol symbol, int surface)
Error _p_reduce(SemTable *sem, T *rt)
T * _makeTestHTTPRequestTree()
[makeTestHTTPRequestTree]
Maddr _m_next_sibling(H h)
H _m_newr(H parent, Symbol s)