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 <iostream>
18 #include <memory>
19 #include <string>
20 #include <vector>
21
22 #include "distributed_device_profile_constants.h"
23 #include "distributed_device_profile_errors.h"
24 #include "distributed_device_profile_log.h"
25 #include "event_handler_factory.h"
26 #include "dm_adapter.h"
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace DistributedDeviceProfile {
30 using namespace std;
31 namespace {
32 const std::string TAG = "DMAdapterTest";
33 const int32_t ERR_DM_IPC_SEND_REQUEST_FAILED = 96929756;
34 }
35 class DMAdapterTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp();
40 void TearDown();
41 };
42
SetUpTestCase()43 void DMAdapterTest::SetUpTestCase()
44 {
45 }
46
TearDownTestCase()47 void DMAdapterTest::TearDownTestCase()
48 {
49 }
50
SetUp()51 void DMAdapterTest::SetUp()
52 {
53 }
54
TearDown()55 void DMAdapterTest::TearDown()
56 {
57 }
58
59 /*
60 * @tc.name: Init001
61 * @tc.desc: Init
62 * @tc.type: FUNC
63 * @tc.require:
64 */
65 HWTEST_F(DMAdapterTest, Init001, TestSize.Level1)
66 {
67 DMAdapter::GetInstance().deviceStateCallback_ = nullptr;
68 int32_t ret = DMAdapter::GetInstance().Init();
69 EXPECT_EQ(ERR_DM_IPC_SEND_REQUEST_FAILED, ret);
70 }
71
72 /*
73 * @tc.name: Init002
74 * @tc.desc: Init
75 * @tc.type: FUNC
76 * @tc.require:
77 */
78 HWTEST_F(DMAdapterTest, Init002, TestSize.Level1)
79 {
80 DMAdapter::GetInstance().deviceStateCallback_ = std::make_shared<DMAdapter::DpDeviceStateCallback>();
81 int32_t ret = DMAdapter::GetInstance().Init();
82 EXPECT_EQ(ERR_DM_IPC_SEND_REQUEST_FAILED, ret);
83 }
84
85 /*
86 * @tc.name: UnInit001
87 * @tc.desc: UnInit
88 * @tc.type: FUNC
89 * @tc.require:
90 */
91 HWTEST_F(DMAdapterTest, UnInit001, TestSize.Level1)
92 {
93 DMAdapter::GetInstance().deviceStateCallback_ = nullptr;
94 int32_t ret = DMAdapter::GetInstance().UnInit();
95 EXPECT_EQ(0, ret);
96 }
97
98 /*
99 * @tc.name: UnInit002
100 * @tc.desc: UnInit
101 * @tc.type: FUNC
102 * @tc.require:
103 */
104 HWTEST_F(DMAdapterTest, UnInit002, TestSize.Level1)
105 {
106 DMAdapter::GetInstance().deviceStateCallback_ = std::make_shared<DMAdapter::DpDeviceStateCallback>();
107 int32_t ret = DMAdapter::GetInstance().Init();
108 EXPECT_EQ(ERR_DM_IPC_SEND_REQUEST_FAILED, ret);
109 }
110
111 /*
112 * @tc.name: ReInit001
113 * @tc.desc: ReInit
114 * @tc.type: FUNC
115 * @tc.require:
116 */
117 HWTEST_F(DMAdapterTest, ReInit001, TestSize.Level1)
118 {
119 int32_t ret = DMAdapter::GetInstance().ReInit();
120 EXPECT_EQ(ERR_DM_IPC_SEND_REQUEST_FAILED, ret);
121 }
122 } // namespace DistributedDeviceProfile
123 } // namespace OHOS
124