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"};
26 for (size_t i = 0; i < NELEMS(elems); i++) {
27 assert(list_add(&head, elems[i]));
28 assert(list_count(head) == i + 1);
32 for (size_t i = 0; i < NELEMS(elems); i++) {
33 assert(!list_add(&head, elems[i]));
34 assert(list_count(head) == NELEMS(elems));
37 fail_copy_on = elems[0];
38 letters_cleared[0] = letters_cleared[1] = letters_cleared[2] = false;
39 assert(!list_map(head, NULL, copy_cb, clear_cb));
40 assert(!letters_cleared[0] && letters_cleared[1] && letters_cleared[2]);
42 /* list_map() has some tricky allocation inside it so
43 * make sure there were as many free()s as calloc()s */
44 fail_calloc = 1 << 28;
46 fail_copy_on = elems[0];
47 assert(!list_map(head, NULL, copy_cb, NULL));
49 assert(fail_calloc == 1 << (28-2));
53 assert(list_count(head) == 0);