2013-07-06 02:23:26 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/tchar.h>
|
|
|
|
#include <winpr/collections.h>
|
|
|
|
|
|
|
|
static char* key1 = "key1";
|
|
|
|
static char* key2 = "key2";
|
|
|
|
static char* key3 = "key3";
|
|
|
|
|
|
|
|
static char* val1 = "val1";
|
|
|
|
static char* val2 = "val2";
|
|
|
|
static char* val3 = "val3";
|
|
|
|
|
|
|
|
int TestListDictionary(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
char* value;
|
|
|
|
wListDictionary* list;
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
list = ListDictionary_New(TRUE);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!list)
|
|
|
|
return -1;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!ListDictionary_Add(list, key1, val1) || !ListDictionary_Add(list, key2, val2) ||
|
|
|
|
!ListDictionary_Add(list, key3, val3))
|
2015-05-18 12:28:00 +03:00
|
|
|
return -1;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
|
|
|
count = ListDictionary_Count(list);
|
|
|
|
|
|
|
|
if (count != 3)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("ListDictionary_Count: Expected : 3, Actual: %d\n", count);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListDictionary_Remove(list, key2);
|
|
|
|
|
|
|
|
count = ListDictionary_Count(list);
|
|
|
|
|
|
|
|
if (count != 2)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("ListDictionary_Count: Expected : 2, Actual: %d\n", count);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListDictionary_Remove(list, key3);
|
|
|
|
|
|
|
|
count = ListDictionary_Count(list);
|
|
|
|
|
|
|
|
if (count != 1)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("ListDictionary_Count: Expected : 1, Actual: %d\n", count);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListDictionary_Remove(list, key1);
|
|
|
|
|
|
|
|
count = ListDictionary_Count(list);
|
|
|
|
|
|
|
|
if (count != 0)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("ListDictionary_Count: Expected : 0, Actual: %d\n", count);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!ListDictionary_Add(list, key1, val1) || !ListDictionary_Add(list, key2, val2) ||
|
|
|
|
!ListDictionary_Add(list, key3, val3))
|
2015-05-18 12:28:00 +03:00
|
|
|
return -1;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
|
|
|
count = ListDictionary_Count(list);
|
|
|
|
|
|
|
|
if (count != 3)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("ListDictionary_Count: Expected : 3, Actual: %d\n", count);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
value = (char*)ListDictionary_GetItemValue(list, key1);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
|
|
|
if (strcmp(value, val1) != 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("ListDictionary_GetItemValue: Expected : %" PRIuz ", Actual: %" PRIuz "\n",
|
|
|
|
(size_t)val1, (size_t)value);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
value = (char*)ListDictionary_GetItemValue(list, key2);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
|
|
|
if (strcmp(value, val2) != 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("ListDictionary_GetItemValue: Expected : %" PRIuz ", Actual: %" PRIuz "\n",
|
|
|
|
(size_t)val2, (size_t)value);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
value = (char*)ListDictionary_GetItemValue(list, key3);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
|
|
|
if (strcmp(value, val3) != 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("ListDictionary_GetItemValue: Expected : %" PRIuz ", Actual: %" PRIuz "\n",
|
|
|
|
(size_t)val3, (size_t)value);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListDictionary_SetItemValue(list, key2, "apple");
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
value = (char*)ListDictionary_GetItemValue(list, key2);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
|
|
|
if (strcmp(value, "apple") != 0)
|
|
|
|
{
|
2014-05-09 02:02:02 +04:00
|
|
|
printf("ListDictionary_GetItemValue: Expected : %s, Actual: %s\n", "apple", value);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ListDictionary_Contains(list, key2))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("ListDictionary_Contains: Expected : TRUE, Actual: FALSE\n");
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-15 16:11:14 +04:00
|
|
|
if (!ListDictionary_Remove(list, key2))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("ListDictionary_Remove: Expected : TRUE, Actual: FALSE\n");
|
2013-10-15 16:11:14 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ListDictionary_Remove(list, key2))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("ListDictionary_Remove: Expected : FALSE, Actual: TRUE\n");
|
2013-10-15 16:11:14 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-15 18:15:44 +04:00
|
|
|
value = ListDictionary_Remove_Head(list);
|
|
|
|
count = ListDictionary_Count(list);
|
|
|
|
if (strncmp(value, val1, 4) || count != 1)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("ListDictionary_Remove_Head: Expected : %s, Actual: %s Count: %d\n", val1, value,
|
|
|
|
count);
|
2013-10-15 18:15:44 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = ListDictionary_Remove_Head(list);
|
|
|
|
count = ListDictionary_Count(list);
|
|
|
|
if (strncmp(value, val3, 4) || count != 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("ListDictionary_Remove_Head: Expected : %s, Actual: %s Count: %d\n", val3, value,
|
|
|
|
count);
|
2013-10-15 18:15:44 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = ListDictionary_Remove_Head(list);
|
|
|
|
if (value)
|
|
|
|
{
|
2014-05-09 02:02:02 +04:00
|
|
|
printf("ListDictionary_Remove_Head: Expected : (null), Actual: %s\n", value);
|
2013-10-15 18:15:44 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!ListDictionary_Add(list, key1, val1) || !ListDictionary_Add(list, key2, val2) ||
|
2019-11-06 17:24:51 +03:00
|
|
|
!ListDictionary_Add(list, key3, val3))
|
2015-05-18 12:28:00 +03:00
|
|
|
return -1;
|
2013-10-15 18:15:44 +04:00
|
|
|
|
2013-07-06 02:23:26 +04:00
|
|
|
ListDictionary_Clear(list);
|
|
|
|
|
|
|
|
count = ListDictionary_Count(list);
|
|
|
|
|
|
|
|
if (count != 0)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("ListDictionary_Count: Expected : 0, Actual: %d\n", count);
|
2013-07-06 02:23:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListDictionary_Free(list);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|