mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-21 21:41:13 +00:00
test/embedded: add test for hci_event
This commit is contained in:
parent
c70b3b486d
commit
89d7e14e49
@ -29,6 +29,7 @@ COMMON = \
|
||||
hci_dump.c \
|
||||
l2cap_signaling.c \
|
||||
hci_cmd.c \
|
||||
hci_event.c \
|
||||
|
||||
FREERTOS = \
|
||||
btstack_run_loop_freertos.c \
|
||||
@ -45,6 +46,7 @@ all: build-coverage/embedded_test build-asan/embedded_test \
|
||||
build-coverage/l2cap_le_signaling_test build-asan/l2cap_le_signaling_test \
|
||||
build-coverage/hci_cmd_test build-asan/hci_cmd_test \
|
||||
build-coverage/hci_dump_test build-asan/hci_dump_test \
|
||||
build-coverage/hci_event_test build-asan/hci_event_test \
|
||||
build-coverage/freertos_test build-asan/freertos_test \
|
||||
|
||||
build-%:
|
||||
@ -110,6 +112,12 @@ build-coverage/hci_dump_test: ${COMMON_OBJ_COVERAGE} build-coverage/hci_dump_tes
|
||||
build-asan/hci_dump_test: ${COMMON_OBJ_ASAN} build-asan/hci_dump_test.o build-asan/hci_dump.o | build-asan
|
||||
${CXX} $^ ${LDFLAGS_ASAN} -o $@
|
||||
|
||||
build-coverage/hci_event_test: ${COMMON_OBJ_COVERAGE} build-coverage/hci_event_test.o | build-coverage
|
||||
${CXX} $^ ${LDFLAGS_COVERAGE} -o $@
|
||||
|
||||
build-asan/hci_event_test: ${COMMON_OBJ_ASAN} build-asan/hci_event_test.o | build-asan
|
||||
${CXX} $^ ${LDFLAGS_ASAN} -o $@
|
||||
|
||||
test: all
|
||||
build-asan/embedded_test
|
||||
build-asan/freertos_test
|
||||
@ -118,6 +126,7 @@ test: all
|
||||
build-asan/l2cap_le_signaling_test
|
||||
build-asan/hci_cmd_test
|
||||
build-asan/hci_dump_test
|
||||
build-asan/hci_event_test
|
||||
|
||||
coverage: all
|
||||
rm -f build-coverage/*.gcda
|
||||
@ -128,6 +137,7 @@ coverage: all
|
||||
build-coverage/l2cap_le_signaling_test
|
||||
build-coverage/hci_cmd_test
|
||||
build-coverage/hci_dump_test
|
||||
build-coverage/hci_event_test
|
||||
|
||||
clean:
|
||||
rm -rf build-coverage build-asan *.dSYM
|
||||
|
62
test/embedded/hci_event_test.cpp
Normal file
62
test/embedded/hci_event_test.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
|
||||
#include "hci_event.h"
|
||||
#include "btstack_util.h"
|
||||
|
||||
uint8_t hci_event_buffer[257];
|
||||
hci_event_t event_1 = { 1, 0, "1"};
|
||||
hci_event_t event_2 = { 1, 0, "2"};
|
||||
hci_event_t event_3 = { 1, 0, "3"};
|
||||
hci_event_t event_4 = { 1, 0, "4"};
|
||||
|
||||
static uint16_t create_hci_event(const hci_event_t *event, ...){
|
||||
va_list argptr;
|
||||
va_start(argptr, event);
|
||||
uint16_t len = hci_event_create_from_template_and_arglist(hci_event_buffer, sizeof(hci_event_buffer), event, argptr);
|
||||
va_end(argptr);
|
||||
return len - 2;
|
||||
}
|
||||
|
||||
TEST_GROUP(hci_event){
|
||||
void setup(void){
|
||||
}
|
||||
void teardown(void){
|
||||
}
|
||||
};
|
||||
|
||||
TEST(hci_event, format_1){
|
||||
const uint8_t expected_buffer[] = { 0x55};
|
||||
uint8_t value = 0x55;
|
||||
uint16_t size = create_hci_event(&event_1, value);
|
||||
CHECK_EQUAL(sizeof(expected_buffer), size);
|
||||
MEMCMP_EQUAL(expected_buffer, &hci_event_buffer[2], sizeof(expected_buffer));
|
||||
}
|
||||
|
||||
TEST(hci_event, format_2){
|
||||
const uint8_t expected_buffer[] = { 0x34, 0x12 };
|
||||
uint16_t value = 0x1234;
|
||||
uint16_t size = create_hci_event(&event_2, value);
|
||||
CHECK_EQUAL(sizeof(expected_buffer), size);
|
||||
MEMCMP_EQUAL(expected_buffer, &hci_event_buffer[2], sizeof(expected_buffer));
|
||||
}
|
||||
|
||||
TEST(hci_event, format_3){
|
||||
const uint8_t expected_buffer[] = { 0x56, 0x34, 0x12};
|
||||
uint32_t value = 0x123456;
|
||||
uint16_t size = create_hci_event(&event_3, value);
|
||||
CHECK_EQUAL(sizeof(expected_buffer), size);
|
||||
MEMCMP_EQUAL(expected_buffer, &hci_event_buffer[2], sizeof(expected_buffer));
|
||||
}
|
||||
|
||||
TEST(hci_event, format_4){
|
||||
const uint8_t expected_buffer[] = { 0x78, 0x56, 0x34, 0x12};
|
||||
uint32_t value = 0x12345678;
|
||||
uint16_t size = create_hci_event(&event_4, value);
|
||||
CHECK_EQUAL(sizeof(expected_buffer), size);
|
||||
MEMCMP_EQUAL(expected_buffer, &hci_event_buffer[2], sizeof(expected_buffer));
|
||||
}
|
||||
|
||||
int main (int argc, const char * argv[]){
|
||||
return CommandLineTestRunner::RunAllTests(argc, argv);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user