1.1 --- a/test/main.c Mon Dec 30 09:54:10 2019 +0100 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,286 +0,0 @@ 1.4 -/* 1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 1.6 - * 1.7 - * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. 1.8 - * 1.9 - * Redistribution and use in source and binary forms, with or without 1.10 - * modification, are permitted provided that the following conditions are met: 1.11 - * 1.12 - * 1. Redistributions of source code must retain the above copyright 1.13 - * notice, this list of conditions and the following disclaimer. 1.14 - * 1.15 - * 2. Redistributions in binary form must reproduce the above copyright 1.16 - * notice, this list of conditions and the following disclaimer in the 1.17 - * documentation and/or other materials provided with the distribution. 1.18 - * 1.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 1.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.29 - * POSSIBILITY OF SUCH DAMAGE. 1.30 - */ 1.31 - 1.32 -#include <stdio.h> 1.33 -#include <stdlib.h> 1.34 - 1.35 -#include <ucx/test.h> 1.36 - 1.37 -#include "main.h" 1.38 - 1.39 -#include "array_tests.h" 1.40 -#include "allocator_tests.h" 1.41 -#include "logging_tests.h" 1.42 -#include "list_tests.h" 1.43 -#include "string_tests.h" 1.44 -#include "mpool_tests.h" 1.45 -#include "stack_tests.h" 1.46 -#include "map_tests.h" 1.47 -#include "prop_tests.h" 1.48 -#include "buffer_tests.h" 1.49 -#include "utils_tests.h" 1.50 -#include "avl_tests.h" 1.51 - 1.52 -#ifdef __cplusplus 1.53 -extern "C" { 1.54 -#endif 1.55 -UCX_TEST(testTestSuitePositive) { 1.56 - UCX_TEST_BEGIN 1.57 - UCX_TEST_ASSERT(2*2 == 4, "the test framework fails"); 1.58 - UCX_TEST_END 1.59 -} 1.60 - 1.61 -UCX_TEST(testTestSuiteNegative) { 1.62 - UCX_TEST_BEGIN 1.63 - UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works"); 1.64 - UCX_TEST_END 1.65 -} 1.66 - 1.67 -UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) { 1.68 - UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails"); 1.69 -} 1.70 - 1.71 -UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) { 1.72 - UCX_TEST_ASSERT(i == 42, "two parameter routine fails"); 1.73 - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f); 1.74 -} 1.75 - 1.76 -UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) { 1.77 - *i += 2; 1.78 - UCX_TEST_ASSERT(*i==4, "the test framework fails"); 1.79 -} 1.80 - 1.81 -UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) { 1.82 - *i += 2; 1.83 - // Next test shall fail! 1.84 - UCX_TEST_ASSERT(*i==4, "the test framework works"); 1.85 -} 1.86 - 1.87 -UCX_TEST(testTestSuiteRoutinePositive) { 1.88 - int i = 2; 1.89 - UCX_TEST_BEGIN 1.90 - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i); 1.91 - UCX_TEST_ASSERT(i==4, "the test framework fails"); 1.92 - UCX_TEST_END 1.93 -} 1.94 - 1.95 -UCX_TEST(testTestSuiteRoutineNegative) { 1.96 - int i = 0; 1.97 - UCX_TEST_BEGIN 1.98 - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i); 1.99 - UCX_TEST_ASSERT(1, "the test framework fails"); 1.100 - UCX_TEST_END 1.101 -} 1.102 - 1.103 -UCX_TEST(testTestSuiteRoutineMultiparam) { 1.104 - UCX_TEST_BEGIN 1.105 - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f); 1.106 - UCX_TEST_END 1.107 -} 1.108 -#ifdef __cplusplus 1.109 -} 1.110 -#endif 1.111 - 1.112 -int main(int argc, char **argv) { 1.113 - printf("UCX Tests\n---------\n"); 1.114 - 1.115 - printf("\nUcxTestSuite tests (2 failures are intended!)\n"); 1.116 - UcxTestSuite* suite = ucx_test_suite_new(); 1.117 - ucx_test_register(suite, testTestSuitePositive); 1.118 - ucx_test_register(suite, testTestSuiteNegative); 1.119 - ucx_test_register(suite, testTestSuiteRoutinePositive); 1.120 - ucx_test_register(suite, testTestSuiteRoutineNegative); 1.121 - ucx_test_register(suite, testTestSuiteRoutineMultiparam); 1.122 - ucx_test_run(suite, stdout); 1.123 - if (suite->failure == 2 && suite->success == 3) { 1.124 - ucx_test_suite_free(suite); 1.125 - 1.126 - printf("\nLibrary function tests\n"); 1.127 - suite = ucx_test_suite_new(); 1.128 - /* UcxAllocator Tests */ 1.129 - ucx_test_register(suite, test_ucx_default_allocator); 1.130 - 1.131 - /* sstring Tests */ 1.132 - ucx_test_register(suite, test_sstr_macros); 1.133 - ucx_test_register(suite, test_sstr); 1.134 - ucx_test_register(suite, test_sstr_len); 1.135 - ucx_test_register(suite, test_sstrcmp); 1.136 - ucx_test_register(suite, test_sstrcasecmp); 1.137 - ucx_test_register(suite, test_sstrcat); 1.138 - ucx_test_register(suite, test_sstrchr_sstrrchr); 1.139 - ucx_test_register(suite, test_sstrstr); 1.140 - ucx_test_register(suite, test_sstrsplit); 1.141 - ucx_test_register(suite, test_sstrtrim); 1.142 - ucx_test_register(suite, test_sstrprefixsuffix); 1.143 - ucx_test_register(suite, test_sstrcaseprefixsuffix); 1.144 - ucx_test_register(suite, test_sstrreplace); 1.145 - 1.146 - /* UcxLogger Tests */ 1.147 - ucx_test_register(suite, test_ucx_logger_new); 1.148 - ucx_test_register(suite, test_ucx_logger_log); 1.149 - 1.150 - /* UcxArray Tests */ 1.151 - ucx_test_register(suite, test_ucx_array_destroy); 1.152 - ucx_test_register(suite, test_ucx_array_new); 1.153 - ucx_test_register(suite, test_ucx_array_at); 1.154 - ucx_test_register(suite, test_ucx_array_append_from); 1.155 - ucx_test_register(suite, test_ucx_array_append_from_struct); 1.156 - ucx_test_register(suite, test_ucx_array_prepend_from); 1.157 - ucx_test_register(suite, test_ucx_array_set_from); 1.158 - ucx_test_register(suite, test_ucx_array_equals); 1.159 - ucx_test_register(suite, test_ucx_array_concat); 1.160 - ucx_test_register(suite, test_ucx_array_find); 1.161 - ucx_test_register(suite, test_ucx_array_contains); 1.162 - ucx_test_register(suite, test_ucx_array_remove); 1.163 - ucx_test_register(suite, test_ucx_array_clone); 1.164 - ucx_test_register(suite, test_ucx_array_sort); 1.165 - ucx_test_register(suite, test_ucx_array_shrink); 1.166 - ucx_test_register(suite, test_ucx_array_resize); 1.167 - ucx_test_register(suite, test_ucx_array_reserve); 1.168 - ucx_test_register(suite, test_ucx_array_grow); 1.169 - ucx_test_register(suite, test_ucx_array_util_set); 1.170 - ucx_test_register(suite, test_ucx_array_util_setptr); 1.171 - 1.172 - /* UcxList Tests */ 1.173 - ucx_test_register(suite, test_ucx_list_append); 1.174 - ucx_test_register(suite, test_ucx_list_prepend); 1.175 - ucx_test_register(suite, test_ucx_list_equals); 1.176 - ucx_test_register(suite, test_ucx_list_concat); 1.177 - ucx_test_register(suite, test_ucx_list_size); 1.178 - ucx_test_register(suite, test_ucx_list_first); 1.179 - ucx_test_register(suite, test_ucx_list_last); 1.180 - ucx_test_register(suite, test_ucx_list_get); 1.181 - ucx_test_register(suite, test_ucx_list_indexof); 1.182 - ucx_test_register(suite, test_ucx_list_find); 1.183 - ucx_test_register(suite, test_ucx_list_contains); 1.184 - ucx_test_register(suite, test_ucx_list_remove); 1.185 - ucx_test_register(suite, test_ucx_list_clone); 1.186 - ucx_test_register(suite, test_ucx_list_sort); 1.187 - ucx_test_register(suite, test_ucx_list_union); 1.188 - ucx_test_register(suite, test_ucx_list_intersection); 1.189 - ucx_test_register(suite, test_ucx_list_difference); 1.190 - 1.191 - /* UcxMemPool Tests */ 1.192 - ucx_test_register(suite, test_ucx_mempool_new); 1.193 - ucx_test_register(suite, test_ucx_mempool_malloc); 1.194 - ucx_test_register(suite, test_ucx_mempool_malloc_with_chcap); 1.195 - ucx_test_register(suite, test_ucx_mempool_calloc); 1.196 - ucx_test_register(suite, test_ucx_mempool_free); 1.197 - ucx_test_register(suite, test_ucx_mempool_set_destr); 1.198 - ucx_test_register(suite, test_ucx_mempool_reg_destr); 1.199 - ucx_test_register(suite, test_ucx_mempool_realloc); 1.200 - 1.201 - /* UcxStack Tests */ 1.202 - ucx_test_register(suite, test_ucx_stack_init); 1.203 - ucx_test_register(suite, test_ucx_stack_malloc); 1.204 - ucx_test_register(suite, test_ucx_stack_calloc); 1.205 - ucx_test_register(suite, test_ucx_stack_free); 1.206 - ucx_test_register(suite, test_ucx_stack_realloc); 1.207 - ucx_test_register(suite, test_ucx_stack_pop); 1.208 - 1.209 - /* UcxMap Tests */ 1.210 - ucx_test_register(suite, test_ucx_map_new); 1.211 - ucx_test_register(suite, test_ucx_key); 1.212 - ucx_test_register(suite, test_ucx_map_put); 1.213 - ucx_test_register(suite, test_ucx_map_get); 1.214 - ucx_test_register(suite, test_ucx_map_remove); 1.215 - ucx_test_register(suite, test_ucx_map_clear); 1.216 - ucx_test_register(suite, test_ucx_map_iterator); 1.217 - ucx_test_register(suite, test_ucx_map_iterator_chain); 1.218 - ucx_test_register(suite, test_ucx_map_clone); 1.219 - ucx_test_register(suite, test_ucx_map_rehash); 1.220 - ucx_test_register(suite, test_ucx_map_union); 1.221 - ucx_test_register(suite, test_ucx_map_intersection); 1.222 - ucx_test_register(suite, test_ucx_map_difference); 1.223 - 1.224 - /* UcxPropertiesParser Tests */ 1.225 - ucx_test_register(suite, test_ucx_properties_new); 1.226 - ucx_test_register(suite, test_ucx_properties_next); 1.227 - ucx_test_register(suite, test_ucx_properties_next_multi); 1.228 - ucx_test_register(suite, test_ucx_properties_next_part); 1.229 - ucx_test_register(suite, test_ucx_properties_next_long); 1.230 - ucx_test_register(suite, test_ucx_properties2map); 1.231 - ucx_test_register(suite, test_ucx_properties_load); 1.232 - ucx_test_register(suite, test_ucx_properties_store); 1.233 - 1.234 - /* UcxBuffer Tests */ 1.235 - ucx_test_register(suite, test_ucx_buffer_new); 1.236 - ucx_test_register(suite, test_ucx_buffer_new_prealloc); 1.237 - ucx_test_register(suite, test_ucx_buffer_eof); 1.238 - ucx_test_register(suite, test_ucx_buffer_seek_set); 1.239 - ucx_test_register(suite, test_ucx_buffer_seek_cur); 1.240 - ucx_test_register(suite, test_ucx_buffer_seek_end); 1.241 - ucx_test_register(suite, test_ucx_buffer_seek_oob); 1.242 - ucx_test_register(suite, test_ucx_buffer_seek_invalid); 1.243 - ucx_test_register(suite, test_ucx_buffer_seek_overflow); 1.244 - ucx_test_register(suite, test_ucx_buffer_putc); 1.245 - ucx_test_register(suite, test_ucx_buffer_putc_ae); 1.246 - ucx_test_register(suite, test_ucx_buffer_putc_oob); 1.247 - ucx_test_register(suite, test_ucx_buffer_putc_oobae); 1.248 - ucx_test_register(suite, test_ucx_buffer_putc_size); 1.249 - ucx_test_register(suite, test_ucx_buffer_getc); 1.250 - ucx_test_register(suite, test_ucx_buffer_read); 1.251 - ucx_test_register(suite, test_ucx_buffer_read_oob); 1.252 - ucx_test_register(suite, test_ucx_buffer_extract); 1.253 - ucx_test_register(suite, test_ucx_buffer_extract_oob); 1.254 - ucx_test_register(suite, test_ucx_buffer_extract_overflow); 1.255 - ucx_test_register(suite, test_ucx_buffer_extend); 1.256 - ucx_test_register(suite, test_ucx_buffer_write); 1.257 - ucx_test_register(suite, test_ucx_buffer_write_oob); 1.258 - ucx_test_register(suite, test_ucx_buffer_write_ax); 1.259 - ucx_test_register(suite, test_ucx_buffer_shl); 1.260 - ucx_test_register(suite, test_ucx_buffer_shr); 1.261 - ucx_test_register(suite, test_ucx_buffer_shr_ax); 1.262 - 1.263 - /* Utils Tests*/ 1.264 - ucx_test_register(suite, test_ucx_fprintf); 1.265 - ucx_test_register(suite, test_ucx_asprintf); 1.266 - ucx_test_register(suite, test_ucx_sprintf); 1.267 - ucx_test_register(suite, test_ucx_bprintf); 1.268 - ucx_test_register(suite, test_ucx_stream_copy); 1.269 - 1.270 - /* AVL Tests */ 1.271 - ucx_test_register(suite, test_ucx_avl_put); 1.272 - ucx_test_register(suite, test_ucx_avl_remove); 1.273 - ucx_test_register(suite, test_ucx_avl_find); 1.274 - ucx_test_register(suite, test_ucx_avl_traverse); 1.275 - 1.276 - ucx_test_run(suite, stdout); 1.277 - fflush(stdout); 1.278 - 1.279 - int exit_code = suite->failure > 0 ? EXIT_FAILURE: EXIT_SUCCESS; 1.280 - 1.281 - ucx_test_suite_free(suite); 1.282 - 1.283 - return exit_code; 1.284 - } else { 1.285 - ucx_test_suite_free(suite); 1.286 - return EXIT_FAILURE; 1.287 - } 1.288 -} 1.289 -