• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_policy_event_handler.h"
19 #include "net_policy_core.h"
20 
21 namespace OHOS {
22 namespace NetManagerStandard {
23 namespace {
24 using namespace testing::ext;
25 constexpr const char *NET_POLICY_WORK_TEST_THREAD = "NET_POLICY_WORK_TEST_THREAD";
26 std::shared_ptr<AppExecFwk::EventRunner> g_runner = nullptr;
27 std::shared_ptr<NetPolicyCore> g_netPolicyCore = nullptr;
28 } // namespace
29 
30 class UtNetPolicyEventHandlerTest : 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<NetPolicyEventHandler> instance_ = nullptr;
37 };
38 
SetUpTestCase()39 void UtNetPolicyEventHandlerTest::SetUpTestCase()
40 {
41     g_runner = AppExecFwk::EventRunner::Create(NET_POLICY_WORK_TEST_THREAD);
42     g_netPolicyCore = DelayedSingleton<NetPolicyCore>::GetInstance();
43     instance_ = std::make_shared<NetPolicyEventHandler>(g_runner, g_netPolicyCore);
44 }
45 
TearDownTestCase()46 void UtNetPolicyEventHandlerTest::TearDownTestCase() {}
47 
SetUp()48 void UtNetPolicyEventHandlerTest::SetUp() {}
49 
TearDown()50 void UtNetPolicyEventHandlerTest::TearDown() {}
51 
52 HWTEST_F(UtNetPolicyEventHandlerTest, ProcessEventTest001, TestSize.Level1)
53 {
54     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get();
55     event.reset();
56     instance_->ProcessEvent(event);
57 }
58 
59 HWTEST_F(UtNetPolicyEventHandlerTest, ProcessEventTest002, TestSize.Level1)
60 {
61     std::shared_ptr<NetPolicyCore> netPolicyCore = nullptr;
62     auto instance = std::make_shared<NetPolicyEventHandler>(g_runner, netPolicyCore);
63     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get();
64     instance->ProcessEvent(event);
65 }
66 
67 HWTEST_F(UtNetPolicyEventHandlerTest, ProcessEventTest003, TestSize.Level1)
68 {
69     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get();
70     instance_->ProcessEvent(event);
71 }
72 
73 } // namespace NetManagerStandard
74 } // namespace OHOS