tests.py 66.9 KB
Newer Older
Sergio Costas's avatar
Sergio Costas committed
1 2 3 4
#!/usr/bin/env python3

import sys
import os
5
#sys.path.append(os.path.abspath(os.path.join(os.getcwd(), os.pardir)))
Sergio Costas's avatar
Sergio Costas committed
6 7

import unittest
8
from crust import crust
Sergio Costas's avatar
Sergio Costas committed
9 10 11

class Test(unittest.TestCase):

Sergio Costas's avatar
Sergio Costas committed
12
    do_print_debug = False
13
    do_print_debug2 = False
14

15
    def _find_variable(self, var_container, var_name):
16
        for var_group in var_container["variables"]:
17 18 19 20
            if var_name in var_group:
                return var_group[var_name]
        return None

21 22 23 24 25 26 27
    def _find_variable_by_id(self, var_container, var_id):
        for var_group in var_container["variables"]:
            for var_name in var_group:
                if var_group[var_name]["uid"] == var_id:
                    return var_group[var_name]
        return None

28
    def _check_var_state(self, lib, variable, status, deep = 0):
29 30
        var = self._find_variable(lib.debug[deep], variable)
        self.assertIsNot(var, None)
31
        self.assertEqual(var["value"], status)
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46
    def _check_block_id_is_the_same(self, lib, variable1, variable2, deep = 0):
        var1 = self._find_variable(lib.debug[deep], variable1)
        self.assertIsNot(var1, None)
        var2 = self._find_variable(lib.debug[deep], variable2)
        self.assertIsNot(var2, None)
        self.assertEqual(var1["uid"], var2["uid"])

    def _check_block_id_is_not_same(self, lib, variable1, variable2, deep = 0):
        var1 = self._find_variable(lib.debug[deep], variable1)
        self.assertIsNot(var1, None)
        var2 = self._find_variable(lib.debug[deep], variable2)
        self.assertIsNot(var2, None)
        self.assertNotEqual(var1["uid"], var2["uid"])

47
    def _test_msg(self, lib, error_element, params):
48 49 50
        with open("error_list.txt", "a") as errorlist:
            errorlist.write(error_element[1])
            errorlist.write("\n")
51
        self.assertEqual(len(error_element), len(params))
Sergio Costas's avatar
Sergio Costas committed
52
        for index in range(len(error_element)):
53
            self.assertEqual(error_element[index], params[index])
Sergio Costas's avatar
Sergio Costas committed
54

55
    def _print_errors(self, filename, lib):
56
        if self.do_print_debug2:
57
            print("\rtest file: {:s}".format(filename))
58
            lib.print_errors(False)
59

60
    def open_crust(self):
61 62
        if (os.path.exists('lexyacclib/crust_code.h')) and (os.path.exists('lexyacclib/crust.so')):
            lib = crust.crust("lexyacclib/crust_code.h", "lexyacclib/crust.so")
63
        else:
64
            lib = crust.crust(pkg_resources.resource_filename('crust','/crust_code.h'),pkg_resources.resource_filename('crust','/crust.so'))
65 66
        return lib

67
    def _generic_test(self, filename, params):
68 69
        if self.do_print_debug:
            print("Running test {:s}".format(filename))
70
        lib = self.open_crust()
71
        tree = lib.read_file(filename, False, [], [], [])
72
        self.assertIsNot(tree, None)
73
        variables = lib.process_tree(tree, filename)
74 75 76
        lib.process_functions(tree, variables)
        self._print_errors(filename, lib)
        self.assertEqual(len(lib.errors), len(params))
77 78 79
        # avoid problems with error order
        lib.errors.sort()
        params.sort()
80
        for i in range(len(lib.errors)):
81
            self._test_msg(lib, lib.errors[i], params[i])
82
        return lib
Sergio Costas's avatar
Sergio Costas committed
83 84


85
    def _all_fine_test(self, filename):
86 87
        if self.do_print_debug:
            print("Running test {:s}".format(filename))
88
        lib = self.open_crust()
89
        tree = lib.read_file(filename, False, [], [], [])
90
        self.assertIsNot(tree, None)
91
        variables = lib.process_tree(tree, filename)
92 93 94
        lib.process_functions(tree, variables)
        self._print_errors(filename, lib)
        self.assertEqual(len(lib.errors), 0)
95
        return lib
Sergio Costas's avatar
Sergio Costas committed
96

97
    def _raise_test(self, filename, exception_class, params):
98 99
        if self.do_print_debug:
            print("Running test {:s}".format(filename))
100
        lib = self.open_crust()
101
        tree = lib.read_file(filename, False, [], [], [])
102
        self.assertIsNot(tree, None)
103
        variables = lib.process_tree(tree, filename)
104
        with self.assertRaises(exception_class):
105 106 107
            lib.process_functions(tree, variables)
        self._print_errors(filename, lib)
        self.assertEqual(len(lib.errors), len(params))
108
        for i in range(len(lib.errors)):
109
            self._test_msg(lib, lib.errors[i], params[i])
110 111
        return lib

112
    def test001AllFine(self):
113 114 115
        # This test just must work
        self._all_fine_test("unitest/test1.c")

116
    def test002UnknownVariable(self):
117
        self._raise_test("unitest/test2.c", crust.crust.VarNotFoundException, [(crust.crust.MSG_CRITICAL, "Unknown variable '{:s}' at line {:d}", "var", 4)])
Sergio Costas's avatar
Sergio Costas committed
118

119
    def test003Overwrite(self):
120
        self._generic_test("unitest/test3.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param3", 7, 6) ])
