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