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 "UTTest_ipc_client_server_proxy.h"
17
18 #include <unistd.h>
19
20 #include "mock/mock_ipc_client_proxy.h"
21 #include "device_manager.h"
22 #include "single_instance.h"
23 #include "device_manager_impl.h"
24 #include "dm_constants.h"
25 #include "dm_log.h"
26 #include "ipc_cmd_register.h"
27 #include "ipc_def.h"
28 #include "ipc_types.h"
29 #include "ipc_set_useroperation_req.h"
30 #include "ipc_stop_discovery_req.h"
31 #include "ipc_start_discovery_req.h"
32
33 namespace OHOS {
34 namespace DistributedHardware {
SetUp()35 void IpcClientServerProxyTest::SetUp()
36 {
37 }
38
TearDown()39 void IpcClientServerProxyTest::TearDown()
40 {
41 }
42
SetUpTestCase()43 void IpcClientServerProxyTest::SetUpTestCase()
44 {
45 }
46
TearDownTestCase()47 void IpcClientServerProxyTest::TearDownTestCase()
48 {
49 }
50
51 namespace {
52 /**
53 * @tc.name: SendCmd_001
54 * @tc.desc: 1. set cmdCode not null
55 * 2. set remoteObject nullptr
56 * 3. call IpcClientServerProxy SendCmd
57 * 4. check ret is DEVICEMANAGER_NULLPTR
58 * @tc.type: FUNC
59 * @tc.require: AR000GHSJK
60 */
61 HWTEST_F(IpcClientServerProxyTest, SendCmd_001, testing::ext::TestSize.Level0)
62 {
63 // 1. set cmdCode not null
64 int32_t cmdCode = 1;
65 // 2. set remoteObject nullptr
66 sptr<IRemoteObject> remoteObject = nullptr;
67 // 3. call IpcClientServerProxy SendCmd
68 auto instance = new IpcClientServerProxy(remoteObject);
69 int ret = instance->SendCmd(cmdCode, nullptr, nullptr);
70 // 4. check ret is DEVICEMANAGER_NULLPTR
71 ASSERT_EQ(ret, ERR_DM_POINT_NULL);
72 }
73
74 /**
75 * @tc.name: SendCmd_002
76 * @tc.type: FUNC
77 */
78 HWTEST_F(IpcClientServerProxyTest, SendCmd_002, testing::ext::TestSize.Level0)
79 {
80 int32_t cmdCode = IPC_MSG_BUTT;
81 sptr<IRemoteObject> remoteObject = nullptr;
82 auto instance = new IpcClientServerProxy(remoteObject);
83 int ret = instance->SendCmd(cmdCode, nullptr, nullptr);
84 ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
85 }
86
87 /**
88 * @tc.name: SendCmd_003
89 * @tc.type: FUNC
90 */
91 HWTEST_F(IpcClientServerProxyTest, SendCmd_003, testing::ext::TestSize.Level0)
92 {
93 int32_t cmdCode = 1;
94 sptr<IRemoteObject> remoteObject = sptr<IpcClientStub>(new IpcClientStub());
95 std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
96 std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
97 auto instance = new IpcClientServerProxy(remoteObject);
98 int ret = instance->SendCmd(cmdCode, req, rsp);
99 ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED);
100 }
101
102 /**
103 * @tc.name: SendCmd_004
104 * @tc.type: FUNC
105 */
106 HWTEST_F(IpcClientServerProxyTest, SendCmd_004, testing::ext::TestSize.Level0)
107 {
108 int32_t cmdCode = -1;
109 sptr<IRemoteObject> remoteObject = nullptr;
110 auto instance = new IpcClientServerProxy(remoteObject);
111 int ret = instance->SendCmd(cmdCode, nullptr, nullptr);
112 ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
113 }
114 } // namespace
115 } // namespace DistributedHardware
116 } // namespace OHOS
117