Skip to content

Commit aeb992e

Browse files
committed
BLE: Add unit test for the Generic GattClient.
These tests are build around gtest and gmock and solely run on a host; cmake is used as a build system: - cd features/FEATURE_BLE/tests - mkdir build - cd build - cmake .. - make - ./gatt-client-tests
1 parent ccff46d commit aeb992e

21 files changed

+3849
-0
lines changed

features/FEATURE_BLE/.mbedignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/*
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
cmake_minimum_required(VERSION 2.8.11)
2+
3+
# Make PROJECT_SOURCE_DIR, PROJECT_BINARY_DIR, and PROJECT_NAME available.
4+
set(PROJECT_NAME ble-tests)
5+
project(${PROJECT_NAME})
6+
7+
set(CMAKE_CXX_STANDARD 14)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
11+
################################
12+
# GTEST
13+
################################
14+
15+
# Download and unpack googletest at configure time
16+
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
17+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
18+
RESULT_VARIABLE result
19+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
20+
if(result)
21+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
22+
endif()
23+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
24+
RESULT_VARIABLE result
25+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
26+
if(result)
27+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
28+
endif()
29+
30+
# Prevent overriding the parent project's compiler/linker
31+
# settings on Windows
32+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
33+
34+
# Add googletest directly to our build. This defines
35+
# the gtest and gtest_main targets.
36+
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
37+
${CMAKE_BINARY_DIR}/googletest-build
38+
EXCLUDE_FROM_ALL)
39+
40+
# The gtest/gtest_main targets carry header search path
41+
# dependencies automatically when using CMake 2.8.11 or
42+
# later. Otherwise we have to add them here ourselves.
43+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
44+
include_directories(BEFORE SYSTEM
45+
"${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
46+
else()
47+
target_include_directories(gmock_main SYSTEM BEFORE INTERFACE
48+
"${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
49+
endif()
50+
51+
52+
################################
53+
# Testing
54+
################################
55+
56+
enable_testing()
57+
58+
###############################
59+
# GattClient test
60+
###############################
61+
62+
add_executable(gatt-client-tests
63+
mbed_os_stub/mbed_assert.c
64+
generic/GattClient/mock/MockCallbacks.cpp
65+
generic/GattClient/mock/MockPalGattClient.cpp
66+
generic/GattClient/util/Equality.cpp
67+
generic/GattClient/TestCharacteristicDesctiptorDiscovery.cpp
68+
generic/GattClient/TestDiscoverAllServices.cpp
69+
generic/GattClient/TestNoCb.cpp
70+
generic/GattClient/TestRead.cpp
71+
generic/GattClient/TestServerEvent.cpp
72+
generic/GattClient/TestWrite.cpp
73+
${PROJECT_SOURCE_DIR}/../source/generic/GenericGattClient.cpp
74+
)
75+
76+
target_include_directories(gatt-client-tests PRIVATE
77+
"${PROJECT_SOURCE_DIR}/.."
78+
"${PROJECT_SOURCE_DIR}/../../.."
79+
"${PROJECT_SOURCE_DIR}/generic/GattClient"
80+
)
81+
82+
# Standard linking to gtest stuff.
83+
target_link_libraries(gatt-client-tests gmock_main)
84+
85+
# This is so you can do 'make gatt-client-tests' to see all your tests run, instead of
86+
# manually running the executable runUnitTests to see those specific tests.
87+
add_test(NAME AllUnitTests COMMAND gatt-client-tests)
88+
89+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 2.8.11)
2+
3+
project(googletest-download NONE)
4+
5+
include(ExternalProject)
6+
ExternalProject_Add(googletest
7+
GIT_REPOSITORY https://github.com/google/googletest.git
8+
GIT_TAG master
9+
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
10+
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
11+
CONFIGURE_COMMAND ""
12+
BUILD_COMMAND ""
13+
INSTALL_COMMAND ""
14+
TEST_COMMAND ""
15+
)

0 commit comments

Comments
 (0)