Sergio Costas's avatar
Sergio Costas committed
121

122
    def test004UseUninitialized(self):
123
        self._generic_test("unitest/test4.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 7) ])
Sergio Costas's avatar
Sergio Costas committed
124

125
    def test005UseFreed(self):
126
        self._generic_test("unitest/test5.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 6, 5) ])
Sergio Costas's avatar
Sergio Costas committed
127

128
    def test006PassedNonCrustyToCrusty(self):
129
        self._generic_test("unitest/test6.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed non __crust__ variable", 1, "function", 8) ])
Sergio Costas's avatar
Sergio Costas committed
130

131
    def test007PassedCrustyToNonCrusty(self):
132
        self._generic_test("unitest/test7.c", [ (crust.crust.MSG_CRITICAL, "Expected a non __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed a __crust__ variable", 1, "function", 8) ])
Sergio Costas's avatar
Sergio Costas committed
133

134
    def test008PassedOtherToCrusty(self):
135
        self._generic_test("unitest/test8.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}", 1, "function", 7) ])
Sergio Costas's avatar
Sergio Costas committed
136

137
    def test009PassedIncorrectNumberOfParameters(self):
138
        self._generic_test("unitest/test9.c", [ (crust.crust.MSG_CRITICAL, "Calling function '{:s}' at line {:d} with an incorrect number of arguments", "function", 7) ])
Sergio Costas's avatar
Sergio Costas committed
139

140
    def test010NonExistingFunction(self):
141
        self._raise_test("unitest/test10.c", crust.crust.FunctionNotFoundException, [ (crust.crust.MSG_CRITICAL, "Calling function '{:s}' at line {:d}, but it is neither declared nor defined", "function3", 5) ])
Sergio Costas's avatar
Sergio Costas committed
142

143
    def test011CrustParameterNotPointer(self):
144
        self._generic_test("unitest/test11.c", [ (crust.crust.MSG_CRITICAL, "An argument is defined as __crust__ type at line {:d}, but it is not a pointer", 1) ])
Sergio Costas's avatar
Sergio Costas committed
145

146
    def test012CrustNamedParameterNotPointer(self):
147
        self._generic_test("unitest/test12.c", [ (crust.crust.MSG_CRITICAL, "Argument '{:s}' defined as __crust__ type at line {:d}, but it is not a pointer", "parameter", 1) ])
Sergio Costas's avatar
Sergio Costas committed
148

149
    def test013CrustVariableNotPointer(self):
150
        self._generic_test("unitest/test13.c", [ (crust.crust.MSG_CRITICAL, "Variable '{:s}' is defined as __crust__ type at line {:d}, but it is not a pointer", "retval", 5) ])
151

152
    def test014CrustRetvalNotPointer(self):
153
        self._generic_test("unitest/test14.c", [ (crust.crust.MSG_CRITICAL, "Return value for function '{:s}', defined at line {:d}, is defined as __crust__ type, but it is not a pointer", "function", 1) ])
Sergio Costas's avatar
Sergio Costas committed
154

155
    def test015CrustOnlyVarNoOthers(self):
156
        self._generic_test("unitest/test15.c", [ (crust.crust.MSG_CRITICAL, "Variable '{:s}', defined at line {:d}, have the __crust_recycle__ modifier, which is not allowed for defined variables", "var", 1) ])
Sergio Costas's avatar
Sergio Costas committed
157

158
    def test016RecycleOrBorrowNotBoth(self):
159
        self._generic_test("unitest/test16.c", [ (crust.crust.MSG_CRITICAL, "An argument can be BORROW or RECYCLE, not both. (error at line {:d})", 1) ])
Sergio Costas's avatar
Sergio Costas committed
160

161
    def test017NamedRecycleOrBorrowNotBoth(self):
162
        self._generic_test("unitest/test17.c", [ (crust.crust.MSG_CRITICAL, "An argument can be BORROW or RECYCLE, not both. (argument '{:s}' at line {:d})", "param", 1) ])
Sergio Costas's avatar
Sergio Costas committed
163

164
    def test018RecycleReturnsCrust(self):
165
        self._generic_test("unitest/test18.c", [ (crust.crust.MSG_CRITICAL, "The function '{:s}', at line {:d}, has a RECYCLE argument, but doesn't return a CRUST pointer", "function", 1) ])
Sergio Costas's avatar
Sergio Costas committed
166

167
    def test019OnlyOneRecycle(self):
168
        self._generic_test("unitest/test19.c", [ (crust.crust.MSG_CRITICAL, "The function '{:s}', at line {:d}, has more than one RECYCLE argument", "function", 1) ])
Sergio Costas's avatar
Sergio Costas committed
169

170
    def test020UninitializedVariable(self):
