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