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