171
        self._generic_test("unitest/test20.c", [ (crust.crust.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", "param4", 5) ])
Sergio Costas's avatar
Sergio Costas committed
172

173
    def test021FreedVariable(self):
174 175
        self._all_fine_test("unitest/test21.c")
        #self._generic_test("unitest/test21.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", "param4", 8, 7) ])
Sergio Costas's avatar
Sergio Costas committed
176

177
    def test022AssignFreedVariable(self):
178
        self._generic_test("unitest/test22.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", "param1", 5, 4), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param4", 4, 7) ])
179

180
    def test023AssignUninitializedVariable(self):
181
        self._generic_test("unitest/test23.c", [ (crust.crust.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", "param4", 5) ])
182

183
    def test024AssignNonCrustToCrust(self):
184
        self._generic_test("unitest/test24.c", [ (crust.crust.MSG_CRITICAL, "Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}", "param4", "param5", 5) ])
185

186
    def test025AssignCrustToNonCrust(self):
187
        self._generic_test("unitest/test25.c", [ (crust.crust.MSG_CRITICAL, "Assigning the crust variable '{:s}' to the non-crust variable '{:s}' at line {:d}", "param4", "param5", 5) ])
188

189
    def test026TypeCast(self):
190
        self._generic_test("unitest/test26.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 6, 8) ])
191

192
    def test027AssignNonCrustToCrust2(self):
193
        self._generic_test("unitest/test27.c", [ (crust.crust.MSG_CRITICAL, "Assigning a non-crust value to the crust variable '{:s}' at line {:d}", "param", 5), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 5, 7) ])
194

195
    def test028CrustRetVal(self):
196
        self._generic_test("unitest/test28.c", [ (crust.crust.MSG_ERROR, "Calling the function '{:s}' at line {:d}, but ignoring the crust-type return value", "function", 7) ])
197

198
    def test029UseUninitialized2(self):
199
        self._generic_test("unitest/test29.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 7) ])
200

201
    def test030UseFreed2(self):
202
        self._generic_test("unitest/test30.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 6, 5) ])
203

204
    def test031PassedNonCrustyToCrusty2(self):
205
        self._generic_test("unitest/test31.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed non __crust__ variable", 1, "function", 8) ])
206

207
    def test032PassedCrustyToNonCrusty2(self):
208
        self._generic_test("unitest/test32.c", [ (crust.crust.MSG_CRITICAL, "Expected a non __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed a __crust__ variable", 1, "function", 6) ])
209

210
    def test033PassedOtherToCrusty2(self):
211
        self._generic_test("unitest/test33.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}", 1, "function", 6) ])
212

213
    def test034MultiAssign(self):
214
        self._generic_test("unitest/test34.c", [ (crust.crust.MSG_CRITICAL, "Assigning a non-crust value to the crust variable '{:s}' at line {:d}", "b", 6), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "a", 6, 8)] )
Sergio Costas's avatar
Sergio Costas committed
215

216
    def test035AmpPointer(self):
217
        self._all_fine_test("unitest/test35.c")
218

219
    def test036StructElement(self):
220 221
        self._all_fine_test("unitest/test36.c")

222
    def test037StructAssign(self):
223
        self._generic_test("unitest/test37.c", [ (crust.crust.MSG_CRITICAL, "Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}", "test", "param4", 10) ])
224

225
    def test038ArrayElement(self):
226 227
        self._all_fine_test("unitest/test38.c")

228
    def test039ArrayAssign(self):
229
        self._generic_test("unitest/test39.c", [ (crust.crust.MSG_CRITICAL, "Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}", "test", "param4", 6) ])
230

231
    def test040StructAssignment(self):
Sergio Costas's avatar
Sergio Costas committed
232 233
        self._all_fine_test("unitest/test40.c")

234
    def test041UsePostStructAssignment(self):
235
        self._generic_test("unitest/test41.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 9, 8) ])
Sergio Costas's avatar
Sergio Costas committed
236

237
    def test042UsePostStructAssignment2(self):
238
        self._generic_test("unitest/test42.c", [ (crust.crust.MSG_CRITICAL, "Assigning the crust variable '{:s}' to the non-crust variable '{:s}' at line {:d}", 'param3', "test", 8) ])
Sergio Costas's avatar
Sergio Costas committed
239

240
    def test043StructAssignmentByRef(self):
241 242
        self._all_fine_test("unitest/test43.c")

243
    def test044IfEqNull(self):
244 245
        self._generic_test("unitest/test44.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 5, 14), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 10, 14), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "var2", 7, 14) ] )

246

247
    def test045IfNoEqNull(self):
248 249
        self._all_fine_test("unitest/test45.c")

250
    def test046IfElseNull(self):
251
        self._generic_test("unitest/test46.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "var2", 7, 14) ])
Sergio Costas's avatar
Sergio Costas committed
252

253
    def test047Recycle(self):
254
        lib = self._all_fine_test("unitest/test47.c")
255 256
        self._check_var_state(lib, "var3", crust.crust.VALUE_NOT_NULL, 0)
        self._check_var_state(lib, "var3", crust.crust.VALUE_FREED, 1)
257

258
    def test048Borrow(self):
259
        lib = self._all_fine_test("unitest/test48.c")
260
        self._check_var_state(lib, "var2", crust.crust.VALUE_NOT_NULL)
261

262
    def test049Borrow2(self):
263
        lib = self._all_fine_test("unitest/test49.c")
264
        self._check_var_state(lib, "var2", crust.crust.VALUE_NULL)
265

266
    def test050PassBorrowToNonBorrow(self):
267
        self._generic_test("unitest/test50.c", [ (crust.crust.MSG_CRITICAL, "Argument '{:s}' at position {:d} when calling function '{:s}' at line {:d} is borrowed, but is used as a non-borrow argument", 'param', 1, "test_function", 8) ])
268

269
    def test051PassBorrowToBorrow(self):
270 271
        self._all_fine_test("unitest/test51.c")

272
    def test052PassBorrowToBorrow2(self):
273 274
        self._all_fine_test("unitest/test52.c")

275
    def test053AssignFunctionToFunctionPointerLocal(self):
276 277
        self._all_fine_test("unitest/test53.c")

278
    def test054AssignFunctionToFunctionPointerGlobal(self):
279 280
        self._all_fine_test("unitest/test54.c")

281
    def test055AssignFunctionPointerToFunctionName(self):
282
        self._generic_test("unitest/test55.c", [ (crust.crust.MSG_CRITICAL, "Trying to assign a value to the function name '{:s}' at line {:d}", 'test_function', 10) ])
283

284
    def test056ComparisonDoesntFreePointer(self):
285
        self._generic_test("unitest/test56.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param1", 5, 3) ])
286

287
    def test057ComparisonWithoutBraces(self):
288 289
        self._all_fine_test("unitest/test57.c")

290
    def test058NestedComparisonWithoutBraces(self):
291 292
        self._all_fine_test("unitest/test58.c")

293
    def test059NestedComparisonWithBraces(self):
294 295
        self._all_fine_test("unitest/test59.c")

296
    def test060IfWithNot(self):
297 298
        self._all_fine_test("unitest/test60.c")

299
    def test061IfWithNot2(self):
300
        self._generic_test("unitest/test61.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 11, 7) ])
301

302
    def test062Return(self):
Sergio Costas's avatar
Sergio Costas committed
303 304
        self._all_fine_test("unitest/test62.c")

305
    def test063BlockInUseAtEnd(self):
306
        self._generic_test("unitest/test63.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 5, 8) ])
307

308
    def test064BlockInUseAtEnd2(self):
309
        self._generic_test("unitest/test64.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 5, 7) ])
310

311
    def test065BlockInUseWithReturn(self):
312
        self._generic_test("unitest/test65.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "var2", 8, 9) ])
313

314
    def test066BlockInUseWithReturn2(self):
315
        self._generic_test("unitest/test66.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "var2", 9, 12) ])
316

317
    def test067BlockInUseWithReturn3(self):
318 319
        self._all_fine_test("unitest/test67.c")

320
    def test068AssignmentToBorrowBlock(self):
321
        self._generic_test("unitest/test68.c", [(crust.crust.MSG_ERROR, "Overwritting the borrowed argument '{:s}' at line {:d}", "param", 7) ])
322

323
    def test069AssignmentFromBorrowBlock(self):
324
        self._generic_test("unitest/test69.c", [ (crust.crust.MSG_CRITICAL, "Assigning a borrowed block into a local variable is not allowed (assigning '{:s}' at line {:d})", "param", 9) ])
325

326
    def test070AssignmentFromBorrowBlock2(self):
327
        self._generic_test("unitest/test70.c", [ (crust.crust.MSG_CRITICAL, "Assigning a borrowed block into a local variable is not allowed (assigning '{:s}' at line {:d})", "param", 9) ])
328

329
    def test071AssignmentToAndFromMemberOfBorrowBlock(self):
330
        self._generic_test("unitest/test71.c", [ (crust.crust.MSG_WARNING, "Using variable '{:s}' at line {:d} with a possible NULL value", "param", 10) ])
331

332
    def test072AliasFreesBlock(self):
333
        lib = self._all_fine_test("unitest/test72.c")
334 335
        self._check_var_state(lib, "param", crust.crust.VALUE_FREED_OR_NULL)
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED_OR_NULL)
336

337
    def test073AliasFreesBlock2(self):
338
        self._generic_test("unitest/test73.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 9, 8) ])
339

340
    def test074BlockFreesAlias(self):
341
        self._generic_test("unitest/test74.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 10, 9) ])
342

343
    def test075DecoupleAlias(self):
344
        lib = self._generic_test("unitest/test75.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 13, 9) ])
345
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
346
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED_OR_NULL, 1)
347
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_NULL, 2)
348

349

350
    def test076DecoupleAlias2(self):
351
        lib = self._all_fine_test("unitest/test76.c")
352
        self._check_var_state(lib, "param1", crust.crust.VALUE_FREED_OR_NULL, 0)
353 354
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
355 356
        self._check_var_state(lib, "param2", crust.crust.VALUE_FREED_OR_NULL, 1)
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED_OR_NULL, 1)
357

358
    def test077DecoupleAlias3(self):
359
        lib = self._generic_test("unitest/test77.c", [ (crust.crust.MSG_ERROR, "Assigning the crust-type result value of function '{:s}' to the alias '{:s}' at line {:d}", "function", "an_alias", 11) ])
360
        self._check_var_state(lib, "param", crust.crust.VALUE_FREED_OR_NULL, 1)
361
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
362

363
    def test078FunctionPointerNull(self):
364
        self._generic_test("unitest/test78.c", [ (crust.crust.MSG_ERROR, "Using function pointer '{:s}' at line {:d} with NULL value", "test1", 9) ])
365

366
    def test079FunctionPointerNull2(self):
367
        self._generic_test("unitest/test79.c", [ (crust.crust.MSG_ERROR, "Using function pointer '{:s}' at line {:d} with NULL value", "test1", 7) ])
368

369
    def test080FunctionPointerFine(self):
370 371 372
        self._all_fine_test("unitest/test80.c")


373
    def test081FunctionPointerFine2(self):
374 375
        self._all_fine_test("unitest/test81.c")

376
    def test082FunctionPointerNonInitialized(self):
377
        self._generic_test("unitest/test82.c", [ (crust.crust.MSG_ERROR, "Using uninitialized function pointer '{:s}' at line {:d}", "test1", 9) ])
378

379
    def test083FunctionPointerNonInitialized2(self):
380
        self._generic_test("unitest/test83.c", [ (crust.crust.MSG_ERROR, "Using uninitialized function pointer '{:s}' at line {:d}", "test1", 7) ])
381

382
    def test084UndefinedPointerFunction(self):
383
        self._raise_test("unitest/test84.c", crust.crust.FunctionNotFoundException, [ (crust.crust.MSG_CRITICAL, "Calling function '{:s}' at line {:d}, but it is neither declared nor defined", "test1", 6) ])
384

385
    def test085FunctionPointerIncorrectNumberOfParameters(self):
386
        self._generic_test("unitest/test85.c", [ (crust.crust.MSG_CRITICAL, "Calling function '{:s}' at line {:d} with an incorrect number of arguments", "test1", 11) ])
387

388
    def test086FunctionPointerIncorrectNumberOfParameters2(self):
389
        self._generic_test("unitest/test86.c", [ (crust.crust.MSG_CRITICAL, "Calling function '{:s}' at line {:d} with an incorrect number of arguments", "test1", 9) ])
390

391
    def test087FunctionPointerExpectedCrustParameter(self):
392
        self._generic_test("unitest/test87.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed non __crust__ variable", 1, "test1", 12) ])
393

394
    def test088FunctionPointerExpectedCrustParameter2(self):
395
        self._generic_test("unitest/test88.c", [ (crust.crust.MSG_CRITICAL, "Expected a __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed non __crust__ variable", 1, "test1", 10) ])
396

397
    def test089FunctionPointerExpectedNonCrustParameter(self):
398
        self._generic_test("unitest/test89.c", [ (crust.crust.MSG_CRITICAL, "Expected a non __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed a __crust__ variable", 1, "test1", 11), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 9 , 12) ])
399

400
    def test090FunctionPointerExpectedNonCrustParameter2(self):
401
        self._generic_test("unitest/test90.c", [ (crust.crust.MSG_CRITICAL, "Expected a non __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}, but passed a __crust__ variable", 1, "test1", 9), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 7 , 10) ])
402

403
    def test091NestedVariables(self):
404
        lib = self._all_fine_test("unitest/test91.c")
405 406
        self._check_var_state(lib, "tmp1", crust.crust.VALUE_UNINITIALIZED, 1)
        self._check_var_state(lib, "tmp1", crust.crust.VALUE_NULL, 0)
407

408
    def test092FunctionPointerFineNoParams(self):
409 410
        self._all_fine_test("unitest/test92.c")

411
    def test093FunctionPointerFineNoParams2(self):
412 413
        self._all_fine_test("unitest/test93.c")

414
    def test094FunctionPointerReturnsCrust(self):
415
        self._generic_test("unitest/test94.c", [ (crust.crust.MSG_ERROR, "Calling the function '{:s}' at line {:d}, but ignoring the crust-type return value", "test1", 11) ])
416

417
    def test095FunctionPointerReturnsCrust2(self):
418
        self._generic_test("unitest/test95.c", [ (crust.crust.MSG_ERROR, "Calling the function '{:s}' at line {:d}, but ignoring the crust-type return value", "test1", 9) ])
419

420
    def test096BreakOutsideLoop(self):
421
        self._generic_test("unitest/test96.c", [ (crust.crust.MSG_CRITICAL, "Break not in a loop at line {:d}", 2) ])
422

423
    def test097WhileFreesTwice(self):
424
        self._generic_test("unitest/test97.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 10, 10) ])
425

426
    def test098AndOpFine(self):
427 428
        self._generic_test("unitest/test98.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 7 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 7 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 10 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 11 , 13) ])

429

430
    def test099OrOpFine(self):
431
        self._generic_test("unitest/test99.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 7 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 7 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 10 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 11 , 13) ])
432

433
    def test100AndOpWrong(self):
434
        self._generic_test("unitest/test100.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param1", 10, 7), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 7 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 7 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 10 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 11 , 13) ])
435

436
    def test101OrOpWrong(self):
437
        self._generic_test("unitest/test101.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param2", 11, 7), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 7 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 7 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 10 , 13), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 11 , 13) ])
