2 * Copyright (c) 2017-2020, Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "test_ptrs_list_wrap.c"
21 list_head head = NULL;
22 assert(list_count(head) == 0);
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);
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]);
37 list_map(head, NULL, copy_cb, NULL);
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]);
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);
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]);
64 list_clear_free_contents(&head);
66 for (size_t i = 0; i < NELEMS(pointers_to_free); ++i)
67 assert(pointers_to_free[i] == NULL);