1"""
2Test std::weak_ptr functionality with a decl from debug info as content.
3"""
4
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class TestDbgInfoContentWeakPtr(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        self.expect_expr("w",
26                         result_type="std::weak_ptr<Foo>",
27                         result_children=[ValueCheck(name="__ptr_")])
28        self.expect_expr("*w.lock()", result_type="Foo")
29        self.expect_expr("w.lock()->a", result_type="int", result_value="3")
30        self.expect_expr("w.lock()->a = 5",
31                         result_type="int",
32                         result_value="5")
33        self.expect_expr("w.lock()->a", result_type="int", result_value="5")
34        self.expect_expr("w.use_count()", result_type="long", result_value="1")
35        self.expect("expr w.reset()")
36        self.expect_expr("w.use_count()", result_type="long", result_value="0")
37