• 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 "gtest/gtest.h"
17 #include "daemon_stub_mock.h"
18 #include "ipc/daemon_stub.h"
19 #include "ipc/i_daemon.h"
20 
21 namespace OHOS {
22 namespace Storage {
23 namespace DistributedFile {
24 namespace Test {
25 namespace {
26     const int ERROR_CODE = 99999;
27 }
28 using namespace testing::ext;
29 
30 class DaemonStubTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36 };
37 
SetUpTestCase(void)38 void DaemonStubTest::SetUpTestCase(void)
39 {
40     // input testsuit setup step,setup invoked before all testcases
41 }
42 
TearDownTestCase(void)43 void DaemonStubTest::TearDownTestCase(void)
44 {
45     // input testsuit teardown step,teardown invoked after all testcases
46 }
47 
SetUp(void)48 void DaemonStubTest::SetUp(void)
49 {
50     // input testcase setup step,setup invoked before each testcases
51 }
52 
TearDown(void)53 void DaemonStubTest::TearDown(void)
54 {
55     // input testcase teardown step,teardown invoked after each testcases
56 }
57 
58 /**
59  * @tc.name: DaemonStubTest_OnRemoteRequest_0100
60  * @tc.desc: Verify the OnRemoteRequest function.
61  * @tc.type: FUNC
62  * @tc.require: SR000H0387
63  */
64 HWTEST_F(DaemonStubTest, DaemonStubTest_OnRemoteRequest_0100, TestSize.Level1)
65 {
66     GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0100 start";
67     DaemonStubMock mock;
68     MessageParcel data;
69     MessageParcel reply;
70     MessageOption option(MessageOption::TF_SYNC);
71     bool bRet = data.WriteInterfaceToken(u"error descriptor");
72     EXPECT_TRUE(bRet) << "write token error";
73 
74     int32_t ret = mock.OnRemoteRequest(IDaemon::DFS_DAEMON_CMD_ECHO, data, reply, option);
75     EXPECT_TRUE(ret != ERR_NONE) << "descriptor error";
76     GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0100 end";
77 }
78 
79 /**
80  * @tc.name: DaemonStubTest_OnRemoteRequest_0200
81  * @tc.desc: Verify the OnRemoteRequest function.
82  * @tc.type: FUNC
83  * @tc.require: SR000H0387
84  */
85 HWTEST_F(DaemonStubTest, DaemonStubTest_OnRemoteRequest_0200, TestSize.Level1)
86 {
87     GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0200 start";
88     DaemonStubMock mock;
89     MessageParcel data;
90     MessageParcel reply;
91     MessageOption option(MessageOption::TF_SYNC);
92     bool bRet = data.WriteInterfaceToken(IDaemon::GetDescriptor());
93     EXPECT_TRUE(bRet) << "write token error";
94 
95     int32_t ret = mock.OnRemoteRequest(ERROR_CODE, data, reply, option);
96     EXPECT_TRUE(ret != IDaemon::DFS_DAEMON_SUCCESS) << "request code error";
97     GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0200 end";
98 }
99 
100 /**
101  * @tc.name: DaemonStubTest_OnRemoteRequest_0300
102  * @tc.desc: Verify the OnRemoteRequest function.
103  * @tc.type: FUNC
104  * @tc.require: AR000GK4HB
105  */
106 HWTEST_F(DaemonStubTest, DaemonStubTest_OnRemoteRequest_0300, TestSize.Level1)
107 {
108     GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0300 start";
109     DaemonStubMock mock;
110     MessageParcel data;
111     MessageParcel reply;
112     MessageOption option(MessageOption::TF_SYNC);
113     bool bRet = data.WriteInterfaceToken(IDaemon::GetDescriptor());
114     EXPECT_TRUE(bRet) << "write token error";
115 
116     int32_t ret = mock.OnRemoteRequest(IDaemon::DFS_DAEMON_CMD_ECHO, data, reply, option);
117     EXPECT_TRUE(ret == IDaemon::DFS_DAEMON_SUCCESS);
118     GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0300 end";
119 }
120 } // namespace Test
121 } // namespace DistributedFile
122 } // namespace Storage
123 } // namespace OHOS