1 /* 2 * Copyright (C) 2022 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 #ifndef _GTS_NANOAPPS_GENERAL_TEST_BASIC_BLE_TEST_H_ 18 #define _GTS_NANOAPPS_GENERAL_TEST_BASIC_BLE_TEST_H_ 19 20 #include <general_test/test.h> 21 22 #include <cstdint> 23 24 #include <shared/test_success_marker.h> 25 26 #include "chre_api/chre.h" 27 28 namespace general_test { 29 30 class BasicBleTest : public Test { 31 public: 32 BasicBleTest(); 33 34 protected: 35 void handleEvent(uint32_t senderInstanceId, uint16_t eventType, 36 const void *eventData) override; 37 void setUp(uint32_t messageSize, const void *message) override; 38 39 private: 40 /** 41 * If true, chreBleFlushAsync(...) was called. If false, it was not called. 42 */ 43 bool mFlushWasCalled; 44 45 /** 46 * If true, the device supports batching, and we can call 47 * chreBleFlushAsync(...). 48 */ 49 bool mSupportsBatching; 50 51 /** 52 * If true, the device supports all filtering available. 53 */ 54 bool mSupportsFiltering; 55 56 enum BasicBleTestStage { 57 BASIC_BLE_TEST_STAGE_SCAN = 58 0, // stage: BLE scanning start and stop was successful 59 BASIC_BLE_TEST_STAGE_FLUSH, // stage: the flush API was successful 60 BASIC_BLE_TEST_STAGE_COUNT, // total number of stages 61 }; 62 63 nanoapp_testing::TestSuccessMarker mTestSuccessMarker = 64 nanoapp_testing::TestSuccessMarker(BASIC_BLE_TEST_STAGE_COUNT); 65 isCapabilitySet(uint32_t capability)66 bool isCapabilitySet(uint32_t capability) { 67 return (chreBleGetCapabilities() & capability); 68 }; 69 isFilterCapabilitySet(uint32_t capability)70 bool isFilterCapabilitySet(uint32_t capability) { 71 return (chreBleGetFilterCapabilities() & capability); 72 }; 73 74 void handleBleAsyncResult(const chreAsyncResult *result); 75 76 void handleAdvertisementEvent(const chreBleAdvertisementEvent *event); 77 78 void handleTimerEvent(); 79 }; 80 81 } // namespace general_test 82 83 #endif // _GTS_NANOAPPS_GENERAL_TEST_BASIC_BLE_TEST_H_ 84