renamed test folder

This commit is contained in:
mila@ringwald.ch 2015-02-12 21:55:27 +00:00
parent 6a52c3a1e2
commit 87495b4700
3 changed files with 201 additions and 0 deletions

View File

@ -0,0 +1,37 @@
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../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I${BTSTACK_ROOT}/ble -I$(CPPUTEST_HOME)/include
LDFLAGS += -L$(CPPUTEST_HOME) -lCppUTest -lCppUTestExt
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)
all: remote_device_db_memory_test remote_device_db_fs_test
remote_device_db_memory_test: ${MEMORY_OBJ} remote_device_db_memory_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
remote_device_db_fs_test: ${FS_OBJ} remote_device_db_fs_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
clean:
rm -f remote_device_db_memory_test remote_device_db_fs_test *.o ../src/*.o
rm -rf *.dSYM

View File

@ -0,0 +1,49 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "CppUTest/TestHarness.h"
#include "CppUTest/CommandLineTestRunner.h"
#include "remote_device_db.h"
#include "btstack-config.h"
const remote_device_db_t * remote_device_db_fs_instance();
TEST_GROUP(RemoteDeviceDB){
bd_addr_t bd_addr;
link_key_t link_key;
link_key_type_t link_key_type;
void setup(){
bd_addr_t addr_1 = {0x00, 0x01, 0x02, 0x03, 0x04, 0x01 };
BD_ADDR_COPY(bd_addr, addr_1);
link_key_type = (link_key_type_t)4;
sprintf((char*)link_key, "%d", 100);
}
void teardown(){}
};
TEST(RemoteDeviceDB, SinglePutGetDeleteKey){
link_key_t test_link_key;
link_key_type_t test_link_key_type;
remote_device_db_fs_instance()->delete_link_key(&bd_addr);
CHECK(remote_device_db_fs_instance()->get_link_key(&bd_addr, &test_link_key, &test_link_key_type) == 0);
remote_device_db_fs_instance()->put_link_key(&bd_addr, &link_key, link_key_type);
CHECK(remote_device_db_fs_instance()->get_link_key(&bd_addr, &test_link_key, &test_link_key_type) == 1);
CHECK(strcmp(link_key_to_str(link_key), link_key_to_str(test_link_key)) == 0);
remote_device_db_fs_instance()->delete_link_key(&bd_addr);
CHECK(remote_device_db_fs_instance()->get_link_key(&bd_addr, &test_link_key, &test_link_key_type) == 0);
}
int main (int argc, const char * argv[]){
return CommandLineTestRunner::RunAllTests(argc, argv);
}

View File

@ -0,0 +1,115 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "CppUTest/TestHarness.h"
#include "CppUTest/CommandLineTestRunner.h"
#include "remote_device_db.h"
#include "btstack_memory.h"
#include "btstack-config.h"
extern linked_list_t db_mem_link_keys ;
extern linked_list_t db_mem_names ;
// 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");
linked_item_t *it;
for (it = (linked_item_t *) list; it ; it = it->next){
db_mem_device_t * item = (db_mem_device_t *) it;
db_mem_device_name_t * item1 = (db_mem_device_name_t *) it;
db_mem_device_link_key_t * item2 = (db_mem_device_link_key_t *) it;
printf("%s + %s + %u\n", item1->device_name, item2->link_key, item->bd_addr[5]);
}
}
TEST_GROUP(RemoteDeviceDB){
bd_addr_t addr1, addr2, addr3;
device_name_t device_name;
link_key_t link_key;
link_key_type_t link_key_type;
void setup(){
btstack_memory_init();
bd_addr_t addr_1 = {0x00, 0x01, 0x02, 0x03, 0x04, 0x01 };
bd_addr_t addr_2 = {0x00, 0x01, 0x02, 0x03, 0x04, 0x02 };
bd_addr_t addr_3 = {0x00, 0x01, 0x02, 0x03, 0x04, 0x03 };
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(){}
};
TEST(RemoteDeviceDB, MemoryPool){
CHECK(MAX_NO_DB_MEM_DEVICE_NAMES > 0);
void * item = btstack_memory_db_mem_device_name_get();
CHECK(item);
}
TEST(RemoteDeviceDB, SinglePutGetDeleteName){
sprintf((char*)device_name, "%d", 100);
remote_device_db_memory.put_name(&addr1, &device_name);
CHECK(remote_device_db_memory.get_name(&addr1, &device_name));
remote_device_db_memory.delete_name(&addr1);
CHECK(!remote_device_db_memory.get_name(&addr1, &device_name));
}
TEST(RemoteDeviceDB, SortByLastUsedName){
sprintf((char*)device_name, "%d", 10);
remote_device_db_memory.put_name(&addr1, &device_name);
sprintf((char*)device_name, "%d", 20);
remote_device_db_memory.put_name(&addr2, &device_name);
sprintf((char*)device_name, "%d", 30);
remote_device_db_memory.put_name(&addr3, &device_name);
CHECK(remote_device_db_memory.get_name(&addr2, &device_name));
//get first element of the list
db_mem_device_name_t * item = (db_mem_device_name_t *) db_mem_names;
STRCMP_EQUAL((char*)item->device_name, "20");
}
TEST(RemoteDeviceDB, SinglePutGetDeleteKey){
sprintf((char*)link_key, "%d", 100);
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, &link_key_type));
remote_device_db_memory.delete_link_key(&addr1);
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, link_key_type);
// dump(db_mem_link_keys);
sprintf((char*)link_key, "%d", 20);
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, link_key_type);
// dump(db_mem_link_keys);
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
db_mem_device_link_key_t * item = (db_mem_device_link_key_t *) db_mem_link_keys;
STRCMP_EQUAL((char*)item->link_key, "20");
}
int main (int argc, const char * argv[]){
return CommandLineTestRunner::RunAllTests(argc, argv);
}