• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #define private public
19 #include "net_policy_service.h"
20 
21 namespace OHOS {
22 namespace NetManagerStandard {
23 namespace {
24 using namespace testing::ext;
25 } // namespace
26 
27 class NetPolicyExceptionServiceUt : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase()35 void NetPolicyExceptionServiceUt::SetUpTestCase() {}
36 
TearDownTestCase()37 void NetPolicyExceptionServiceUt::TearDownTestCase() {}
38 
SetUp()39 void NetPolicyExceptionServiceUt::SetUp() {}
40 
TearDown()41 void NetPolicyExceptionServiceUt::TearDown() {}
42 
43 /**
44  * @tc.name: IsUidNetAllowed
45  * @tc.desc: Test NetPolicyService IsUidNetAllowed.
46  * @tc.type: FUNC
47  */
48 HWTEST_F(NetPolicyExceptionServiceUt, IsUidNetAllowed, TestSize.Level1)
49 {
50     int uit = 1000;
51     bool metered = false;
52     bool isAllowed = false;
53     int32_t ret = DelayedSingleton<NetPolicyService>::GetInstance()->IsUidNetAllowed(uit, metered, isAllowed);
54     EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
55 }
56 
57 /**
58  * @tc.name: RegisterNetPolicyCallback
59  * @tc.desc: Test NetPolicyService RegisterNetPolicyCallback.
60  * @tc.type: FUNC
61  */
62 HWTEST_F(NetPolicyExceptionServiceUt, RegisterNetPolicyCallback, TestSize.Level1)
63 {
64     int32_t ret = DelayedSingleton<NetPolicyService>::GetInstance()->RegisterNetPolicyCallback(nullptr);
65     EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
66 }
67 
68 /**
69  * @tc.name: UnregisterNetPolicyCallback
70  * @tc.desc: Test NetPolicyService UnregisterNetPolicyCallback.
71  * @tc.type: FUNC
72  */
73 HWTEST_F(NetPolicyExceptionServiceUt, UnregisterNetPolicyCallback, TestSize.Level1)
74 {
75     int32_t ret = DelayedSingleton<NetPolicyService>::GetInstance()->UnregisterNetPolicyCallback(nullptr);
76     EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
77 }
78 } // namespace NetManagerStandard
79 } // namespace OHOS