mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 03:35:20 +00:00
updated test and Makefile, removed printf
This commit is contained in:
parent
befc8792ad
commit
6a52c3a1e2
@ -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) {
|
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);
|
set_path(bd_addr);
|
||||||
|
if (access(keypath, R_OK)) return 0;
|
||||||
|
|
||||||
char link_key_str[LINK_KEY_STR_LEN + 1];
|
char link_key_str[LINK_KEY_STR_LEN + 1];
|
||||||
char link_key_type_str[2];
|
char link_key_type_str[2];
|
||||||
|
|
||||||
if (access(keypath, R_OK)) return 0;
|
|
||||||
|
|
||||||
FILE * rFile = fopen(keypath,"r+");
|
FILE * rFile = fopen(keypath,"r+");
|
||||||
size_t objects_read = fread(link_key_str, LINK_KEY_STR_LEN, 1, rFile );
|
size_t objects_read = fread(link_key_str, LINK_KEY_STR_LEN, 1, rFile );
|
||||||
if (objects_read == 1){
|
if (objects_read == 1){
|
||||||
link_key_str[LINK_KEY_STR_LEN] = 0;
|
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 );
|
objects_read = fread(link_key_type_str, 1, 1, rFile );
|
||||||
}
|
}
|
||||||
fclose(rFile);
|
fclose(rFile);
|
||||||
|
|
||||||
if (objects_read != 1) return 0;
|
if (objects_read != 1) return 0;
|
||||||
link_key_type_str[1] = 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);
|
int scan_result = sscan_link_key(link_key_str, *link_key);
|
||||||
if (scan_result == 0 ) return 0;
|
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){
|
static void delete_link_key(bd_addr_t *bd_addr){
|
||||||
set_path(bd_addr);
|
set_path(bd_addr);
|
||||||
|
|
||||||
if (access(keypath, R_OK)) return;
|
if (access(keypath, R_OK)) return;
|
||||||
|
|
||||||
if(remove(keypath) != 0){
|
if(remove(keypath) != 0){
|
||||||
|
@ -5,24 +5,32 @@ CC=g++
|
|||||||
BTSTACK_ROOT = ../..
|
BTSTACK_ROOT = ../..
|
||||||
CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest
|
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
|
LDFLAGS += -L$(CPPUTEST_HOME) -lCppUTest -lCppUTestExt
|
||||||
|
|
||||||
COMMON = \
|
FS = \
|
||||||
${BTSTACK_ROOT}/src/memory_pool.c \
|
${BTSTACK_ROOT}/src/utils.c \
|
||||||
${BTSTACK_ROOT}/src/remote_device_db_memory.c \
|
${BTSTACK_ROOT}/platforms/posix/src/remote_device_db_fs.c
|
||||||
${BTSTACK_ROOT}/src/btstack_memory.c \
|
|
||||||
${BTSTACK_ROOT}/src/linked_list.c \
|
|
||||||
|
MEMORY = \
|
||||||
${BTSTACK_ROOT}/src/utils.c \
|
${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 $@
|
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f remote-memory *.o ../src/*.o
|
rm -f remote_device_db_memory_test remote_device_db_fs_test *.o ../src/*.o
|
||||||
|
|
||||||
|
@ -11,14 +11,8 @@
|
|||||||
|
|
||||||
extern linked_list_t db_mem_link_keys ;
|
extern linked_list_t db_mem_link_keys ;
|
||||||
extern linked_list_t db_mem_names ;
|
extern linked_list_t db_mem_names ;
|
||||||
|
// const extern "C" db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void);
|
||||||
typedef struct teststruct{
|
// const extern "C" void btstack_memory_init(void);
|
||||||
int type;
|
|
||||||
} teststruct_t;
|
|
||||||
|
|
||||||
teststruct_t tr = {
|
|
||||||
type : 0
|
|
||||||
};
|
|
||||||
|
|
||||||
void dump(linked_list_t list){
|
void dump(linked_list_t list){
|
||||||
printf("dump:\n");
|
printf("dump:\n");
|
||||||
@ -37,9 +31,9 @@ TEST_GROUP(RemoteDeviceDB){
|
|||||||
bd_addr_t addr1, addr2, addr3;
|
bd_addr_t addr1, addr2, addr3;
|
||||||
device_name_t device_name;
|
device_name_t device_name;
|
||||||
link_key_t link_key;
|
link_key_t link_key;
|
||||||
|
link_key_type_t link_key_type;
|
||||||
void setup(){
|
|
||||||
|
|
||||||
|
void setup(){
|
||||||
btstack_memory_init();
|
btstack_memory_init();
|
||||||
|
|
||||||
bd_addr_t addr_1 = {0x00, 0x01, 0x02, 0x03, 0x04, 0x01 };
|
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(addr1, addr_1);
|
||||||
BD_ADDR_COPY(addr2, addr_2);
|
BD_ADDR_COPY(addr2, addr_2);
|
||||||
BD_ADDR_COPY(addr3, addr_3);
|
BD_ADDR_COPY(addr3, addr_3);
|
||||||
|
|
||||||
|
link_key_type = (link_key_type_t)4;
|
||||||
|
sprintf((char*)link_key, "%d", 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void teardown(){}
|
void teardown(){}
|
||||||
@ -85,27 +82,27 @@ TEST(RemoteDeviceDB, SortByLastUsedName){
|
|||||||
|
|
||||||
TEST(RemoteDeviceDB, SinglePutGetDeleteKey){
|
TEST(RemoteDeviceDB, SinglePutGetDeleteKey){
|
||||||
sprintf((char*)link_key, "%d", 100);
|
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);
|
// 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);
|
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){
|
TEST(RemoteDeviceDB, SortByLastUsedKey){
|
||||||
sprintf((char*)link_key, "%d", 10);
|
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);
|
// dump(db_mem_link_keys);
|
||||||
sprintf((char*)link_key, "%d", 20);
|
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);
|
// dump(db_mem_link_keys);
|
||||||
sprintf((char*)link_key, "%d", 30);
|
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);
|
// 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);
|
// dump(db_mem_link_keys);
|
||||||
|
|
||||||
//get first element of the list
|
//get first element of the list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user