1 /* 2 * Copyright (C) 2023 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 "wifi_event_handler_test.h" 17 18 using namespace testing::ext; 19 20 namespace OHOS { 21 namespace Wifi { 22 int WifiEventHandlerTest::result = 0; 23 const std::string g_errLog = "wifitest"; 24 HWTEST_F(WifiEventHandlerTest, PostSyncTaskTest, TestSize.Level1) 25 { 26 std::function<void()> callback = EventHandlerCallback; 27 result = 0; 28 EXPECT_EQ(testEventHandler->PostSyncTask(callback), true); 29 EXPECT_EQ(result, 1); 30 } 31 32 HWTEST_F(WifiEventHandlerTest, PostAsyncTaskTest, TestSize.Level1) 33 { 34 std::function<void()> callback = EventHandlerCallback; 35 result = 0; 36 EXPECT_EQ(testEventHandler->PostAsyncTask(callback, 0), true); 37 sleep(1); 38 EXPECT_EQ(result, 1); 39 } 40 41 HWTEST_F(WifiEventHandlerTest, PostAsyncTaskAndNameTest, TestSize.Level1) 42 { 43 std::function<void()> callback = EventHandlerCallback; 44 result = 0; 45 EXPECT_EQ(testEventHandler->PostAsyncTask(callback, "callback"), true); 46 sleep(1); 47 EXPECT_EQ(result, 1); 48 } 49 50 HWTEST_F(WifiEventHandlerTest, PostAsyncTaskWithHigerPriorityAndNameTest, TestSize.Level1) 51 { 52 std::function<void()> callback = EventHandlerCallback; 53 result = 0; 54 EXPECT_EQ(testEventHandler->PostAsyncTask(callback, "callback", true), true); 55 sleep(1); 56 EXPECT_EQ(result, 1); 57 } 58 59 HWTEST_F(WifiEventHandlerTest, RemoveAsyncTaskTest, TestSize.Level1) 60 { 61 testEventHandler->RemoveAsyncTask("callback"); 62 EXPECT_FALSE(g_errLog.find("processWiTasDecisiveMessage")!=std::string::npos); 63 } 64 65 HWTEST_F(WifiEventHandlerTest, PostSyncTimeOutTaskTest, TestSize.Level1) 66 { 67 std::function<void()> callback = EventHandlerCallback; 68 EXPECT_EQ(WifiEventHandler::PostSyncTimeOutTask(EventHandlerCallback), true); 69 } 70 } // namespace Wifi 71 } // namespace OHOS