Skip to content

Commit 27160db

Browse files
author
Abbas Bracken Ziad
committed
Add unit test for BLE trace helper
1 parent 7ac8ab9 commit 27160db

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2021 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "gtest/gtest.h"
19+
20+
#include "ble_trace_helpers.h"
21+
#include "ble/common/UUID.h"
22+
23+
TEST(to_string, UUID)
24+
{
25+
static constexpr const size_t HYPHENS_DELIMITER_COUNT = 4;
26+
static constexpr const size_t LENGTH_OF_LONG_UUID_STRING = \
27+
2 * UUID::LENGTH_OF_LONG_UUID + HYPHENS_DELIMITER_COUNT + 1;
28+
29+
static constexpr const char *STRING_UUID_0 = "53880000-65FD-4651-BA8E-91527F06C887";
30+
static constexpr const char *STRING_UUID_1 = "53880001-65FD-4651-BA8E-91527F06C887";
31+
static constexpr const char *STRING_UUID_2 = "53880002-65FD-4651-BA8E-91527F06C887";
32+
static constexpr const char *STRING_UUID_3 = "53880003-65FD-4651-BA8E-91527F06C887";
33+
34+
const UUID UUID_0 = UUID(STRING_UUID_0);
35+
const UUID UUID_1 = UUID(STRING_UUID_1);
36+
const UUID UUID_2 = UUID(STRING_UUID_2);
37+
const UUID UUID_3 = UUID(STRING_UUID_3);
38+
39+
EXPECT_TRUE(0 == std::memcmp(ble::to_string(UUID_0), STRING_UUID_0, LENGTH_OF_LONG_UUID_STRING));
40+
EXPECT_TRUE(0 == std::memcmp(ble::to_string(UUID_1), STRING_UUID_1, LENGTH_OF_LONG_UUID_STRING));
41+
EXPECT_TRUE(0 == std::memcmp(ble::to_string(UUID_2), STRING_UUID_2, LENGTH_OF_LONG_UUID_STRING));
42+
EXPECT_TRUE(0 == std::memcmp(ble::to_string(UUID_3), STRING_UUID_3, LENGTH_OF_LONG_UUID_STRING));
43+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
####################
2+
# UNIT TESTS
3+
####################
4+
5+
set(unittest-includes ${unittest-includes}
6+
../connectivity/FEATURE_BLE/source/common
7+
../connectivity/FEATURE_BLE/source
8+
../connectivity/FEATURE_BLE/include/ble
9+
../connectivity/FEATURE_BLE/include
10+
../connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/cfg
11+
../connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/include
12+
../connectivity/FEATURE_BLE/libraries/cordio_stack/wsf/include
13+
14+
../platform/mbed-trace/include/mbed-trace
15+
)
16+
17+
set(unittest-sources
18+
../connectivity/FEATURE_BLE/source/common/ble_trace_helpers.cpp
19+
20+
../platform/mbed-trace/source/mbed_trace.c
21+
)
22+
23+
set(unittest-test-sources
24+
${CMAKE_CURRENT_LIST_DIR}/test_ble_trace_helpers.cpp
25+
)
26+
27+
# BLE requires at least one role 'BROADCASTER' or 'OBSERVER' to be enabled
28+
add_compile_definitions(BLE_ROLE_BROADCASTER=1)

0 commit comments

Comments
 (0)