From f45e14b19041af909a6453287a1db1fda104302a Mon Sep 17 00:00:00 2001 From: "mila@ringwald.ch" Date: Thu, 10 Apr 2014 12:52:42 +0000 Subject: [PATCH] added ble-client unit-test skeleton --- test/gatt_client/Makefile | 35 ++++++++++++++++ test/gatt_client/gatt_client.c | 39 +++++++++++++++++ test/gatt_client/mock.c | 77 ++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 test/gatt_client/Makefile create mode 100644 test/gatt_client/gatt_client.c create mode 100644 test/gatt_client/mock.c diff --git a/test/gatt_client/Makefile b/test/gatt_client/Makefile new file mode 100644 index 000000000..849ca1b10 --- /dev/null +++ b/test/gatt_client/Makefile @@ -0,0 +1,35 @@ +CC = g++ + +# Requirements: http://www.cpputest.org/ should be placed in btstack/test + +BTSTACK_ROOT = ../.. +CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest + +CFLAGS = -DUNIT_TEST -g -Wall -I. -I${BTSTACK_ROOT}/example/libusb -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include +LDFLAGS += -L$(CPPUTEST_HOME) -lCppUTest -lCppUTestExt + +COMMON = \ + ${BTSTACK_ROOT}/src/utils.c \ + ${BTSTACK_ROOT}/src/btstack_memory.c \ + ${BTSTACK_ROOT}/src/memory_pool.c \ + ${BTSTACK_ROOT}/src/linked_list.c \ + ${BTSTACK_ROOT}/src/sdp_util.c \ + ${BTSTACK_ROOT}/src/remote_device_db_memory.c \ + ${BTSTACK_ROOT}/src/run_loop.c \ + ${BTSTACK_ROOT}/src/run_loop_posix.c \ + ${BTSTACK_ROOT}/src/hci_cmds.c \ + ${BTSTACK_ROOT}/example/libusb/ble_client.c \ + mock.c + +COMMON_OBJ = $(COMMON:.c=.o) + +all: gatt_client + +gatt_client: ${CORE_OBJ} ${COMMON_OBJ} gatt_client.c + ${CC} ${CORE_OBJ} ${COMMON_OBJ} gatt_client.c ${CFLAGS} ${LDFLAGS} -o $@ + +clean: + rm -f gatt_client + rm -f *.o ${BTSTACK_ROOT}/src/*.o + rm -rf *.dSYM + \ No newline at end of file diff --git a/test/gatt_client/gatt_client.c b/test/gatt_client/gatt_client.c new file mode 100644 index 000000000..da977da84 --- /dev/null +++ b/test/gatt_client/gatt_client.c @@ -0,0 +1,39 @@ + +//***************************************************************************** +// +// test rfcomm query tests +// +//***************************************************************************** + + +#include +#include +#include +#include + +#include "CppUTest/TestHarness.h" +#include "CppUTest/CommandLineTestRunner.h" + +#include + +#include "btstack_memory.h" +#include "hci.h" + +// #include "hci_dump.h" +// #include "l2cap.h" +// #include "sdp_parser.h" + +TEST_GROUP(ADParser){ +}; + + +TEST(ADParser, TestDataParsing){ +} + +TEST(ADParser, TestHasUUID){ + +} + +int main (int argc, const char * argv[]){ + return CommandLineTestRunner::RunAllTests(argc, argv); +} diff --git a/test/gatt_client/mock.c b/test/gatt_client/mock.c new file mode 100644 index 000000000..01d82c392 --- /dev/null +++ b/test/gatt_client/mock.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include + +#include +#include "hci.h" +#include "hci_dump.h" +#include "l2cap.h" + +int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){ + printf("hci_can_send_packet_now_using_packet_buffer \n"); + return 1; +} + +void hci_disconnect_security_block(hci_con_handle_t con_handle){ + printf("hci_disconnect_security_block \n"); +} + +void hci_dump_log(const char * format, ...){ + printf("hci_disconnect_security_block \n"); +} + +int hci_send_cmd(const hci_cmd_t *cmd, ...){ + printf("hci_send_cmd \n"); + return 0; +} + + +int l2cap_can_send_connectionless_packet_now(void){ + printf("l2cap_can_send_connectionless_packet_now \n"); + return 1; +} + +static uint8_t l2cap_stack_buffer[20]; +static uint16_t max_l2cap_data_packet_length = 20; + + +uint8_t *l2cap_get_outgoing_buffer(void){ + printf("l2cap_get_outgoing_buffer \n"); + return (uint8_t *)&l2cap_stack_buffer; // 8 bytes +} + + + +uint16_t l2cap_max_mtu(void){ + printf("l2cap_max_mtu \n"); + return max_l2cap_data_packet_length; +} + + +void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id) { + printf("l2cap_register_fixed_channel \n"); +} + +void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){ + printf("l2cap_register_packet_handler \n"); +} + +int hci_reserve_packet_buffer(void){ + printf("hci_reserve_packet_buffer \n"); + return 1; +} + +int l2cap_reserve_packet_buffer(void){ + printf("l2cap_reserve_packet_buffer \n"); + return hci_reserve_packet_buffer(); +} + +int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){ + printf("l2cap_send_prepared_connectionless \n"); + return 0; +} + + +void l2cap_run(void){ +}