xref: /btstack/test/btstack_link_key_db/btstack_link_key_db_fs_test.cpp (revision 4902524cc6a45a01cfead054f48b6584dbb1f1cc)
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include "CppUTest/TestHarness.h"
5 #include "CppUTest/CommandLineTestRunner.h"
6 
7 #include "classic/btstack_link_key_db.h"
8 #include "btstack_link_key_db_fs.h"
9 #include "btstack_util.h"
10 
11 #include "btstack_config.h"
12 
btstack_run_loop_get_time_ms(void)13 extern "C" uint32_t btstack_run_loop_get_time_ms(void) { return 0; }
14 
TEST_GROUP(RemoteDeviceDB)15 TEST_GROUP(RemoteDeviceDB){
16     bd_addr_t bd_addr;
17     link_key_t link_key;
18     link_key_type_t link_key_type;
19 
20     void setup(void){
21         bd_addr_t addr_1 = {0x00, 0x01, 0x02, 0x03, 0x04, 0x01 };
22         bd_addr_copy(bd_addr, addr_1);
23 
24         link_key_type = (link_key_type_t)4;
25         sprintf((char*)link_key, "%d", 100);
26     }
27 
28     void teardown(void){}
29 };
30 
31 
TEST(RemoteDeviceDB,SinglePutGetDeleteKey)32 TEST(RemoteDeviceDB, SinglePutGetDeleteKey){
33 	link_key_t test_link_key;
34     link_key_type_t test_link_key_type;
35 
36     btstack_link_key_db_fs_instance()->delete_link_key(bd_addr);
37     CHECK(btstack_link_key_db_fs_instance()->get_link_key(bd_addr, test_link_key, &test_link_key_type) == 0);
38 
39 	btstack_link_key_db_fs_instance()->put_link_key(bd_addr, link_key, link_key_type);
40     CHECK(btstack_link_key_db_fs_instance()->get_link_key(bd_addr, test_link_key, &test_link_key_type) == 1);
41 
42     CHECK(memcmp(link_key, test_link_key, 16) == 0);
43 
44     btstack_link_key_db_fs_instance()->delete_link_key(bd_addr);
45     CHECK(btstack_link_key_db_fs_instance()->get_link_key(bd_addr, test_link_key, &test_link_key_type) == 0);
46 }
47 
48 
main(int argc,const char * argv[])49 int main (int argc, const char * argv[]){
50     return CommandLineTestRunner::RunAllTests(argc, argv);
51 }