2 Tests imported namespaces in C++.
5 from lldbsuite
.test
.decorators
import *
6 from lldbsuite
.test
.lldbtest
import *
7 from lldbsuite
.test
import lldbutil
10 class TestCppNsImport(TestBase
):
11 def test_with_run_command(self
):
12 """Tests imported namespaces in C++."""
15 # Get main source file
16 src_file
= os
.path
.join(self
.getSourceDir(), "main.cpp")
17 src_file_spec
= lldb
.SBFileSpec(src_file
)
18 self
.assertTrue(src_file_spec
.IsValid(), "Main source file")
20 # Get the path of the executable
21 exe_path
= self
.getBuildArtifact("a.out")
24 target
= self
.dbg
.CreateTarget(exe_path
)
25 self
.assertTrue(target
.IsValid(), VALID_TARGET
)
27 # Break on main function
28 break_0
= target
.BreakpointCreateBySourceRegex("// break 0", src_file_spec
)
30 break_0
.IsValid() and break_0
.GetNumLocations() >= 1, VALID_BREAKPOINT
32 break_1
= target
.BreakpointCreateBySourceRegex("// break 1", src_file_spec
)
34 break_1
.IsValid() and break_1
.GetNumLocations() >= 1, VALID_BREAKPOINT
40 process
= target
.LaunchSimple(args
, env
, self
.get_process_working_directory())
41 self
.assertTrue(process
.IsValid(), PROCESS_IS_VALID
)
43 # Get the thread of the process
44 self
.assertEqual(process
.GetState(), lldb
.eStateStopped
, PROCESS_STOPPED
)
45 thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonBreakpoint
)
47 # Get current fream of the thread at the breakpoint
48 frame
= thread
.GetSelectedFrame()
50 # Test imported namespaces
51 test_result
= frame
.EvaluateExpression("n")
53 test_result
.IsValid() and test_result
.GetValueAsSigned() == 1, "n = 1"
56 test_result
= frame
.EvaluateExpression("N::n")
58 test_result
.IsValid() and test_result
.GetValueAsSigned() == 1, "N::n = 1"
61 test_result
= frame
.EvaluateExpression("nested")
63 test_result
.IsValid() and test_result
.GetValueAsSigned() == 3, "nested = 3"
66 test_result
= frame
.EvaluateExpression("anon")
68 test_result
.IsValid() and test_result
.GetValueAsSigned() == 2, "anon = 2"
71 test_result
= frame
.EvaluateExpression("global")
73 test_result
.IsValid() and test_result
.GetValueAsSigned() == 4, "global = 4"
76 test_result
= frame
.EvaluateExpression("fun_var")
78 test_result
.IsValid() and test_result
.GetValueAsSigned() == 9, "fun_var = 9"
81 test_result
= frame
.EvaluateExpression("Fun::fun_var")
83 test_result
.IsValid() and test_result
.GetValueAsSigned() == 0,
87 test_result
= frame
.EvaluateExpression("not_imported")
89 test_result
.IsValid() and test_result
.GetValueAsSigned() == 35,
93 # Currently there is no way to distinguish between "::imported" and "imported" in ClangExpressionDeclMap so this fails
94 # test_result = frame.EvaluateExpression("::imported")
95 # self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 89, "::imported = 89")
97 test_result
= frame
.EvaluateExpression("Imported::imported")
99 test_result
.IsValid() and test_result
.GetValueAsSigned() == 99,
100 "Imported::imported = 99",
103 test_result
= frame
.EvaluateExpression("imported")
105 test_result
.IsValid() and test_result
.GetValueAsSigned() == 99,
109 test_result
= frame
.EvaluateExpression("single")
111 test_result
.IsValid() and test_result
.GetValueAsSigned() == 3, "single = 3"
114 # Continue to second breakpoint
117 # Get the thread of the process
118 self
.assertEqual(process
.GetState(), lldb
.eStateStopped
, PROCESS_STOPPED
)
119 thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonBreakpoint
)
121 # Get current fream of the thread at the breakpoint
122 frame
= thread
.GetSelectedFrame()
124 # Test function inside namespace
125 test_result
= frame
.EvaluateExpression("fun_var")
127 test_result
.IsValid() and test_result
.GetValueAsSigned() == 5, "fun_var = 5"