• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include <gmock/gmock.h>
18 
19 #include "dns_quality_event_handler.h"
20 #include "dns_quality_diag.h"
21 
22 namespace OHOS::nmd {
23 namespace {
24 using namespace testing::ext;
25 const char *DNS_DIAG_WORK_THREAD = "DNS_DIAG_WORK_THREAD";
26 }  // namespace
27 
28 class DnsQualityEventHandlerMock : public DnsQualityEventHandler {
29 public:
DnsQualityEventHandlerMock(const std::shared_ptr<AppExecFwk::EventRunner> & runner)30     explicit DnsQualityEventHandlerMock(const std::shared_ptr<AppExecFwk::EventRunner> &runner)
31         : DnsQualityEventHandler(runner)
32     {
33     }
34     MOCK_METHOD1(ProcessEvent, void(const AppExecFwk::InnerEvent::Pointer &event));
35 };
36 
37 class DnsQualityEventHandlerTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp();
42     void TearDown();
43 };
44 
SetUpTestCase()45 void DnsQualityEventHandlerTest::SetUpTestCase() {}
46 
TearDownTestCase()47 void DnsQualityEventHandlerTest::TearDownTestCase() {}
48 
SetUp()49 void DnsQualityEventHandlerTest::SetUp() {}
50 
TearDown()51 void DnsQualityEventHandlerTest::TearDown() {}
52 
53 HWTEST_F(DnsQualityEventHandlerTest, ProcessEvent_ShouldHandleEvent_WhenEventIsNotNull, TestSize.Level0)
54 {
55     std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(DNS_DIAG_WORK_THREAD);
56     DnsQualityEventHandler *dnsQualityEventHandler = new DnsQualityEventHandler(runner);
57     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get();
58     dnsQualityEventHandler->ProcessEvent(event);
59     EXPECT_NE(event.get(), nullptr);
60 }
61 
62 HWTEST_F(DnsQualityEventHandlerTest, ProcessEvent_ShouldNotHandleEvent_WhenEventIsNull, TestSize.Level0)
63 {
64     std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(DNS_DIAG_WORK_THREAD);
65     DnsQualityEventHandler *dnsQualityEventHandler = new DnsQualityEventHandler(runner);
66     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get();
67     event.reset();
68     dnsQualityEventHandler->ProcessEvent(event);
69     EXPECT_EQ(event.get(), nullptr);
70 }
71 
72 }  // namespace OHOS::nmd
73