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 "locator_agent_test.h"
17 #include "accesstoken_kit.h"
18 #include "nativetoken_kit.h"
19 #include "token_setproc.h"
20 #include "locator.h"
21 #include "permission_manager.h"
22
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace Location {
26 const int32_t LOCATION_PERM_NUM = 5;
SetUp()27 void LocatorAgentManagerTest::SetUp()
28 {
29 MockNativePermission();
30 }
31
TearDown()32 void LocatorAgentManagerTest::TearDown()
33 {
34 }
35
MockNativePermission()36 void LocatorAgentManagerTest::MockNativePermission()
37 {
38 const char *perms[] = {
39 ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(),
40 ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(),
41 ACCESS_CONTROL_LOCATION_SWITCH.c_str(),
42 };
43 NativeTokenInfoParams infoInstance = {
44 .dcapsNum = 0,
45 .permsNum = LOCATION_PERM_NUM,
46 .aclsNum = 0,
47 .dcaps = nullptr,
48 .perms = perms,
49 .acls = nullptr,
50 .processName = "LocatorAgentManagerTest",
51 .aplStr = "system_basic",
52 };
53 tokenId_ = GetAccessTokenId(&infoInstance);
54 SetSelfTokenID(tokenId_);
55 Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
56 }
57
58 HWTEST_F(LocatorAgentManagerTest, StartGnssLocatingTest001, TestSize.Level0)
59 {
60 GTEST_LOG_(INFO)
61 << "LocatorAgentManagerTest, StartGnssLocatingTest001, TestSize.Level0";
62 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] StartGnssLocatingTest001 begin");
63 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
64 static OHOS::Location::LocationCallbackIfaces locationCallback;
65 locatorAgentManager->StartGnssLocating(locationCallback);
66 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] StartGnssLocatingTest001 end");
67 }
68
69 HWTEST_F(LocatorAgentManagerTest, StopGnssLocatingTest001, TestSize.Level0)
70 {
71 GTEST_LOG_(INFO)
72 << "LocatorAgentManagerTest, StopGnssLocatingTest001, TestSize.Level0";
73 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] StopGnssLocatingTest001 begin");
74 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
75 locatorAgentManager->StopGnssLocating();
76 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] StopGnssLocatingTest001 end");
77 }
78
79 HWTEST_F(LocatorAgentManagerTest, RegisterGnssStatusCallbackTest001, TestSize.Level1)
80 {
81 GTEST_LOG_(INFO)
82 << "LocatorAgentManagerTest, RegisterGnssStatusCallbackTest001, TestSize.Level1";
83 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] RegisterGnssStatusCallbackTest001 begin");
84 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
85 static OHOS::Location::SvStatusCallbackIfaces svCallback;
86 locatorAgentManager->RegisterGnssStatusCallback(svCallback);
87 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] RegisterGnssStatusCallbackTest001 end");
88 }
89
90 HWTEST_F(LocatorAgentManagerTest, UnregisterGnssStatusCallbackTest001, TestSize.Level1)
91 {
92 GTEST_LOG_(INFO)
93 << "LocatorAgentManagerTest, UnregisterGnssStatusCallbackTest001, TestSize.Level1";
94 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] UnregisterGnssStatusCallbackTest001 begin");
95 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
96 locatorAgentManager->UnregisterGnssStatusCallback();
97 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] UnregisterGnssStatusCallbackTest001 end");
98 }
99
100 HWTEST_F(LocatorAgentManagerTest, RegisterNmeaMessageCallbackTest001, TestSize.Level1)
101 {
102 GTEST_LOG_(INFO)
103 << "LocatorAgentTest, RegisterNmeaMessageCallbackTest001, TestSize.Level1";
104 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] RegisterNmeaMessageCallbackTest001 begin");
105 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
106 static OHOS::Location::GnssNmeaCallbackIfaces nmeaCallback;
107 locatorAgentManager->RegisterNmeaMessageCallback(nmeaCallback);
108 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] RegisterNmeaMessageCallbackTest001 end");
109 }
110
111 HWTEST_F(LocatorAgentManagerTest, UnregisterNmeaMessageCallbackTest001, TestSize.Level1)
112 {
113 GTEST_LOG_(INFO)
114 << "LocatorAgentManagerTest, UnregisterNmeaMessageCallbackTest001, TestSize.Level1";
115 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] UnregisterNmeaMessageCallbackTest001 begin");
116 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
117 locatorAgentManager->UnregisterNmeaMessageCallback();
118 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] UnregisterNmeaMessageCallbackTest001 end");
119 }
120
121 HWTEST_F(LocatorAgentManagerTest, GetLocatorAgentTest001, TestSize.Level1)
122 {
123 GTEST_LOG_(INFO)
124 << "LocatorAgentManagerTest, GetLocatorAgentTest001, TestSize.Level1";
125 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] GetLocatorAgentTest001 begin");
126 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
127 locatorAgentManager->GetLocatorAgent();
128 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] GetLocatorAgentTest001 end");
129 }
130
131 HWTEST_F(LocatorAgentManagerTest, TryLoadLocatorSystemAbilityTest001, TestSize.Level1)
132 {
133 GTEST_LOG_(INFO)
134 << "LocatorAgentManagerTest, TryLoadLocatorSystemAbilityTest001, TestSize.Level1";
135 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] TryLoadLocatorSystemAbilityTest001 begin");
136 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
137 locatorAgentManager->TryLoadLocatorSystemAbility();
138 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] TryLoadLocatorSystemAbilityTest001 end");
139 }
140
141 HWTEST_F(LocatorAgentManagerTest, InitLocatorAgentTest001, TestSize.Level1)
142 {
143 GTEST_LOG_(INFO)
144 << "LocatorAgentManagerTest, InitLocatorAgentTest001, TestSize.Level1";
145 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] InitLocatorAgentTest001 begin");
146 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
147 sptr<IRemoteObject> saObject = locatorAgentManager->CheckLocatorSystemAbilityLoaded();
148 locatorAgentManager->InitLocatorAgent(saObject);
149 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] InitLocatorAgentTest001 end");
150 }
151
152 HWTEST_F(LocatorAgentManagerTest, ResetLocatorAgentTest001, TestSize.Level1)
153 {
154 GTEST_LOG_(INFO)
155 << "LocatorAgentManagerTest, ResetLocatorAgentTest001, TestSize.Level1";
156 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] ResetLocatorAgentTest001 begin");
157 auto locatorAgentManager = std::make_shared<LocatorAgentManager>();
158 sptr<IRemoteObject> saObject = locatorAgentManager->CheckLocatorSystemAbilityLoaded();
159 locatorAgentManager->ResetLocatorAgent(saObject);
160 LBSLOGI(LOCATOR_STANDARD, "[LocatorAgentManagerTest] ResetLocatorAgentTest001 end");
161 }
162 } // namespace Location
163 } // namespace OHOS