• 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 #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
51     GTEST_LOG_(INFO)
52         << "PeripheralAGnssTest, SetAgnssCallbackTest001, TestSize.Level1";
53     EXPECT_NE(nullptr, agnssInstance_);
54     int32_t ret = 0;
55     if (agnssInstance_ != nullptr) {
56         sptr<ISystemAbilityManager> samgr =
57             SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
58         sptr<IRemoteObject> saObject = samgr->CheckSystemAbility(LOCATION_LOCATOR_SA_ID);
59 
60         auto callbackObj2 = new (std::nothrow) AgnssEventCallbackMock(saObject);
61         ret = agnssInstance_->SetAgnssCallback(callbackObj2);
62     }
63 #endif
64 }
65 
66 HWTEST_F(PeripheralAGnssTest, RequestSetupAgnssDataConnectionTest001, TestSize.Level1)
67 {
68     GTEST_LOG_(INFO)
69         << "PeripheralAGnssTest, RequestSetupAgnssDataConnectionTest001, TestSize.Level1";
70     EXPECT_NE(nullptr, agnssInstance_);
71     GetSetidCb(0);
72     RequestSetupAgnssDataConnection(nullptr);
73     AgnssDataConnectionRequest status;
74     status.agnssCategory = 1;
75     status.requestCategory = 2;
76     RequestSetupAgnssDataConnection(&status);
77 
78     int32_t ret = 0;
79     sptr<ISystemAbilityManager> samgr =
80         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
81     sptr<IRemoteObject> saObject = samgr->CheckSystemAbility(LOCATION_LOCATOR_SA_ID);
82 
83     auto callbackObj2 = new (std::nothrow) AgnssEventCallbackMock(saObject);
84     ret = agnssInstance_->SetAgnssCallback(callbackObj2);
85 
86     GetSetidCb(0);
87     RequestSetupAgnssDataConnection(&status);
88 }
89 
90 HWTEST_F(PeripheralAGnssTest, SetAgnssServerTest001, TestSize.Level1)
91 {
92     GTEST_LOG_(INFO)
93         << "PeripheralAGnssTest, SetAgnssServerTest001, TestSize.Level1";
94     EXPECT_NE(nullptr, agnssInstance_);
95     if (agnssInstance_ != nullptr) {
96         AGnssServerInfo server;
97         server.type = AGNSS_TYPE_SUPL;
98         server.port = 8700;
99         int32_t ret = agnssInstance_->SetAgnssServer(server);
100         EXPECT_EQ(HDF_SUCCESS, ret);
101     }
102 }
103 
104 HWTEST_F(PeripheralAGnssTest, SetAgnssRefInfoTest001, TestSize.Level1)
105 {
106     GTEST_LOG_(INFO)
107         << "PeripheralAGnssTest, SetAgnssRefInfoTest001, TestSize.Level1";
108     EXPECT_NE(nullptr, agnssInstance_);
109     AGnssRefInfo refInfo;
110     refInfo.type = HDI::Location::Agnss::V2_0::ANSS_REF_INFO_TYPE_CELLID;
111     refInfo.mac.mac = {2, 2, 2, 2, 21, 1};
112     if (agnssInstance_ != nullptr) {
113         GetRefLocationidCb(2);
114         agnssInstance_->SetAgnssRefInfo(refInfo);
115         GetRefLocationidCb(1);
116         refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_GSM;
117         agnssInstance_->SetAgnssRefInfo(refInfo);
118         refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_UMTS;
119         agnssInstance_->SetAgnssRefInfo(refInfo);
120         refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_NR;
121         agnssInstance_->SetAgnssRefInfo(refInfo);
122         refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_LTE;
123         agnssInstance_->SetAgnssRefInfo(refInfo);
124     }
125 }
126 
127 HWTEST_F(PeripheralAGnssTest, SetSubscriberSetIdTest001, TestSize.Level1)
128 {
129     GTEST_LOG_(INFO)
130         << "PeripheralAGnssTest, SetSubscriberSetIdTest001, TestSize.Level1";
131     EXPECT_NE(nullptr, agnssInstance_);
132     SubscriberSetId setId;
133     setId.type = HDI::Location::Agnss::V2_0::AGNSS_SETID_TYPE_IMSI;
134     if (agnssInstance_ != nullptr) {
135         agnssInstance_->SetSubscriberSetId(setId);
136     }
137 }
138 
139 HWTEST_F(PeripheralAGnssTest, ResetAgnssTest001, TestSize.Level1)
140 {
141     GTEST_LOG_(INFO)
142         << "PeripheralAGnssTest, ResetAgnssTest001, TestSize.Level1";
143     EXPECT_NE(nullptr, agnssInstance_);
144     agnssInstance_->ResetAgnss();
145 }
146 
147 } // V2_0
148 } // Gnss
149 } // Location
150 } // HDI
151 } // OHOS
152