• 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 "hook_service.h"
20 #include "hook_socket_client.h"
21 #include "socket_context.h"
22 #include "share_memory_allocator.h"
23 #include "event_notifier.h"
24 
25 using namespace testing::ext;
26 
27 namespace {
28 const int SLEEP_TIME = 30000;
29 
30 class HookServiceTest : public ::testing::Test {
31 public:
SetUpTestCase()32     static void SetUpTestCase() {}
TearDownTestCase()33     static void TearDownTestCase() {}
SetUp()34     void SetUp() {}
TearDown()35     void TearDown() {}
36 };
37 
38 /*
39  * @tc.name: ProtocolProc
40  * @tc.desc: test HookService::ProtocolProc with normal case.
41  * @tc.type: FUNC
42  */
43 HWTEST_F(HookServiceTest, ProtocolProc, TestSize.Level1)
44 {
45     auto shareMemoryBlock = ShareMemoryAllocator::GetInstance().CreateMemoryBlockLocal("hooknativesmb", 4096);
46     ASSERT_TRUE(shareMemoryBlock != nullptr);
47     auto eventNotifier = EventNotifier::Create(0, EventNotifier::NONBLOCK);
48     ASSERT_TRUE(eventNotifier != nullptr);
49     int smbFd = shareMemoryBlock->GetfileDescriptor();
50     int eventFd = eventNotifier->GetFd();
51     SocketContext socketContext;
52     std::vector<unsigned char> buf(4096);
53     struct ProtocolHead* pph = (struct ProtocolHead*)buf.data();
54     uint32_t head_size = sizeof(struct ProtocolHead);
55     auto hookService = std::make_shared<HookService>(smbFd, eventFd, 0, "", 0);
56     ASSERT_TRUE(hookService != nullptr);
57     ASSERT_TRUE(hookService->ProtocolProc(socketContext, 0, pph->datas, head_size));
58 }
59 } // namespace
60