From fe739638d3592ac55aaf23d632af06e0c396efe5 Mon Sep 17 00:00:00 2001 From: "mila@ringwald.ch" Date: Sat, 3 Sep 2011 21:04:27 +0000 Subject: [PATCH] added explicit casts for btstack mallocs --- src/remote_device_db_memory.c | 6 +-- test/Makefile | 15 ++++-- test/remote_device_db_memory_test.c | 73 ++++++++++------------------- 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/src/remote_device_db_memory.c b/src/remote_device_db_memory.c index e5ad5e429..4f67389df 100644 --- a/src/remote_device_db_memory.c +++ b/src/remote_device_db_memory.c @@ -93,7 +93,7 @@ static void put_link_key(bd_addr_t *bd_addr, link_key_t *link_key){ if ( get_link_key(bd_addr, link_key) ) return; // Record not found, create new one for this device - db_mem_device_link_key_t * newItem = btstack_memory_db_mem_device_link_key_get(); + db_mem_device_link_key_t * newItem = (db_mem_device_link_key_t *)btstack_memory_db_mem_device_link_key_get(); if (!newItem) return; @@ -115,7 +115,7 @@ static void put_name(bd_addr_t *bd_addr, device_name_t *device_name){ if (get_name(bd_addr, device_name)) return; // Record not found, create a new one for this device - db_mem_device_name_t * newItem = btstack_memory_db_mem_device_name_get(); + db_mem_device_name_t * newItem = (db_mem_device_name_t *) btstack_memory_db_mem_device_name_get(); if (!newItem) return; @@ -144,7 +144,7 @@ static uint8_t persistent_rfcomm_channel(char *serviceName){ } // Allocate new persistant channel - db_mem_service_t * newItem = btstack_memory_db_mem_service_get(); + db_mem_service_t * newItem = (db_mem_service_t *) btstack_memory_db_mem_service_get(); if (!newItem) return 0; diff --git a/test/Makefile b/test/Makefile index 658ce19d9..2b533b291 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,12 +1,17 @@ -CC=gcc -CPPFLAGS=-I../include -I../src -g +CC=g++ +CPPUTEST_HOME = /usr/local/cpputest + +CPPFLAGS=-I../include -I../src -I$(CPPUTEST_HOME)/include -g +LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt + VPATH=../src + DEPS = remote_device_db_memory.h OBJ = remote_device_db_memory_test.o remote_device_db_memory.o btstack_memory.o linked_list.o -remote_device_db_memory_test: $(OBJ) - $(CC) $(CPPFLAGS) -o $@ $^ +remote-memory: $(OBJ) + $(CC) $(CPPFLAGS) -o $@ $^ $(LD_LIBRARIES) clean: - rm -f remote_device_db_memory_test *.o + rm -f remote-memory *.o diff --git a/test/remote_device_db_memory_test.c b/test/remote_device_db_memory_test.c index 64fee5a12..a1d10e07a 100644 --- a/test/remote_device_db_memory_test.c +++ b/test/remote_device_db_memory_test.c @@ -1,63 +1,40 @@ #include #include +#include "CppUTest/TestHarness.h" +#include "CppUTest/CommandLineTestRunner.h" + #include "remote_device_db.h" -bd_addr_t addr = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; -device_name_t device_name = {'m', 'a', 't', 't'}; -link_key_t link_key = {'h', 'i', 'a', 's'}; +TEST_GROUP(RemoteDeviceDB){ + bd_addr_t addr; + device_name_t device_name; + link_key_t link_key; -void testPutGetDeleteName(void){ + void setup(){ + bd_addr_t addr = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; + strcpy((char*)device_name, "matthias"); + strcpy((char*)link_key, "matthias"); + } + + void teardown(){} +}; + +TEST(RemoteDeviceDB, PutGetDeleteName){ remote_device_db_memory.put_name(&addr, &device_name); - if (remote_device_db_memory.get_name(&addr, &device_name)) { - printf("OK ------> found device \n"); - } else { - printf("ERROR ------> device not found \n"); - }; + CHECK(remote_device_db_memory.get_name(&addr, &device_name)); remote_device_db_memory.delete_name(&addr); - if (remote_device_db_memory.get_name(&addr, &device_name)) { - printf("ERROR ------> device not deleted \n"); - } else { - printf("OK ------> device deleted \n"); - }; - - remote_device_db_memory.put_link_key(&addr, &link_key); - if (remote_device_db_memory.get_name(&addr, &device_name)) { - printf("ERROR ------> no device with such name\n"); - } else { - printf("OK ------> device with such name does not exist \n"); - }; - + CHECK(!remote_device_db_memory.get_name(&addr, &device_name)); } -void testPutGetDeleteKey(void){ - remote_device_db_memory.put_link_key(&addr, &link_key); - if (remote_device_db_memory.get_link_key(&addr, &link_key)) { - printf("OK ------> found key \n"); - } else { - printf("ERROR ------> key not found \n"); - }; - +TEST(RemoteDeviceDB, PutGetDeleteKey){ + remote_device_db_memory.put_link_key(&addr, &link_key); + CHECK(remote_device_db_memory.get_link_key(&addr, &link_key)); + remote_device_db_memory.delete_link_key(&addr); - if (remote_device_db_memory.get_link_key(&addr, &link_key)) { - printf("ERROR ------> key not deleted \n"); - } else { - printf("OK ------> key deleted \n"); - }; - - remote_device_db_memory.put_name(&addr, &device_name); - if (remote_device_db_memory.get_link_key(&addr, &link_key)) { - printf("ERROR ------> no device with such link key\n"); - } else { - printf("OK ------> device with such link key does not exist \n"); - }; + CHECK(!remote_device_db_memory.get_link_key(&addr, &link_key)); } int main (int argc, const char * argv[]){ - printf("\n \n"); - testPutGetDeleteName(); - testPutGetDeleteKey(); - printf(" \n\n"); - - return 0; + return CommandLineTestRunner::RunAllTests(argc, argv); } \ No newline at end of file