Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
dbt_server_test.hpp
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#ifndef DBT_SERVER_TEST_HPP_
26#define DBT_SERVER_TEST_HPP_
27
28#include "dbt_endpoint.hpp"
29
30class DBTServerTest;
31typedef std::shared_ptr<DBTServerTest> DBTServerTestRef;
32
33class DBTServerTest : public DBTEndpoint {
34
35 public:
37
38 virtual HCIStatusCode startAdvertising(const std::string& msg) = 0;
39
40 static void startAdvertising(const DBTServerTestRef& server, const bool current_exp_advertising_state, const std::string& msg) {
41 BTAdapterRef adapter = server->getAdapter();
42 REQUIRE( current_exp_advertising_state == adapter->isAdvertising() );
43 REQUIRE( false == adapter->isDiscovering() );
44
45 REQUIRE( HCIStatusCode::SUCCESS == server->startAdvertising(msg) );
46 REQUIRE( true == adapter->isAdvertising() );
47 REQUIRE( false == adapter->isDiscovering() );
48 REQUIRE( BTRole::Slave == adapter->getRole() );
49 REQUIRE( server->getName() == adapter->getName() );
50 }
51
52 static void stop(const DBTServerTestRef& server, const std::string& msg) {
53 BTAdapterRef adapter = server->getAdapter();
54 REQUIRE( false == adapter->isDiscovering() );
55 REQUIRE( BTRole::Slave == adapter->getRole() ); // kept
56
57 // Stopping advertising and serving even if stopped must be OK!
58 server->close(msg);
59 REQUIRE( false == adapter->isAdvertising() );
60 REQUIRE( false == adapter->isDiscovering() );
61 REQUIRE( BTRole::Slave == adapter->getRole() ); // kept
62 }
63};
64
65#endif // DBT_SERVER_TEST_HPP_
virtual BTSecurityLevel getSecurityLevel()=0
virtual HCIStatusCode startAdvertising(const std::string &msg)=0
static void startAdvertising(const DBTServerTestRef &server, const bool current_exp_advertising_state, const std::string &msg)
static void stop(const DBTServerTestRef &server, const std::string &msg)
std::shared_ptr< DBTServerTest > DBTServerTestRef
std::shared_ptr< BTAdapter > BTAdapterRef
Definition: BTAdapter.hpp:1354
BTSecurityLevel
Bluetooth Security Level.
Definition: BTTypes0.hpp:267
HCIStatusCode
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
Definition: HCITypes.hpp:138