RSS

(root)/ildjit/libiljitir : 1 : test/unit_src/ir_method_instr.c

« back to all changes in this revision

Viewing changes to test/unit_src/ir_method_instr.c

Speziale Ettore
2009-11-18 09:19:57
Revision ID: ettore@mars-20091118091957-5qdu9yqf186fftwr
Initial import into Bazaar.

Show diffs side-by-side

added added

removed removed

 
1
#include <tests_utils.h>
 
2
#include <ir_method.h>
 
3
 
 
4
int main(int argc, char * argv[]) {
 
5
        ir_lib_t ir_lib;
 
6
        ir_method_t method;
 
7
        t_ir_instruction * firstInstr;
 
8
        t_ir_instruction * secondInstr;
 
9
 
 
10
        IRLibNew(&ir_lib, NULL, tests_malloc, tests_realloc, tests_free, NULL);
 
11
        ir_method_init(&ir_lib, &method);
 
12
 
 
13
        assert(method.getNextInstruction(&method, NULL) == NULL);
 
14
        assert(method.getFirstInstruction(&method) == NULL);
 
15
        assert(method.getLastInstruction(&method) == NULL);
 
16
 
 
17
        assert(method.getInstructionsNumber(&method) == 0);
 
18
        firstInstr = method.newInstruction(&method);
 
19
        assert(firstInstr != NULL);
 
20
        assert(method.getInstructionsNumber(&method) == 1);
 
21
 
 
22
        assert(method.getPrevInstruction(&method, firstInstr) == NULL);
 
23
        assert(method.getInstructionAt(&method, 0) == firstInstr);
 
24
        assert(method.getNextInstruction(&method, firstInstr) == NULL);
 
25
 
 
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);
 
30
 
 
31
        assert(method.getInstructionsNumber(&method) == 1);
 
32
        secondInstr = method.newInstruction(&method);
 
33
        assert(secondInstr != NULL);
 
34
        assert(method.getInstructionsNumber(&method) == 2);
 
35
 
 
36
        assert(method.getNextInstruction(&method, NULL) == firstInstr);
 
37
        assert(method.getFirstInstruction(&method) == firstInstr);
 
38
        assert(method.getLastInstruction(&method) == secondInstr);
 
39
 
 
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);
 
44
 
 
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);
 
50
 
 
51
        assert(method.getFirstInstruction(&method) == firstInstr);
 
52
        assert(method.getLastInstruction(&method) == secondInstr);
 
53
 
 
54
        assert(method.getInstructionsNumber(&method) == 2);
 
55
        method.deleteInstructions(&method);
 
56
        assert(method.getInstructionsNumber(&method) == 0);
 
57
 
 
58
        assert(method.getFirstInstruction(&method) == NULL);
 
59
        assert(method.getLastInstruction(&method) == NULL);
 
60
 
 
61
        firstInstr = method.newInstruction(&method);
 
62
        assert(firstInstr != NULL);
 
63
        secondInstr = method.newInstruction(&method);
 
64
        assert(secondInstr != NULL);
 
65
        assert(method.getInstructionsNumber(&method) == 2);
 
66
 
 
67
        assert(method.getFirstInstruction(&method) == firstInstr);
 
68
        assert(method.getLastInstruction(&method) == secondInstr);
 
69
 
 
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);
 
74
 
 
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);
 
80
 
 
81
        assert(method.getInstructionsNumber(&method) == 2);
 
82
        method.deleteInstruction(&method, firstInstr);
 
83
 
 
84
        assert(method.getInstructionsNumber(&method) == 1);
 
85
 
 
86
        assert(method.getFirstInstruction(&method) == secondInstr);
 
87
        assert(method.getLastInstruction(&method) == secondInstr);
 
88
 
 
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);
 
93
 
 
94
        assert(method.getInstructionsNumber(&method) == 1);
 
95
        method.deleteInstruction(&method, secondInstr);
 
96
        assert(method.getInstructionsNumber(&method) == 0);
 
97
 
 
98
        assert(method.getFirstInstruction(&method) == NULL);
 
99
        assert(method.getLastInstruction(&method) == NULL);
 
100
 
 
101
        firstInstr = method.newInstruction(&method);
 
102
        assert(firstInstr != NULL);
 
103
        secondInstr = method.newInstruction(&method);
 
104
        assert(secondInstr != NULL);
 
105
        assert(method.getInstructionsNumber(&method) == 2);
 
106
 
 
107
        assert(method.getFirstInstruction(&method) == firstInstr);
 
108
        assert(method.getLastInstruction(&method) == secondInstr);
 
109
 
 
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);
 
114
 
 
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);
 
120
 
 
121
        assert(method.getInstructionsNumber(&method) == 2);
 
122
        method.deleteInstruction(&method, secondInstr);
 
123
        assert(method.getInstructionsNumber(&method) == 1);
 
124
 
 
125
        assert(method.getFirstInstruction(&method) == firstInstr);
 
126
        assert(method.getLastInstruction(&method) == firstInstr);
 
127
 
 
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);
 
132
 
 
133
        assert(method.getInstructionsNumber(&method) == 1);
 
134
        method.deleteInstruction(&method, firstInstr);
 
135
        assert(method.getInstructionsNumber(&method) == 0);
 
136
 
 
137
        assert(method.getFirstInstruction(&method) == NULL);
 
138
        assert(method.getLastInstruction(&method) == NULL);
 
139
 
 
140
        assert(method.getInstructionsNumber(&method) == 0);
 
141
        firstInstr = method.newInstruction(&method);
 
142
        assert(firstInstr != NULL);
 
143
        assert(method.getInstructionsNumber(&method) == 1);
 
144
 
 
145
        method.destroy(&method);
 
146
 
 
147
        assert(method.instructions == NULL);
 
148
 
 
149
        return 0;
 
150
}

Loggerhead 1.17 is a web-based interface for Bazaar branches