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