From 6a52c3a1e28cf795d9206fe2d036edb5daf6a27b Mon Sep 17 00:00:00 2001 From: "mila@ringwald.ch" Date: Thu, 12 Feb 2015 21:51:32 +0000 Subject: [PATCH] updated test and Makefile, removed printf --- platforms/posix/src/remote_device_db_fs.c | 9 +++--- test/device_db_memory/Makefile | 28 +++++++++++------ .../remote_device_db_memory_test.c | 31 +++++++++---------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/platforms/posix/src/remote_device_db_fs.c b/platforms/posix/src/remote_device_db_fs.c index c399759c5..ea455fa3a 100644 --- a/platforms/posix/src/remote_device_db_fs.c +++ b/platforms/posix/src/remote_device_db_fs.c @@ -98,23 +98,23 @@ static void put_link_key(bd_addr_t *bd_addr, link_key_t *link_key, link_key_type static int get_link_key(bd_addr_t *bd_addr, link_key_t *link_key, link_key_type_t * link_key_type) { set_path(bd_addr); + if (access(keypath, R_OK)) return 0; + char link_key_str[LINK_KEY_STR_LEN + 1]; char link_key_type_str[2]; - if (access(keypath, R_OK)) return 0; - FILE * rFile = fopen(keypath,"r+"); size_t objects_read = fread(link_key_str, LINK_KEY_STR_LEN, 1, rFile ); if (objects_read == 1){ link_key_str[LINK_KEY_STR_LEN] = 0; - printf("found link key %s\n", link_key_str); + log_info("Found link key %s\n", link_key_str); objects_read = fread(link_key_type_str, 1, 1, rFile ); } fclose(rFile); if (objects_read != 1) return 0; link_key_type_str[1] = 0; - printf("found link key type %s\n", link_key_type_str); + log_info("Found link key type %s\n", link_key_type_str); int scan_result = sscan_link_key(link_key_str, *link_key); if (scan_result == 0 ) return 0; @@ -127,7 +127,6 @@ static int get_link_key(bd_addr_t *bd_addr, link_key_t *link_key, link_key_type_ static void delete_link_key(bd_addr_t *bd_addr){ set_path(bd_addr); - if (access(keypath, R_OK)) return; if(remove(keypath) != 0){ diff --git a/test/device_db_memory/Makefile b/test/device_db_memory/Makefile index 1a781daec..768fbcd70 100644 --- a/test/device_db_memory/Makefile +++ b/test/device_db_memory/Makefile @@ -5,24 +5,32 @@ CC=g++ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include +CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I${BTSTACK_ROOT}/ble -I$(CPPUTEST_HOME)/include LDFLAGS += -L$(CPPUTEST_HOME) -lCppUTest -lCppUTestExt -COMMON = \ - ${BTSTACK_ROOT}/src/memory_pool.c \ - ${BTSTACK_ROOT}/src/remote_device_db_memory.c \ - ${BTSTACK_ROOT}/src/btstack_memory.c \ - ${BTSTACK_ROOT}/src/linked_list.c \ +FS = \ + ${BTSTACK_ROOT}/src/utils.c \ + ${BTSTACK_ROOT}/platforms/posix/src/remote_device_db_fs.c + + +MEMORY = \ ${BTSTACK_ROOT}/src/utils.c \ + ${BTSTACK_ROOT}/src/memory_pool.c \ + ${BTSTACK_ROOT}/src/btstack_memory.c \ + ${BTSTACK_ROOT}/src/remote_device_db_memory.c \ + ${BTSTACK_ROOT}/src/linked_list.c +FS_OBJ = $(FS:.c=.o) +MEMORY_OBJ = $(MEMORY:.c=.o) -COMMON_OBJ = $(COMMON:.c=.o) +all: remote_device_db_memory_test remote_device_db_fs_test -all: remote-memory +remote_device_db_memory_test: ${MEMORY_OBJ} remote_device_db_memory_test.c + ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ -remote-memory: ${COMMON_OBJ} remote_device_db_memory_test.c +remote_device_db_fs_test: ${FS_OBJ} remote_device_db_fs_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ clean: - rm -f remote-memory *.o ../src/*.o + rm -f remote_device_db_memory_test remote_device_db_fs_test *.o ../src/*.o diff --git a/test/device_db_memory/remote_device_db_memory_test.c b/test/device_db_memory/remote_device_db_memory_test.c index f80435107..d924b7a04 100644 --- a/test/device_db_memory/remote_device_db_memory_test.c +++ b/test/device_db_memory/remote_device_db_memory_test.c @@ -11,14 +11,8 @@ extern linked_list_t db_mem_link_keys ; extern linked_list_t db_mem_names ; - -typedef struct teststruct{ - int type; -} teststruct_t; - -teststruct_t tr = { - type : 0 -}; +// const extern "C" db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void); +// const extern "C" void btstack_memory_init(void); void dump(linked_list_t list){ printf("dump:\n"); @@ -37,9 +31,9 @@ TEST_GROUP(RemoteDeviceDB){ bd_addr_t addr1, addr2, addr3; device_name_t device_name; link_key_t link_key; - - void setup(){ + link_key_type_t link_key_type; + void setup(){ btstack_memory_init(); bd_addr_t addr_1 = {0x00, 0x01, 0x02, 0x03, 0x04, 0x01 }; @@ -48,6 +42,9 @@ TEST_GROUP(RemoteDeviceDB){ BD_ADDR_COPY(addr1, addr_1); BD_ADDR_COPY(addr2, addr_2); BD_ADDR_COPY(addr3, addr_3); + + link_key_type = (link_key_type_t)4; + sprintf((char*)link_key, "%d", 100); } void teardown(){} @@ -85,27 +82,27 @@ TEST(RemoteDeviceDB, SortByLastUsedName){ TEST(RemoteDeviceDB, SinglePutGetDeleteKey){ sprintf((char*)link_key, "%d", 100); - remote_device_db_memory.put_link_key(&addr1, &link_key); + remote_device_db_memory.put_link_key(&addr1, &link_key, link_key_type); // dump(db_mem_link_keys); - CHECK(remote_device_db_memory.get_link_key(&addr1, &link_key)); + CHECK(remote_device_db_memory.get_link_key(&addr1, &link_key, &link_key_type)); remote_device_db_memory.delete_link_key(&addr1); - CHECK(!remote_device_db_memory.get_link_key(&addr1, &link_key)); + CHECK(!remote_device_db_memory.get_link_key(&addr1, &link_key, &link_key_type)); } TEST(RemoteDeviceDB, SortByLastUsedKey){ sprintf((char*)link_key, "%d", 10); - remote_device_db_memory.put_link_key(&addr1, &link_key); + remote_device_db_memory.put_link_key(&addr1, &link_key, link_key_type); // dump(db_mem_link_keys); sprintf((char*)link_key, "%d", 20); - remote_device_db_memory.put_link_key(&addr2, &link_key); + remote_device_db_memory.put_link_key(&addr2, &link_key, link_key_type); // dump(db_mem_link_keys); sprintf((char*)link_key, "%d", 30); - remote_device_db_memory.put_link_key(&addr3, &link_key); + remote_device_db_memory.put_link_key(&addr3, &link_key, link_key_type); // dump(db_mem_link_keys); - CHECK(remote_device_db_memory.get_link_key(&addr2, &link_key)); + CHECK(remote_device_db_memory.get_link_key(&addr2, &link_key, &link_key_type)); // dump(db_mem_link_keys); //get first element of the list