• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <memory>
18 
19 #include "dfs_error.h"
20 #include "distributed_file_daemon_proxy.h"
21 #include "i_daemon_mock.h"
22 #include "utils_log.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 namespace {
31     DistributedHardware::DmDeviceInfo deviceInfo = {
32         .deviceId = "testdevid",
33         .deviceName = "testdevname",
34         .networkId = "testnetworkid",
35     };
36 }
37 
38 class DistributedDaemonProxyTest : public testing::Test {
39 public:
40     static void SetUpTestCase(void);
41     static void TearDownTestCase(void);
42     void SetUp();
43     void TearDown();
44     shared_ptr<DistributedFileDaemonProxy> proxy_ = nullptr;
45     sptr<DaemonServiceMock> mock_ = nullptr;
46 };
47 
SetUpTestCase(void)48 void DistributedDaemonProxyTest::SetUpTestCase(void)
49 {
50     GTEST_LOG_(INFO) << "SetUpTestCase";
51 }
52 
TearDownTestCase(void)53 void DistributedDaemonProxyTest::TearDownTestCase(void)
54 {
55     GTEST_LOG_(INFO) << "TearDownTestCase";
56 }
57 
SetUp(void)58 void DistributedDaemonProxyTest::SetUp(void)
59 {
60     mock_ = sptr(new DaemonServiceMock());
61     proxy_ = make_shared<DistributedFileDaemonProxy>(mock_);
62     GTEST_LOG_(INFO) << "SetUp";
63 }
64 
TearDown(void)65 void DistributedDaemonProxyTest::TearDown(void)
66 {
67     mock_ = nullptr;
68     proxy_ = nullptr;
69     GTEST_LOG_(INFO) << "TearDown";
70 }
71 
72 /**
73  * @tc.name: OpenP2PConnectionTest
74  * @tc.desc: Verify the OpenP2PConnection function.
75  * @tc.type: FUNC
76  * @tc.require: I7M6L1
77  */
78 HWTEST_F(DistributedDaemonProxyTest, OpenP2PConnectionTest, TestSize.Level1)
79 {
80     GTEST_LOG_(INFO) << "OpenP2PConnectionTest Start";
81     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).Times(1).WillOnce(Return(E_OK));
82     int ret = proxy_->OpenP2PConnection(deviceInfo);
83     EXPECT_EQ(ret, E_OK);
84     GTEST_LOG_(INFO) << "OpenP2PConnectionTest End";
85 }
86 
87 /**
88  * @tc.name: CloseP2PConnectionTest
89  * @tc.desc: Verify the CloseP2PConnection function.
90  * @tc.type: FUNC
91  * @tc.require: I7M6L1
92  */
93 HWTEST_F(DistributedDaemonProxyTest, CloseP2PConnectionTest, TestSize.Level1)
94 {
95     GTEST_LOG_(INFO) << "CloseP2PConnectionTest Start";
96     EXPECT_CALL(*mock_, SendRequest(_, _, _, _)).Times(1).WillOnce(Return(E_OK));
97     int ret = proxy_->OpenP2PConnection(deviceInfo);
98     EXPECT_EQ(ret, E_OK);
99     GTEST_LOG_(INFO) << "CloseP2PConnectionTest End";
100 }
101 
102 } // namespace OHOS::Storage::DistributedFile::Test