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 <gtest/gtest.h>
17 #include <codecvt>
18 #include <string>
19 #include "hdi_support.h"
20 #include "object_collector.h"
21 #include "hdf_base.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26     struct TestService {
27     };
28 
29     const std::u16string  INTERFACE_NAME = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,
30         char16_t> {}.from_bytes("sample_driver");
31 
32 
33 class ObjectCollectorTest : public testing::Test {
34 public:
SetUpTestCase()35     static void SetUpTestCase() {}
TearDownTestCase()36     static void TearDownTestCase() {}
37 
SetUp()38     void SetUp() {};
TearDown()39     void TearDown() {};
40 };
TestRemove()41 static bool TestRemove()
42 {
43     return HDI::ObjectCollector::GetInstance().RemoveObject(nullptr);
44 }
45 
46 HWTEST_F(ObjectCollectorTest, ObjectCollectorTest001, TestSize.Level1)
47 {
48     sptr<IRemoteObject> object = HDI::ObjectCollector::GetInstance().NewObject(nullptr, INTERFACE_NAME);
49     ASSERT_EQ(object, nullptr);
50     object = HDI::ObjectCollector::GetInstance().GetOrNewObject(nullptr, INTERFACE_NAME);
51     ASSERT_EQ(object, nullptr);
52     bool remove = false;
53     if (!TestRemove()) {
54         remove = true;
55     }
56     ASSERT_EQ(remove, true);
57 }
58 } // namespace OHOS