• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_event_manager_test.h"
17 
18 #include "event_handler.h"
19 #include "event_runner.h"
20 
21 #include "constant_definition.h"
22 #include "locator_event_manager.h"
23 #include "request.h"
24 #include "request_config.h"
25 
26 #include "location_log.h"
27 
28 using namespace testing::ext;
29 namespace OHOS {
30 namespace Location {
SetUp()31 void LocatorEventManagerTest::SetUp()
32 {
33 }
34 
TearDown()35 void LocatorEventManagerTest::TearDown()
36 {
37 }
38 
39 HWTEST_F(LocatorEventManagerTest, DftEventTest001, TestSize.Level1)
40 {
41     GTEST_LOG_(INFO)
42         << "LocatorEventManagerTest, DftEventTest001, TestSize.Level1";
43     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] DftEventTest001 begin");
44     std::unique_ptr<DftEvent> dftEvent = std::make_unique<DftEvent>();
45     EXPECT_NE(nullptr, dftEvent);
46     dftEvent->PutInt("name", 1);
47     EXPECT_EQ(1, dftEvent->GetInt("name"));
48     EXPECT_EQ(0, dftEvent->GetInt("name_not_exist"));
49     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] DftEventTest001 end");
50 }
51 
52 HWTEST_F(LocatorEventManagerTest, DftHandlerTest002, TestSize.Level1)
53 {
54     GTEST_LOG_(INFO)
55         << "LocatorEventManagerTest, DftHandlerTest002, TestSize.Level1";
56     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] DftHandlerTest002 begin");
57     std::shared_ptr<DftHandler> dftHandler =
58         std::make_shared<DftHandler>(AppExecFwk::EventRunner::Create(true));
59     EXPECT_NE(nullptr, dftHandler);
60     AppExecFwk::InnerEvent::Pointer event =
61         AppExecFwk::InnerEvent::Get(0, dftHandler, 0);
62     dftHandler->ProcessEvent(event); // empty func
63     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] DftHandlerTest002 end");
64 }
65 
66 HWTEST_F(LocatorEventManagerTest, LocatorDftManagerInitTest001, TestSize.Level1)
67 {
68     GTEST_LOG_(INFO)
69         << "LocatorEventManagerTest, LocatorDftManagerInitTest001, TestSize.Level1";
70     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocatorDftManagerInitTest001 begin");
71     auto locatorDftManager =
72         DelayedSingleton<LocatorDftManager>::GetInstance();
73     EXPECT_NE(nullptr, locatorDftManager);
74     locatorDftManager->Init();
75     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocatorDftManagerInitTest001 end");
76 }
77 
78 HWTEST_F(LocatorEventManagerTest, LocatorDftManagerIpcCallingErrTest001, TestSize.Level1)
79 {
80     GTEST_LOG_(INFO)
81         << "LocatorEventManagerTest, LocatorDftManagerIpcCallingErrTest001, TestSize.Level1";
82     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocatorDftManagerIpcCallingErrTest001 begin");
83     auto locatorDftManager =
84         DelayedSingleton<LocatorDftManager>::GetInstance();
85     EXPECT_NE(nullptr, locatorDftManager);
86     locatorDftManager->IpcCallingErr(0);
87     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocatorDftManagerIpcCallingErrTest001 end");
88 }
89 
90 HWTEST_F(LocatorEventManagerTest, LocationSessionStartTest001, TestSize.Level1)
91 {
92     GTEST_LOG_(INFO)
93         << "LocatorEventManagerTest, LocationSessionStartTest001, TestSize.Level1";
94     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocationSessionStartTest001 begin");
95     auto locatorDftManager =
96         DelayedSingleton<LocatorDftManager>::GetInstance();
97     EXPECT_NE(nullptr, locatorDftManager);
98     locatorDftManager->LocationSessionStart(nullptr);
99     std::shared_ptr<Request> request1 = std::make_shared<Request>();
100     request1->SetUid(1000);
101     request1->SetPid(0);
102     request1->SetTokenId(0);
103     request1->SetFirstTokenId(0);
104     request1->SetPackageName("LocatorEventManagerTest");
105     locatorDftManager->LocationSessionStart(request1); // no request config
106     auto requestConfig1 = std::make_unique<RequestConfig>();
107     EXPECT_NE(nullptr, requestConfig1);
108     requestConfig1->SetPriority(PRIORITY_FAST_FIRST_FIX);
109     requestConfig1->SetMaxAccuracy(1000.0);
110     requestConfig1->SetFixNumber(1);
111     request1->SetRequestConfig(*requestConfig1);
112     locatorDftManager->LocationSessionStart(request1); // has request config
113     locatorDftManager->LocationSessionStart(request1); // the same request
114 
115     std::shared_ptr<Request> request2 = std::make_shared<Request>();
116     request2->SetUid(1000);
117     request2->SetPid(0);
118     request2->SetTokenId(0);
119     request2->SetFirstTokenId(0);
120     request2->SetPackageName("LocatorEventManagerTest");
121     auto requestConfig2 = std::make_unique<RequestConfig>();
122     EXPECT_NE(nullptr, requestConfig2);
123     requestConfig2->SetPriority(PRIORITY_UNSET);
124     requestConfig2->SetMaxAccuracy(1000.0);
125     requestConfig2->SetFixNumber(1);
126     request2->SetRequestConfig(*requestConfig2);
127     locatorDftManager->LocationSessionStart(request2); // different request config
128     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocationSessionStartTest001 end");
129 }
130 
131 HWTEST_F(LocatorEventManagerTest, LocationSessionStartTest002, TestSize.Level1)
132 {
133     GTEST_LOG_(INFO)
134         << "LocatorEventManagerTest, LocationSessionStartTest002, TestSize.Level1";
135     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocationSessionStartTest002 begin");
136     auto locatorDftManager =
137         DelayedSingleton<LocatorDftManager>::GetInstance();
138     EXPECT_NE(nullptr, locatorDftManager);
139     std::shared_ptr<Request> request1 = std::make_shared<Request>();
140     request1->SetUid(1000);
141     request1->SetPid(0);
142     request1->SetTokenId(0);
143     request1->SetFirstTokenId(0);
144     request1->SetPackageName("LocatorEventManagerTest");
145     locatorDftManager->LocationSessionStart(request1); // no request config
146     auto requestConfig1 = std::make_unique<RequestConfig>();
147     EXPECT_NE(nullptr, requestConfig1);
148     requestConfig1->SetScenario(SCENE_NAVIGATION);
149     requestConfig1->SetMaxAccuracy(1000.0);
150     requestConfig1->SetFixNumber(1);
151     request1->SetRequestConfig(*requestConfig1);
152     locatorDftManager->LocationSessionStart(request1); // has request config
153 
154     locatorDftManager->LocationSessionStart(request1); // the same request
155 
156     std::shared_ptr<Request> request2 = std::make_shared<Request>();
157     request2->SetUid(1000);
158     request2->SetPid(0);
159     request2->SetTokenId(0);
160     request2->SetFirstTokenId(0);
161     request2->SetPackageName("LocatorEventManagerTest");
162     auto requestConfig2 = std::make_unique<RequestConfig>();
163     EXPECT_NE(nullptr, requestConfig2);
164     requestConfig2->SetScenario(SCENE_UNSET);
165     requestConfig2->SetPriority(PRIORITY_FAST_FIRST_FIX);
166     requestConfig2->SetMaxAccuracy(1000.0);
167     requestConfig2->SetFixNumber(1);
168     request2->SetRequestConfig(*requestConfig2);
169     locatorDftManager->LocationSessionStart(request2); // different request config
170     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocationSessionStartTest002 end");
171 }
172 
173 HWTEST_F(LocatorEventManagerTest, LocatorDftManagerDistributionTest001, TestSize.Level1)
174 {
175     GTEST_LOG_(INFO)
176         << "LocatorEventManagerTest, LocatorDftManagerDistributionTest001, TestSize.Level1";
177     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocatorDftManagerDistributionTest001 begin");
178     auto locatorDftManager =
179         DelayedSingleton<LocatorDftManager>::GetInstance();
180     EXPECT_NE(nullptr, locatorDftManager);
181     for (uint32_t i = 0; i <= COUNT_MAX; i++) {
182         locatorDftManager->DistributionDisconnect();
183     }
184     for (uint32_t i = 0; i <= COUNT_MAX; i++) {
185         locatorDftManager->DistributionSessionStart();
186     }
187     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocatorDftManagerDistributionTest001 end");
188 }
189 
190 HWTEST_F(LocatorEventManagerTest, LocatorDftManagerDistributionTest002, TestSize.Level1)
191 {
192     GTEST_LOG_(INFO)
193         << "LocatorEventManagerTest, LocatorDftManagerDistributionTest002, TestSize.Level1";
194     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocatorDftManagerDistributionTest002 begin");
195     auto locatorDftManager =
196         DelayedSingleton<LocatorDftManager>::GetInstance();
197     EXPECT_NE(nullptr, locatorDftManager);
198     locatorDftManager->SendDistributionDailyCount();
199     locatorDftManager->SendRequestDailyCount();
200     LBSLOGI(LOCATOR_EVENT, "[LocatorEventManagerTest] LocatorDftManagerDistributionTest002 end");
201 }
202 } // namespace Location
203 } // namespace OHOS
204