1 /*
2 * Copyright (c) 2022 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 <gtest/gtest.h>
17
18 #include "net_conn_event_handler.h"
19
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 using namespace testing::ext;
__anone2e50d3a0202() 24 NetConnEventHandler::Callback g_testCallback = []() { std::cout << "Run event task" << std::endl; };
25 constexpr int64_t TEST_DELAY_TIME = 112;
26 constexpr const char *TEST_TASK_NAME = "test_task";
27 constexpr const char *TEST_RUNNER_CREATE = "RUNNER_CREATE";
28 } // namespace
29
30 class NetConnEventHandlerTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp();
35 void TearDown();
36 static inline std::shared_ptr<AppExecFwk::EventRunner> runner_ =
37 AppExecFwk::EventRunner::Create(TEST_RUNNER_CREATE);
38 static inline std::shared_ptr<NetConnEventHandler> instance_ = std::make_shared<NetConnEventHandler>(runner_);
39 };
40
SetUpTestCase()41 void NetConnEventHandlerTest::SetUpTestCase() {}
42
TearDownTestCase()43 void NetConnEventHandlerTest::TearDownTestCase() {}
44
SetUp()45 void NetConnEventHandlerTest::SetUp() {}
46
TearDown()47 void NetConnEventHandlerTest::TearDown() {}
48
49 HWTEST_F(NetConnEventHandlerTest, PostAsyncTaskTest001, TestSize.Level1)
50 {
51 bool ret = instance_->PostAsyncTask(g_testCallback, TEST_DELAY_TIME);
52 EXPECT_TRUE(ret);
53 }
54
55 HWTEST_F(NetConnEventHandlerTest, PostAsyncTaskTest002, TestSize.Level1)
56 {
57 bool ret = instance_->PostAsyncTask(g_testCallback, TEST_TASK_NAME, TEST_DELAY_TIME);
58 EXPECT_TRUE(ret);
59 }
60
61 HWTEST_F(NetConnEventHandlerTest, RemoveAsyncTaskTest001, TestSize.Level1)
62 {
63 instance_->RemoveAsyncTask(TEST_TASK_NAME);
64 }
65 } // namespace NetManagerStandard
66 } // namespace OHOS