added explicit casts for btstack mallocs

This commit is contained in:
mila@ringwald.ch 2011-09-03 21:04:27 +00:00
parent d1845e3403
commit fe739638d3
3 changed files with 38 additions and 56 deletions

View File

@ -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; if ( get_link_key(bd_addr, link_key) ) return;
// Record not found, create new one for this device // 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; 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; if (get_name(bd_addr, device_name)) return;
// Record not found, create a new one for this device // 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; if (!newItem) return;
@ -144,7 +144,7 @@ static uint8_t persistent_rfcomm_channel(char *serviceName){
} }
// Allocate new persistant channel // 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; if (!newItem) return 0;

View File

@ -1,12 +1,17 @@
CC=gcc CC=g++
CPPFLAGS=-I../include -I../src -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 VPATH=../src
DEPS = remote_device_db_memory.h DEPS = remote_device_db_memory.h
OBJ = remote_device_db_memory_test.o remote_device_db_memory.o btstack_memory.o linked_list.o OBJ = remote_device_db_memory_test.o remote_device_db_memory.o btstack_memory.o linked_list.o
remote_device_db_memory_test: $(OBJ) remote-memory: $(OBJ)
$(CC) $(CPPFLAGS) -o $@ $^ $(CC) $(CPPFLAGS) -o $@ $^ $(LD_LIBRARIES)
clean: clean:
rm -f remote_device_db_memory_test *.o rm -f remote-memory *.o

View File

@ -1,63 +1,40 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "CppUTest/TestHarness.h"
#include "CppUTest/CommandLineTestRunner.h"
#include "remote_device_db.h" #include "remote_device_db.h"
bd_addr_t addr = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; TEST_GROUP(RemoteDeviceDB){
device_name_t device_name = {'m', 'a', 't', 't'}; bd_addr_t addr;
link_key_t link_key = {'h', 'i', 'a', 's'}; 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); remote_device_db_memory.put_name(&addr, &device_name);
if (remote_device_db_memory.get_name(&addr, &device_name)) { CHECK(remote_device_db_memory.get_name(&addr, &device_name));
printf("OK ------> found device \n");
} else {
printf("ERROR ------> device not found \n");
};
remote_device_db_memory.delete_name(&addr); remote_device_db_memory.delete_name(&addr);
if (remote_device_db_memory.get_name(&addr, &device_name)) { CHECK(!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");
};
} }
void testPutGetDeleteKey(void){ TEST(RemoteDeviceDB, PutGetDeleteKey){
remote_device_db_memory.put_link_key(&addr, &link_key); remote_device_db_memory.put_link_key(&addr, &link_key);
if (remote_device_db_memory.get_link_key(&addr, &link_key)) { CHECK(remote_device_db_memory.get_link_key(&addr, &link_key));
printf("OK ------> found key \n");
} else {
printf("ERROR ------> key not found \n");
};
remote_device_db_memory.delete_link_key(&addr); remote_device_db_memory.delete_link_key(&addr);
if (remote_device_db_memory.get_link_key(&addr, &link_key)) { CHECK(!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");
};
} }
int main (int argc, const char * argv[]){ int main (int argc, const char * argv[]){
printf("\n<remote_device_db_memory_test> \n"); return CommandLineTestRunner::RunAllTests(argc, argv);
testPutGetDeleteName();
testPutGetDeleteKey();
printf("</remote_device_db_memory_test> \n\n");
return 0;
} }