1
#include <tests_utils.h>
4
int main(int argc, char * argv[]) {
7
t_ir_instruction * firstInstr;
8
t_ir_instruction * secondInstr;
10
IRLibNew(&ir_lib, NULL, tests_malloc, tests_realloc, tests_free, NULL);
11
ir_method_init(&ir_lib, &method);
13
assert(method.getNextInstruction(&method, NULL) == NULL);
14
assert(method.getFirstInstruction(&method) == NULL);
15
assert(method.getLastInstruction(&method) == NULL);
17
assert(method.getInstructionsNumber(&method) == 0);
18
firstInstr = method.newInstruction(&method);
19
assert(firstInstr != NULL);
20
assert(method.getInstructionsNumber(&method) == 1);
22
assert(method.getPrevInstruction(&method, firstInstr) == NULL);
23
assert(method.getInstructionAt(&method, 0) == firstInstr);
24
assert(method.getNextInstruction(&method, firstInstr) == NULL);
26
assert(method.getNextInstruction(&method, NULL) == firstInstr);
27
assert(method.getFirstInstruction(&method) == firstInstr);
28
assert(method.getLastInstruction(&method) == firstInstr);
29
assert(method.getInstructionID(&method, firstInstr) == 0);
31
assert(method.getInstructionsNumber(&method) == 1);
32
secondInstr = method.newInstruction(&method);
33
assert(secondInstr != NULL);
34
assert(method.getInstructionsNumber(&method) == 2);
36
assert(method.getNextInstruction(&method, NULL) == firstInstr);
37
assert(method.getFirstInstruction(&method) == firstInstr);
38
assert(method.getLastInstruction(&method) == secondInstr);
40
assert(method.getPrevInstruction(&method, firstInstr) == NULL);
41
assert(method.getInstructionAt(&method, 0) == firstInstr);
42
assert(method.getNextInstruction(&method, firstInstr) == secondInstr);
43
assert(method.getInstructionID(&method, firstInstr) == 0);
45
assert(method.getPrevInstruction(&method, secondInstr) == firstInstr);
46
assert(method.getInstructionAt(&method, 1) == secondInstr);
47
assert(method.getNextInstruction(&method, secondInstr) == NULL);
48
assert(method.getInstructionID(&method, firstInstr) == 0);
49
assert(method.getInstructionID(&method, secondInstr) == 1);
51
assert(method.getFirstInstruction(&method) == firstInstr);
52
assert(method.getLastInstruction(&method) == secondInstr);
54
assert(method.getInstructionsNumber(&method) == 2);
55
method.deleteInstructions(&method);
56
assert(method.getInstructionsNumber(&method) == 0);
58
assert(method.getFirstInstruction(&method) == NULL);
59
assert(method.getLastInstruction(&method) == NULL);
61
firstInstr = method.newInstruction(&method);
62
assert(firstInstr != NULL);
63
secondInstr = method.newInstruction(&method);
64
assert(secondInstr != NULL);
65
assert(method.getInstructionsNumber(&method) == 2);
67
assert(method.getFirstInstruction(&method) == firstInstr);
68
assert(method.getLastInstruction(&method) == secondInstr);
70
assert(method.getPrevInstruction(&method, firstInstr) == NULL);
71
assert(method.getInstructionAt(&method, 0) == firstInstr);
72
assert(method.getNextInstruction(&method, firstInstr) == secondInstr);
73
assert(method.getInstructionID(&method, firstInstr) == 0);
75
assert(method.getPrevInstruction(&method, secondInstr) == firstInstr);
76
assert(method.getInstructionAt(&method, 1) == secondInstr);
77
assert(method.getNextInstruction(&method, secondInstr) == NULL);
78
assert(method.getInstructionID(&method, firstInstr) == 0);
79
assert(method.getInstructionID(&method, secondInstr) == 1);
81
assert(method.getInstructionsNumber(&method) == 2);
82
method.deleteInstruction(&method, firstInstr);
84
assert(method.getInstructionsNumber(&method) == 1);
86
assert(method.getFirstInstruction(&method) == secondInstr);
87
assert(method.getLastInstruction(&method) == secondInstr);
89
assert(method.getPrevInstruction(&method, secondInstr) == NULL);
90
assert(method.getInstructionAt(&method, 0) == secondInstr);
91
assert(method.getNextInstruction(&method, secondInstr) == NULL);
92
assert(method.getInstructionID(&method, secondInstr) == 0);
94
assert(method.getInstructionsNumber(&method) == 1);
95
method.deleteInstruction(&method, secondInstr);
96
assert(method.getInstructionsNumber(&method) == 0);
98
assert(method.getFirstInstruction(&method) == NULL);
99
assert(method.getLastInstruction(&method) == NULL);
101
firstInstr = method.newInstruction(&method);
102
assert(firstInstr != NULL);
103
secondInstr = method.newInstruction(&method);
104
assert(secondInstr != NULL);
105
assert(method.getInstructionsNumber(&method) == 2);
107
assert(method.getFirstInstruction(&method) == firstInstr);
108
assert(method.getLastInstruction(&method) == secondInstr);
110
assert(method.getPrevInstruction(&method, firstInstr) == NULL);
111
assert(method.getInstructionAt(&method, 0) == firstInstr);
112
assert(method.getNextInstruction(&method, firstInstr) == secondInstr);
113
assert(method.getInstructionID(&method, firstInstr) == 0);
115
assert(method.getPrevInstruction(&method, secondInstr) == firstInstr);
116
assert(method.getInstructionAt(&method, 1) == secondInstr);
117
assert(method.getNextInstruction(&method, secondInstr) == NULL);
118
assert(method.getInstructionID(&method, firstInstr) == 0);
119
assert(method.getInstructionID(&method, secondInstr) == 1);
121
assert(method.getInstructionsNumber(&method) == 2);
122
method.deleteInstruction(&method, secondInstr);
123
assert(method.getInstructionsNumber(&method) == 1);
125
assert(method.getFirstInstruction(&method) == firstInstr);
126
assert(method.getLastInstruction(&method) == firstInstr);
128
assert(method.getPrevInstruction(&method, firstInstr) == NULL);
129
assert(method.getInstructionAt(&method, 0) == firstInstr);
130
assert(method.getNextInstruction(&method, firstInstr) == NULL);
131
assert(method.getInstructionID(&method, firstInstr) == 0);
133
assert(method.getInstructionsNumber(&method) == 1);
134
method.deleteInstruction(&method, firstInstr);
135
assert(method.getInstructionsNumber(&method) == 0);
137
assert(method.getFirstInstruction(&method) == NULL);
138
assert(method.getLastInstruction(&method) == NULL);
140
assert(method.getInstructionsNumber(&method) == 0);
141
firstInstr = method.newInstruction(&method);
142
assert(firstInstr != NULL);
143
assert(method.getInstructionsNumber(&method) == 1);
145
method.destroy(&method);
147
assert(method.instructions == NULL);