• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #include "gtest/gtest.h"
16 #include "cellular_data_error.h"
17 #include "net_all_capabilities.h"
18 #include "net_manager_call_back.h"
19 
20 namespace OHOS {
21 namespace Telephony {
22 using namespace testing::ext;
23 
24 class NetManagerCallBackTest : public testing::Test {
25 public:
SetUpTestCase()26     static void SetUpTestCase() {}
TearDownTestCase()27     static void TearDownTestCase() {}
SetUp()28     void SetUp() {}
TearDown()29     void TearDown() {}
30 };
31 
32 /**
33  * @tc.number   RequestNetwork_001
34  * @tc.name     Test NetManagerCallBack RequestNetwork
35  * @tc.desc     RequestNetwork ipc
36  */
37 HWTEST_F(NetManagerCallBackTest, RequestNetwork_001, TestSize.Level3)
38 {
39     auto netManagerCallBack = std::make_shared<NetManagerCallBack>();
40     NetManagerStandard::NetRequest request;
41     std::string ident = "testIdent";
42     std::set<NetManagerStandard::NetCap> netCaps = {};
43     int32_t result = netManagerCallBack->RequestNetwork(ident, netCaps, request);
44     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
45     netCaps.insert(NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET);
46     result = netManagerCallBack->RequestNetwork(ident, netCaps, request);
47     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
48 }
49 
50 /**
51  * @tc.number   ReleaseNetwork_001
52  * @tc.name     Test NetManagerCallBack ReleaseNetwork
53  * @tc.desc     ReleaseNetwork ipc
54  */
55 HWTEST_F(NetManagerCallBackTest, ReleaseNetwork_001, TestSize.Level3)
56 {
57     auto netManagerCallBack = std::make_shared<NetManagerCallBack>();
58     NetManagerStandard::NetRequest request;
59     request.ident = "testIdent";
60     int32_t result = netManagerCallBack->ReleaseNetwork(request);
61     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
62     request.netCaps.insert(NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET);
63     result = netManagerCallBack->ReleaseNetwork(request);
64     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
65 }
66 
67 /**
68  * @tc.number   AddRequest_001
69  * @tc.name     Test NetManagerCallBack AddRequest
70  * @tc.desc     Add Request and uid
71  */
72 HWTEST_F(NetManagerCallBackTest, AddRequest_001, TestSize.Level3)
73 {
74     auto netManagerCallBack = std::make_shared<NetManagerCallBack>();
75     NetManagerStandard::NetRequest request;
76     request.ident = "testIdent";
77     int32_t result = netManagerCallBack->AddRequest(request);
78     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
79     request.netCaps.insert(NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET);
80     result = netManagerCallBack->AddRequest(request);
81     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
82 }
83 }
84 }