Replace () with (void) in function prototypes
[platform/core/system/dlog.git] / src / tests / test_ptrs_list_pos.c
1 /*
2  * Copyright (c) 2017-2020, Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "test_ptrs_list_wrap.c"
18
19 int main(void)
20 {
21         list_head head = NULL;
22         assert(list_count(head) == 0);
23
24         void *const elems[] = {"a", "b", "c"};
25         for (size_t i = 0; i < NELEMS(elems); i++) {
26                 assert(list_add(&head, elems[i]));
27                 assert(list_count(head) == i + 1);
28         }
29
30         list_head iter = head;
31         for (size_t i = 0; i < NELEMS(elems); ++i, list_next(&iter))
32                 assert(list_at(iter) == elems[NELEMS(elems) - 1 - i]);
33         assert(iter == NULL);
34
35         fail_calloc = 1 << 2;
36         frees = 0;
37         list_map(head, NULL, copy_cb, NULL);
38         assert(frees == 2);
39
40         fail_calloc = 4;
41         letters_cleared[0] = letters_cleared[1] = letters_cleared[2] = false;
42         list_map(head, NULL, copy_cb, clear_cb);
43         assert(letters_cleared[0] && letters_cleared[1] && letters_cleared[2]);
44
45         list_remove(&head, elems[0]); //remove tail
46         assert(list_count(head) == 2);
47         assert(list_at(head) == elems[2]);
48         list_remove(&head, elems[2]); //remove head
49         assert(list_count(head) == 1);
50         assert(list_at(head) == elems[1]);
51         list_remove(&head, elems[1]); //remove last
52         assert(list_count(head) == 0);
53         assert(head == NULL);
54
55         iter = NULL;
56         list_next(&iter);
57         assert(iter == NULL);
58
59         for (size_t i = 0; i < NELEMS(pointers_to_free); ++i) {
60                 pointers_to_free[i] = malloc(i + 5);
61                 list_add(&head, pointers_to_free[i]);
62         }
63
64         list_clear_free_contents(&head);
65         assert(head == NULL);
66         for (size_t i = 0; i < NELEMS(pointers_to_free); ++i)
67                 assert(pointers_to_free[i] == NULL);
68
69         return 0;
70 }