438

439
    def test102WhileCrustVarFine(self):
440
        self._all_fine_test("unitest/test102.c")
441

442
    def test103WhileWithoutNoZero(self):
443
        self._generic_test("unitest/test103.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 15) ])
444

445
    def test104WhileWithNoZeroFine(self):
446 447
        self._all_fine_test("unitest/test104.c")

448 449 450 451
    def test105DifferenParameterNumberNoCrust(self):
        self._all_fine_test("unitest/test105.c")

    def test106DifferenParameterNumberCrust(self):
452
        self._generic_test("unitest/test106.c", [ (crust.crust.MSG_ERROR, "Trying to assign the function '{:s}' to the function pointer '{:s}' at line {:d}, but they have a different number of arguments", "function", "test1", 10) ])
453 454

    def test107DifferenParameterNumberCrust(self):
455
        self._generic_test("unitest/test107.c", [ (crust.crust.MSG_ERROR, "Trying to assign the function '{:s}' to the function pointer '{:s}' at line {:d}, but they have a different number of arguments", "function", "test1", 10) ])
456

457
    def test108DifferenParameterTypes(self):
458
        self._generic_test("unitest/test108.c", [ (crust.crust.MSG_ERROR, "Trying to assign the function '{:s}' to the function pointer '{:s}' at line {:d}, but argument {:d} differs", "function", "test1", 10, 1) ])
459 460

    def test109DifferenParameterTypes(self):
461
        self._generic_test("unitest/test109.c", [ (crust.crust.MSG_ERROR, "Trying to assign the function '{:s}' to the function pointer '{:s}' at line {:d}, but the return types differ", "function", "test1", 10) ])
462 463 464 465

    def test110ParameterTypesMatch(self):
        self._all_fine_test("unitest/test110.c")

466
    def test111CommaOperatorFine(self):
467
        self._generic_test("unitest/test111.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 12 , 13) ])
468 469

    def test112CommaOperatorBad(self):
470
        self._generic_test("unitest/test112.c", [ (crust.crust.MSG_ERROR, "Calling the function '{:s}' at line {:d}, but ignoring the crust-type return value", "function", 12), (crust.crust.MSG_CRITICAL, "Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}", "b", "param", 12), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 12 , 13) ])
471 472

    def test113CommaOperatorFine2(self):
473
        self._generic_test("unitest/test113.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 12 , 13) ])
474

475 476 477
    def test114CheckSelfAssignOps(self):
        self._all_fine_test("unitest/test114.c")

478
    def test115VariableNumberOfArguments(self):
479
        self._generic_test("unitest/test115.c", [ (crust.crust.MSG_CRITICAL, "Passed a __crust__ variable as argument {:d} when calling function '{:s}' at line {:d}, but __crust__ variables are not allowed for optional arguments in functions with variable number of arguments", 3, "function", 11), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 7 , 12) ])
480

481
    def test116NonCrustRetValToCrust(self):
482
        self._generic_test("unitest/test116.c", [ (crust.crust.MSG_ERROR, "Assigning the non-crust-type result value of function '{:s}' at line {:d} to the crust variable '{:s}'", "function", 5, "retval"), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "retval", 5 , 6) ])
