~paulliu/ubuntu/quantal/freerdp/fixext

« back to all changes in this revision

Viewing changes to cunit/test_list.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-01-31 10:02:14 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20120131100214-zvig71djj2sqgq22
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * FreeRDP: A Remote Desktop Protocol Client
 
3
 * List Unit Tests
 
4
 *
 
5
 * Copyright 2011 Vic Lee
 
6
 *
 
7
 * Licensed under the Apache License, Version 2.0 (the "License");
 
8
 * you may not use this file except in compliance with the License.
 
9
 * You may obtain a copy of the License at
 
10
 *
 
11
 *     http://www.apache.org/licenses/LICENSE-2.0
 
12
 *
 
13
 * Unless required by applicable law or agreed to in writing, software
 
14
 * distributed under the License is distributed on an "AS IS" BASIS,
 
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
 * See the License for the specific language governing permissions and
 
17
 * limitations under the License.
 
18
 */
 
19
 
 
20
#include <stdio.h>
 
21
#include <string.h>
 
22
#include <stdlib.h>
 
23
#include <freerdp/freerdp.h>
 
24
#include <freerdp/utils/list.h>
 
25
 
 
26
#include "test_list.h"
 
27
 
 
28
int init_list_suite(void)
 
29
{
 
30
        return 0;
 
31
}
 
32
 
 
33
int clean_list_suite(void)
 
34
{
 
35
        return 0;
 
36
}
 
37
 
 
38
int add_list_suite(void)
 
39
{
 
40
        add_test_suite(list);
 
41
 
 
42
        add_test_function(list);
 
43
 
 
44
        return 0;
 
45
}
 
46
 
 
47
struct _my_list_item
 
48
{
 
49
        uint32 a;
 
50
        uint32 b;
 
51
};
 
52
typedef struct _my_list_item my_list_item;
 
53
 
 
54
void test_list(void)
 
55
{
 
56
        LIST* list;
 
57
        LIST_ITEM* list_item;
 
58
        my_list_item* item;
 
59
        my_list_item* item1;
 
60
        my_list_item* item2;
 
61
        int i;
 
62
 
 
63
        list = list_new();
 
64
 
 
65
        for (i = 0; i < 10; i++)
 
66
        {
 
67
                item = xnew(my_list_item);
 
68
                item->a = i;
 
69
                item->b = i * i;
 
70
                list_enqueue(list, item);
 
71
        }
 
72
 
 
73
        for (i = 0, list_item = list->head; list_item; i++, list_item = list_item->next)
 
74
        {
 
75
                CU_ASSERT(((my_list_item*)list_item->data)->a == i);
 
76
                CU_ASSERT(((my_list_item*)list_item->data)->b == i * i);
 
77
                /*printf("%d %d\n", item->a, item->b);*/
 
78
        }
 
79
 
 
80
        item1 = xnew(my_list_item);
 
81
        list_add(list, item1);
 
82
        item2 = xnew(my_list_item);
 
83
        list_add(list, item2);
 
84
 
 
85
        CU_ASSERT(list_remove(list, item1) == item1);
 
86
        xfree(item1);
 
87
        CU_ASSERT(list_remove(list, item2) == item2);
 
88
        CU_ASSERT(list_remove(list, item2) == NULL);
 
89
        xfree(item2);
 
90
 
 
91
        while ((item = list_dequeue(list)) != NULL)
 
92
                xfree(item);
 
93
        list_free(list);
 
94
}