Beispiel #1
0
 def test_pointer_to_const(self):
     src = """
     const char *a = "";
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     self.assertFalse(a.const)
Beispiel #2
0
 def test_static_const(self):
     src = """
     static constexpr int a = 2;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     self.assertTrue(a.const)
Beispiel #3
0
 def test_extern_c(self):
     src = """
     extern "C" int c_function(int);
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     self.assertIn('c_function', result.g.functions)
     pass
Beispiel #4
0
 def test_global_const(self):
     src = """
     const int a = 1;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     self.assertTrue(a.const)
Beispiel #5
0
 def test_stl_optional(self):
     src = """
     #include <optional>
     std::optional<int> v = 1;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     v = result.g.variables['v']
     self.assertEqual("std::optional<int>", v.type)
 def test_prefix_and_suffix(self):
     src = """
     const int a = 0x01l;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     self.assertEqual(int, type(a.value))
     self.assertEqual(1, a.value)
 def test_double(self):
     src = """
     const double a = 1.0;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     self.assertEqual(float, type(a.value))
     self.assertEqual(1.0, a.value)
 def test_int_as_float(self):
     src = """
     const float a = 1;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     self.assertEqual(int, type(a.value))
     self.assertEqual(1, a.value)
Beispiel #9
0
 def test_negative_int(self):
     src = """
     const int a = -1;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     self.assertEqual(int, type(a.value))
     self.assertEqual(-1, a.value)
Beispiel #10
0
 def test_const_pointer(self):
     src = """
     char * const a = "";
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     self.assertTrue(is_const_type(a.type))
     self.assertTrue(a.const)
Beispiel #11
0
 def test_variable_short_brief_comment(self):
     src = """
     //! ss
     int short_ = 1;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     short = result.g.variables['short_']
     self.assertEqual("ss", short.brief_comment)
Beispiel #12
0
 def test_const_multiple_level_pointer(self):
     src = """
     #define N 0
     char ** const a = N;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     self.assertTrue(is_const_type(a.type))
     self.assertTrue(a.const)
Beispiel #13
0
 def test_variable_long_brief_comment(self):
     src = """
     /*!
      * abcd
      */
     int long_ = 1;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     long = result.g.variables['long_']
     self.assertEqual("abcd", long.brief_comment)
Beispiel #14
0
 def test_union_no_typename_anonymous(self):
     src = """
     struct C{
         union {
             int a;
         };
     };
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     C = result.g.classes['C']
     self.assertIn("a", C.variables)