483 484 485 486 487 488 489

    def test117CrustRetValToNonCrust(self):
        self._generic_test("unitest/test117.c", [ (crust.crust.MSG_ERROR, "Assigning the crust-type result value of function '{:s}' at line {:d} to the non-crust variable '{:s}'", "function", 5, "retval") ])

    def test118CallingPointerWithPosibleNull(self):
        self._generic_test("unitest/test118.c", [ (crust.crust.MSG_WARNING, "Using function pointer '{:s}' at line {:d} with a possible NULL value", "test1", 11) ])

490 491
    def test119BlockToGlobalVar(self):
        self._all_fine_test("unitest/test119.c")
492

493
    def test120DoWhileUsesTwice(self):
494
        self._generic_test("unitest/test120.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 10, 10) ])
495 496 497 498 499 500 501

    def test121DoWhileExitsFine(self):
        self._all_fine_test("unitest/test121.c")

    def test122DoWhileExitsBreak(self):
        self._all_fine_test("unitest/test122.c")

502
    def test123ForDefinedOutside(self):
503
        self._generic_test("unitest/test123.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 10, 10) ])
504 505

    def test124ForDefinedInside(self):
506
        self._generic_test("unitest/test124.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 8, 8) ])
507 508

    def test125ForDefinedOutside(self):
509
        self._generic_test("unitest/test125.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 10, 10) ])
510 511 512 513 514

    def test126ForFreesBlocks(self):
        self._all_fine_test("unitest/test126.c")

    def test127ForProcessesBlocks(self):
515
        self._generic_test("unitest/test127.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 7, 13) ])
516

517
    def test128AssignAliasFromAlias(self):
518
        lib = self._generic_test("unitest/test128.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 5, 15) ])
519 520 521
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_UNINITIALIZED, 0)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 0)
Sergio Costas's avatar
Sergio Costas committed
522

523

524 525 526
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 1)
527

528 529 530
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
531 532 533

    def test129AssignAliasFromAlias2(self):
        lib = self._all_fine_test("unitest/test129.c")
534
        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
535
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 0)
536 537
        self._check_var_state(lib, "alias1", crust.crust.VALUE_UNINITIALIZED, 0)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 0)
538
        self._check_block_id_is_not_same(lib, "param1", "param2", 0)
539 540

        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
541
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 1)
542 543
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 1)
544 545
        self._check_block_id_is_not_same(lib, "param1", "param2", 1)
        self._check_block_id_is_the_same(lib, "param1", "alias1", 1)
