le_device_db_tlv_test: test add existing entry

This commit is contained in:
Milanka Ringwald 2020-09-24 15:16:39 +02:00
parent db5aaf2afe
commit 05e0a7f4e6
2 changed files with 32 additions and 9 deletions

View File

@ -10,6 +10,7 @@
#define HAVE_POSIX_TIME
#define HAVE_POSIX_FILE_IO
#define HAVE_BTSTACK_STDIN
#define HAVE_ASSERT
// BTstack features that can be enabled
#define ENABLE_BLE

View File

@ -150,6 +150,28 @@ TEST(LE_DEVICE_DB_TLV, AddOTwoRemoveOne){
MEMCMP_EQUAL(addr_bb, addr, 6);
}
TEST(LE_DEVICE_DB_TLV, AddOTwoRemoveThree){
int index_a = le_device_db_add(BD_ADDR_TYPE_LE_PUBLIC, addr_aa, sm_key_aa);
CHECK_TRUE(index_a >= 0);
int index_b = le_device_db_add(BD_ADDR_TYPE_LE_PUBLIC, addr_bb, sm_key_bb);
CHECK_TRUE(index_b >= 0);
CHECK_EQUAL(2, le_device_db_count());
le_device_db_remove((uint16_t) index_a);
CHECK_EQUAL(1, le_device_db_count());
le_device_db_remove((uint16_t) index_b);
CHECK_EQUAL(0, le_device_db_count());
le_device_db_remove((uint16_t) index_b);
CHECK_EQUAL(0, le_device_db_count());
}
TEST(LE_DEVICE_DB_TLV, RemoveOneFromEmpty){
CHECK_EQUAL(0, le_device_db_count());
le_device_db_remove(0);
CHECK_EQUAL(0, le_device_db_count());
}
TEST(LE_DEVICE_DB_TLV, AddTwoRemoveOneAddOne){
int index_a = le_device_db_add(BD_ADDR_TYPE_LE_PUBLIC, addr_aa, sm_key_aa);
CHECK_TRUE(index_a >= 0);
@ -167,17 +189,17 @@ TEST(LE_DEVICE_DB_TLV, AddTwoRemoveOneAddOne){
MEMCMP_EQUAL(addr_cc, addr, 6);
}
TEST(LE_DEVICE_DB_TLV, le_device_db_add){
uint8_t i;
for (i=0; i < NVM_NUM_DEVICE_DB_ENTRIES; i++){
init_addr_and_key(i);
int index = le_device_db_add(BD_ADDR_TYPE_LE_PUBLIC, addr, sm_key);
CHECK_TRUE(index >= 0);
CHECK_EQUAL(i+1, le_device_db_count());
}
TEST(LE_DEVICE_DB_TLV, AddExisting){
int index = le_device_db_add(BD_ADDR_TYPE_LE_PUBLIC, addr_aa, sm_key_aa);
CHECK_TRUE(index >= 0);
CHECK_EQUAL(1, le_device_db_count());
index = le_device_db_add(BD_ADDR_TYPE_LE_PUBLIC, addr_aa, sm_key_aa);
CHECK_TRUE(index >= 0);
CHECK_EQUAL(1, le_device_db_count());
}
int main (int argc, const char * argv[]){
return CommandLineTestRunner::RunAllTests(argc, argv);
}