1d9f0492fSopenharmony_ci/* 2d9f0492fSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3d9f0492fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4d9f0492fSopenharmony_ci * you may not use this file except in compliance with the License. 5d9f0492fSopenharmony_ci * You may obtain a copy of the License at 6d9f0492fSopenharmony_ci * 7d9f0492fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8d9f0492fSopenharmony_ci * 9d9f0492fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10d9f0492fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11d9f0492fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12d9f0492fSopenharmony_ci * See the License for the specific language governing permissions and 13d9f0492fSopenharmony_ci * limitations under the License. 14d9f0492fSopenharmony_ci */ 15d9f0492fSopenharmony_ci 16d9f0492fSopenharmony_ci#include <cerrno> 17d9f0492fSopenharmony_ci#include <cstdio> 18d9f0492fSopenharmony_ci#include "init_unittest.h" 19d9f0492fSopenharmony_ci#include "init.h" 20d9f0492fSopenharmony_ci#include "loop_event.h" 21d9f0492fSopenharmony_ci#include "le_epoll.h" 22d9f0492fSopenharmony_ci#include "le_signal.h" 23d9f0492fSopenharmony_ci#include "init_hashmap.h" 24d9f0492fSopenharmony_ci 25d9f0492fSopenharmony_ciusing namespace testing::ext; 26d9f0492fSopenharmony_ciusing namespace std; 27d9f0492fSopenharmony_ci 28d9f0492fSopenharmony_cistatic SignalHandle g_sigHandler = nullptr; 29d9f0492fSopenharmony_ci 30d9f0492fSopenharmony_cistatic void TestProcessSignal(const struct signalfd_siginfo *siginfo) 31d9f0492fSopenharmony_ci{ 32d9f0492fSopenharmony_ci return; 33d9f0492fSopenharmony_ci} 34d9f0492fSopenharmony_ci 35d9f0492fSopenharmony_cinamespace init_ut { 36d9f0492fSopenharmony_ciclass LoopSignalUnitTest : public testing::Test { 37d9f0492fSopenharmony_cipublic: 38d9f0492fSopenharmony_ci static void SetUpTestCase(void) {}; 39d9f0492fSopenharmony_ci static void TearDownTestCase(void) {}; 40d9f0492fSopenharmony_ci void SetUp() {}; 41d9f0492fSopenharmony_ci void TearDown() {}; 42d9f0492fSopenharmony_ci}; 43d9f0492fSopenharmony_ci 44d9f0492fSopenharmony_ciHWTEST_F(LoopSignalUnitTest, Init_TestSignalInitTestRmSig_001, TestSize.Level1) 45d9f0492fSopenharmony_ci{ 46d9f0492fSopenharmony_ci static LoopHandle loopClient = nullptr; 47d9f0492fSopenharmony_ci LE_STATUS status = LE_CreateLoop(&loopClient); 48d9f0492fSopenharmony_ci EXPECT_EQ(status, 0); 49d9f0492fSopenharmony_ci LE_CreateSignalTask(loopClient, &g_sigHandler, TestProcessSignal); 50d9f0492fSopenharmony_ci ASSERT_NE(g_sigHandler, nullptr); 51d9f0492fSopenharmony_ci int ret = LE_AddSignal(loopClient, g_sigHandler, SIGUSR1); 52d9f0492fSopenharmony_ci ASSERT_EQ(ret, 0); 53d9f0492fSopenharmony_ci LE_AddSignal(loopClient, g_sigHandler, SIGUSR1); 54d9f0492fSopenharmony_ci LE_AddSignal(loopClient, g_sigHandler, SIGUSR2); 55d9f0492fSopenharmony_ci ret = LE_RemoveSignal(loopClient, g_sigHandler, SIGUSR1); 56d9f0492fSopenharmony_ci ASSERT_EQ(ret, 0); 57d9f0492fSopenharmony_ci LE_RemoveSignal(loopClient, g_sigHandler, SIGUSR1); 58d9f0492fSopenharmony_ci LE_RemoveSignal(loopClient, g_sigHandler, SIGUSR2); 59d9f0492fSopenharmony_ci ((BaseTask *)g_sigHandler)->handleEvent(loopClient, (TaskHandle)&g_sigHandler, EVENT_WRITE); 60d9f0492fSopenharmony_ci LE_CloseSignalTask(loopClient, g_sigHandler); 61d9f0492fSopenharmony_ci ASSERT_EQ(ret, 0); 62d9f0492fSopenharmony_ci LE_StopLoop(loopClient); 63d9f0492fSopenharmony_ci LE_CloseLoop(loopClient); 64d9f0492fSopenharmony_ci loopClient = nullptr; 65d9f0492fSopenharmony_ci} 66d9f0492fSopenharmony_ci} 67