xref: /llvm-project/lldb/test/API/commands/expression/import-std-module/queue/TestQueueFromStdModule.py (revision cabee89bed69ce37c9e588f9190ed9c33f6bfdee)
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
12    mydir = TestBase.compute_mydir(__file__)
13
14    @add_test_categories(["libc++"])
15    @skipIf(compiler=no_match("clang"))
16    def test(self):
17        self.build()
18
19        lldbutil.run_to_source_breakpoint(self,
20                                          "// Set break point at this line.",
21                                          lldb.SBFileSpec("main.cpp"))
22
23        self.runCmd("settings set target.import-std-module true")
24
25        queue_type = "std::queue<C, std::deque<C, std::allocator<C> > >"
26        size_type = queue_type + "::size_type"
27        value_type = "std::__deque_base<C, std::allocator<C> >::value_type"
28
29        # Test std::queue functionality with a std::deque.
30        self.expect_expr(
31            "q_deque",
32            result_type=queue_type,
33            result_children=[ValueCheck(children=[ValueCheck(value="1")])])
34        self.expect("expr q_deque.pop()")
35        self.expect("expr q_deque.push({4})")
36        self.expect_expr("q_deque.size()",
37                         result_type=size_type,
38                         result_value="1")
39        self.expect_expr("q_deque.front()", result_type=value_type)
40        self.expect_expr("q_deque.back()", result_type=value_type)
41        self.expect_expr("q_deque.front().i",
42                         result_type="int",
43                         result_value="4")
44        self.expect_expr("q_deque.back().i",
45                         result_type="int",
46                         result_value="4")
47        self.expect_expr("q_deque.empty()",
48                         result_type="bool",
49                         result_value="false")
50        self.expect("expr q_deque.pop()")
51        self.expect("expr q_deque.emplace(5)")
52        self.expect_expr("q_deque.front().i",
53                         result_type="int",
54                         result_value="5")
55
56        # Test std::queue functionality with a std::list.
57        queue_type = "std::queue<C, std::list<C, std::allocator<C> > >"
58        size_type = queue_type + "::size_type"
59        value_type = "std::list<C, std::allocator<C> >::value_type"
60        self.expect_expr(
61            "q_list",
62            result_type=queue_type,
63            result_children=[ValueCheck(children=[ValueCheck(value="1")])])
64
65        self.expect("expr q_list.pop()")
66        self.expect("expr q_list.push({4})")
67        self.expect_expr("q_list.size()",
68                         result_type=size_type,
69                         result_value="1")
70        self.expect_expr("q_list.front()", result_type=value_type)
71        self.expect_expr("q_list.back()", result_type=value_type)
72        self.expect_expr("q_list.front().i",
73                         result_type="int",
74                         result_value="4")
75        self.expect_expr("q_list.back().i",
76                         result_type="int",
77                         result_value="4")
78        self.expect_expr("q_list.empty()",
79                         result_type="bool",
80                         result_value="false")
81        self.expect("expr q_list.pop()")
82        self.expect("expr q_list.emplace(5)")
83        self.expect_expr("q_list.front().i",
84                         result_type="int",
85                         result_value="5")
86