Пример #1
0
    def setUp(self):

        ast = parse('./test_data/c_files/valid.c',
                    ['-E', r'-Ipycreviewer/utils/fake_libc_include'])
        sourcecode_valid = SourceCode(ast)
        ast = parse('./test_data/c_files/none.c',
                    ['-E', r'-Ipycreviewer/utils/fake_libc_include'])
        sourcecode_none = SourceCode(ast)
        conditions = CheckConditions('./test_data/default.json')
        self.rules_valid = CodinfgRules(sourcecode_valid, conditions)
        self.rules_none = CodinfgRules(sourcecode_none, conditions)
Пример #2
0
 def test_SearchRecursiveFunctionCall_None(self):
     target = SourceCode(self.none_ast)
     steps = target.SearchRecursiveFunctionCall()
     self.assertEqual(steps, [])
Пример #3
0
 def test_SearchRecursiveFunctionCall_valid(self):
     target = SourceCode(self.valid_ast)
     funccalls = target.SearchRecursiveFunctionCall()
     self.assertEqual(len(funccalls), 6)
     example = funccalls[0]
     self.assertEqual(example.name, 'g_function_def1')
Пример #4
0
 def test_SearchFunctionCalls_none(self):
     target = SourceCode(self.none_ast)
     funccalls = target.SearchFunctionCalls('free')
     self.assertEqual(len(funccalls), 0)
Пример #5
0
 def test_DefinedFunctions_None(self):
     target = SourceCode(self.none_ast)
     functions = target.DefinedFunctions()
     self.assertEqual(functions, [])
Пример #6
0
 def test_DefinedFunctions_valid(self):
     target = SourceCode(self.valid_ast)
     functions = target.DefinedFunctions()
     self.assertEqual(len(functions), 2)
     example = functions[0]
     self.assertEqual(example.name, 'g_function_def1')
Пример #7
0
 def test_Variables_none(self):
     target = SourceCode(self.none_ast)
     variables = target.Varialbles()
     self.assertEqual(len(variables), 0)
Пример #8
0
 def test_GlobalValiables_None(self):
     target = SourceCode(self.none_ast)
     valiables = target.GlobalValiables()
     self.assertEqual(valiables, [])
Пример #9
0
 def test_GlobalValiables_valid(self):
     target = SourceCode(self.valid_ast)
     valiables = target.GlobalValiables()
     self.assertEqual(len(valiables), 3)
     example = valiables[0]
     self.assertEqual(example.name, 'g_int_val1')
Пример #10
0
 def test_SearchNoDefaultInSwitch_none(self):
     target = SourceCode(self.none_ast)
     cases = target.SearchNoDefaultInSwitch()
     self.assertEqual(cases, [])
Пример #11
0
 def test_SearchNoDefaultInSwitch_valid(self):
     target = SourceCode(self.valid_ast)
     cases = target.SearchNoDefaultInSwitch()
     self.assertEqual(len(cases), 1)
Пример #12
0
 def test_SearchNoBreakInCase_none(self):
     target = SourceCode(self.none_ast)
     cases = target.SearchNoBreakInCase()
     self.assertEqual(cases, [])
Пример #13
0
 def test_SearchNoBreakInCase_valid(self):
     target = SourceCode(self.valid_ast)
     cases = target.SearchNoBreakInCase()
     self.assertEqual(len(cases), 1)