Beispiel #15
0
 def test_nested_const(self):
     src = """
     struct S{
         const int a = 1;
     };
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     s = result.g.classes['S']
     a = s.variables['a']
     self.assertTrue(is_const_type(a.type))
     self.assertTrue(a.const)
 def test_define(self):
     src = """
     #define N 2
     const int a = N;
     #define M 3
     const int b = M;
     """
     parser = CXXParser("./test.cpp", [("./test.cpp", src)])
     result = parser.parse()
     a = result.g.variables['a']
     b = result.g.variables['b']
     self.assertEqual(2, a.value)
     self.assertEqual(3, b.value)
    def test_in_scope_type(self):
        src = """
        namespace ns1{
            using int32 = int;
            int32 a = 1;
        };
        """
        parser = CXXParser("./test.cpp", [
            ("./test.cpp", src)
        ])
        result = parser.parse()
        ns1 = result.g.namespaces['ns1']

        self.assertIn("a", ns1.variables)
        self.assertEqual("ns1::int32", ns1.variables['a'].type)
Beispiel #18
0
    def test_named_union_all_named(self):
        src = """
        struct C{
            union U{
                int a;
            }s;
        };
        """
        parser = CXXParser("./test.cpp", [("./test.cpp", src)])
        result = parser.parse()
        C = result.g.classes['C']
        self.assertIn("s", C.variables)
        self.assertIn('U', C.classes)

        U = C.classes['U']
        self.assertIn('a', U.variables)
Beispiel #19
0
 def test_undef(self):
     src = """
     #define A 1234
     #undef A
     """
     extra_options = CXXParserExtraOptions()
     extra_options.arch = Arch.X86
     unsaved_files = [
         ("./test.cpp", src)
     ]
     parser = CXXParser("./test.cpp",
                        unsaved_files,
                        extra_options=extra_options,
                        )
     result = parser.parse()
     self.assertNotIn('A', result.macros)
Beispiel #20
0
    def test_using_type(self):
        src = """
        namespace ns1{
            class A{};
        };
        namespace ns2{
            using ns1::A;
        }
        """
        parser = CXXParser("./test.cpp", [("./test.cpp", src)])
        result = parser.parse()
        self.assertIn("ns1", result.g.namespaces)
        ns1 = result.g.namespaces['ns1']
        self.assertIn("A", ns1.classes)

        self.assertIn("ns2", result.g.namespaces)
        ns2 = result.g.namespaces['ns2']
        self.assertIn("A", ns2.classes)
Beispiel #21
0
    def test_nested_namespace(self):
        src = """
        namespace outer{
            namespace inner{
                class Inner1{};
            }
            class Outer1{};
            int namespace_func();
        };
        """
        parser = CXXParser("./test.cpp", [("./test.cpp", src)])
        result = parser.parse()
        self.assertIn("outer", result.g.namespaces)
        outer = result.g.namespaces['outer']
        self.assertIn("Outer1", outer.classes)
        self.assertIn("inner", outer.namespaces)

        inner = outer.namespaces['inner']
        self.assertIn("Inner1", inner.classes)
Beispiel #22
0
 def test_value(self):
     src = """
     #define A 1234
     #undef A
     #define A 123
     int a = A;
     """
     extra_options = CXXParserExtraOptions()
     extra_options.arch = Arch.X86
     unsaved_files = [
         ("./test.cpp", src)
     ]
     parser = CXXParser("./test.cpp",
                        unsaved_files,
                        extra_options=extra_options,
                        )
     result = parser.parse()
     self.assertEqual('123', result.macros['A'].definition)
     self.assertEqual(123, result.g.variables['a'].value)
    def test_cross_scope_typedef(self):
        src = """
        namespace ns1{
            using int32 = int;
        };
        namespace ns2{
            using int32 = ns1::int32;
        }
        """
        parser = CXXParser("./test.cpp", [
            ("./test.cpp", src)
        ])
        result = parser.parse()
        ns1 = result.g.namespaces['ns1']
        self.assertIn("int32", ns1.typedefs)
        self.assertEqual("int", ns1.typedefs['int32'].target)

        ns2 = result.g.namespaces['ns2']
        self.assertIn("int32", ns2.typedefs)
        self.assertEqual("::ns1::int32", ns2.typedefs['int32'].target)
Beispiel #24
0
 def test_partial_namespace(self):
     src1 = """
     namespace ns1{
         class A{};
     };
     """
     src2 = """
     namespace ns1{
         class B{};
     };
     """
     parser = CXXParser("src.h", [
         ("src.h", '#include "1.h"\n#include "2.h"'),
         ("./1.h", src1),
         ("./2.h", src2),
     ])
     result = parser.parse()
     self.assertIn("ns1", result.g.namespaces)
     ns1 = result.g.namespaces['ns1']
     self.assertIn("A", ns1.classes)
     self.assertIn("B", ns1.classes)
Beispiel #25
0
 def test_32(self):
     src = """
     #ifdef _WIN64
     const int a = 64;
     #else
     const int a = 32;
     #endif
     """
     extra_options = CXXParserExtraOptions()
     extra_options.arch = Arch.X86
     unsaved_files = [
         ("./test.cpp", src)
     ]
     parser = CXXParser("./test.cpp",
                        unsaved_files,
                        extra_options=extra_options,
                        )
     result = parser.parse()
     a = result.g.variables['a']
     self.assertEqual(int, type(a.value))
     self.assertEqual(32, a.value)