• 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 "string_ex.h"
17 #include "iremote_object.h"
18 #include "if_system_ability_manager.h"
19 #include "iservice_registry.h"
20 #include "system_ability_definition.h"
21 #include "peripheral_agnss_test.h"
22 #include "agnss_interface_impl.h"
23 #include <iproxy_broker.h>
24 #include <v2_0/ia_gnss_callback.h>
25 
26 using namespace testing;
27 using namespace testing::ext;
28 using OHOS::HDI::Location::Agnss::V2_0::IAGnssCallback;
29 using OHOS::HDI::Location::Agnss::V2_0::AGNSS_TYPE_SUPL;
30 using OHOS::HDI::Location::Agnss::V2_0::AGnssServerInfo;
31 using OHOS::HDI::Location::Agnss::V2_0::AGnssRefInfo;
32 namespace OHOS {
33 namespace HDI {
34 namespace Location {
35 namespace Agnss {
36 namespace V2_0 {
37 
SetUp()38 void PeripheralAGnssTest::SetUp()
39 {
40     agnssInstance_ = new (std::nothrow) AGnssInterfaceImpl();
41 }
42 
TearDown()43 void PeripheralAGnssTest::TearDown()
44 {
45     agnssInstance_ = nullptr;
46 }
47 
48 HWTEST_F(PeripheralAGnssTest, SetAgnssCallbackTest001, TestSize.Level1)
49 {
50     GTEST_LOG_(INFO)
51         << "PeripheralAGnssTest, SetAgnssCallbackTest001, TestSize.Level1";
52     EXPECT_NE(nullptr, agnssInstance_);
53     if (agnssInstance_ != nullptr) {
54         sptr<ISystemAbilityManager> samgr =
55             SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
56         sptr<IRemoteObject> saObject = samgr->CheckSystemAbility(LOCATION_LOCATOR_SA_ID);
57 
58         auto callbackObj2 = new (std::nothrow) AgnssEventCallbackMock(saObject);
59         agnssInstance_->SetAgnssCallback(callbackObj2);
60     }
61 }
62 
63 HWTEST_F(PeripheralAGnssTest, RequestSetupAgnssDataConnectionTest001, TestSize.Level1)
64 {
65     GTEST_LOG_(INFO)
66         << "PeripheralAGnssTest, RequestSetupAgnssDataConnectionTest001, TestSize.Level1";
67     EXPECT_NE(nullptr, agnssInstance_);
68     GetSetidCb(0);
69     RequestSetupAgnssDataConnection(nullptr);
70     AgnssDataConnectionRequest status;
71     status.agnssCategory = 1;
72     status.requestCategory = 2;
73     RequestSetupAgnssDataConnection(&status);
74 
75     sptr<ISystemAbilityManager> samgr =
76         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
77     sptr<IRemoteObject> saObject = samgr->CheckSystemAbility(LOCATION_LOCATOR_SA_ID);
78 
79     auto callbackObj2 = new (std::nothrow) AgnssEventCallbackMock(saObject);
80     agnssInstance_->SetAgnssCallback(callbackObj2);
81 
82     GetSetidCb(0);
83     RequestSetupAgnssDataConnection(&status);
84 }
85 
86 HWTEST_F(PeripheralAGnssTest, SetAgnssServerTest001, TestSize.Level1)
87 {
88     GTEST_LOG_(INFO)
89         << "PeripheralAGnssTest, SetAgnssServerTest001, TestSize.Level1";
90 
91     EXPECT_NE(nullptr, agnssInstance_);
92     if (agnssInstance_ != nullptr) {
93         AGnssServerInfo server;
94         server.type = AGNSS_TYPE_SUPL;
95         server.port = 8700;
96         agnssInstance_->SetAgnssServer(server);
97     }
98 }
99 
100 HWTEST_F(PeripheralAGnssTest, SetAgnssRefInfoTest001, TestSize.Level1)
101 {
102     GTEST_LOG_(INFO)
103         << "PeripheralAGnssTest, SetAgnssRefInfoTest001, TestSize.Level1";
104 
105     EXPECT_NE(nullptr, agnssInstance_);
106     AGnssRefInfo refInfo;
107     refInfo.type = HDI::Location::Agnss::V2_0::ANSS_REF_INFO_TYPE_CELLID;
108     refInfo.mac.mac = {2, 2, 2, 2, 21, 1};
109     if (agnssInstance_ != nullptr) {
110         GetRefLocationidCb(2);
111         agnssInstance_->SetAgnssRefInfo(refInfo);
112         GetRefLocationidCb(1);
113         refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_GSM;
114         agnssInstance_->SetAgnssRefInfo(refInfo);
115         refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_UMTS;
116         agnssInstance_->SetAgnssRefInfo(refInfo);
117         refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_NR;
118         agnssInstance_->SetAgnssRefInfo(refInfo);
119         refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_LTE;
120         agnssInstance_->SetAgnssRefInfo(refInfo);
121     }
122 }
123 
124 HWTEST_F(PeripheralAGnssTest, SetSubscriberSetIdTest001, TestSize.Level1)
125 {
126     GTEST_LOG_(INFO)
127         << "PeripheralAGnssTest, SetSubscriberSetIdTest001, TestSize.Level1";
128 
129     EXPECT_NE(nullptr, agnssInstance_);
130     SubscriberSetId setId;
131     setId.type = HDI::Location::Agnss::V2_0::AGNSS_SETID_TYPE_IMSI;
132     if (agnssInstance_ != nullptr) {
133         agnssInstance_->SetSubscriberSetId(setId);
134     }
135 }
136 
137 HWTEST_F(PeripheralAGnssTest, ResetAgnssTest001, TestSize.Level1)
138 {
139     GTEST_LOG_(INFO)
140         << "PeripheralAGnssTest, ResetAgnssTest001, TestSize.Level1";
141 
142     agnssInstance_->ResetAgnss();
143     EXPECT_NE(nullptr, agnssInstance_);
144 }
145 
146 } // V2_0
147 } // Gnss
148 } // Location
149 } // HDI
150 } // OHOS
151