1 /* <!-- copyright */
2 /*
3 * libmetalink
4 *
5 * Copyright (c) 2008 Tatsuhiro Tsujikawa
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25 /* copyright --> */
26 #include "metalink_list_test.h"
27
28 #include <CUnit/CUnit.h>
29
30 #include "metalink_list.h"
31
test_metalink_list(void)32 void test_metalink_list(void)
33 {
34 metalink_list_t* l;
35 int a, b, c;
36 int* int_ptr_array[3];
37
38 l = metalink_list_new();
39 CU_ASSERT_PTR_NOT_NULL(l);
40
41 /* Add 3 ints. */
42 a = 1;
43 b = 2;
44 c = 4;
45 metalink_list_append(l, &a);
46 metalink_list_append(l, &b);
47 metalink_list_append(l, &c);
48 CU_ASSERT_EQUAL(3, metalink_list_length(l));
49
50 /* get 2nd(index = 1) element = (2) */
51 CU_ASSERT_EQUAL(2, *(int*)metalink_list_get_data(l, 1));
52
53 /* dump the contents of list to array */
54 metalink_list_to_array(l, (void**)int_ptr_array);
55 CU_ASSERT_EQUAL(1, *int_ptr_array[0]);
56 CU_ASSERT_EQUAL(2, *int_ptr_array[1]);
57 CU_ASSERT_EQUAL(4, *int_ptr_array[2]);
58
59 /* clear all data */
60 metalink_list_clear(l);
61 CU_ASSERT_EQUAL(0, metalink_list_length(l));
62
63 /* delete list */
64 metalink_list_delete(l);
65 }
66