• 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     ASSERT_TRUE(mock_ != nullptr);
58     GTEST_LOG_(INFO) << "SetUp";
59 }
60 
TearDown(void)61 void DistributedFileDaemonProxyTest::TearDown(void)
62 {
63     GTEST_LOG_(INFO) << "TearDown";
64 }
65 
66 /**
67  * @tc.name: DistributedFileDaemon_OpenP2PConnection_0100
68  * @tc.desc: The execution of the OpenP2PConnection failed.
69  * @tc.type: FUNC
70  * @tc.require: I7TDJK
71  */
72 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_OpenP2PConnection_0100, TestSize.Level1)
73 {
74     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0100 Start";
75     DistributedHardware::DmDeviceInfo deviceInfo;
76     auto testProxy = make_shared<DistributedFileDaemonProxy>(nullptr);
77     auto ret = testProxy->OpenP2PConnection(deviceInfo);
78     EXPECT_EQ(ret, E_BROKEN_IPC);
79     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0100 End";
80 }
81 
82 /**
83  * @tc.name: DistributedFileDaemon_OpenP2PConnection_0200
84  * @tc.desc: The execution of the OpenP2PConnection failed.
85  * @tc.type: FUNC
86  * @tc.require: I7TDJK
87  */
88 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_OpenP2PConnection_0200, TestSize.Level1)
89 {
90     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0200 Start";
91     DistributedHardware::DmDeviceInfo deviceInfo;
92     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(E_INVAL_ARG));
93     auto ret = proxy_->OpenP2PConnection(deviceInfo);
94     EXPECT_EQ(ret, E_BROKEN_IPC);
95     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0200 End";
96 }
97 
98 /**
99  * @tc.name: DistributedFileDaemon_OpenP2PConnection_0300
100  * @tc.desc: The execution of the OpenP2PConnection success.
101  * @tc.type: FUNC
102  * @tc.require: I7TDJK
103  */
104 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_OpenP2PConnection_0300, TestSize.Level1)
105 {
106     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0300 Start";
107     DistributedHardware::DmDeviceInfo deviceInfo;
108     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(E_OK));
109     auto ret = proxy_->OpenP2PConnection(deviceInfo);
110     EXPECT_EQ(ret, E_OK);
111     GTEST_LOG_(INFO) << "DistributedFileDaemon_OpenP2PConnection_0300 End";
112 }
113 
114 /**
115  * @tc.name: DistributedFileDaemon_CloseP2PConnection_0100
116  * @tc.desc: The execution of the CloseP2PConnection failed.
117  * @tc.type: FUNC
118  * @tc.require: I7TDJK
119  */
120 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_CloseP2PConnection_0100, TestSize.Level1)
121 {
122     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0100 Start";
123     DistributedHardware::DmDeviceInfo deviceInfo;
124     auto testProxy = make_shared<DistributedFileDaemonProxy>(nullptr);
125     auto ret = testProxy->CloseP2PConnection(deviceInfo);
126     EXPECT_EQ(ret, E_BROKEN_IPC);
127     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0100 End";
128 }
129 
130 /**
131  * @tc.name: DistributedFileDaemon_CloseP2PConnection_0200
132  * @tc.desc: The execution of the CloseP2PConnection failed.
133  * @tc.type: FUNC
134  * @tc.require: I7TDJK
135  */
136 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_CloseP2PConnection_0200, TestSize.Level1)
137 {
138     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0200 Start";
139     DistributedHardware::DmDeviceInfo deviceInfo;
140     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(E_INVAL_ARG));
141     auto ret = proxy_->CloseP2PConnection(deviceInfo);
142     EXPECT_EQ(ret, E_BROKEN_IPC);
143     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0200 End";
144 }
145 
146 /**
147  * @tc.name: DistributedFileDaemon_CloseP2PConnection_0300
148  * @tc.desc: The execution of the CloseP2PConnection success.
149  * @tc.type: FUNC
150  * @tc.require: I7TDJK
151  */
152 HWTEST_F(DistributedFileDaemonProxyTest, DistributedFileDaemon_CloseP2PConnection_0300, TestSize.Level1)
153 {
154     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0300 Start";
155     DistributedHardware::DmDeviceInfo deviceInfo;
156     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).WillOnce(Return(E_OK));
157     auto ret = proxy_->CloseP2PConnection(deviceInfo);
158     EXPECT_EQ(ret, E_OK);
159     GTEST_LOG_(INFO) << "DistributedFileDaemon_CloseP2PConnection_0300 End";
160 }
161 }