• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "UTTest_ipc_client_stub.h"
17 #include "dm_device_info.h"
18 #include "ipc_remote_broker.h"
19 #include "iremote_object.h"
20 #include "iservice_registry.h"
21 #include "system_ability_definition.h"
22 #include "ipc_client_manager.h"
23 #include "ipc_set_useroperation_req.h"
24 #include "ipc_cmd_register.h"
25 #include "ipc_skeleton.h"
26 #include "ipc_types.h"
27 #include "ipc_rsp.h"
28 #include "ipc_def.h"
29 #include "dm_constants.h"
30 
31 #include <unistd.h>
32 
33 namespace OHOS {
34 namespace DistributedHardware {
SetUp()35 void IpcClientStubTest::SetUp()
36 {
37 }
38 
TearDown()39 void IpcClientStubTest::TearDown()
40 {
41 }
42 
SetUpTestCase()43 void IpcClientStubTest::SetUpTestCase()
44 {
45 }
46 
TearDownTestCase()47 void IpcClientStubTest::TearDownTestCase()
48 {
49 }
50 
51 namespace {
52 /**
53  * @tc.name: OnRemoteRequest_001
54  * @tc.desc: 1. set MessageOption not null
55  *              set MessageParcel not null
56  *              set MessageParcel not null
57  *           2. set set code is 999
58  *           3. call IpcClientStub OnRemoteRequest with parameter
59  *           4. check result is DM_FAILED
60  * @tc.type: FUNC
61  * @tc.require: AR000GHSJK
62  */
63 HWTEST_F(IpcClientStubTest, OnRemoteRequest_001, testing::ext::TestSize.Level0)
64 {
65     // 1. set MessageOption not null
66     MessageOption option;
67     // set MessageParcel not null
68     MessageParcel data;
69     // set MessageParcel not null
70     MessageParcel reply;
71     // 2. set set code is 999
72     int code = 999;
73     sptr<IpcClientStub> instance = new IpcClientStub();
74     // 3. call IpcClientStub OnRemoteRequest with parameter
75     int32_t result = instance->OnRemoteRequest(code, data, reply, option);
76     if (result != DM_OK) {
77         result = DM_FAILED;
78     }
79     // 4. check result is DM_FAILED
80     ASSERT_EQ(result, DM_FAILED);
81 }
82 
83 /**
84  * @tc.name: OnRemoteRequest_002
85  * @tc.desc: 1. set MessageOption not null
86  *              set MessageParcel not null
87  *              set MessageParcel not null
88  *           2. set set code is SERVER_DEVICE_FA_NOTIFY
89  *           3. call IpcClientStub OnRemoteRequest with parameter
90  *           4. check result is DM_OK
91  * @tc.type: FUNC
92  * @tc.require: AR000GHSJK
93  */
94 HWTEST_F(IpcClientStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0)
95 {
96     // 1. set MessageOption not null
97     MessageOption option;
98     // set MessageParcel not null
99     MessageParcel data;
100     // set MessageParcel not null
101     MessageParcel reply;
102     // 2. set set code is SERVER_DEVICE_FA_NOTIFY
103     int code = SERVER_DEVICE_FA_NOTIFY;
104     sptr<IpcClientStub> instance = new IpcClientStub();
105     // 3. call IpcClientStub OnRemoteRequest with parameter
106     int ret = instance->OnRemoteRequest(code, data, reply, option);
107     // 4. check result is DM_OK
108     ASSERT_NE(ret, DM_OK);
109 }
110 
111 /**
112  * @tc.name: SendCmd_001
113  * @tc.desc: 1. set set code is SERVER_DEVICE_FA_NOTIFY
114  *              set req is nullptr
115  *              set rsp is nullptr
116  *           2. call IpcClientStub SendCmd with parameter
117  *           3. check result is DM_IPC_FAILED
118  * @tc.type: FUNC
119  * @tc.require: AR000GHSJK
120  */
121 HWTEST_F(IpcClientStubTest, SendCmd_001, testing::ext::TestSize.Level0)
122 {
123     // 1. set set code is SERVER_DEVICE_FA_NOTIFY
124     int cmdCode = SERVER_DEVICE_FA_NOTIFY;
125     // set req is nullptr
126     std::shared_ptr<IpcReq> req = nullptr;
127     // set rsp is nullptr
128     std::shared_ptr<IpcRsp> rsp = nullptr;
129     sptr<IpcClientStub> instance = new IpcClientStub();
130     // 2. call IpcClientStub SendCmd with parameter
131     int ret = instance->SendCmd(cmdCode, req, rsp);
132     // 3. check result is DM_IPC_FAILED
133     ASSERT_EQ(ret, DM_IPC_FAILED);
134 }
135 } // namespace
136 } // namespace DistributedHardware
137 } // namespace OHOS
138