olaf@0: /* olaf@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. olaf@0: * universe@103: * Copyright 2013 Olaf Wintermann. All rights reserved. olaf@0: * olaf@0: * Redistribution and use in source and binary forms, with or without olaf@0: * modification, are permitted provided that the following conditions are met: olaf@0: * olaf@0: * 1. Redistributions of source code must retain the above copyright olaf@0: * notice, this list of conditions and the following disclaimer. olaf@0: * olaf@0: * 2. Redistributions in binary form must reproduce the above copyright olaf@0: * notice, this list of conditions and the following disclaimer in the olaf@0: * documentation and/or other materials provided with the distribution. olaf@0: * olaf@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" olaf@0: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE olaf@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE olaf@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE olaf@0: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR olaf@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF olaf@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS olaf@0: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN olaf@0: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) olaf@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE olaf@0: * POSSIBILITY OF SUCH DAMAGE. olaf@0: */ olaf@0: olaf@0: #include olaf@0: #include olaf@0: universe@26: #include "ucx/test.h" universe@26: universe@27: #include "main.h" universe@27: universe@54: #include "logging_tests.h" olaf@9: #include "list_tests.h" universe@27: #include "dlist_tests.h" universe@39: #include "string_tests.h" olaf@13: #include "mpool_tests.h" olaf@20: #include "map_tests.h" olaf@108: #include "prop_tests.h" universe@60: #include "buffer_tests.h" olaf@9: universe@33: UCX_TEST_IMPLEMENT(testTestSuitePositive) { universe@33: UCX_TEST_BEGIN universe@40: UCX_TEST_ASSERT(2*2 == 4, "the test framework fails"); universe@26: UCX_TEST_END universe@26: } universe@26: universe@33: UCX_TEST_IMPLEMENT(testTestSuiteNegative) { universe@33: UCX_TEST_BEGIN universe@40: UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works"); universe@26: UCX_TEST_END universe@26: } universe@26: universe@88: UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) { universe@88: UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails"); universe@88: } universe@88: universe@88: UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) { universe@88: UCX_TEST_ASSERT(i == 42, "two parameter routine fails"); universe@88: UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f); universe@88: } universe@88: universe@88: UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) { universe@33: *i += 2; universe@33: UCX_TEST_ASSERT(*i==4, "the test framework fails"); universe@33: } universe@33: universe@88: UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) { universe@33: *i += 2; universe@88: // Next test shall fail! universe@33: UCX_TEST_ASSERT(*i==4, "the test framework works"); universe@33: } universe@33: universe@33: UCX_TEST_IMPLEMENT(testTestSuiteRoutinePositive) { universe@33: int i = 2; universe@33: UCX_TEST_BEGIN universe@33: UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i); universe@33: UCX_TEST_ASSERT(i==4, "the test framework fails"); universe@33: UCX_TEST_END universe@33: } universe@33: universe@33: UCX_TEST_IMPLEMENT(testTestSuiteRoutineNegative) { universe@33: int i = 0; universe@33: UCX_TEST_BEGIN universe@33: UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i); universe@33: UCX_TEST_ASSERT(1, "the test framework fails"); universe@33: UCX_TEST_END universe@33: } universe@33: universe@88: UCX_TEST_IMPLEMENT(testTestSuiteRoutineMultiparam) { universe@88: UCX_TEST_BEGIN universe@88: UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f); universe@88: UCX_TEST_END universe@88: } universe@88: olaf@0: int main(int argc, char **argv) { olaf@13: printf("UCX Tests\n---------\n"); olaf@9: universe@33: printf("\nUcxTestSuite tests (2 failures are intended!)\n"); universe@26: UcxTestSuite* suite = ucx_test_suite_new(); universe@26: ucx_test_register(suite, testTestSuitePositive); universe@26: ucx_test_register(suite, testTestSuiteNegative); universe@33: ucx_test_register(suite, testTestSuiteRoutinePositive); universe@33: ucx_test_register(suite, testTestSuiteRoutineNegative); universe@88: ucx_test_register(suite, testTestSuiteRoutineMultiparam); universe@26: ucx_test_run(suite, stdout); universe@88: if (suite->failure == 2 && suite->success == 3) { universe@26: ucx_test_suite_free(suite); universe@27: universe@28: printf("\nLibrary function tests\n"); universe@27: suite = ucx_test_suite_new(); universe@97: /* sstring Tests */ universe@97: ucx_test_register(suite, test_sstr); universe@97: ucx_test_register(suite, test_sstr_len_cat); universe@97: ucx_test_register(suite, test_sstrsplit); universe@97: ucx_test_register(suite, test_sstrtrim); universe@97: universe@54: /* UcxLogger Tests */ universe@54: ucx_test_register(suite, test_ucx_logger_log); universe@54: universe@27: /* UcxList Tests */ universe@27: ucx_test_register(suite, test_ucx_list_append); universe@27: ucx_test_register(suite, test_ucx_list_prepend); universe@27: ucx_test_register(suite, test_ucx_list_equals); universe@27: ucx_test_register(suite, test_ucx_list_concat); universe@27: ucx_test_register(suite, test_ucx_list_size); universe@27: ucx_test_register(suite, test_ucx_list_last); universe@27: ucx_test_register(suite, test_ucx_list_get); universe@90: ucx_test_register(suite, test_ucx_list_contains); universe@27: ucx_test_register(suite, test_ucx_list_remove); universe@27: ucx_test_register(suite, test_ucx_list_clone); universe@36: ucx_test_register(suite, test_ucx_list_sort); universe@27: universe@27: /* UcxDlist Tests */ universe@27: ucx_test_register(suite, test_ucx_dlist_append); universe@27: ucx_test_register(suite, test_ucx_dlist_prepend); universe@27: ucx_test_register(suite, test_ucx_dlist_equals); universe@27: ucx_test_register(suite, test_ucx_dlist_concat); universe@27: ucx_test_register(suite, test_ucx_dlist_size); universe@27: ucx_test_register(suite, test_ucx_dlist_first); universe@27: ucx_test_register(suite, test_ucx_dlist_last); universe@27: ucx_test_register(suite, test_ucx_dlist_get); universe@90: ucx_test_register(suite, test_ucx_dlist_contains); universe@27: ucx_test_register(suite, test_ucx_dlist_remove); universe@27: ucx_test_register(suite, test_ucx_dlist_clone); universe@36: ucx_test_register(suite, test_ucx_dlist_sort); universe@27: universe@28: /* UcxMemPool Tests */ universe@28: ucx_test_register(suite, test_ucx_mempool_new); universe@28: ucx_test_register(suite, test_ucx_mempool_malloc); universe@28: ucx_test_register(suite, test_ucx_mempool_malloc_with_chcap); universe@28: ucx_test_register(suite, test_ucx_mempool_calloc); universe@28: ucx_test_register(suite, test_ucx_mempool_set_destr); universe@28: ucx_test_register(suite, test_ucx_mempool_reg_destr); universe@28: ucx_test_register(suite, test_ucx_mempool_realloc); universe@26: universe@29: /* UcxMap Tests */ universe@29: ucx_test_register(suite, test_ucx_map_new); universe@29: ucx_test_register(suite, test_ucx_key); universe@29: ucx_test_register(suite, test_ucx_map_put); universe@29: ucx_test_register(suite, test_ucx_map_get); universe@53: ucx_test_register(suite, test_ucx_map_remove); olaf@31: ucx_test_register(suite, test_ucx_map_iterator); universe@33: ucx_test_register(suite, test_ucx_map_iterator_chain); universe@42: ucx_test_register(suite, test_ucx_map_store_load); universe@48: ucx_test_register(suite, test_ucx_map_store_load_with_mempool); olaf@44: ucx_test_register(suite, test_ucx_map_clone); universe@51: ucx_test_register(suite, test_ucx_map_rehash); olaf@108: olaf@108: /* UcxPropertiesParser Tests */ olaf@108: ucx_test_register(suite, test_ucx_prop_new); olaf@108: ucx_test_register(suite, test_ucx_prop_parse); olaf@108: ucx_test_register(suite, test_ucx_prop_parse_multi); olaf@108: ucx_test_register(suite, test_ucx_prop_parse_part); olaf@108: ucx_test_register(suite, test_ucx_prop_parse_long); olaf@109: ucx_test_register(suite, test_ucx_prop_parse2map); olaf@109: ucx_test_register(suite, test_ucx_properties_load); olaf@109: ucx_test_register(suite, test_ucx_properties_store); olaf@108: olaf@108: /* UcxBuffer Tests */ universe@60: ucx_test_register(suite, test_ucx_buffer_seektell); universe@60: ucx_test_register(suite, test_ucx_buffer_putc); olaf@76: ucx_test_register(suite, test_ucx_buffer_putc_ax); universe@60: ucx_test_register(suite, test_ucx_buffer_getc); universe@60: ucx_test_register(suite, test_ucx_buffer_write); universe@64: ucx_test_register(suite, test_ucx_buffer_write_ax); universe@60: ucx_test_register(suite, test_ucx_buffer_read); universe@62: ucx_test_register(suite, test_ucx_buffer_extract); olaf@76: ucx_test_register(suite, test_ucx_buffer_generic_copy); universe@56: universe@27: ucx_test_run(suite, stdout); universe@55: fflush(stdout); universe@27: ucx_test_suite_free(suite); universe@27: universe@26: return EXIT_SUCCESS; universe@26: } else { universe@26: ucx_test_suite_free(suite); universe@26: return EXIT_FAILURE; olaf@13: } olaf@0: } olaf@0: