tests.py 59.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 not declared or 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
        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
175

176
    def test022AssignFreedVariable(self):
177
        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) ])
178

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

182
    def test024AssignNonCrustToCrust(self):
183
        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) ])
184

185
    def test025AssignCrustToNonCrust(self):
186
        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) ])
187

188
    def test026TypeCast(self):
189
        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) ])
190

191
    def test027AssignNonCrustToCrust2(self):
192
        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) ])
193

194
    def test028CrustRetVal(self):
195
        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) ])
196

197
    def test029UseUninitialized2(self):
198
        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) ])
199

200
    def test030UseFreed2(self):
201
        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) ])
202

203
    def test031PassedNonCrustyToCrusty2(self):
204
        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) ])
205

206
    def test032PassedCrustyToNonCrusty2(self):
207
        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) ])
208

209
    def test033PassedOtherToCrusty2(self):
210
        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) ])
211

212
    def test034MultiAssign(self):
213
        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
214

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

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

221
    def test037StructAssign(self):
222
        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) ])
223

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

227
    def test039ArrayAssign(self):
228
        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) ])
229

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

233
    def test041UsePostStructAssignment(self):
234
        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
235

236
    def test042UsePostStructAssignment2(self):
237
        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
238

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

242
    def test044IfEqNull(self):
243 244
        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) ] )

245

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

249
    def test046IfElseNull(self):
250
        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
251

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

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

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

265
    def test050PassBorrowToNonBorrow(self):
266
        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) ])
267

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

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

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

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

280
    def test055AssignFunctionPointerToFunctionName(self):
281
        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) ])
282

283
    def test056ComparisonDoesntFreePointer(self):
284
        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) ])
285

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

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

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

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

298
    def test061IfWithNot2(self):
299
        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) ])
300

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

304
    def test063BlockInUseAtEnd(self):
305
        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) ])
306

307
    def test064BlockInUseAtEnd2(self):
308
        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) ])
309

310
    def test065BlockInUseWithReturn(self):
311
        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) ])
312

313
    def test066BlockInUseWithReturn2(self):
314
        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) ])
315

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

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

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

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

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

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

336
    def test073AliasFreesBlock2(self):
337
        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) ])
338

339
    def test074BlockFreesAlias(self):
340
        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) ])
341

342
    def test075DecoupleAlias(self):
343
        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) ])
344 345 346
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED, 1)
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_NULL, 2)
347

348

349
    def test076DecoupleAlias2(self):
350
        lib = self._all_fine_test("unitest/test76.c")
351 352 353 354 355
        self._check_var_state(lib, "param1", crust.crust.VALUE_FREED, 0)
        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)
        self._check_var_state(lib, "param2", crust.crust.VALUE_FREED, 1)
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED, 1)
356

357
    def test077DecoupleAlias3(self):
358
        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) ])
359 360
        self._check_var_state(lib, "param", crust.crust.VALUE_FREED, 1)
        self._check_var_state(lib, "an_alias", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
361

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

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

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


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

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

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

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

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

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

390
    def test087FunctionPointerExpectedCrustParameter(self):
391
        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) ])
392

393
    def test088FunctionPointerExpectedCrustParameter2(self):
394
        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) ])
395

396
    def test089FunctionPointerExpectedNonCrustParameter(self):
397
        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) ])
398

399
    def test090FunctionPointerExpectedNonCrustParameter2(self):
400
        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) ])
401

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

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

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

413
    def test094FunctionPointerReturnsCrust(self):
414
        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) ])
415

416
    def test095FunctionPointerReturnsCrust2(self):
417
        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) ])
418

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

422
    def test097WhileFreesTwice(self):
423
        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) ])
424

425
    def test098AndOpFine(self):
426 427
        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) ])

428

429
    def test099OrOpFine(self):
430
        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) ])
431

432
    def test100AndOpWrong(self):
433
        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) ])
434

435
    def test101OrOpWrong(self):
436
        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) ])
437

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

441
    def test103WhileWithoutNoZero(self):
442
        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) ])
443

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

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

    def test106DifferenParameterNumberCrust(self):
451
        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) ])
452 453

    def test107DifferenParameterNumberCrust(self):
454
        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) ])
455

456
    def test108DifferenParameterTypes(self):
457
        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) ])
458 459

    def test109DifferenParameterTypes(self):
460
        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) ])
461 462 463 464

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

465
    def test111CommaOperatorFine(self):
466
        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) ])
467 468

    def test112CommaOperatorBad(self):
469
        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) ])
470 471

    def test113CommaOperatorFine2(self):
472
        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) ])
473

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

477
    def test115VariableNumberOfArguments(self):
478
        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) ])
479

480
    def test116NonCrustRetValToCrust(self):
481
        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) ])
482 483 484 485 486 487 488

    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) ])

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

492
    def test120DoWhileUsesTwice(self):
493
        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) ])
494 495 496 497 498 499 500

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

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

501
    def test123ForDefinedOutside(self):
502
        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) ])
503 504

    def test124ForDefinedInside(self):
505
        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) ])
506 507

    def test125ForDefinedOutside(self):
508
        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) ])
509 510 511 512 513

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

    def test127ForProcessesBlocks(self):
514
        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) ])
515

516
    def test128AssignAliasFromAlias(self):
517
        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) ])
518 519 520
        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
521

522

523 524 525
        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)
526

527 528 529
        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)
530 531 532

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

        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
540
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 1)
541 542
        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)
543 544
        self._check_block_id_is_not_same(lib, "param1", "param2", 1)
        self._check_block_id_is_the_same(lib, "param1", "alias1", 1)
545 546

        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 2)
547
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 2)
548 549
        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)
550 551 552
        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)
553 554

        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 3)
555 556
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 3)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_NOT_NULL, 3)
557
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL_OR_NULL, 3)
558 559 560 561 562 563 564 565 566
        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)

        self._check_var_state(lib, "param1", crust.crust.VALUE_FREED, 4)
        self._check_var_state(lib, "param2", crust.crust.VALUE_FREED, 4)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED, 4)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_FREED, 4)

567 568 569

    def test130AssignAliasFromAlias(self):
        lib = self._all_fine_test("unitest/test130.c")
570 571 572
        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)
573

574 575 576
        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)
577
        self._check_block_id_is_the_same(lib, "param", "alias1", 1)
578

579 580 581
        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)
582 583
        self._check_block_id_is_the_same(lib, "param", "alias1", 2)
        self._check_block_id_is_the_same(lib, "param", "alias2", 2)
584

585 586 587
        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)
588 589
        self._check_block_id_is_not_same(lib, "param", "alias1", 3)
        self._check_block_id_is_the_same(lib, "param", "alias2", 3)
590

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

597

598 599
    def test131AssignAliasFromAlias(self):
        lib = self._all_fine_test("unitest/test131.c")
600 601 602
        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)
603

604 605 606
        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)
607
        self._check_block_id_is_the_same(lib, "param", "alias1", 1)
608

609 610 611
        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)
612 613
        self._check_block_id_is_the_same(lib, "param", "alias1", 2)
        self._check_block_id_is_the_same(lib, "param", "alias2", 2)
614

615 616 617
        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)
618 619 620

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

        self._check_var_state(lib, "param1", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
628
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 1)
629 630
        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)
631
        self._check_block_id_is_not_same(lib, "param1", "param2", 1)
632
        self._check_block_id_is_the_same(lib, "param1", "alias1", 1)
633

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

642 643 644 645
        self._check_var_state(lib, "param1", crust.crust.VALUE_FREED, 3)
        self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 3)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED, 3)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL, 3)
646 647 648 649 650 651 652
        self._check_block_id_is_the_same(lib, "param2", "alias2", 3)

        self._check_var_state(lib, "param1", crust.crust.VALUE_FREED, 4)
        self._check_var_state(lib, "param2", crust.crust.VALUE_FREED, 4)
        self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED, 4)
        self._check_var_state(lib, "alias2", crust.crust.VALUE_FREED, 4)

653

654
    def test133GotoJumpsOverAll(self):
655
        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) ])
656

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

    def test135ReturnNoCrustExpectNoCrust(self):
661
        self._all_fine_test("unitest/test135.c")
662 663 664 665 666 667 668

    def test136ReturnCrustExpectNoCrust(self):
        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) ])

    def test137ReturnNoCrustExpectCrust(self):
        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
    def test138OddBreakInFor(self):
670
        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) ])
671 672

    def test139BreakInNestedFor(self):
673
        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) ])
674

675
    def test140Switch1(self):
676
        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) ])
677 678

    def test141Switch2(self):
679
        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) ])
680 681

    def test142Switc3(self):
682
        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) ])
683

684 685 686 687 688 689
    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") ])

690
    def test145CheckAssignAndCallPointerToPossibleNull(self):
691
        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) ])
692 693 694 695 696 697

    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) ])
698

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

Sergio Costas's avatar
Sergio Costas committed
702
    def test149TestWhileContinue(self):
703
        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
704 705

    def test150TestDoWhileContinue(self):
706
        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
707 708

    def test151TestForContinue(self):
709
        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
710 711

    def test152TestWhileContinue2(self):
712
        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
713 714 715 716 717

    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):
718
        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
719 720 721 722 723 724 725

    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) ])

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

729 730 731 732 733 734 735
    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):
736
        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) ])
737 738

    def test161AssignRetNonBorrowToNonBorrow(self):
739
        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) ])
740 741 742 743 744 745 746 747

    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):
748
        self._generic_test("unitest/test164.c", [ (crust.crust.MSG_ERROR, "Overwritting the borrowed argument '{:s}' at line {:d}", "param1", 9) ])
749 750 751 752 753 754 755 756 757 758 759 760 761

    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):
        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") ])

    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) ])

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

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

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

771
    def test172AssignCrustToNoCrustThroughTypecast(self):
772
        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") ])
773

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

    def test174AssignCrustToNoCrustThroughTypecast(self):
778
        self._generic_test("unitest/test174.c", [ (crust.crust.MSG_WARNING, "Argument '{:s}' at position {:d} when calling function '{:s}' at line {:d} is defined as not_null, but is being called with a possible NULL value", "param", 1, "function1", 9) ])
779 780 781 782 783 784 785

    def test175AssignCrustToNoCrustThroughTypecast(self):
        self._generic_test("unitest/test175.c", [ (crust.crust.MSG_ERROR, "Passing NULL as argument {:d} when calling function '{:s}' at line {:d}, but it must be a not_null value", 1, "function1", 9) ])

    def test176AssignCrustToNoCrustThroughTypecast(self):
        self._generic_test("unitest/test176.c", [ (crust.crust.MSG_ERROR, "Argument '{:s}' at position {:d} when calling function '{:s}' at line {:d} is defined as not_null, but is being called with a NULL value", "param", 1, "function1", 10) ])

786 787 788 789 790 791 792 793
    def test177TestNoNullParameter(self):
        self._all_fine_test("unitest/test177.c")

    def test178AssignCrustToNoCrustThroughTypecast(self):
        self._generic_test("unitest/test178.c", [ (crust.crust.MSG_ERROR, "Return value at line {:d} is NULL, but the function must not return a NULL value", 7) ])

    def test179AssignCrustToNoCrustThroughTypecast(self):
        self._generic_test("unitest/test179.c", [ (crust.crust.MSG_ERROR, "Return value at line {:d} is NULL, but the function must not return a NULL value", 7) ])
794

795 796 797
    def test180ReturnFunctionReturn(self):
        self._all_fine_test("unitest/test180.c")

798 799 800 801 802 803
    def test181CheckIfWithUninitializedVariable(self):
        self._generic_test("unitest/test181.c", [ (crust.crust.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", "param1", 7) ])

    def test182CheckCompareWithNullWhenFreed(self):
        self._all_fine_test("unitest/test182.c")

804
    def test183CheckIfWithUninitializedVariable(self):
805
        self._generic_test("unitest/test183.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param3", 5, 9) ])
806

807
    def test184CheckAssignToSeveralGlobalVars(self):
808
        lib = self._generic_test("unitest/test184.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to the same block than global variable '{:s}'.", 18, "global_var1", "global_var2") ])
809 810
        self._check_block_id_is_the_same(lib, "param1", "global_var1")
        self._check_block_id_is_the_same(lib, "param1", "global_var2")
811

812
    def test185CheckAssignToSeveralGlobalVars2(self):
Sergio Costas's avatar