Fri, 20 Dec 2019 14:29:41 +0100
adds proper cmake build targets
olaf@0 | 1 | /* |
olaf@0 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
olaf@0 | 3 | * |
universe@259 | 4 | * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. |
olaf@0 | 5 | * |
olaf@0 | 6 | * Redistribution and use in source and binary forms, with or without |
olaf@0 | 7 | * modification, are permitted provided that the following conditions are met: |
olaf@0 | 8 | * |
olaf@0 | 9 | * 1. Redistributions of source code must retain the above copyright |
olaf@0 | 10 | * notice, this list of conditions and the following disclaimer. |
olaf@0 | 11 | * |
olaf@0 | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
olaf@0 | 13 | * notice, this list of conditions and the following disclaimer in the |
olaf@0 | 14 | * documentation and/or other materials provided with the distribution. |
olaf@0 | 15 | * |
olaf@0 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
olaf@0 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
olaf@0 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
olaf@0 | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
olaf@0 | 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
olaf@0 | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
olaf@0 | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
olaf@0 | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
olaf@0 | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
olaf@0 | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
olaf@0 | 26 | * POSSIBILITY OF SUCH DAMAGE. |
olaf@0 | 27 | */ |
olaf@0 | 28 | |
olaf@0 | 29 | #include <stdio.h> |
olaf@0 | 30 | #include <stdlib.h> |
olaf@0 | 31 | |
universe@251 | 32 | #include <ucx/test.h> |
universe@26 | 33 | |
universe@27 | 34 | #include "main.h" |
universe@27 | 35 | |
universe@334 | 36 | #include "array_tests.h" |
universe@164 | 37 | #include "allocator_tests.h" |
universe@54 | 38 | #include "logging_tests.h" |
universe@122 | 39 | #include "list_tests.h" |
universe@39 | 40 | #include "string_tests.h" |
olaf@13 | 41 | #include "mpool_tests.h" |
universe@185 | 42 | #include "stack_tests.h" |
olaf@20 | 43 | #include "map_tests.h" |
olaf@108 | 44 | #include "prop_tests.h" |
universe@60 | 45 | #include "buffer_tests.h" |
olaf@142 | 46 | #include "utils_tests.h" |
olaf@198 | 47 | #include "avl_tests.h" |
olaf@9 | 48 | |
universe@254 | 49 | #ifdef __cplusplus |
universe@253 | 50 | extern "C" { |
universe@254 | 51 | #endif |
universe@254 | 52 | UCX_TEST(testTestSuitePositive) { |
universe@254 | 53 | UCX_TEST_BEGIN |
universe@254 | 54 | UCX_TEST_ASSERT(2*2 == 4, "the test framework fails"); |
universe@254 | 55 | UCX_TEST_END |
universe@254 | 56 | } |
universe@26 | 57 | |
universe@254 | 58 | UCX_TEST(testTestSuiteNegative) { |
universe@254 | 59 | UCX_TEST_BEGIN |
universe@254 | 60 | UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works"); |
universe@254 | 61 | UCX_TEST_END |
universe@254 | 62 | } |
universe@26 | 63 | |
universe@254 | 64 | UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) { |
universe@254 | 65 | UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails"); |
universe@254 | 66 | } |
universe@88 | 67 | |
universe@254 | 68 | UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) { |
universe@254 | 69 | UCX_TEST_ASSERT(i == 42, "two parameter routine fails"); |
universe@254 | 70 | UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f); |
universe@254 | 71 | } |
universe@88 | 72 | |
universe@254 | 73 | UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) { |
universe@254 | 74 | *i += 2; |
universe@254 | 75 | UCX_TEST_ASSERT(*i==4, "the test framework fails"); |
universe@254 | 76 | } |
universe@33 | 77 | |
universe@254 | 78 | UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) { |
universe@254 | 79 | *i += 2; |
universe@254 | 80 | // Next test shall fail! |
universe@254 | 81 | UCX_TEST_ASSERT(*i==4, "the test framework works"); |
universe@254 | 82 | } |
universe@33 | 83 | |
universe@254 | 84 | UCX_TEST(testTestSuiteRoutinePositive) { |
universe@254 | 85 | int i = 2; |
universe@254 | 86 | UCX_TEST_BEGIN |
universe@254 | 87 | UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i); |
universe@254 | 88 | UCX_TEST_ASSERT(i==4, "the test framework fails"); |
universe@254 | 89 | UCX_TEST_END |
universe@254 | 90 | } |
universe@33 | 91 | |
universe@254 | 92 | UCX_TEST(testTestSuiteRoutineNegative) { |
universe@254 | 93 | int i = 0; |
universe@254 | 94 | UCX_TEST_BEGIN |
universe@254 | 95 | UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i); |
universe@254 | 96 | UCX_TEST_ASSERT(1, "the test framework fails"); |
universe@254 | 97 | UCX_TEST_END |
universe@254 | 98 | } |
universe@33 | 99 | |
universe@254 | 100 | UCX_TEST(testTestSuiteRoutineMultiparam) { |
universe@254 | 101 | UCX_TEST_BEGIN |
universe@254 | 102 | UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f); |
universe@254 | 103 | UCX_TEST_END |
universe@88 | 104 | } |
universe@254 | 105 | #ifdef __cplusplus |
universe@254 | 106 | } |
universe@254 | 107 | #endif |
universe@88 | 108 | |
olaf@0 | 109 | int main(int argc, char **argv) { |
olaf@13 | 110 | printf("UCX Tests\n---------\n"); |
olaf@9 | 111 | |
universe@33 | 112 | printf("\nUcxTestSuite tests (2 failures are intended!)\n"); |
universe@26 | 113 | UcxTestSuite* suite = ucx_test_suite_new(); |
universe@26 | 114 | ucx_test_register(suite, testTestSuitePositive); |
universe@26 | 115 | ucx_test_register(suite, testTestSuiteNegative); |
universe@33 | 116 | ucx_test_register(suite, testTestSuiteRoutinePositive); |
universe@33 | 117 | ucx_test_register(suite, testTestSuiteRoutineNegative); |
universe@88 | 118 | ucx_test_register(suite, testTestSuiteRoutineMultiparam); |
universe@26 | 119 | ucx_test_run(suite, stdout); |
universe@88 | 120 | if (suite->failure == 2 && suite->success == 3) { |
universe@26 | 121 | ucx_test_suite_free(suite); |
universe@27 | 122 | |
universe@28 | 123 | printf("\nLibrary function tests\n"); |
universe@27 | 124 | suite = ucx_test_suite_new(); |
universe@164 | 125 | /* UcxAllocator Tests */ |
universe@164 | 126 | ucx_test_register(suite, test_ucx_default_allocator); |
universe@164 | 127 | |
universe@97 | 128 | /* sstring Tests */ |
universe@283 | 129 | ucx_test_register(suite, test_sstr_macros); |
universe@97 | 130 | ucx_test_register(suite, test_sstr); |
universe@179 | 131 | ucx_test_register(suite, test_sstr_len); |
universe@149 | 132 | ucx_test_register(suite, test_sstrcmp); |
universe@149 | 133 | ucx_test_register(suite, test_sstrcasecmp); |
olaf@180 | 134 | ucx_test_register(suite, test_sstrcat); |
universe@149 | 135 | ucx_test_register(suite, test_sstrchr_sstrrchr); |
universe@214 | 136 | ucx_test_register(suite, test_sstrstr); |
universe@97 | 137 | ucx_test_register(suite, test_sstrsplit); |
universe@97 | 138 | ucx_test_register(suite, test_sstrtrim); |
universe@146 | 139 | ucx_test_register(suite, test_sstrprefixsuffix); |
universe@364 | 140 | ucx_test_register(suite, test_sstrcaseprefixsuffix); |
universe@97 | 141 | |
universe@54 | 142 | /* UcxLogger Tests */ |
universe@170 | 143 | ucx_test_register(suite, test_ucx_logger_new); |
universe@54 | 144 | ucx_test_register(suite, test_ucx_logger_log); |
universe@27 | 145 | |
universe@334 | 146 | /* UcxArray Tests */ |
universe@356 | 147 | ucx_test_register(suite, test_ucx_array_destroy); |
universe@334 | 148 | ucx_test_register(suite, test_ucx_array_new); |
universe@344 | 149 | ucx_test_register(suite, test_ucx_array_at); |
universe@354 | 150 | ucx_test_register(suite, test_ucx_array_append_from); |
universe@366 | 151 | ucx_test_register(suite, test_ucx_array_append_from_struct); |
universe@354 | 152 | ucx_test_register(suite, test_ucx_array_prepend_from); |
universe@354 | 153 | ucx_test_register(suite, test_ucx_array_set_from); |
universe@334 | 154 | ucx_test_register(suite, test_ucx_array_equals); |
universe@334 | 155 | ucx_test_register(suite, test_ucx_array_concat); |
universe@334 | 156 | ucx_test_register(suite, test_ucx_array_find); |
universe@334 | 157 | ucx_test_register(suite, test_ucx_array_contains); |
universe@334 | 158 | ucx_test_register(suite, test_ucx_array_remove); |
universe@334 | 159 | ucx_test_register(suite, test_ucx_array_clone); |
universe@334 | 160 | ucx_test_register(suite, test_ucx_array_sort); |
universe@334 | 161 | ucx_test_register(suite, test_ucx_array_shrink); |
universe@334 | 162 | ucx_test_register(suite, test_ucx_array_resize); |
universe@334 | 163 | ucx_test_register(suite, test_ucx_array_reserve); |
universe@369 | 164 | ucx_test_register(suite, test_ucx_array_grow); |
universe@355 | 165 | ucx_test_register(suite, test_ucx_array_util_set); |
universe@369 | 166 | ucx_test_register(suite, test_ucx_array_util_setptr); |
universe@334 | 167 | |
universe@123 | 168 | /* UcxList Tests */ |
universe@122 | 169 | ucx_test_register(suite, test_ucx_list_append); |
universe@122 | 170 | ucx_test_register(suite, test_ucx_list_prepend); |
universe@122 | 171 | ucx_test_register(suite, test_ucx_list_equals); |
universe@122 | 172 | ucx_test_register(suite, test_ucx_list_concat); |
universe@122 | 173 | ucx_test_register(suite, test_ucx_list_size); |
universe@122 | 174 | ucx_test_register(suite, test_ucx_list_first); |
universe@122 | 175 | ucx_test_register(suite, test_ucx_list_last); |
universe@122 | 176 | ucx_test_register(suite, test_ucx_list_get); |
universe@123 | 177 | ucx_test_register(suite, test_ucx_list_indexof); |
universe@123 | 178 | ucx_test_register(suite, test_ucx_list_find); |
universe@122 | 179 | ucx_test_register(suite, test_ucx_list_contains); |
universe@122 | 180 | ucx_test_register(suite, test_ucx_list_remove); |
universe@122 | 181 | ucx_test_register(suite, test_ucx_list_clone); |
universe@122 | 182 | ucx_test_register(suite, test_ucx_list_sort); |
universe@371 | 183 | ucx_test_register(suite, test_ucx_list_union); |
universe@371 | 184 | ucx_test_register(suite, test_ucx_list_intersection); |
universe@371 | 185 | ucx_test_register(suite, test_ucx_list_difference); |
universe@27 | 186 | |
universe@28 | 187 | /* UcxMemPool Tests */ |
universe@28 | 188 | ucx_test_register(suite, test_ucx_mempool_new); |
universe@28 | 189 | ucx_test_register(suite, test_ucx_mempool_malloc); |
universe@28 | 190 | ucx_test_register(suite, test_ucx_mempool_malloc_with_chcap); |
universe@28 | 191 | ucx_test_register(suite, test_ucx_mempool_calloc); |
olaf@113 | 192 | ucx_test_register(suite, test_ucx_mempool_free); |
universe@28 | 193 | ucx_test_register(suite, test_ucx_mempool_set_destr); |
universe@28 | 194 | ucx_test_register(suite, test_ucx_mempool_reg_destr); |
universe@28 | 195 | ucx_test_register(suite, test_ucx_mempool_realloc); |
universe@185 | 196 | |
universe@185 | 197 | /* UcxStack Tests */ |
universe@185 | 198 | ucx_test_register(suite, test_ucx_stack_init); |
universe@185 | 199 | ucx_test_register(suite, test_ucx_stack_malloc); |
universe@185 | 200 | ucx_test_register(suite, test_ucx_stack_calloc); |
universe@185 | 201 | ucx_test_register(suite, test_ucx_stack_free); |
universe@185 | 202 | ucx_test_register(suite, test_ucx_stack_realloc); |
universe@185 | 203 | ucx_test_register(suite, test_ucx_stack_pop); |
universe@26 | 204 | |
universe@29 | 205 | /* UcxMap Tests */ |
universe@29 | 206 | ucx_test_register(suite, test_ucx_map_new); |
universe@29 | 207 | ucx_test_register(suite, test_ucx_key); |
universe@29 | 208 | ucx_test_register(suite, test_ucx_map_put); |
universe@29 | 209 | ucx_test_register(suite, test_ucx_map_get); |
universe@53 | 210 | ucx_test_register(suite, test_ucx_map_remove); |
universe@206 | 211 | ucx_test_register(suite, test_ucx_map_clear); |
olaf@31 | 212 | ucx_test_register(suite, test_ucx_map_iterator); |
universe@33 | 213 | ucx_test_register(suite, test_ucx_map_iterator_chain); |
olaf@44 | 214 | ucx_test_register(suite, test_ucx_map_clone); |
universe@51 | 215 | ucx_test_register(suite, test_ucx_map_rehash); |
universe@374 | 216 | ucx_test_register(suite, test_ucx_map_union); |
universe@374 | 217 | ucx_test_register(suite, test_ucx_map_intersection); |
universe@374 | 218 | ucx_test_register(suite, test_ucx_map_difference); |
olaf@108 | 219 | |
olaf@108 | 220 | /* UcxPropertiesParser Tests */ |
olaf@110 | 221 | ucx_test_register(suite, test_ucx_properties_new); |
olaf@110 | 222 | ucx_test_register(suite, test_ucx_properties_next); |
olaf@110 | 223 | ucx_test_register(suite, test_ucx_properties_next_multi); |
olaf@110 | 224 | ucx_test_register(suite, test_ucx_properties_next_part); |
olaf@110 | 225 | ucx_test_register(suite, test_ucx_properties_next_long); |
olaf@110 | 226 | ucx_test_register(suite, test_ucx_properties2map); |
olaf@109 | 227 | ucx_test_register(suite, test_ucx_properties_load); |
olaf@109 | 228 | ucx_test_register(suite, test_ucx_properties_store); |
olaf@108 | 229 | |
olaf@108 | 230 | /* UcxBuffer Tests */ |
universe@166 | 231 | ucx_test_register(suite, test_ucx_buffer_new); |
universe@166 | 232 | ucx_test_register(suite, test_ucx_buffer_new_prealloc); |
universe@164 | 233 | ucx_test_register(suite, test_ucx_buffer_eof); |
universe@164 | 234 | ucx_test_register(suite, test_ucx_buffer_seek_set); |
universe@164 | 235 | ucx_test_register(suite, test_ucx_buffer_seek_cur); |
universe@164 | 236 | ucx_test_register(suite, test_ucx_buffer_seek_end); |
universe@164 | 237 | ucx_test_register(suite, test_ucx_buffer_seek_oob); |
universe@164 | 238 | ucx_test_register(suite, test_ucx_buffer_seek_invalid); |
universe@164 | 239 | ucx_test_register(suite, test_ucx_buffer_seek_overflow); |
universe@60 | 240 | ucx_test_register(suite, test_ucx_buffer_putc); |
universe@164 | 241 | ucx_test_register(suite, test_ucx_buffer_putc_ae); |
universe@164 | 242 | ucx_test_register(suite, test_ucx_buffer_putc_oob); |
universe@164 | 243 | ucx_test_register(suite, test_ucx_buffer_putc_oobae); |
universe@164 | 244 | ucx_test_register(suite, test_ucx_buffer_putc_size); |
universe@60 | 245 | ucx_test_register(suite, test_ucx_buffer_getc); |
universe@166 | 246 | ucx_test_register(suite, test_ucx_buffer_read); |
universe@166 | 247 | ucx_test_register(suite, test_ucx_buffer_read_oob); |
universe@167 | 248 | ucx_test_register(suite, test_ucx_buffer_extract); |
universe@167 | 249 | ucx_test_register(suite, test_ucx_buffer_extract_oob); |
universe@167 | 250 | ucx_test_register(suite, test_ucx_buffer_extract_overflow); |
universe@168 | 251 | ucx_test_register(suite, test_ucx_buffer_extend); |
universe@60 | 252 | ucx_test_register(suite, test_ucx_buffer_write); |
universe@168 | 253 | ucx_test_register(suite, test_ucx_buffer_write_oob); |
universe@64 | 254 | ucx_test_register(suite, test_ucx_buffer_write_ax); |
universe@290 | 255 | ucx_test_register(suite, test_ucx_buffer_shl); |
universe@290 | 256 | ucx_test_register(suite, test_ucx_buffer_shr); |
universe@290 | 257 | ucx_test_register(suite, test_ucx_buffer_shr_ax); |
olaf@142 | 258 | |
olaf@142 | 259 | /* Utils Tests*/ |
olaf@142 | 260 | ucx_test_register(suite, test_ucx_fprintf); |
olaf@142 | 261 | ucx_test_register(suite, test_ucx_asprintf); |
universe@223 | 262 | ucx_test_register(suite, test_ucx_sprintf); |
universe@223 | 263 | ucx_test_register(suite, test_ucx_bprintf); |
universe@168 | 264 | ucx_test_register(suite, test_ucx_stream_copy); |
olaf@198 | 265 | |
olaf@198 | 266 | /* AVL Tests */ |
olaf@198 | 267 | ucx_test_register(suite, test_ucx_avl_put); |
olaf@200 | 268 | ucx_test_register(suite, test_ucx_avl_remove); |
universe@243 | 269 | ucx_test_register(suite, test_ucx_avl_find); |
universe@245 | 270 | ucx_test_register(suite, test_ucx_avl_traverse); |
universe@56 | 271 | |
universe@27 | 272 | ucx_test_run(suite, stdout); |
universe@55 | 273 | fflush(stdout); |
universe@252 | 274 | |
universe@252 | 275 | int exit_code = suite->failure > 0 ? EXIT_FAILURE: EXIT_SUCCESS; |
universe@252 | 276 | |
universe@27 | 277 | ucx_test_suite_free(suite); |
universe@27 | 278 | |
universe@252 | 279 | return exit_code; |
universe@26 | 280 | } else { |
universe@26 | 281 | ucx_test_suite_free(suite); |
universe@26 | 282 | return EXIT_FAILURE; |
olaf@13 | 283 | } |
olaf@0 | 284 | } |
olaf@0 | 285 |