546 547

        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
548
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 2)
549 550
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
551 552 553
        self._check_block_id_is_not_same(lib, "param1", "param2", 2)
        self._check_block_id_is_the_same(lib, "param1", "alias1", 2)
        self._check_block_id_is_the_same(lib, "param1", "alias2", 2)
554 555

        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 3)
556 557
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 3)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL, 3)
558
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL_OR_NULL, 3)
559 560 561 562
        self._check_block_id_is_not_same(lib, "param1", "param2", 3)
        self._check_block_id_is_the_same(lib, "param2", "alias1", 3)
        self._check_block_id_is_the_same(lib, "param1", "alias2", 3)

563
        self._check_var_state(lib, "param1", crust.crust.VALUE_FREED_OR_NULL, 4)
564 565
        self._check_var_state(lib, "param2", crust.crust.VALUE_FREED, 4)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED, 4)
566
        self._check_var_state(lib, "alias2", crust.crust.VALUE_FREED_OR_NULL, 4)
567

568 569 570

    def test130AssignAliasFromAlias(self):
        lib = self._all_fine_test("unitest/test130.c")
571 572 573
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_UNINITIALIZED, 0)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 0)
574

575 576 577
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 1)
578
        self._check_block_id_is_the_same(lib, "param", "alias1", 1)
579

580 581 582
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
583 584
        self._check_block_id_is_the_same(lib, "param", "alias1", 2)
        self._check_block_id_is_the_same(lib, "param", "alias2", 2)
585

586 587 588
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 3)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 3)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL_OR_NULL, 3)
589 590
        self._check_block_id_is_not_same(lib, "param", "alias1", 3)
        self._check_block_id_is_the_same(lib, "param", "alias2", 3)
