Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
test_bringup00.cpp
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#include <iostream>
26#include <cassert>
27#include <cinttypes>
28#include <cstring>
29
31
33#include <jau/os/os_support.hpp>
34
35using namespace direct_bt;
36
38 std::shared_ptr<BTManager> mngr = BTManager::get();
39 jau::darray<BTAdapterRef> adapters = mngr->getAdapters();
40 for(const BTAdapterRef& a : adapters) {
41 a->removeAllStatusListener();
42 // test runs w/o elevated permissions
43 // a->stopAdvertising();
44 // a->stopDiscovery();
45 // REQUIRE( a->setPowered(false) );
46 }
47 mngr->removeAllChangedAdapterSetCallbacks();
51}
52
53/**
54 * Testing BTManager bring up:
55 * - test loading native libraries
56 * - show all installed adapter
57 * - no extra permissions required
58 */
59TEST_CASE( "BTManager Bringup Test 00", "[test][BTManager][bringup]" ) {
60 {
61 // setenv("direct_bt.debug", "true", 1 /* overwrite */);
62 }
63 jau::fprintf_td(stderr, "Direct-BT Native Version %s (API %s)\n", DIRECT_BT_VERSION, DIRECT_BT_VERSION_API);
64 jau::fprintf_td(stderr, "%s\n", jau::os::get_platform_info().c_str());
66
67 BTManagerRef manager = BTManager::get();
68
69 jau::darray<BTAdapterRef> adapters = manager->getAdapters();
70 jau::fprintf_td(stderr, "Adapter: Count %u\n", adapters.size());
71
72 for(jau::nsize_t i=0; i<adapters.size(); i++) {
73 jau::fprintf_td(stderr, "%u: %s\n", i, adapters[i]->toString().c_str());
74 }
75 jau::fprintf_td(stderr, "Adapter: Status Checks\n");
76 for(const BTAdapterRef& a : adapters) {
77 // test runs w/o elevated permissions
78 REQUIRE( false == a->isInitialized() );
79 // REQUIRE( false == a->isPowered() );
80 REQUIRE( BTRole::Master == a->getRole() ); // default role
81 REQUIRE( 4 <= a->getBTMajorVersion() );
82 }
83
84 jau::fprintf_td(stderr, "Manager: Closing\n");
85 adapters.clear();
87 manager->close(); /* implies: adapter.close(); */
88
89 jau::fprintf_td(stderr, "Test: Done\n");
90}
Implementation of a dynamic linear array storage, aka vector.
Definition: darray.hpp:148
constexpr size_type size() const noexcept
Like std::vector::size().
Definition: darray.hpp:763
constexpr void clear() noexcept
Like std::vector::clear(), but ending with zero capacity.
Definition: darray.hpp:904
std::shared_ptr< BTManager > BTManagerRef
Definition: BTAdapter.hpp:61
void clear() noexcept
Clears internal list.
std::shared_ptr< BTAdapter > BTAdapterRef
Definition: BTAdapter.hpp:1354
Entry * get(const EUI48 &addr, const std::string &name, AddressNameEntryMatchFunc m) noexcept
Returns a matching BTSecurityRegistry::Entry with the given addr and/or name.
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
Definition: int_types.hpp:53
std::string get_platform_info(std::string &sb) noexcept
Definition: os_support.cpp:207
void clearProcessedDevices() noexcept
Clears internal list.
void clearWaitForDevices() noexcept
Clears internal list.
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, const char *format,...) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
Definition: debug.cpp:270
void resetStates()
TEST_CASE("BTManager Bringup Test 00", "[test][BTManager][bringup]")
Testing BTManager bring up: