1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "samgr_rust_test_mem.h"
17 
18 #include <cstdint>
19 #include <iostream>
20 #include <memory>
21 
22 #include "refbase.h"
23 namespace OHOS {
24 extern "C" {
25 int32_t g_testDrop = 0;
26 }
27 
~Foo()28 Foo::~Foo()
29 {
30     g_testDrop += 1;
31 }
32 
Keeper(sptr<Foo> inner)33 Keeper::Keeper(sptr<Foo> inner) : inner_(inner)
34 {
35 }
36 
GetUniqueSptr()37 std::unique_ptr<sptr<Foo>> GetUniqueSptr()
38 {
39     auto foo = sptr<Foo>::MakeSptr();
40     return std::make_unique<sptr<Foo>>(std::move(foo));
41 }
42 
KeepUniqueSptr(std::unique_ptr<sptr<Foo>> foo)43 std::unique_ptr<Keeper> KeepUniqueSptr(std::unique_ptr<sptr<Foo>> foo)
44 {
45     return std::make_unique<Keeper>(std::move(*foo.release()));
46 }
47 } // namespace OHOS