1*b8338983SRaphael Isemann"""
2*b8338983SRaphael IsemannTest basic std::array functionality.
3*b8338983SRaphael Isemann"""
4*b8338983SRaphael Isemann
5*b8338983SRaphael Isemannfrom lldbsuite.test.decorators import *
6*b8338983SRaphael Isemannfrom lldbsuite.test.lldbtest import *
7*b8338983SRaphael Isemannfrom lldbsuite.test import lldbutil
8*b8338983SRaphael Isemann
9*b8338983SRaphael Isemann
10*b8338983SRaphael Isemannclass TestCase(TestBase):
11*b8338983SRaphael Isemann
12*b8338983SRaphael Isemann    @add_test_categories(["libc++"])
13*b8338983SRaphael Isemann    @skipIf(compiler=no_match("clang"))
14*b8338983SRaphael Isemann    def test(self):
15*b8338983SRaphael Isemann        self.build()
16*b8338983SRaphael Isemann
17*b8338983SRaphael Isemann        lldbutil.run_to_source_breakpoint(self,
18*b8338983SRaphael Isemann                                          "// Set break point at this line.",
19*b8338983SRaphael Isemann                                          lldb.SBFileSpec("main.cpp"))
20*b8338983SRaphael Isemann
21*b8338983SRaphael Isemann        self.runCmd("settings set target.import-std-module true")
22*b8338983SRaphael Isemann
23*b8338983SRaphael Isemann
24*b8338983SRaphael Isemann        # Test inspecting an array of integers.
25*b8338983SRaphael Isemann        array_type = "std::array<int, 3>"
26*b8338983SRaphael Isemann        size_type = "std::array::size_type"
27*b8338983SRaphael Isemann        value_type = array_type + "::value_type"
28*b8338983SRaphael Isemann
29*b8338983SRaphael Isemann        iterator = array_type + "::iterator"
30*b8338983SRaphael Isemann        riterator = array_type + "::reverse_iterator"
31*b8338983SRaphael Isemann
32*b8338983SRaphael Isemann        self.expect_expr("a",
33*b8338983SRaphael Isemann                         result_type=array_type,
34*b8338983SRaphael Isemann                         result_children=[
35*b8338983SRaphael Isemann                             ValueCheck(name="__elems_", children=[
36*b8338983SRaphael Isemann                                 ValueCheck(value="3"),
37*b8338983SRaphael Isemann                                 ValueCheck(value="1"),
38*b8338983SRaphael Isemann                                 ValueCheck(value="2"),
39*b8338983SRaphael Isemann                             ])
40*b8338983SRaphael Isemann                         ])
41*b8338983SRaphael Isemann        self.expect_expr("a.size()", result_type=size_type, result_value="3")
42*b8338983SRaphael Isemann        self.expect_expr("a.front()", result_type=value_type, result_value="3")
43*b8338983SRaphael Isemann        self.expect_expr("a[1]", result_type=value_type, result_value="1")
44*b8338983SRaphael Isemann        self.expect_expr("a.back()", result_type=value_type, result_value="2")
45*b8338983SRaphael Isemann
46*b8338983SRaphael Isemann        # Both are just pointers to the underlying elements.
47*b8338983SRaphael Isemann        self.expect_expr("a.begin()", result_type=iterator)
48*b8338983SRaphael Isemann        self.expect_expr("a.rbegin()", result_type=riterator)
49*b8338983SRaphael Isemann
50*b8338983SRaphael Isemann        self.expect_expr("*a.begin()", result_type=value_type, result_value="3")
51*b8338983SRaphael Isemann        self.expect_expr("*a.rbegin()", result_type="int", result_value="2")
52*b8338983SRaphael Isemann
53*b8338983SRaphael Isemann        self.expect_expr("a.at(0)", result_type=value_type, result_value="3")
54*b8338983SRaphael Isemann
55*b8338983SRaphael Isemann
56*b8338983SRaphael Isemann        # Same again with an array that has an element type from debug info.
57*b8338983SRaphael Isemann        array_type = "std::array<DbgInfo, 1>"
58*b8338983SRaphael Isemann        size_type = "std::array::size_type"
59*b8338983SRaphael Isemann        value_type = array_type + "::value_type"
60*b8338983SRaphael Isemann
61*b8338983SRaphael Isemann        iterator = array_type + "::iterator"
62*b8338983SRaphael Isemann        riterator = array_type + "::reverse_iterator"
63*b8338983SRaphael Isemann        dbg_info_elem_children = [ValueCheck(value="4")]
64*b8338983SRaphael Isemann        dbg_info_elem = [ValueCheck(children=dbg_info_elem_children)]
65*b8338983SRaphael Isemann
66*b8338983SRaphael Isemann        self.expect_expr("b",
67*b8338983SRaphael Isemann                         result_type=array_type,
68*b8338983SRaphael Isemann                         result_children=[
69*b8338983SRaphael Isemann                             ValueCheck(name="__elems_", children=dbg_info_elem)
70*b8338983SRaphael Isemann                         ])
71*b8338983SRaphael Isemann        self.expect_expr("b.size()", result_type=size_type, result_value="1")
72*b8338983SRaphael Isemann        self.expect_expr("b.front()", result_type=value_type, result_children=dbg_info_elem_children)
73*b8338983SRaphael Isemann        self.expect_expr("b[0]", result_type=value_type, result_children=dbg_info_elem_children)
74*b8338983SRaphael Isemann        self.expect_expr("b.back()", result_type=value_type, result_children=dbg_info_elem_children)
75*b8338983SRaphael Isemann
76*b8338983SRaphael Isemann        # Both are just pointers to the underlying elements.
77*b8338983SRaphael Isemann        self.expect_expr("b.begin()", result_type=iterator)
78*b8338983SRaphael Isemann        self.expect_expr("b.rbegin()", result_type=riterator)
79*b8338983SRaphael Isemann
80*b8338983SRaphael Isemann        self.expect_expr("*b.begin()", result_type=value_type, result_children=dbg_info_elem_children)
81*b8338983SRaphael Isemann        self.expect_expr("*b.rbegin()", result_type="DbgInfo", result_children=dbg_info_elem_children)
82*b8338983SRaphael Isemann
83*b8338983SRaphael Isemann        self.expect_expr("b.at(0)", result_type=value_type, result_children=dbg_info_elem_children)
84*b8338983SRaphael Isemann
85