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(1000 /* minIntervalMs */,
34 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() : Test(CHRE_API_VERSION_1_1) {}
48
setUp(uint32_t messageSize,const void *)49 void BasicGnssTest::setUp(uint32_t messageSize, const void * /* message */) {
50 if (messageSize != 0) {
51 nanoapp_testing::sendFatalFailureToHost(
52 "Expected 0 byte message, got more bytes:", &messageSize);
53 } else {
54 uint32_t capabilities = chreGnssGetCapabilities();
55
56 if (capabilities & CHRE_GNSS_CAPABILITIES_LOCATION) {
57 testLocationSessionAsync();
58 // TODO: Add tests for chreGnssMeasurementXxx and
59 // chreGnssConfigurePassiveLocationListener
60 }
61
62 nanoapp_testing::sendSuccessToHost();
63 }
64 }
65
handleEvent(uint32_t,uint16_t eventType,const void *)66 void BasicGnssTest::handleEvent(uint32_t /* senderInstanceId */,
67 uint16_t eventType,
68 const void * /* eventData */) {
69 if (eventType != CHRE_EVENT_GNSS_ASYNC_RESULT &&
70 eventType != CHRE_EVENT_GNSS_LOCATION) {
71 unexpectedEvent(eventType);
72 }
73 }
74
75 } // namespace general_test
76