1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <general_test/basic_gnss_test.h>
18
19 #include <chre.h>
20 #include <shared/send_message.h>
21
22 /*
23 * Test to check expected functionality of the CHRE GNSS APIs.
24 * TODO: Currently the test only exists to verify that expected APIs are
25 * implemented and doesn't fail. Make the test more comprehensive by
26 * validating callback results, etc.
27 */
28 namespace general_test {
29
30 namespace {
31
testLocationSessionAsync()32 void testLocationSessionAsync() {
33 if (!chreGnssLocationSessionStartAsync(
34 1000 /* minIntervalMs */, 0 /* minTimeToNextFixMs */,
35 nullptr /* cookie */)) {
36 nanoapp_testing::sendFatalFailureToHost(
37 "Failed to start a location session");
38 }
39 if (!chreGnssLocationSessionStopAsync(nullptr /* cookie */)) {
40 nanoapp_testing::sendFatalFailureToHost(
41 "Failed to stop a location session");
42 }
43 }
44
45 } // anonymous namespace
46
BasicGnssTest()47 BasicGnssTest::BasicGnssTest()
48 : Test(CHRE_API_VERSION_1_1) {
49 }
50
setUp(uint32_t messageSize,const void *)51 void BasicGnssTest::setUp(
52 uint32_t messageSize, const void * /* message */) {
53 if (messageSize != 0) {
54 nanoapp_testing::sendFatalFailureToHost(
55 "Expected 0 byte message, got more bytes:", &messageSize);
56 } else {
57 uint32_t capabilities = chreGnssGetCapabilities();
58
59 if (capabilities & CHRE_GNSS_CAPABILITIES_LOCATION) {
60 testLocationSessionAsync();
61 // TODO: Add tests for chreGnssMeasurementXxx and
62 // chreGnssConfigurePassiveLocationListener
63 }
64
65 nanoapp_testing::sendSuccessToHost();
66 }
67 }
68
handleEvent(uint32_t,uint16_t eventType,const void *)69 void BasicGnssTest::handleEvent(uint32_t /* senderInstanceId */,
70 uint16_t eventType,
71 const void * /* eventData */) {
72 if (eventType != CHRE_EVENT_GNSS_ASYNC_RESULT
73 && eventType != CHRE_EVENT_GNSS_LOCATION) {
74 unexpectedEvent(eventType);
75 }
76 }
77
78 } // namespace general_test
79