xref: /llvm-project/lldb/test/API/commands/expression/nested/TestNestedExpressions.py (revision 096c530ab3ea5c96526451181117f30db17b4b1d)
1e42edb55SGreg Clayton"""
2e42edb55SGreg ClaytonTest calling an expression with errors that a FixIt can fix.
3e42edb55SGreg Clayton"""
4e42edb55SGreg Clayton
5e42edb55SGreg Claytonimport lldb
6e42edb55SGreg Claytonfrom lldbsuite.test.decorators import *
7e42edb55SGreg Claytonfrom lldbsuite.test.lldbtest import *
8e42edb55SGreg Claytonfrom lldbsuite.test import lldbutil
9e42edb55SGreg Clayton
10e42edb55SGreg Clayton
11e42edb55SGreg Claytonclass NestedExpressions(TestBase):
12e42edb55SGreg Clayton    def test_enum_in_nested_structs(self):
13e42edb55SGreg Clayton        """
14e42edb55SGreg Clayton        Test expressions that references an enumeration in nested structs.
15e42edb55SGreg Clayton        """
16e42edb55SGreg Clayton        self.build()
17e42edb55SGreg Clayton        exe_path = self.getBuildArtifact("a.out")
18e42edb55SGreg Clayton        target = self.dbg.CreateTarget(exe_path)
19e42edb55SGreg Clayton        self.assertTrue(target, "Target: %s is not valid." % (exe_path))
20*096c530aSJonas Devlieghere        self.expect_expr(
21*096c530aSJonas Devlieghere            "A::B::C::EnumType::Eleven",
22e42edb55SGreg Clayton            result_type="A::B::C::EnumType",
23*096c530aSJonas Devlieghere            result_value="Eleven",
24*096c530aSJonas Devlieghere        )
25e42edb55SGreg Clayton
26e42edb55SGreg Clayton    def test_struct_in_nested_structs(self):
27e42edb55SGreg Clayton        """
28e42edb55SGreg Clayton        Test expressions that references a struct in nested structs.
29e42edb55SGreg Clayton        """
30e42edb55SGreg Clayton        self.build()
31e42edb55SGreg Clayton        exe_path = self.getBuildArtifact("a.out")
32e42edb55SGreg Clayton        target = self.dbg.CreateTarget(exe_path)
33e42edb55SGreg Clayton        self.assertTrue(target, "Target: %s is not valid." % (exe_path))
34e42edb55SGreg Clayton        self.expect_expr("sizeof(A::B::C)", result_value="1")
35e42edb55SGreg Clayton        self.expect_expr("sizeof(A::B)", result_value="2")
36e42edb55SGreg Clayton
37ba4cf31fSDavid Spickett    # Fails on Windows for unknown reasons.
38ba4cf31fSDavid Spickett    @skipIfWindows
39e42edb55SGreg Clayton    def test_static_in_nested_structs(self):
40e42edb55SGreg Clayton        """
41e42edb55SGreg Clayton        Test expressions that references a static variable in nested structs.
42e42edb55SGreg Clayton        """
43e42edb55SGreg Clayton        self.build()
44e42edb55SGreg Clayton        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
45e42edb55SGreg Clayton            self, "Stop here to evaluate expressions", lldb.SBFileSpec("main.cpp")
46e42edb55SGreg Clayton        )
47*096c530aSJonas Devlieghere        self.expect_expr(
48*096c530aSJonas Devlieghere            "A::B::C::enum_static",
49e42edb55SGreg Clayton            result_type="A::B::C::EnumType",
50*096c530aSJonas Devlieghere            result_value="Eleven",
51*096c530aSJonas Devlieghere        )
52e42edb55SGreg Clayton
53e42edb55SGreg Clayton    def test_enum_in_nested_namespaces(self):
54e42edb55SGreg Clayton        """
55e42edb55SGreg Clayton        Test expressions that references an enumeration in nested namespaces.
56e42edb55SGreg Clayton        """
57e42edb55SGreg Clayton        self.build()
58e42edb55SGreg Clayton        exe_path = self.getBuildArtifact("a.out")
59e42edb55SGreg Clayton        target = self.dbg.CreateTarget(exe_path)
60e42edb55SGreg Clayton        self.assertTrue(target, "Target: %s is not valid." % (exe_path))
61*096c530aSJonas Devlieghere        self.expect_expr(
62*096c530aSJonas Devlieghere            "a::b::c::Color::Blue", result_type="a::b::c::Color", result_value="Blue"
63*096c530aSJonas Devlieghere        )
64e42edb55SGreg Clayton
65e42edb55SGreg Clayton    def test_static_in_nested_namespaces(self):
66e42edb55SGreg Clayton        """
67e42edb55SGreg Clayton        Test expressions that references an enumeration in nested namespaces.
68e42edb55SGreg Clayton        """
69e42edb55SGreg Clayton        self.build()
70e42edb55SGreg Clayton        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
71e42edb55SGreg Clayton            self, "Stop here to evaluate expressions", lldb.SBFileSpec("main.cpp")
72e42edb55SGreg Clayton        )
73*096c530aSJonas Devlieghere        self.expect_expr("a::b::c::d", result_type="int", result_value="12")
74