xref: /llvm-project/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py (revision 4cc8f2a017c76af25234afc7c380550e9c93135c)
1"""
2Tests std::stack functionality.
3"""
4
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9class TestStack(TestBase):
10
11    @add_test_categories(["libc++"])
12    @skipIf(compiler=no_match("clang"))
13    @skipIfLinux # Declaration in some Linux headers causes LLDB to crash.
14    def test(self):
15        self.build()
16
17        lldbutil.run_to_source_breakpoint(self,
18            "// Set break point at this line.", lldb.SBFileSpec("main.cpp"))
19
20        self.runCmd("settings set target.import-std-module true")
21
22        # Test std::stack functionality with a std::deque.
23        stack_type = "std::stack<C>"
24        size_type = stack_type + "::size_type"
25
26        self.expect_expr("s_deque", result_type=stack_type)
27        self.expect("expr s_deque.pop()")
28        self.expect("expr s_deque.push({4})")
29        self.expect_expr("s_deque.size()",
30                         result_type=size_type,
31                         result_value="3")
32        self.expect_expr("s_deque.top().i",
33                         result_type="int",
34                         result_value="4")
35        self.expect("expr s_deque.emplace(5)")
36        self.expect_expr("s_deque.top().i",
37                         result_type="int",
38                         result_value="5")
39
40        # Test std::stack functionality with a std::vector.
41        stack_type = "std::stack<C, std::vector<C> >"
42        size_type = stack_type + "::size_type"
43
44        self.expect_expr("s_vector", result_type=stack_type)
45        self.expect("expr s_vector.pop()")
46        self.expect("expr s_vector.push({4})")
47        self.expect_expr("s_vector.size()",
48                         result_type=size_type,
49                         result_value="3")
50        self.expect_expr("s_vector.top().i",
51                         result_type="int",
52                         result_value="4")
53        self.expect("expr s_vector.emplace(5)")
54        self.expect_expr("s_vector.top().i",
55                         result_type="int",
56                         result_value="5")
57
58        # Test std::stack functionality with a std::list.
59        stack_type = "std::stack<C, std::list<C> >"
60        size_type = stack_type + "::size_type"
61        self.expect_expr("s_list", result_type=stack_type)
62        self.expect("expr s_list.pop()")
63        self.expect("expr s_list.push({4})")
64        self.expect_expr("s_list.size()",
65                         result_type=size_type,
66                         result_value="3")
67        self.expect_expr("s_list.top().i", result_type="int", result_value="4")
68        self.expect("expr s_list.emplace(5)")
69        self.expect_expr("s_list.top().i", result_type="int", result_value="5")
70