591

592
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL, 4)
593
        self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED_OR_NULL, 4)
594
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL, 4)
595 596 597
        self._check_block_id_is_not_same(lib, "param", "alias1", 4)
        self._check_block_id_is_the_same(lib, "param", "alias2", 4)

598

599 600
    def test131AssignAliasFromAlias(self):
        lib = self._all_fine_test("unitest/test131.c")
601 602 603
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_UNINITIALIZED, 0)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 0)
604

605 606 607
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 1)
608
        self._check_block_id_is_the_same(lib, "param", "alias1", 1)
609

610 611 612
        self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
613 614
        self._check_block_id_is_the_same(lib, "param", "alias1", 2)
        self._check_block_id_is_the_same(lib, "param", "alias2", 2)
615

616 617 618
        self._check_var_state(lib, "param", crust.crust.VALUE_FREED, 3)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED, 3)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_FREED, 3)
619 620 621

    def test132AssignAliasFromAlias(self):
        lib = self._all_fine_test("unitest/test132.c")
622
        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
623
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 0)
624 625
        self._check_var_state(lib, "alias1", crust.crust.VALUE_UNINITIALIZED, 0)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 0)
626
        self._check_block_id_is_not_same(lib, "param1", "param2", 0)
627 628

        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
629
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 1)
630 631
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_UNINITIALIZED, 1)
632
        self._check_block_id_is_not_same(lib, "param1", "param2", 1)
633
        self._check_block_id_is_the_same(lib, "param1", "alias1", 1)
634

635
        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
636
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 2)
637
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
638 639
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL, 2)
        self._check_block_id_is_not_same(lib, "param1", "param2", 2)
640 641
        self._check_block_id_is_the_same(lib, "param1", "alias1", 2)
        self._check_block_id_is_the_same(lib, "param2", "alias2", 2)
642

643
        self._check_var_state(lib, "param1", crust.crust.VALUE_FREED_OR_NULL, 3)
644
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 3)
645
        self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED_OR_NULL, 3)
646
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL, 3)
647 648
        self._check_block_id_is_the_same(lib, "param2", "alias2", 3)

649
        self._check_var_state(lib, "param1", crust.crust.VALUE_FREED_OR_NULL, 4)
650
        self._check_var_state(lib, "param2", crust.crust.VALUE_FREED, 4)
651
        self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED_OR_NULL, 4)
652 653
        self._check_var_state(lib, "alias2", crust.crust.VALUE_FREED, 4)

654

655
    def test133GotoJumpsOverAll(self):
656
        self._generic_test("unitest/test133.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 12, 21) ])
657

658
    def test134ReturnCrustExpectCrust(self):
659
        self._all_fine_test("unitest/test134.c")
660 661

    def test135ReturnNoCrustExpectNoCrust(self):
662
        self._all_fine_test("unitest/test135.c")
663 664

    def test136ReturnCrustExpectNoCrust(self):
665
        self._generic_test("unitest/test136.c", [ (crust.crust.MSG_ERROR, "Return statement at line {:d} is returning a crust value, but is must return a non-crust one", 7) ])
666 667

    def test137ReturnNoCrustExpectCrust(self):
668
        self._generic_test("unitest/test137.c", [ (crust.crust.MSG_ERROR, "Return statement at line {:d} is returning a non-crust value, but is must return a crust one", 7) ])
669

670
    def test138OddBreakInFor(self):
671
        self._generic_test("unitest/test138.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 7, 15) ])
672 673

    def test139BreakInNestedFor(self):
674
        self._generic_test("unitest/test139.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 7, 22), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 7, 22) ])
675

676
    def test140Switch1(self):
677
        self._generic_test("unitest/test140.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param1", 7, 27), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param2", 7, 27), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param3", 7, 27) ])
678 679

    def test141Switch2(self):
680
        self._generic_test("unitest/test141.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 23, 11), (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 23, 14), (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 23, 17), (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 23, 20) ])
681 682

    def test142Switc3(self):
683
        self._generic_test("unitest/test142.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 15, 13), (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 15, 11), (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 13, 11) ])
684

685 686 687 688 689 690
    def test143CheckSignatures(self):
        self._generic_test("unitest/test143.c", [ (crust.crust.MSG_CRITICAL, "Function definition for '{:s}' at line {:d}, file '{:s}' differs from definition at line {:d}, file '{:s}'", "main", 7, "unitest/test143.c", 5, "unitest/test143.c") ])

    def test144CheckSignatures(self):
        self._generic_test("unitest/test144.c", [ (crust.crust.MSG_CRITICAL, "Function definition for '{:s}' at line {:d}, file '{:s}' differs from definition at line {:d}, file '{:s}'", "main", 7, "unitest/test144.c", 5, "unitest/test144.c") ])

691
    def test145CheckAssignAndCallPointerToPossibleNull(self):
692
        self._generic_test("unitest/test145.c", [ (crust.crust.MSG_WARNING, "Using variable '{:s}' at line {:d} with a possible NULL value", "param1", 16), (crust.crust.MSG_WARNING, "Using variable '{:s}' at line {:d} with a possible NULL value", "param1", 17) ])
693 694 695 696 697 698

    def test146CheckAssignToElementOfNullPointer(self):
        self._generic_test("unitest/test146.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, but it has been already freed", "param1", 15) ])

    def test147CheckAssignToElementOfUninitializedPointer(self):
        self._generic_test("unitest/test147.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, but it hasn't been initialized yet", "param1", 15) ])
699

