• 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_settings.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 using namespace testing::ext;
24 constexpr uint32_t TEST_UID = 1001;
25 constexpr uint32_t TEST_UID_MAX = 666;
26 } // namespace
27 
28 class NetSettingsTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp();
33     void TearDown();
34     static inline NetSettings &instance_ = NetSettings::GetInstance();
35 };
36 
SetUpTestCase()37 void NetSettingsTest::SetUpTestCase()
38 {
39     for (uint32_t i = 0; i < TEST_UID_MAX; i++) {
40         instance_.AddSystemUid(i);
41     }
42 }
43 
TearDownTestCase()44 void NetSettingsTest::TearDownTestCase() {}
45 
SetUp()46 void NetSettingsTest::SetUp() {}
47 
TearDown()48 void NetSettingsTest::TearDown() {}
49 
50 HWTEST_F(NetSettingsTest, ConstructorTest001, TestSize.Level1)
51 {
52     std::unique_ptr<NetSettings> settings = std::make_unique<NetSettings>();
53     ASSERT_NE(settings, nullptr);
54 }
55 
56 HWTEST_F(NetSettingsTest, IsUidForegroundTest001, TestSize.Level1)
57 {
58     bool ret = instance_.IsUidForeground(TEST_UID);
59     ASSERT_FALSE(ret);
60 }
61 
62 HWTEST_F(NetSettingsTest, IsUidForegroundTest002, TestSize.Level1)
63 {
64     uint32_t testUid = 1111;
65     instance_.SetForegroundUid(testUid);
66     bool ret = instance_.IsUidForeground(testUid);
67     ASSERT_TRUE(ret);
68 }
69 
70 HWTEST_F(NetSettingsTest, IsSystemTest001, TestSize.Level1) {
71     uint32_t testSysUid = 500;
72     bool ret = instance_.IsSystem(testSysUid);
73     ASSERT_TRUE(ret);
74 }
75 
76 HWTEST_F(NetSettingsTest, IsSystemTest002, TestSize.Level1) {
77     bool ret = instance_.IsSystem(TEST_UID);
78     ASSERT_FALSE(ret);
79 }
80 
81 HWTEST_F(NetSettingsTest, RemoveSystemUidTest001, TestSize.Level1)
82 {
83     uint32_t testSysUid = 100;
84     instance_.RemoveSystemUid(testSysUid);
85     bool ret = instance_.IsSystem(testSysUid);
86     ASSERT_FALSE(ret);
87 }
88 
89 HWTEST_F(NetSettingsTest, RouteUtilsBranchTest001, TestSize.Level1)
90 {
91     uint32_t testSysUid = 0;
92     instance_.RemoveSystemUid(testSysUid);
93     bool ret = instance_.IsSystem(testSysUid);
94     ASSERT_FALSE(ret);
95 }
96 } // namespace NetManagerStandard
97 } // namespace OHOS