From 7ebf954ce989664d562264b51208f06c9c6d33ae Mon Sep 17 00:00:00 2001 From: "mila@ringwald.ch" Date: Fri, 29 Aug 2014 12:01:39 +0000 Subject: [PATCH] started des iterator --- test/des_iterator/Makefile | 27 +++++++++++++++++ test/des_iterator/btstack-config.h | 18 ++++++++++++ test/des_iterator/des_iterator.c | 29 ++++++++++++++++++ test/des_iterator/des_iterator.h | 35 ++++++++++++++++++++++ test/des_iterator/des_iterator_test.c | 42 +++++++++++++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 test/des_iterator/Makefile create mode 100644 test/des_iterator/btstack-config.h create mode 100644 test/des_iterator/des_iterator.c create mode 100644 test/des_iterator/des_iterator.h create mode 100644 test/des_iterator/des_iterator_test.c diff --git a/test/des_iterator/Makefile b/test/des_iterator/Makefile new file mode 100644 index 000000000..fa6182a81 --- /dev/null +++ b/test/des_iterator/Makefile @@ -0,0 +1,27 @@ +CC = g++ + +# Requirements: http://www.cpputest.org/ should be placed in btstack/test + +BTSTACK_ROOT = ../.. +CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest + +CFLAGS = -g -Wall -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include +LDFLAGS += -L$(CPPUTEST_HOME) -lCppUTest -lCppUTestExt + +COMMON = \ + ${BTSTACK_ROOT}/src/sdp_util.c \ + ${BTSTACK_ROOT}/src/utils.c \ + des_iterator.c + +COMMON_OBJ = $(COMMON:.c=.o) + +all: des_iterator_test + +des_iterator_test: ${COMMON_OBJ} des_iterator_test.c + ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ + + +clean: + rm -f des_iterator_test *.o ${BTSTACK_ROOT}/src/*.o + rm -rf *.dSYM + \ No newline at end of file diff --git a/test/des_iterator/btstack-config.h b/test/des_iterator/btstack-config.h new file mode 100644 index 000000000..3fa069bfa --- /dev/null +++ b/test/des_iterator/btstack-config.h @@ -0,0 +1,18 @@ +// config.h created by configure for BTstack Sun Sep 25 16:06:59 CEST 2011 +#ifndef __CONFIG_H +#define __CONFIG_H +#define HAVE_TRANSPORT_H4 +#define UART_DEVICE "/dev/tty.usbserial-A600eIDu" +#define UART_SPEED 115200 +#define USE_POSIX_RUN_LOOP +#define HAVE_TIME +#define HAVE_MALLOC +#define HAVE_BZERO +#define ENABLE_LOG_INFO +#define ENABLE_LOG_ERROR +#define HAVE_SDP_EXTRA_QUERIES +#define SDP_DES_DUMP +#define HCI_ACL_PAYLOAD_SIZE 1021 +// #define HCI_ACL_PAYLOAD_SIZE 52 + +#endif // __CONFIG_H diff --git a/test/des_iterator/des_iterator.c b/test/des_iterator/des_iterator.c new file mode 100644 index 000000000..ffc6e0393 --- /dev/null +++ b/test/des_iterator/des_iterator.c @@ -0,0 +1,29 @@ +#include "des_iterator.h" + +int des_iterator_init(des_iterator_t * it, uint8_t * element){ + de_type_t type = de_get_element_type(element); + if (type != DE_DES) return 0; + + it->element = element; + it->pos = de_get_header_size(element); + it->length = de_get_len(element); + return 1; +} + +de_type_t des_iterator_get_type (des_iterator_t * it){ + return de_get_element_type(&it->element[it->pos]); +} + +uint16_t des_iterator_get_size (des_iterator_t * it){ + int length = de_get_len(&it->element[it->pos]); + int header_size = de_get_header_size(&it->element[it->pos]); + return length - header_size; +} + +int des_iterator_has_more(des_iterator_t * it){ + return 0; +} + +uint8_t * des_iterator_get_value(des_iterator_t * it){ + return NULL; +} diff --git a/test/des_iterator/des_iterator.h b/test/des_iterator/des_iterator.h new file mode 100644 index 000000000..aebb7f237 --- /dev/null +++ b/test/des_iterator/des_iterator.h @@ -0,0 +1,35 @@ + +#ifndef __SDP_PARSER_H +#define __SDP_PARSER_H + +#include "btstack-config.h" + +#include +#include +#include +#include + +#include +#include + +#if defined __cplusplus +extern "C" { +#endif + +typedef struct { + uint8_t * element; + uint16_t pos; + uint16_t length; +} des_iterator_t; + +int des_iterator_init(des_iterator_t * it, uint8_t * element); +int des_iterator_has_more(des_iterator_t * it); +de_type_t des_iterator_get_type (des_iterator_t * it); +uint16_t des_iterator_get_size (des_iterator_t * it); +uint8_t * des_iterator_get_value(des_iterator_t * it); + +#if defined __cplusplus +} +#endif + +#endif // __DES_PARSER_H \ No newline at end of file diff --git a/test/des_iterator/des_iterator_test.c b/test/des_iterator/des_iterator_test.c new file mode 100644 index 000000000..e97c32bf0 --- /dev/null +++ b/test/des_iterator/des_iterator_test.c @@ -0,0 +1,42 @@ + +//***************************************************************************** +// +// des iterator tests +// +//***************************************************************************** + + +#include +#include +#include +#include + +#include "des_iterator.h" +#include "CppUTest/TestHarness.h" +#include "CppUTest/CommandLineTestRunner.h" + + +static uint8_t des_test[] = { + 0x35, 0x1E, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x0F, 0x35, 0x14, 0x19, 0x00, 0x0F, 0x09, + 0x01, 0x00, 0x35, 0x0C, 0x09, 0x08, 0x00, 0x09, 0x08, 0x06, 0x09, 0x86, 0xDD, 0x09, 0x88, 0x0B +}; + + +TEST_GROUP(DESParser){ + des_iterator_t des_protcol_list_it; + int iterator_initialized; + + void setup(){ + iterator_initialized = des_iterator_init(&des_protcol_list_it, des_test); + } +}; + + +TEST(DESParser, DESIterator){ + CHECK_EQUAL(iterator_initialized, 1); +} + + +int main (int argc, const char * argv[]){ + return CommandLineTestRunner::RunAllTests(argc, argv); +}