xref: /llvm-project/lldb/test/API/commands/expression/import-std-module/queue/TestQueueFromStdModule.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Tests std::queue functionality.
3"""
4
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class TestQueue(TestBase):
11    @add_test_categories(["libc++"])
12    @skipIf(compiler=no_match("clang"))
13    def test(self):
14        self.build()
15
16        lldbutil.run_to_source_breakpoint(
17            self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")
18        )
19
20        self.runCmd("settings set target.import-std-module true")
21
22        if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
23            [">", "16.0"]
24        ):
25            queue_type = "std::queue<C>"
26        else:
27            queue_type = "std::queue<C, std::deque<C, std::allocator<C> > >"
28
29        size_type = "size_type"
30        value_type = "value_type"
31
32        # Test std::queue functionality with a std::deque.
33        self.expect_expr(
34            "q_deque",
35            result_type=queue_type,
36            result_children=[ValueCheck(children=[ValueCheck(value="1")])],
37        )
38        self.expect("expr q_deque.pop()")
39        self.expect("expr q_deque.push({4})")
40        self.expect_expr("q_deque.size()", result_type=size_type, result_value="1")
41        self.expect_expr("q_deque.front()", result_type=value_type)
42        self.expect_expr("q_deque.back()", result_type=value_type)
43        self.expect_expr("q_deque.front().i", result_type="int", result_value="4")
44        self.expect_expr("q_deque.back().i", result_type="int", result_value="4")
45        self.expect_expr("q_deque.empty()", result_type="bool", result_value="false")
46        self.expect("expr q_deque.pop()")
47        self.expect("expr q_deque.emplace(5)")
48        self.expect_expr("q_deque.front().i", result_type="int", result_value="5")
49
50        # Test std::queue functionality with a std::list.
51        if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
52            [">", "16.0"]
53        ):
54            queue_type = "std::queue<C, std::list<C> >"
55        else:
56            queue_type = "std::queue<C, std::list<C, std::allocator<C> > >"
57
58        self.expect_expr(
59            "q_list",
60            result_type=queue_type,
61            result_children=[ValueCheck(children=[ValueCheck(value="1")])],
62        )
63
64        self.expect("expr q_list.pop()")
65        self.expect("expr q_list.push({4})")
66        self.expect_expr("q_list.size()", result_type=size_type, result_value="1")
67        self.expect_expr("q_list.front()", result_type=value_type)
68        self.expect_expr("q_list.back()", result_type=value_type)
69        self.expect_expr("q_list.front().i", result_type="int", result_value="4")
70        self.expect_expr("q_list.back().i", result_type="int", result_value="4")
71        self.expect_expr("q_list.empty()", result_type="bool", result_value="false")
72        self.expect("expr q_list.pop()")
73        self.expect("expr q_list.emplace(5)")
74        self.expect_expr("q_list.front().i", result_type="int", result_value="5")
75