1 /*
2 * Copyright (c) 2025 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 "UTTest_mini_tools_kit.h"
17 #include "accesstoken_kit.h"
18 #include "dm_constants.h"
19 #include "nativetoken_kit.h"
20 #include "token_setproc.h"
21
22
23 namespace OHOS {
24 namespace DistributedHardware {
25 namespace {
26 constexpr int32_t TEST_MAX_NAME_LENGTH = 30;
27 const std::string TEST_PKG_NAME = "test_pkg_name";
28 const std::string TEST_SERVICE_NAME = "test_service_name";
29 } // namespace
SetUp()30 void MiniToolsKitTest::SetUp()
31 {
32 const int32_t permsNum = 3;
33 const int32_t indexZero = 0;
34 const int32_t indexOne = 1;
35 const int32_t indexTwo = 2;
36 uint64_t tokenId;
37 const char *perms[permsNum];
38 perms[indexZero] = "ohos.permission.ACCESS_SERVICE_DM";
39 perms[indexOne] = "ohos.permission.DISTRIBUTED_DATASYNC";
40 perms[indexTwo] = "ohos.permission.MONITOR_DEVICE_NETWORK_STATE";
41 NativeTokenInfoParams infoInstance = {
42 .dcapsNum = 0,
43 .permsNum = permsNum,
44 .aclsNum = 0,
45 .dcaps = NULL,
46 .perms = perms,
47 .acls = NULL,
48 .processName = "dsoftbus_service",
49 .aplStr = "system_core",
50 };
51 tokenId = GetAccessTokenId(&infoInstance);
52 SetSelfTokenID(tokenId);
53 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
54 }
55
TearDown()56 void MiniToolsKitTest::TearDown()
57 {}
58
SetUpTestCase()59 void MiniToolsKitTest::SetUpTestCase()
60 {}
61
TearDownTestCase()62 void MiniToolsKitTest::TearDownTestCase()
63 {}
64
65 HWTEST_F(MiniToolsKitTest, InitDeviceManager_001, testing::ext::TestSize.Level1)
66 {
67 int32_t ret = DeviceManagerMini::GetInstance().InitDeviceManager(TEST_PKG_NAME);
68 EXPECT_EQ(ret, DM_OK);
69 }
70
71 HWTEST_F(MiniToolsKitTest, InitDeviceManager_002, testing::ext::TestSize.Level1)
72 {
73 int32_t ret = DeviceManagerMini::GetInstance().InitDeviceManager("");
74 EXPECT_NE(ret, DM_OK);
75 }
76
77 HWTEST_F(MiniToolsKitTest, GetLocalDisplayDeviceName001, testing::ext::TestSize.Level1)
78 {
79 std::string localName = "";
80 int32_t ret = DeviceManagerMini::GetInstance().GetLocalDisplayDeviceName(TEST_PKG_NAME, TEST_MAX_NAME_LENGTH,
81 localName);
82 EXPECT_EQ(ret, DM_OK);
83 }
84
85 HWTEST_F(MiniToolsKitTest, UnInitDeviceManager_001, testing::ext::TestSize.Level1)
86 {
87 int32_t ret = DeviceManagerMini::GetInstance().UnInitDeviceManager(TEST_PKG_NAME);
88 EXPECT_EQ(ret, DM_OK);
89 }
90
91 HWTEST_F(MiniToolsKitTest, UnInitDeviceManager_002, testing::ext::TestSize.Level1)
92 {
93 int32_t ret = DeviceManagerMini::GetInstance().UnInitDeviceManager("");
94 EXPECT_NE(ret, DM_OK);
95 }
96
97 HWTEST_F(MiniToolsKitTest, OnDmServiceDied_001, testing::ext::TestSize.Level1)
98 {
99 int32_t ret = DeviceManagerImplMini::GetInstance().OnDmServiceDied();
100 EXPECT_EQ(ret, DM_OK);
101 }
102
103 } // namespace DistributedHardware
104 } // namespace OHOS
105