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 "dns_result_call_back.h" 17 #include "net_manager_constants.h" 18 19 #include <fcntl.h> 20 #include <gtest/gtest.h> 21 #include <iostream> 22 #include <memory> 23 namespace OHOS { 24 namespace NetManagerStandard { 25 using namespace testing::ext; 26 namespace { 27 constexpr const int32_t TEST_NETID = 0; 28 constexpr const int32_t TEST_UID = 10000; 29 constexpr const int32_t TEST_PID = 1000; 30 constexpr const int32_t TEST_TIME = 500; 31 constexpr const int32_t TEST_PASS = 0; 32 constexpr const int32_t TEST_FAIL = -1; 33 constexpr const char *TEST_HOST = "www.test.com"; 34 35 class TestDnsResultCallback : public testing::Test { 36 public: 37 static void SetUpTestCase(); 38 static void TearDownTestCase(); 39 void SetUp(); 40 void TearDown(); 41 42 static inline std::shared_ptr<NetDnsResultCallback> instance_ = std::make_shared<NetDnsResultCallback>(); 43 }; 44 SetUpTestCase()45void TestDnsResultCallback::SetUpTestCase() {} 46 TearDownTestCase()47void TestDnsResultCallback::TearDownTestCase() {} 48 SetUp()49void TestDnsResultCallback::SetUp() {} 50 TearDown()51void TestDnsResultCallback::TearDown() {} 52 53 HWTEST_F(TestDnsResultCallback, OnDnsResultReportTest001, TestSize.Level1) 54 { 55 NetsysNative::NetDnsResultReport netDnsPassReport; 56 NetsysNative::NetDnsResultReport netDnsFailReport; 57 netDnsPassReport.netid_ = TEST_NETID; 58 netDnsPassReport.uid_ = TEST_UID; 59 netDnsPassReport.pid_ = TEST_PID; 60 netDnsPassReport.timeused_ = TEST_TIME; 61 netDnsPassReport.queryresult_ = TEST_PASS; 62 netDnsPassReport.host_ = TEST_HOST; 63 64 netDnsFailReport.netid_ = TEST_NETID; 65 netDnsFailReport.uid_ = TEST_UID; 66 netDnsFailReport.pid_ = TEST_PID; 67 netDnsFailReport.timeused_ = TEST_TIME; 68 netDnsFailReport.queryresult_ = TEST_FAIL; 69 netDnsFailReport.host_ = TEST_HOST; 70 71 std::list<NetsysNative::NetDnsResultReport> netDnsResultReport; 72 netDnsResultReport.push_back(netDnsPassReport); 73 netDnsResultReport.push_back(netDnsFailReport); 74 int32_t ret = instance_->OnDnsResultReport(netDnsResultReport.size(), netDnsResultReport); 75 EXPECT_EQ(ret, 0); 76 } 77 } // namespace 78 } // namespace NetManagerStandard 79 } // namespace OHOS 80