universe@390: /* universe@390: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@390: * universe@390: * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. universe@390: * universe@390: * Redistribution and use in source and binary forms, with or without universe@390: * modification, are permitted provided that the following conditions are met: universe@390: * universe@390: * 1. Redistributions of source code must retain the above copyright universe@390: * notice, this list of conditions and the following disclaimer. universe@390: * universe@390: * 2. Redistributions in binary form must reproduce the above copyright universe@390: * notice, this list of conditions and the following disclaimer in the universe@390: * documentation and/or other materials provided with the distribution. universe@390: * universe@390: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@390: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@390: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@390: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@390: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@390: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@390: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@390: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@390: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@390: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@390: * POSSIBILITY OF SUCH DAMAGE. universe@390: */ universe@390: universe@398: #include "cx/linked_list.h" universe@411: #include "test_config.h" universe@398: universe@412: int cmp_int(int const *l, int const *r) { universe@412: int left = *l, right = *r; universe@412: return left == right ? 0 : (left < right ? -1 : 1); universe@412: } universe@412: universe@412: void test_linked_list_create() { universe@412: CxList list = cxLinkedListCreate(cxDefaultAllocator, (CxListComparator) cmp_int, sizeof(int)); universe@412: universe@412: CU_ASSERT_EQUAL(list->data.size, 0) universe@412: CU_ASSERT_EQUAL(list->data.capacity, (size_t) -1) universe@412: CU_ASSERT_PTR_EQUAL(list->data.allocator, cxDefaultAllocator) universe@412: CU_ASSERT_EQUAL(list->data.itemsize, sizeof(int)) universe@412: CU_ASSERT_PTR_EQUAL(list->data.cmpfunc, cmp_int) universe@412: universe@412: struct node { universe@412: void* begin; void* end; ptrdiff_t ploc; ptrdiff_t nloc; universe@412: }; universe@412: universe@412: struct node* actual = (struct node*) list->data.listdata; universe@412: CU_ASSERT_PTR_NULL(actual->begin) universe@412: CU_ASSERT_PTR_NULL(actual->end) universe@412: CU_ASSERT_EQUAL(0, actual->ploc) universe@412: CU_ASSERT_EQUAL(sizeof(void*), actual->nloc) universe@412: universe@412: cxLinkedListDestroy(list); universe@413: universe@413: // TODO: use allocator that keeps track of the freed memory universe@411: } universe@398: universe@390: int main() { universe@411: CU_pSuite suite = NULL; universe@411: universe@411: if (CUE_SUCCESS != CU_initialize_registry()) { universe@411: return CU_get_error(); universe@411: } universe@411: universe@413: suite = CU_add_suite("linked list suite", NULL, NULL); universe@411: if (NULL == suite) { universe@411: CU_cleanup_registry(); universe@411: return CU_get_error(); universe@411: } universe@411: universe@411: if ( universe@413: !CU_add_test(suite, "create and destroy linked list", test_linked_list_create) universe@411: ) { universe@411: CU_cleanup_registry(); universe@411: return CU_get_error(); universe@411: } universe@411: universe@413: suite = CU_add_suite("array suite", NULL, NULL); universe@413: if (NULL == suite) { universe@413: CU_cleanup_registry(); universe@413: return CU_get_error(); universe@413: } universe@413: universe@413: /* universe@413: if ( universe@413: !CU_add_test(suite, "array...", test_array...) universe@413: ) { universe@413: CU_cleanup_registry(); universe@413: return CU_get_error(); universe@413: } universe@413: */ universe@413: universe@411: CU_basic_set_mode(UCX_CU_BRM); universe@411: universe@411: int exitcode; universe@411: if (CU_basic_run_tests()) { universe@411: exitcode = CU_get_error(); universe@411: } else { universe@411: exitcode = CU_get_number_of_failures() == 0 ? 0 : 1; universe@411: } universe@411: CU_cleanup_registry(); universe@411: return exitcode; universe@390: }