forked from stepcode/stepcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_resolve2.c
More file actions
122 lines (94 loc) · 3.13 KB
/
test_resolve2.c
File metadata and controls
122 lines (94 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <assert.h>
#include "express/resolve.h"
/* core */
#include "express/hash.h"
#include "express/linklist.h"
/* non-core */
#include "express/type.h"
#include "driver.h"
#include "fff.h"
/*
* mock globals
*/
char * EXPRESSprogram_name;
int EXPRESSpass;
int yylineno;
int print_objects_while_running;
/*
* mock functions
*/
DEFINE_FFF_GLOBALS
FAKE_VOID_FUNC(ENTITYresolve_supertypes, Entity)
FAKE_VOID_FUNC(ENTITYresolve_subtypes, Schema)
FAKE_VOID_FUNC(TYPE_resolve, Type *)
FAKE_VOID_FUNC(TYPEresolve_expressions, Type, Scope)
FAKE_VOID_FUNC(EXP_resolve, Expression, Scope, Type)
FAKE_VOID_FUNC(STMTlist_resolve, Linked_List, Scope)
FAKE_VOID_FUNC(ENTITYresolve_expressions, Entity)
FAKE_VALUE_FUNC(int, WHEREresolve, Linked_List, Scope, int)
FAKE_VALUE_FUNC(int, EXPRESS_fail, Express)
void setup() {
RESET_FAKE(ENTITYresolve_supertypes);
RESET_FAKE(ENTITYresolve_subtypes);
RESET_FAKE(TYPE_resolve);
RESET_FAKE(TYPEresolve_expressions);
RESET_FAKE(EXP_resolve);
RESET_FAKE(STMTlist_resolve);
RESET_FAKE(ENTITYresolve_expressions);
RESET_FAKE(WHEREresolve);
RESET_FAKE(EXPRESS_fail);
}
int test_scope_resolve_expr_stmt() {
Schema scope;
Type sel, ent_base;
Entity ent;
Symbol *ent_id, *sel_id;
scope = SCHEMAcreate();
ent_id = SYMBOLcreate("ent", 1, "test_4");
sel_id = SYMBOLcreate("sel_typ", 1, "test_4");
ent_base = TYPEcreate_name(ent_id);
ent_base->superscope = scope;
ent = ENTITYcreate(ent_id);
ent->superscope = scope;
sel = TYPEcreate(select_);
sel->symbol = *sel_id;
sel->u.type->body->list = LISTcreate();
sel->superscope = scope;
LISTadd_last(sel->u.type->body->list, ent_base);
DICTdefine(scope->symbol_table, ent_id->name, ent, ent_id, OBJ_ENTITY);
DICTdefine(scope->symbol_table, sel_id->name, sel, sel_id, OBJ_TYPE);
SCOPEresolve_expressions_statements(scope);
assert(ENTITYresolve_expressions_fake.call_count == 1);
assert(TYPEresolve_expressions_fake.call_count == 1);
return 0;
}
int test_scope_resolve_subsupers() {
Schema scope;
Type sel, ent_base;
Entity ent;
Symbol *ent_id, *sel_id;
scope = SCHEMAcreate();
ent_id = SYMBOLcreate("ent", 1, "test_4");
sel_id = SYMBOLcreate("sel_typ", 1, "test_4");
ent_base = TYPEcreate_name(ent_id);
ent_base->superscope = scope;
ent = ENTITYcreate(ent_id);
ent->superscope = scope;
sel = TYPEcreate(select_);
sel->symbol = *sel_id;
sel->u.type->body->list = LISTcreate();
sel->superscope = scope;
LISTadd_last(sel->u.type->body->list, ent_base);
DICTdefine(scope->symbol_table, ent_id->name, ent, ent_id, OBJ_ENTITY);
DICTdefine(scope->symbol_table, sel_id->name, sel, sel_id, OBJ_TYPE);
SCOPEresolve_subsupers(scope);
assert(TYPE_resolve_fake.call_count == 1);
assert(ENTITYresolve_supertypes_fake.call_count == 1);
assert(ENTITYresolve_subtypes_fake.call_count == 1);
return 0;
}
struct test_def tests[] = {
{"scope_resolve_expr_stmt", test_scope_resolve_expr_stmt},
{"scope_resolve_subsupers", test_scope_resolve_subsupers},
{NULL}
};