update keylist to use bool and stdint value for key not found. (#572)

* Updated keylist to use bool and stdint value for key not found.

* Added Keylist_Index_Key to deprecate Keylist_Key function

* Changed the deprecated Keylist_Key API to Keylist_Index_Key

* Added unit test for Keylist_Index_Key API
This commit is contained in:
Steve Karg
2024-02-12 17:35:15 -06:00
committed by GitHub
parent 7eedaa406d
commit 190183966c
16 changed files with 143 additions and 55 deletions
+15 -7
View File
@@ -122,6 +122,7 @@ ZTEST(keylist_tests, testKeyListDataKey)
static void testKeyListDataKey(void)
#endif
{
bool status = false;
OS_Keylist list;
KEY key;
KEY test_key;
@@ -137,19 +138,22 @@ static void testKeyListDataKey(void)
key = 1;
index = Keylist_Data_Add(list, key, data1);
zassert_equal(index, 0, NULL);
test_key = Keylist_Key(list, index);
status = Keylist_Index_Key(list, index, &test_key);
zassert_true(status, NULL);
zassert_equal(test_key, key, NULL);
key = 2;
index = Keylist_Data_Add(list, key, data2);
zassert_equal(index, 1, NULL);
test_key = Keylist_Key(list, index);
status = Keylist_Index_Key(list, index, &test_key);
zassert_true(status, NULL);
zassert_equal(test_key, key, NULL);
key = 3;
index = Keylist_Data_Add(list, key, data3);
zassert_equal(index, 2, NULL);
test_key = Keylist_Key(list, index);
status = Keylist_Index_Key(list, index, &test_key);
zassert_true(status, NULL);
zassert_equal(test_key, key, NULL);
zassert_equal(Keylist_Count(list), 3, NULL);
@@ -278,7 +282,8 @@ ZTEST(keylist_tests, testKeyListLarge)
static void testKeyListLarge(void)
#endif
{
int data1 = 42;
bool status = false;
int data_list[1024 * 16] = { 0 };
int *data;
OS_Keylist list;
KEY key;
@@ -290,15 +295,18 @@ static void testKeyListLarge(void)
return;
for (key = 0; key < num_keys; key++) {
index = Keylist_Data_Add(list, key, &data1);
data_list[key] = 42 + key;
index = Keylist_Data_Add(list, key, &data_list[key]);
}
for (key = 0; key < num_keys; key++) {
data = Keylist_Data(list, key);
zassert_equal(*data, data1, NULL);
zassert_equal(*data, data_list[key], NULL);
}
for (index = 0; index < num_keys; index++) {
data = Keylist_Data_Index(list, index);
zassert_equal(*data, data1, NULL);
status = Keylist_Index_Key(list, index, &key);
zassert_true(status, NULL);
zassert_equal(*data, data_list[key], NULL);
}
Keylist_Delete(list);