• 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 #ifdef GTEST_API_
19 #define private public
20 #endif
21 #include "net_manager_constants.h"
22 #include "net_policy_service_common.h"
23 #include "net_settings.h"
24 #include "net_policy_service.h"
25 
26 namespace OHOS {
27 namespace NetManagerStandard {
28 namespace {
29 using namespace testing::ext;
30 } // namespace
31 
32 class UtNetPolicyServiceCommonTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp();
37     void TearDown();
38     static inline auto instance_ = std::make_shared<NetPolicyServiceCommon>();
39 };
40 
SetUpTestCase()41 void UtNetPolicyServiceCommonTest::SetUpTestCase() {}
42 
TearDownTestCase()43 void UtNetPolicyServiceCommonTest::TearDownTestCase() {}
44 
SetUp()45 void UtNetPolicyServiceCommonTest::SetUp() {}
46 
TearDown()47 void UtNetPolicyServiceCommonTest::TearDown() {}
48 
49 HWTEST_F(UtNetPolicyServiceCommonTest, ResetPoliciesTest001, TestSize.Level1)
50 {
51     auto ret = instance_->ResetPolicies();
52     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
53 }
54 
55 HWTEST_F(UtNetPolicyServiceCommonTest, ResetPoliciesTest002, TestSize.Level1)
56 {
57     DelayedSingleton<NetPolicyService>::GetInstance()->netPolicyRule_ = nullptr;
58     auto ret = instance_->ResetPolicies();
59     EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
60 }
61 
62 HWTEST_F(UtNetPolicyServiceCommonTest, IsUidNetAllowedTest001, TestSize.Level1)
63 {
64     uint32_t uid = 1251;
65     bool metered = true;
66     NetSettings::GetInstance().AddSystemUid(uid);
67     auto ret = instance_->IsUidNetAllowed(uid, metered);
68     EXPECT_TRUE(ret);
69 }
70 } // namespace NetManagerStandard
71 } // namespace OHOS