• 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 #include "distributed_file_daemon_proxy.h"
16 
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 
20 #include "dfs_error.h"
21 #include "file_dfs_listener_mock.h"
22 #include "i_daemon_mock.h"
23 
24 namespace OHOS::Storage::DistributedFile::Test {
25 using namespace OHOS::FileManagement;
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace std;
29 
30 class DistributedFileDaemonProxyTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36 public:
37     static inline shared_ptr<DistributedFileDaemonProxy> proxy_ = nullptr;
38     static inline sptr<DaemonServiceMock> mock_ = nullptr;
39 };
40 
SetUpTestCase(void)41 void DistributedFileDaemonProxyTest::SetUpTestCase(void)
42 {
43     GTEST_LOG_(INFO) << "SetUpTestCase";
44     mock_ = sptr(new DaemonServiceMock());
45     proxy_ = make_shared<DistributedFileDaemonProxy>(mock_);
46 }
47 
TearDownTestCase(void)48 void DistributedFileDaemonProxyTest::TearDownTestCase(void)
49 {
50     GTEST_LOG_(INFO) << "TearDownTestCase";
51     mock_ = nullptr;
52     proxy_ = nullptr;
53 }
54 
SetUp(void)55 void DistributedFileDaemonProxyTest::SetUp(void)
56 {
57     GTEST_LOG_(INFO) << "SetUp";
58 }
59 
TearDown(void)60 void DistributedFileDaemonProxyTest::TearDown(void)
61 {
62     GTEST_LOG_(INFO) << "TearDown";
63 }
64 
65 /**
66  * @tc.name: DistributedFileDaemon_OpenP2PConnection_0100
67  * @tc.desc: The execution of the OpenP2PConnection failed.
68  * @tc.type: FUNC
69  * @tc.require: I7TDJK
70  */
71 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_OpenP2PConnection_0100, TestSize.Level1)
72 {
73     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0100 Start";
74     DistributedHardware::DmDeviceInfo deviceInfo;
75     auto testProxy = make_shared<DistributedFileDaemonProxy>(nullptr);
76     auto ret = testProxy->OpenP2PConnection(deviceInfo);
77     EXPECT_EQ(ret, E_BROKEN_IPC);
78     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0100 End";
79 }
80 
81 /**
82  * @tc.name: DistributedFileDaemon_OpenP2PConnection_0200
83  * @tc.desc: The execution of the OpenP2PConnection failed.
84  * @tc.type: FUNC
85  * @tc.require: I7TDJK
86  */
87 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_OpenP2PConnection_0200, TestSize.Level1)
88 {
89     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0200 Start";
90     DistributedHardware::DmDeviceInfo deviceInfo;
91     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(E_INVAL_ARG));
92     auto ret = proxy_->OpenP2PConnection(deviceInfo);
93     EXPECT_EQ(ret, E_BROKEN_IPC);
94     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0200 End";
95 }
96 
97 /**
98  * @tc.name: DistributedFileDaemon_OpenP2PConnection_0300
99  * @tc.desc: The execution of the OpenP2PConnection success.
100  * @tc.type: FUNC
101  * @tc.require: I7TDJK
102  */
103 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_OpenP2PConnection_0300, TestSize.Level1)
104 {
105     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0300 Start";
106     DistributedHardware::DmDeviceInfo deviceInfo;
107     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(E_OK));
108     auto ret = proxy_->OpenP2PConnection(deviceInfo);
109     EXPECT_EQ(ret, E_OK);
110     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0300 End";
111 }
112 
113 /**
114  * @tc.name: DistributedFileDaemon_CloseP2PConnection_0100
115  * @tc.desc: The execution of the CloseP2PConnection failed.
116  * @tc.type: FUNC
117  * @tc.require: I7TDJK
118  */
119 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_CloseP2PConnection_0100, TestSize.Level1)
120 {
121     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0100 Start";
122     DistributedHardware::DmDeviceInfo deviceInfo;
123     auto testProxy = make_shared<DistributedFileDaemonProxy>(nullptr);
124     auto ret = testProxy->CloseP2PConnection(deviceInfo);
125     EXPECT_EQ(ret, E_BROKEN_IPC);
126     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0100 End";
127 }
128 
129 /**
130  * @tc.name: DistributedFileDaemon_CloseP2PConnection_0200
131  * @tc.desc: The execution of the CloseP2PConnection failed.
132  * @tc.type: FUNC
133  * @tc.require: I7TDJK
134  */
135 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_CloseP2PConnection_0200, TestSize.Level1)
136 {
137     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0200 Start";
138     DistributedHardware::DmDeviceInfo deviceInfo;
139     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(E_INVAL_ARG));
140     auto ret = proxy_->CloseP2PConnection(deviceInfo);
141     EXPECT_EQ(ret, E_BROKEN_IPC);
142     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0200 End";
143 }
144 
145 /**
146  * @tc.name: DistributedFileDaemon_CloseP2PConnection_0300
147  * @tc.desc: The execution of the CloseP2PConnection success.
148  * @tc.type: FUNC
149  * @tc.require: I7TDJK
150  */
151 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_CloseP2PConnection_0300, TestSize.Level1)
152 {
153     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0300 Start";
154     DistributedHardware::DmDeviceInfo deviceInfo;
155     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(E_OK));
156     auto ret = proxy_->CloseP2PConnection(deviceInfo);
157     EXPECT_EQ(ret, E_OK);
158     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0300 End";
159 }
160 }