700 701 702
    def test148CheckStructAccessWithoutPointer(self):
        self._all_fine_test("unitest/test148.c")

Sergio Costas's avatar
Sergio Costas committed
703
    def test149TestWhileContinue(self):
704
        self._generic_test("unitest/test149.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 12, 16), (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 12, 12) ])
Sergio Costas's avatar
Sergio Costas committed
705 706

    def test150TestDoWhileContinue(self):
707
        self._generic_test("unitest/test150.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 12, 16), (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 12, 12) ])
Sergio Costas's avatar
Sergio Costas committed
708 709

    def test151TestForContinue(self):
710
        self._generic_test("unitest/test151.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param", 12, 16), (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 12, 12) ])
Sergio Costas's avatar
Sergio Costas committed
711 712

    def test152TestWhileContinue2(self):
713
        self._generic_test("unitest/test152.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 16), (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 12, 12) ])
Sergio Costas's avatar
Sergio Costas committed
714 715 716 717 718

    def test153TestDoWhileContinue2(self):
        self._generic_test("unitest/test153.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 12, 12) ])

    def test154TestForContinue2(self):
719
        self._generic_test("unitest/test154.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 16), (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 12, 12) ])
Sergio Costas's avatar
Sergio Costas committed
720 721 722 723 724 725 726

    def test155TestWhileContinue3(self):
        self._generic_test("unitest/test155.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 12, 12) ])

    def test156TestForContinue3(self):
        self._generic_test("unitest/test156.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 12, 12) ])

727 728 729
    def test157CheckEnums(self):
        self._all_fine_test("unitest/test157.c")

730 731 732 733 734 735 736
    def test158TestBorrowVariables(self):
        self._generic_test("unitest/test158.c", [ (crust.crust.MSG_CRITICAL, "Global variable '{:s}', defined as __crust_borrow__ in line {:d}, but that is not allowed", "global_var", 1) ])

    def test159TestBorrowVariables2(self):
        self._generic_test("unitest/test159.c", [ (crust.crust.MSG_ERROR, "Assigning the non-borrowed block '{:s}' to the borrowed variable '{:s}' at line {:d}", "param2", "var2", 12), (crust.crust.MSG_ERROR, "Assigning a value to the borrowed variable '{:s}' at line {:d}", "var4", 14) ])

    def test160AssignRetBorrowToNonBorrow(self):
737
        self._generic_test("unitest/test160.c", [ (crust.crust.MSG_ERROR, "Assigning the borrowed result value of function '{:s}' to the non-borrowed variable '{:s}' at line {:d}", "function1", "var1", 11), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "var1", 11, 12) ])
738 739

    def test161AssignRetNonBorrowToNonBorrow(self):
740
        self._generic_test("unitest/test161.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "var1", 11, 12) ])
741 742 743 744 745 746 747 748

    def test162AssignRetBorrowToBorrow(self):
        self._all_fine_test("unitest/test162.c")

    def test163AssignRetBorrowToNonBorrow(self):
        self._generic_test("unitest/test163.c", [ (crust.crust.MSG_ERROR, "Assigning the non-borrowed result value of function '{:s}' to the borrowed variable '{:s}' at line {:d}", "function1", "var1", 11) ])

    def test164AssignRetBorrowToBorrowParam(self):
749
        self._generic_test("unitest/test164.c", [ (crust.crust.MSG_ERROR, "Overwritting the borrowed argument '{:s}' at line {:d}", "param1", 9) ])
750 751 752 753 754

    def test165ExpectedReturnValueButNoValueAtEnd(self):
        self._generic_test("unitest/test165.c", [ (crust.crust.MSG_ERROR, "Function '{:s}' expects a return value, but the code exited without it", "main") ])

    def test166ExpectedNoReturnValueButValueAvailable(self):
755
        self._generic_test("unitest/test166.c", [ (crust.crust.MSG_ERROR, "Return statement at line {:d} is returning a value, but the function '{:s}' does not return a value", 7, "main") ])
756 757 758 759 760 761 762

    def test167ExpectedReturnValueEmptyReturn(self):
        self._generic_test("unitest/test167.c", [ (crust.crust.MSG_ERROR, "Function '{:s}' expects a return value, but the code exited at line {:d} without it", "main", 9) ])

    def test168ExpectedReturnValueEmptyReturn(self):
        self._generic_test("unitest/test168.c", [ (crust.crust.MSG_ERROR, "Function '{:s}' expects a borrowed value to return, but a non-borrowed was used at line {:d}", "function1", 6) ])

763
    def test169ReturnedFreedValue(self):
764
        self._generic_test("unitest/test169.c", [ (crust.crust.MSG_ERROR, "Returning variable '{:s}' at line {:d} was freed at line {:d}", "param", 7, 6) ])
765 766

    def test170ReturnedUninitializedValue(self):
767
        self._generic_test("unitest/test170.c", [ (crust.crust.MSG_ERROR, "Returning variable '{:s}' at line {:d} is uninitialized", "param", 5) ])
768

769 770 771
    def test171IgnoreBorrowReturnValue(self):
        self._all_fine_test("unitest/test171.c")

772
    def test172AssignCrustToNoCrustThroughTypecast(self):
773
        self._generic_test("unitest/test172.c", [ (crust.crust.MSG_WARNING, "Assigning, with a typecast, the crust-type result value of function '{:s}' at line {:d} to the non-crust variable '{:s}'", "function1", 11, "var1") ])
774

775 776 777 778
    def test173TestNoNullParameter(self):
        self._all_fine_test("unitest/test173.c")

    def test174AssignCrustToNoCrustThroughTypecast(self):