199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTests std::queue functionality.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
799451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
899451b44SJordan Rupprecht
9cabee89bSRaphael Isemann
1099451b44SJordan Rupprechtclass TestQueue(TestBase):
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprecht    @add_test_categories(["libc++"])
1399451b44SJordan Rupprecht    @skipIf(compiler=no_match("clang"))
1499451b44SJordan Rupprecht    def test(self):
1599451b44SJordan Rupprecht        self.build()
1699451b44SJordan Rupprecht
1799451b44SJordan Rupprecht        lldbutil.run_to_source_breakpoint(self,
18cabee89bSRaphael Isemann                                          "// Set break point at this line.",
19cabee89bSRaphael Isemann                                          lldb.SBFileSpec("main.cpp"))
2099451b44SJordan Rupprecht
2199451b44SJordan Rupprecht        self.runCmd("settings set target.import-std-module true")
2299451b44SJordan Rupprecht
23*3f6c856bSRaphael Isemann        queue_type = "std::queue<C>"
24cabee89bSRaphael Isemann        size_type = queue_type + "::size_type"
25cabee89bSRaphael Isemann        value_type = "std::__deque_base<C, std::allocator<C> >::value_type"
26cabee89bSRaphael Isemann
2799451b44SJordan Rupprecht        # Test std::queue functionality with a std::deque.
28cabee89bSRaphael Isemann        self.expect_expr(
29cabee89bSRaphael Isemann            "q_deque",
30cabee89bSRaphael Isemann            result_type=queue_type,
31cabee89bSRaphael Isemann            result_children=[ValueCheck(children=[ValueCheck(value="1")])])
3299451b44SJordan Rupprecht        self.expect("expr q_deque.pop()")
3399451b44SJordan Rupprecht        self.expect("expr q_deque.push({4})")
34cabee89bSRaphael Isemann        self.expect_expr("q_deque.size()",
35cabee89bSRaphael Isemann                         result_type=size_type,
36cabee89bSRaphael Isemann                         result_value="1")
37cabee89bSRaphael Isemann        self.expect_expr("q_deque.front()", result_type=value_type)
38cabee89bSRaphael Isemann        self.expect_expr("q_deque.back()", result_type=value_type)
39cabee89bSRaphael Isemann        self.expect_expr("q_deque.front().i",
40cabee89bSRaphael Isemann                         result_type="int",
41cabee89bSRaphael Isemann                         result_value="4")
42cabee89bSRaphael Isemann        self.expect_expr("q_deque.back().i",
43cabee89bSRaphael Isemann                         result_type="int",
44cabee89bSRaphael Isemann                         result_value="4")
45cabee89bSRaphael Isemann        self.expect_expr("q_deque.empty()",
46cabee89bSRaphael Isemann                         result_type="bool",
47cabee89bSRaphael Isemann                         result_value="false")
4899451b44SJordan Rupprecht        self.expect("expr q_deque.pop()")
4999451b44SJordan Rupprecht        self.expect("expr q_deque.emplace(5)")
50cabee89bSRaphael Isemann        self.expect_expr("q_deque.front().i",
51cabee89bSRaphael Isemann                         result_type="int",
52cabee89bSRaphael Isemann                         result_value="5")
5399451b44SJordan Rupprecht
5499451b44SJordan Rupprecht        # Test std::queue functionality with a std::list.
55*3f6c856bSRaphael Isemann        queue_type = "std::queue<C, std::list<C> >"
56cabee89bSRaphael Isemann        size_type = queue_type + "::size_type"
57*3f6c856bSRaphael Isemann        value_type = "std::list<C>::value_type"
58cabee89bSRaphael Isemann        self.expect_expr(
59cabee89bSRaphael Isemann            "q_list",
60cabee89bSRaphael Isemann            result_type=queue_type,
61cabee89bSRaphael Isemann            result_children=[ValueCheck(children=[ValueCheck(value="1")])])
62cabee89bSRaphael Isemann
6399451b44SJordan Rupprecht        self.expect("expr q_list.pop()")
6499451b44SJordan Rupprecht        self.expect("expr q_list.push({4})")
65cabee89bSRaphael Isemann        self.expect_expr("q_list.size()",
66cabee89bSRaphael Isemann                         result_type=size_type,
67cabee89bSRaphael Isemann                         result_value="1")
68cabee89bSRaphael Isemann        self.expect_expr("q_list.front()", result_type=value_type)
69cabee89bSRaphael Isemann        self.expect_expr("q_list.back()", result_type=value_type)
70cabee89bSRaphael Isemann        self.expect_expr("q_list.front().i",
71cabee89bSRaphael Isemann                         result_type="int",
72cabee89bSRaphael Isemann                         result_value="4")
73cabee89bSRaphael Isemann        self.expect_expr("q_list.back().i",
74cabee89bSRaphael Isemann                         result_type="int",
75cabee89bSRaphael Isemann                         result_value="4")
76cabee89bSRaphael Isemann        self.expect_expr("q_list.empty()",
77cabee89bSRaphael Isemann                         result_type="bool",
78cabee89bSRaphael Isemann                         result_value="false")
7999451b44SJordan Rupprecht        self.expect("expr q_list.pop()")
8099451b44SJordan Rupprecht        self.expect("expr q_list.emplace(5)")
81cabee89bSRaphael Isemann        self.expect_expr("q_list.front().i",
82cabee89bSRaphael Isemann                         result_type="int",
83cabee89bSRaphael Isemann                         result_value="5")
84