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