diff -r 92e482410453 -r d345541018fa test/main.c --- a/test/main.c Mon Dec 30 09:54:10 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,286 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include - -#include "main.h" - -#include "array_tests.h" -#include "allocator_tests.h" -#include "logging_tests.h" -#include "list_tests.h" -#include "string_tests.h" -#include "mpool_tests.h" -#include "stack_tests.h" -#include "map_tests.h" -#include "prop_tests.h" -#include "buffer_tests.h" -#include "utils_tests.h" -#include "avl_tests.h" - -#ifdef __cplusplus -extern "C" { -#endif -UCX_TEST(testTestSuitePositive) { - UCX_TEST_BEGIN - UCX_TEST_ASSERT(2*2 == 4, "the test framework fails"); - UCX_TEST_END -} - -UCX_TEST(testTestSuiteNegative) { - UCX_TEST_BEGIN - UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works"); - UCX_TEST_END -} - -UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) { - UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails"); -} - -UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) { - UCX_TEST_ASSERT(i == 42, "two parameter routine fails"); - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f); -} - -UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) { - *i += 2; - UCX_TEST_ASSERT(*i==4, "the test framework fails"); -} - -UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) { - *i += 2; - // Next test shall fail! - UCX_TEST_ASSERT(*i==4, "the test framework works"); -} - -UCX_TEST(testTestSuiteRoutinePositive) { - int i = 2; - UCX_TEST_BEGIN - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i); - UCX_TEST_ASSERT(i==4, "the test framework fails"); - UCX_TEST_END -} - -UCX_TEST(testTestSuiteRoutineNegative) { - int i = 0; - UCX_TEST_BEGIN - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i); - UCX_TEST_ASSERT(1, "the test framework fails"); - UCX_TEST_END -} - -UCX_TEST(testTestSuiteRoutineMultiparam) { - UCX_TEST_BEGIN - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f); - UCX_TEST_END -} -#ifdef __cplusplus -} -#endif - -int main(int argc, char **argv) { - printf("UCX Tests\n---------\n"); - - printf("\nUcxTestSuite tests (2 failures are intended!)\n"); - UcxTestSuite* suite = ucx_test_suite_new(); - ucx_test_register(suite, testTestSuitePositive); - ucx_test_register(suite, testTestSuiteNegative); - ucx_test_register(suite, testTestSuiteRoutinePositive); - ucx_test_register(suite, testTestSuiteRoutineNegative); - ucx_test_register(suite, testTestSuiteRoutineMultiparam); - ucx_test_run(suite, stdout); - if (suite->failure == 2 && suite->success == 3) { - ucx_test_suite_free(suite); - - printf("\nLibrary function tests\n"); - suite = ucx_test_suite_new(); - /* UcxAllocator Tests */ - ucx_test_register(suite, test_ucx_default_allocator); - - /* sstring Tests */ - ucx_test_register(suite, test_sstr_macros); - ucx_test_register(suite, test_sstr); - ucx_test_register(suite, test_sstr_len); - ucx_test_register(suite, test_sstrcmp); - ucx_test_register(suite, test_sstrcasecmp); - ucx_test_register(suite, test_sstrcat); - ucx_test_register(suite, test_sstrchr_sstrrchr); - ucx_test_register(suite, test_sstrstr); - ucx_test_register(suite, test_sstrsplit); - ucx_test_register(suite, test_sstrtrim); - ucx_test_register(suite, test_sstrprefixsuffix); - ucx_test_register(suite, test_sstrcaseprefixsuffix); - ucx_test_register(suite, test_sstrreplace); - - /* UcxLogger Tests */ - ucx_test_register(suite, test_ucx_logger_new); - ucx_test_register(suite, test_ucx_logger_log); - - /* UcxArray Tests */ - ucx_test_register(suite, test_ucx_array_destroy); - ucx_test_register(suite, test_ucx_array_new); - ucx_test_register(suite, test_ucx_array_at); - ucx_test_register(suite, test_ucx_array_append_from); - ucx_test_register(suite, test_ucx_array_append_from_struct); - ucx_test_register(suite, test_ucx_array_prepend_from); - ucx_test_register(suite, test_ucx_array_set_from); - ucx_test_register(suite, test_ucx_array_equals); - ucx_test_register(suite, test_ucx_array_concat); - ucx_test_register(suite, test_ucx_array_find); - ucx_test_register(suite, test_ucx_array_contains); - ucx_test_register(suite, test_ucx_array_remove); - ucx_test_register(suite, test_ucx_array_clone); - ucx_test_register(suite, test_ucx_array_sort); - ucx_test_register(suite, test_ucx_array_shrink); - ucx_test_register(suite, test_ucx_array_resize); - ucx_test_register(suite, test_ucx_array_reserve); - ucx_test_register(suite, test_ucx_array_grow); - ucx_test_register(suite, test_ucx_array_util_set); - ucx_test_register(suite, test_ucx_array_util_setptr); - - /* UcxList Tests */ - ucx_test_register(suite, test_ucx_list_append); - ucx_test_register(suite, test_ucx_list_prepend); - ucx_test_register(suite, test_ucx_list_equals); - ucx_test_register(suite, test_ucx_list_concat); - ucx_test_register(suite, test_ucx_list_size); - ucx_test_register(suite, test_ucx_list_first); - ucx_test_register(suite, test_ucx_list_last); - ucx_test_register(suite, test_ucx_list_get); - ucx_test_register(suite, test_ucx_list_indexof); - ucx_test_register(suite, test_ucx_list_find); - ucx_test_register(suite, test_ucx_list_contains); - ucx_test_register(suite, test_ucx_list_remove); - ucx_test_register(suite, test_ucx_list_clone); - ucx_test_register(suite, test_ucx_list_sort); - ucx_test_register(suite, test_ucx_list_union); - ucx_test_register(suite, test_ucx_list_intersection); - ucx_test_register(suite, test_ucx_list_difference); - - /* UcxMemPool Tests */ - ucx_test_register(suite, test_ucx_mempool_new); - ucx_test_register(suite, test_ucx_mempool_malloc); - ucx_test_register(suite, test_ucx_mempool_malloc_with_chcap); - ucx_test_register(suite, test_ucx_mempool_calloc); - ucx_test_register(suite, test_ucx_mempool_free); - ucx_test_register(suite, test_ucx_mempool_set_destr); - ucx_test_register(suite, test_ucx_mempool_reg_destr); - ucx_test_register(suite, test_ucx_mempool_realloc); - - /* UcxStack Tests */ - ucx_test_register(suite, test_ucx_stack_init); - ucx_test_register(suite, test_ucx_stack_malloc); - ucx_test_register(suite, test_ucx_stack_calloc); - ucx_test_register(suite, test_ucx_stack_free); - ucx_test_register(suite, test_ucx_stack_realloc); - ucx_test_register(suite, test_ucx_stack_pop); - - /* UcxMap Tests */ - ucx_test_register(suite, test_ucx_map_new); - ucx_test_register(suite, test_ucx_key); - ucx_test_register(suite, test_ucx_map_put); - ucx_test_register(suite, test_ucx_map_get); - ucx_test_register(suite, test_ucx_map_remove); - ucx_test_register(suite, test_ucx_map_clear); - ucx_test_register(suite, test_ucx_map_iterator); - ucx_test_register(suite, test_ucx_map_iterator_chain); - ucx_test_register(suite, test_ucx_map_clone); - ucx_test_register(suite, test_ucx_map_rehash); - ucx_test_register(suite, test_ucx_map_union); - ucx_test_register(suite, test_ucx_map_intersection); - ucx_test_register(suite, test_ucx_map_difference); - - /* UcxPropertiesParser Tests */ - ucx_test_register(suite, test_ucx_properties_new); - ucx_test_register(suite, test_ucx_properties_next); - ucx_test_register(suite, test_ucx_properties_next_multi); - ucx_test_register(suite, test_ucx_properties_next_part); - ucx_test_register(suite, test_ucx_properties_next_long); - ucx_test_register(suite, test_ucx_properties2map); - ucx_test_register(suite, test_ucx_properties_load); - ucx_test_register(suite, test_ucx_properties_store); - - /* UcxBuffer Tests */ - ucx_test_register(suite, test_ucx_buffer_new); - ucx_test_register(suite, test_ucx_buffer_new_prealloc); - ucx_test_register(suite, test_ucx_buffer_eof); - ucx_test_register(suite, test_ucx_buffer_seek_set); - ucx_test_register(suite, test_ucx_buffer_seek_cur); - ucx_test_register(suite, test_ucx_buffer_seek_end); - ucx_test_register(suite, test_ucx_buffer_seek_oob); - ucx_test_register(suite, test_ucx_buffer_seek_invalid); - ucx_test_register(suite, test_ucx_buffer_seek_overflow); - ucx_test_register(suite, test_ucx_buffer_putc); - ucx_test_register(suite, test_ucx_buffer_putc_ae); - ucx_test_register(suite, test_ucx_buffer_putc_oob); - ucx_test_register(suite, test_ucx_buffer_putc_oobae); - ucx_test_register(suite, test_ucx_buffer_putc_size); - ucx_test_register(suite, test_ucx_buffer_getc); - ucx_test_register(suite, test_ucx_buffer_read); - ucx_test_register(suite, test_ucx_buffer_read_oob); - ucx_test_register(suite, test_ucx_buffer_extract); - ucx_test_register(suite, test_ucx_buffer_extract_oob); - ucx_test_register(suite, test_ucx_buffer_extract_overflow); - ucx_test_register(suite, test_ucx_buffer_extend); - ucx_test_register(suite, test_ucx_buffer_write); - ucx_test_register(suite, test_ucx_buffer_write_oob); - ucx_test_register(suite, test_ucx_buffer_write_ax); - ucx_test_register(suite, test_ucx_buffer_shl); - ucx_test_register(suite, test_ucx_buffer_shr); - ucx_test_register(suite, test_ucx_buffer_shr_ax); - - /* Utils Tests*/ - ucx_test_register(suite, test_ucx_fprintf); - ucx_test_register(suite, test_ucx_asprintf); - ucx_test_register(suite, test_ucx_sprintf); - ucx_test_register(suite, test_ucx_bprintf); - ucx_test_register(suite, test_ucx_stream_copy); - - /* AVL Tests */ - ucx_test_register(suite, test_ucx_avl_put); - ucx_test_register(suite, test_ucx_avl_remove); - ucx_test_register(suite, test_ucx_avl_find); - ucx_test_register(suite, test_ucx_avl_traverse); - - ucx_test_run(suite, stdout); - fflush(stdout); - - int exit_code = suite->failure > 0 ? EXIT_FAILURE: EXIT_SUCCESS; - - ucx_test_suite_free(suite); - - return exit_code; - } else { - ucx_test_suite_free(suite); - return EXIT_FAILURE; - } -} -