• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "dm_adapter.h"
26 #include "event_handler_factory.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 }
34 class DMAdapterTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp();
39     void TearDown();
40 };
41 
SetUpTestCase()42 void DMAdapterTest::SetUpTestCase()
43 {
44 }
45 
TearDownTestCase()46 void DMAdapterTest::TearDownTestCase()
47 {
48 }
49 
SetUp()50 void DMAdapterTest::SetUp()
51 {
52 }
53 
TearDown()54 void DMAdapterTest::TearDown()
55 {
56 }
57 
58 /*
59  * @tc.name: Init001
60  * @tc.desc: Init
61  * @tc.type: FUNC
62  * @tc.require:
63  */
64 HWTEST_F(DMAdapterTest, Init001, TestSize.Level1)
65 {
66     DMAdapter::GetInstance().dmInitCallback_ = nullptr;
67     DMAdapter::GetInstance().deviceStateCallback_ = nullptr;
68     int32_t ret = DMAdapter::GetInstance().Init();
69     EXPECT_EQ(0, ret);
70     ret = DMAdapter::GetInstance().UnInit();
71     EXPECT_EQ(DP_SUCCESS, ret);
72 }
73 
74 /*
75  * @tc.name: UnInit001
76  * @tc.desc: UnInit
77  * @tc.type: FUNC
78  * @tc.require:
79  */
80 HWTEST_F(DMAdapterTest, UnInit001, TestSize.Level1)
81 {
82     DMAdapter::GetInstance().dmInitCallback_ = nullptr;
83     DMAdapter::GetInstance().deviceStateCallback_ = nullptr;
84     int32_t ret = DMAdapter::GetInstance().UnInit();
85     EXPECT_EQ(DP_SUCCESS, ret);
86 }
87 
88 /*
89  * @tc.name: UnInit002
90  * @tc.desc: UnInit
91  * @tc.type: FUNC
92  * @tc.require:
93  */
94 HWTEST_F(DMAdapterTest, UnInit002, TestSize.Level1)
95 {
96     int32_t ret = DMAdapter::GetInstance().Init();
97     EXPECT_EQ(0, ret);
98     ret = DMAdapter::GetInstance().UnInit();
99     EXPECT_EQ(DP_SUCCESS, ret);
100 }
101 
102 /*
103  * @tc.name: ReInit001
104  * @tc.desc: ReInit
105  * @tc.type: FUNC
106  * @tc.require:
107  */
108 HWTEST_F(DMAdapterTest, ReInit001, TestSize.Level1)
109 {
110     int32_t ret = DMAdapter::GetInstance().ReInit();
111     EXPECT_EQ(0, ret);
112     ret = DMAdapter::GetInstance().UnInit();
113     EXPECT_EQ(DP_SUCCESS, ret);
114 }
115 
116 /*
117  * @tc.name: GetUuidByNetworkId001
118  * @tc.desc: GetUuidByNetworkId
119  * @tc.type: FUNC
120  * @tc.require:
121  */
122 HWTEST_F(DMAdapterTest, GetUuidByNetworkId001, TestSize.Level1)
123 {
124     std::string networkId = "networkId";
125     std::string uuid = "";
126     bool ret = DMAdapter::GetInstance().GetUuidByNetworkId(networkId, uuid);
127     EXPECT_FALSE(ret);
128 }
129 } // namespace DistributedDeviceProfile
130 } // namespace OHOS
131