1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
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
18 #include "plugin_service.ipc.h"
19 #include "socket_context.h"
20
21 using namespace testing::ext;
22 namespace {
23 uint32_t g_pluginId;
24
25 class PluginClient final : public IPluginServiceClient {
26 public:
27 bool OnRegisterPluginResponse(SocketContext& context, ::RegisterPluginResponse& response) override
28 {
29 g_pluginId = response.plugin_id();
30 return true;
31 }
32 bool OnUnregisterPluginResponse(SocketContext& context, ::UnregisterPluginResponse& response) override
33 {
34 return true;
35 }
36 bool OnGetCommandResponse(SocketContext& context, ::GetCommandResponse& response) override
37 {
38 return true;
39 }
40 bool OnNotifyResultResponse(SocketContext& context, ::NotifyResultResponse& response) override
41 {
42 return true;
43 }
44 };
45
46 std::unique_ptr<PluginClient> g_pluginClient;
47
48 class ModuleTestPluginService : public testing::Test {
49 public:
SetUpTestCase()50 static void SetUpTestCase()
51 {
52 g_pluginClient = std::make_unique<PluginClient>();
53 ASSERT_FALSE(g_pluginClient->Connect("test"));
54 }
55
TearDownTestCase()56 static void TearDownTestCase()
57 {
58 usleep(1000000); // sleep 1000000 us.
59 g_pluginClient = nullptr;
60 }
SetUp()61 void SetUp() {}
TearDown()62 void TearDown() {}
63 };
64
HWTEST_F(ModuleTestPluginService, RegisterPlugin, TestSize.Level1)65 HWTEST_F(ModuleTestPluginService, RegisterPlugin, TestSize.Level1)
66 {
67 RegisterPluginRequest request;
68 RegisterPluginResponse response;
69
70 request.set_request_id(1);
71 request.set_path("abc.so");
72 request.set_sha256("ADSFAFASFASFASF");
73 request.set_name("abc.so");
74 ASSERT_TRUE(response.status() != ResponseStatus::OK);
75 g_pluginId = response.plugin_id();
76 }
77 } // namespace