2011-07-07 20:51:24 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* List Unit Tests
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <freerdp/utils/list.h>
|
|
|
|
|
|
|
|
#include "test_list.h"
|
|
|
|
|
|
|
|
int init_list_suite(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clean_list_suite(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int add_list_suite(void)
|
|
|
|
{
|
|
|
|
add_test_suite(list);
|
|
|
|
|
|
|
|
add_test_function(list);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-04 18:02:46 +04:00
|
|
|
struct _my_list_item
|
2011-07-07 20:51:24 +04:00
|
|
|
{
|
|
|
|
uint32 a;
|
|
|
|
uint32 b;
|
|
|
|
};
|
2011-08-04 18:02:46 +04:00
|
|
|
typedef struct _my_list_item my_list_item;
|
2011-07-07 20:51:24 +04:00
|
|
|
|
|
|
|
void test_list(void)
|
|
|
|
{
|
2011-08-04 18:02:46 +04:00
|
|
|
LIST* list;
|
|
|
|
LIST_ITEM* list_item;
|
|
|
|
my_list_item* item;
|
|
|
|
my_list_item* item1;
|
|
|
|
my_list_item* item2;
|
2011-07-07 20:51:24 +04:00
|
|
|
int i;
|
|
|
|
|
2011-08-04 18:02:46 +04:00
|
|
|
list = list_new();
|
2011-07-07 20:51:24 +04:00
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
2011-08-04 18:02:46 +04:00
|
|
|
item = xnew(my_list_item);
|
2011-07-07 20:51:24 +04:00
|
|
|
item->a = i;
|
|
|
|
item->b = i * i;
|
2011-08-04 18:02:46 +04:00
|
|
|
list_enqueue(list, item);
|
2011-07-07 20:51:24 +04:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:02:46 +04:00
|
|
|
for (i = 0, list_item = list->head; list_item; i++, list_item = list_item->next)
|
2011-07-07 20:51:24 +04:00
|
|
|
{
|
2011-08-04 18:02:46 +04:00
|
|
|
CU_ASSERT(((my_list_item*)list_item->data)->a == i);
|
|
|
|
CU_ASSERT(((my_list_item*)list_item->data)->b == i * i);
|
2011-07-07 20:51:24 +04:00
|
|
|
/*printf("%d %d\n", item->a, item->b);*/
|
|
|
|
}
|
|
|
|
|
2011-08-04 18:02:46 +04:00
|
|
|
item1 = xnew(my_list_item);
|
|
|
|
list_add(list, item1);
|
|
|
|
item2 = xnew(my_list_item);
|
|
|
|
list_add(list, item2);
|
2011-07-19 07:01:42 +04:00
|
|
|
|
2011-08-04 18:02:46 +04:00
|
|
|
CU_ASSERT(list_remove(list, item1) == item1);
|
2011-07-26 05:19:58 +04:00
|
|
|
xfree(item1);
|
2011-08-04 18:02:46 +04:00
|
|
|
CU_ASSERT(list_remove(list, item2) == item2);
|
|
|
|
CU_ASSERT(list_remove(list, item2) == NULL);
|
2011-07-26 05:19:58 +04:00
|
|
|
xfree(item2);
|
2011-07-19 07:01:42 +04:00
|
|
|
|
2011-08-04 18:02:46 +04:00
|
|
|
while ((item = list_dequeue(list)) != NULL)
|
|
|
|
xfree(item);
|
|
|
|
list_free(list);
|
2011-07-07 20:51:24 +04:00
|
|
|
}
|