• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <exception>
17 #include <memory>
18 #include <unistd.h>
19 
20 #include "gtest/gtest.h"
21 #include "device/device_manager_agent.h"
22 #include "mountpoint/mount_point.h"
23 
24 namespace OHOS {
25 namespace Storage {
26 namespace DistributedFile {
27 namespace Test {
28 using namespace testing::ext;
29 using namespace std;
30 
31 DistributedHardware::DmDeviceInfo deviceInfo = {
32     .deviceId = "testdevid",
33     .deviceName = "testdevname",
34     .deviceTypeId = 1,
35 };
36 
37 class DeviceManagerAgentTest : public testing::Test {
38 public:
39     static void SetUpTestCase(void);
40     static void TearDownTestCase(void);
41     void SetUp();
42     void TearDown();
43 };
44 
SetUpTestCase(void)45 void DeviceManagerAgentTest::SetUpTestCase(void)
46 {
47     // input testsuit setup step,setup invoked before all testcases
48 }
49 
TearDownTestCase(void)50 void DeviceManagerAgentTest::TearDownTestCase(void)
51 {
52     // input testsuit teardown step,teardown invoked after all testcases
53 }
54 
SetUp(void)55 void DeviceManagerAgentTest::SetUp(void)
56 {
57     // input testcase setup step,setup invoked before each testcases
58 }
59 
TearDown(void)60 void DeviceManagerAgentTest::TearDown(void)
61 {
62     // input testcase teardown step,teardown invoked after each testcases
63 }
64 
65 /**
66  * @tc.name: DeviceManagerAgentTest_OnDeviceOnline_0100
67  * @tc.desc: Verify the OnDeviceOnline function.
68  * @tc.type: FUNC
69  * @tc.require: SR000H0387
70  */
71 HWTEST_F(DeviceManagerAgentTest, DeviceManagerAgentTest_OnDeviceOnline_0100, TestSize.Level1)
72 {
73     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceOnline_0100 start";
74     bool res = true;
75 
76     try {
77         DeviceManagerAgent::GetInstance()->OnDeviceOnline(deviceInfo);
78     } catch (const exception &e) {
79         LOGE("Error:%{public}s", e.what());
80         res = false;
81     }
82 
83     EXPECT_TRUE(res == true);
84     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceOnline_0100 end";
85 }
86 
87 /**
88  * @tc.name: DeviceManagerAgentTest_OnDeviceOffline_0100
89  * @tc.desc: Verify the OnDeviceOffline function.
90  * @tc.type: FUNC
91  * @tc.require: SR000H0387
92  */
93 HWTEST_F(DeviceManagerAgentTest, DeviceManagerAgentTest_OnDeviceOffline_0100, TestSize.Level1)
94 {
95     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceOffline_0100 start";
96     bool res = true;
97 
98     try {
99         DeviceManagerAgent::GetInstance()->OnDeviceOffline(deviceInfo);
100     } catch (const exception &e) {
101         LOGE("Error:%{public}s", e.what());
102         res = false;
103     }
104 
105     EXPECT_TRUE(res == true);
106     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceOffline_0100 end";
107 }
108 
109 /**
110  * @tc.name: DeviceManagerAgentTest_OnDeviceOffline_0200
111  * @tc.desc: Verify the OnDeviceOffline function.
112  * @tc.type: FUNC
113  * @tc.require: SR000H0387
114  */
115 HWTEST_F(DeviceManagerAgentTest, DeviceManagerAgentTest_OnDeviceOffline_0200, TestSize.Level1)
116 {
117     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceOffline_0200 start";
118     bool res = true;
119 
120     try {
121         DeviceManagerAgent::GetInstance()->OnDeviceOnline(deviceInfo);
122         DeviceManagerAgent::GetInstance()->OnDeviceOffline(deviceInfo);
123     } catch (const exception &e) {
124         LOGE("Error:%{public}s", e.what());
125         res = false;
126     }
127 
128     EXPECT_TRUE(res == true);
129     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceOffline_0200 end";
130 }
131 
132 /**
133  * @tc.name: DeviceManagerAgentTest_OnDeviceChanged_0100
134  * @tc.desc: Verify the OnDeviceChanged function.
135  * @tc.type: FUNC
136  * @tc.require: SR000H0387
137  */
138 HWTEST_F(DeviceManagerAgentTest, DeviceManagerAgentTest_OnDeviceChanged_0100, TestSize.Level1)
139 {
140     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceChanged_0100 start";
141     bool res = true;
142 
143     try {
144         DeviceManagerAgent::GetInstance()->OnDeviceChanged(deviceInfo);
145     } catch (const exception &e) {
146         LOGE("Error:%{public}s", e.what());
147         res = false;
148     }
149 
150     EXPECT_TRUE(res == true);
151     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceChanged_0100 end";
152 }
153 
154 /**
155  * @tc.name: DeviceManagerAgentTest_OnDeviceReady_0100
156  * @tc.desc: Verify the OnDeviceReady function.
157  * @tc.type: FUNC
158  * @tc.require: SR000H0387
159  */
160 HWTEST_F(DeviceManagerAgentTest, DeviceManagerAgentTest_OnDeviceReady_0100, TestSize.Level1)
161 {
162     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceReady_0100 start";
163     bool res = true;
164 
165     try {
166         DeviceManagerAgent::GetInstance()->OnDeviceReady(deviceInfo);
167     } catch (const exception &e) {
168         LOGE("Error:%{public}s", e.what());
169         res = false;
170     }
171 
172     EXPECT_TRUE(res == true);
173     GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceReady_0100 end";
174 }
175 } // namespace Test
176 } // namespace DistributedFile
177 } // namespace Storage
178 } // namespace OHOS
179