44 lines · python
1"""2Test basic std::unique_ptr functionality.3"""4 5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7from lldbsuite.test import lldbutil8 9 10class TestUniquePtr(TestBase):11 @add_test_categories(["libc++"])12 @skipIf(compiler=no_match("clang"))13 @skipIf(compiler="clang", compiler_version=["<", "9.0"])14 @skipIf(macos_version=["<", "15.0"])15 @skipIfLinux # s.reset() causes link errors on ubuntu 18.04/Clang 916 def test(self):17 self.build()18 19 lldbutil.run_to_source_breakpoint(20 self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")21 )22 23 self.runCmd("settings set target.import-std-module true")24 25 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(26 [">", "16.0"]27 ):28 ptr_type = "std::unique_ptr<int>"29 else:30 ptr_type = "std::unique_ptr<int, std::default_delete<int> >"31 32 self.expect_expr(33 "s",34 result_type=ptr_type,35 result_summary="3",36 result_children=[ValueCheck(name="pointer")],37 )38 self.expect_expr("*s", result_type="int", result_value="3")39 self.expect_expr("*s = 5", result_type="int", result_value="5")40 self.expect_expr("*s", result_type="int", result_value="5")41 self.expect_expr("(bool)s", result_type="bool", result_value="true")42 self.expect("expr s.reset()")43 self.expect_expr("(bool)s", result_type="bool", result_value="false")44