199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTests std::stack 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
999451b44SJordan Rupprechtclass TestStack(TestBase):
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprecht    @add_test_categories(["libc++"])
1299451b44SJordan Rupprecht    @skipIf(compiler=no_match("clang"))
13a703998eSRaphael Isemann    @skipIfLinux # Declaration in some Linux headers causes LLDB to crash.
14*5ee910feSAugusto Noronha    @skipIf(bugnumber="rdar://97622854")
1599451b44SJordan Rupprecht    def test(self):
1699451b44SJordan Rupprecht        self.build()
1799451b44SJordan Rupprecht
1899451b44SJordan Rupprecht        lldbutil.run_to_source_breakpoint(self,
1999451b44SJordan Rupprecht            "// Set break point at this line.", lldb.SBFileSpec("main.cpp"))
2099451b44SJordan Rupprecht
2199451b44SJordan Rupprecht        self.runCmd("settings set target.import-std-module true")
2299451b44SJordan Rupprecht
2399451b44SJordan Rupprecht        # Test std::stack functionality with a std::deque.
243f6c856bSRaphael Isemann        stack_type = "std::stack<C>"
25a703998eSRaphael Isemann        size_type = stack_type + "::size_type"
26a703998eSRaphael Isemann
27a703998eSRaphael Isemann        self.expect_expr("s_deque", result_type=stack_type)
2899451b44SJordan Rupprecht        self.expect("expr s_deque.pop()")
2999451b44SJordan Rupprecht        self.expect("expr s_deque.push({4})")
30a703998eSRaphael Isemann        self.expect_expr("s_deque.size()",
31a703998eSRaphael Isemann                         result_type=size_type,
32a703998eSRaphael Isemann                         result_value="3")
33a703998eSRaphael Isemann        self.expect_expr("s_deque.top().i",
34a703998eSRaphael Isemann                         result_type="int",
35a703998eSRaphael Isemann                         result_value="4")
3699451b44SJordan Rupprecht        self.expect("expr s_deque.emplace(5)")
37a703998eSRaphael Isemann        self.expect_expr("s_deque.top().i",
38a703998eSRaphael Isemann                         result_type="int",
39a703998eSRaphael Isemann                         result_value="5")
4099451b44SJordan Rupprecht
4199451b44SJordan Rupprecht        # Test std::stack functionality with a std::vector.
423f6c856bSRaphael Isemann        stack_type = "std::stack<C, std::vector<C> >"
43a703998eSRaphael Isemann        size_type = stack_type + "::size_type"
44a703998eSRaphael Isemann
45a703998eSRaphael Isemann        self.expect_expr("s_vector", result_type=stack_type)
4699451b44SJordan Rupprecht        self.expect("expr s_vector.pop()")
4799451b44SJordan Rupprecht        self.expect("expr s_vector.push({4})")
48a703998eSRaphael Isemann        self.expect_expr("s_vector.size()",
49a703998eSRaphael Isemann                         result_type=size_type,
50a703998eSRaphael Isemann                         result_value="3")
51a703998eSRaphael Isemann        self.expect_expr("s_vector.top().i",
52a703998eSRaphael Isemann                         result_type="int",
53a703998eSRaphael Isemann                         result_value="4")
5499451b44SJordan Rupprecht        self.expect("expr s_vector.emplace(5)")
55a703998eSRaphael Isemann        self.expect_expr("s_vector.top().i",
56a703998eSRaphael Isemann                         result_type="int",
57a703998eSRaphael Isemann                         result_value="5")
5899451b44SJordan Rupprecht
5999451b44SJordan Rupprecht        # Test std::stack functionality with a std::list.
603f6c856bSRaphael Isemann        stack_type = "std::stack<C, std::list<C> >"
61a703998eSRaphael Isemann        size_type = stack_type + "::size_type"
62a703998eSRaphael Isemann        self.expect_expr("s_list", result_type=stack_type)
6399451b44SJordan Rupprecht        self.expect("expr s_list.pop()")
6499451b44SJordan Rupprecht        self.expect("expr s_list.push({4})")
65a703998eSRaphael Isemann        self.expect_expr("s_list.size()",
66a703998eSRaphael Isemann                         result_type=size_type,
67a703998eSRaphael Isemann                         result_value="3")
68a703998eSRaphael Isemann        self.expect_expr("s_list.top().i", result_type="int", result_value="4")
6999451b44SJordan Rupprecht        self.expect("expr s_list.emplace(5)")
70a703998eSRaphael Isemann        self.expect_expr("s_list.top().i", result_type="int", result_value="5")
71