test/main.c

Wed, 18 Oct 2017 14:23:57 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 18 Oct 2017 14:23:57 +0200
changeset 253
e19825a1430a
parent 252
6342cbbd1922
child 254
c45c385ac578
permissions
-rw-r--r--

removes unnecessary macros from ucx.h + removes the usage of restrict and _Bool completely, instead of defining macros

olaf@0 1 /*
olaf@0 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
olaf@0 3 *
universe@250 4 * Copyright 2017 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@164 36 #include "allocator_tests.h"
universe@54 37 #include "logging_tests.h"
universe@122 38 #include "list_tests.h"
universe@39 39 #include "string_tests.h"
olaf@13 40 #include "mpool_tests.h"
universe@185 41 #include "stack_tests.h"
olaf@20 42 #include "map_tests.h"
olaf@108 43 #include "prop_tests.h"
universe@60 44 #include "buffer_tests.h"
olaf@142 45 #include "utils_tests.h"
olaf@198 46 #include "avl_tests.h"
olaf@9 47
universe@253 48 extern "C" {
universe@253 49 UCX_TEST(testTestSuitePositive) {
universe@253 50 UCX_TEST_BEGIN
universe@253 51 UCX_TEST_ASSERT(2*2 == 4, "the test framework fails");
universe@253 52 UCX_TEST_END
universe@253 53 }
universe@26 54
universe@253 55 UCX_TEST(testTestSuiteNegative) {
universe@253 56 UCX_TEST_BEGIN
universe@253 57 UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works");
universe@253 58 UCX_TEST_END
universe@253 59 }
universe@26 60
universe@253 61 UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) {
universe@253 62 UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails");
universe@253 63 }
universe@88 64
universe@253 65 UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) {
universe@253 66 UCX_TEST_ASSERT(i == 42, "two parameter routine fails");
universe@253 67 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f);
universe@253 68 }
universe@88 69
universe@253 70 UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) {
universe@253 71 *i += 2;
universe@253 72 UCX_TEST_ASSERT(*i==4, "the test framework fails");
universe@253 73 }
universe@33 74
universe@253 75 UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) {
universe@253 76 *i += 2;
universe@253 77 // Next test shall fail!
universe@253 78 UCX_TEST_ASSERT(*i==4, "the test framework works");
universe@253 79 }
universe@33 80
universe@253 81 UCX_TEST(testTestSuiteRoutinePositive) {
universe@253 82 int i = 2;
universe@253 83 UCX_TEST_BEGIN
universe@253 84 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i);
universe@253 85 UCX_TEST_ASSERT(i==4, "the test framework fails");
universe@253 86 UCX_TEST_END
universe@253 87 }
universe@33 88
universe@253 89 UCX_TEST(testTestSuiteRoutineNegative) {
universe@253 90 int i = 0;
universe@253 91 UCX_TEST_BEGIN
universe@253 92 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i);
universe@253 93 UCX_TEST_ASSERT(1, "the test framework fails");
universe@253 94 UCX_TEST_END
universe@253 95 }
universe@33 96
universe@253 97 UCX_TEST(testTestSuiteRoutineMultiparam) {
universe@253 98 UCX_TEST_BEGIN
universe@253 99 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f);
universe@253 100 UCX_TEST_END
universe@253 101 }
universe@88 102 }
universe@88 103
olaf@0 104 int main(int argc, char **argv) {
olaf@13 105 printf("UCX Tests\n---------\n");
olaf@9 106
universe@33 107 printf("\nUcxTestSuite tests (2 failures are intended!)\n");
universe@26 108 UcxTestSuite* suite = ucx_test_suite_new();
universe@26 109 ucx_test_register(suite, testTestSuitePositive);
universe@26 110 ucx_test_register(suite, testTestSuiteNegative);
universe@33 111 ucx_test_register(suite, testTestSuiteRoutinePositive);
universe@33 112 ucx_test_register(suite, testTestSuiteRoutineNegative);
universe@88 113 ucx_test_register(suite, testTestSuiteRoutineMultiparam);
universe@26 114 ucx_test_run(suite, stdout);
universe@88 115 if (suite->failure == 2 && suite->success == 3) {
universe@26 116 ucx_test_suite_free(suite);
universe@27 117
universe@28 118 printf("\nLibrary function tests\n");
universe@27 119 suite = ucx_test_suite_new();
universe@164 120 /* UcxAllocator Tests */
universe@164 121 ucx_test_register(suite, test_ucx_default_allocator);
universe@164 122
universe@97 123 /* sstring Tests */
universe@97 124 ucx_test_register(suite, test_sstr);
universe@179 125 ucx_test_register(suite, test_sstr_len);
universe@149 126 ucx_test_register(suite, test_sstrcmp);
universe@149 127 ucx_test_register(suite, test_sstrcasecmp);
olaf@180 128 ucx_test_register(suite, test_sstrcat);
universe@149 129 ucx_test_register(suite, test_sstrchr_sstrrchr);
universe@214 130 ucx_test_register(suite, test_sstrstr);
universe@97 131 ucx_test_register(suite, test_sstrsplit);
universe@97 132 ucx_test_register(suite, test_sstrtrim);
universe@146 133 ucx_test_register(suite, test_sstrprefixsuffix);
universe@97 134
universe@54 135 /* UcxLogger Tests */
universe@170 136 ucx_test_register(suite, test_ucx_logger_new);
universe@54 137 ucx_test_register(suite, test_ucx_logger_log);
universe@27 138
universe@123 139 /* UcxList Tests */
universe@122 140 ucx_test_register(suite, test_ucx_list_append);
universe@122 141 ucx_test_register(suite, test_ucx_list_prepend);
universe@228 142 ucx_test_register(suite, test_ucx_list_append_once);
universe@122 143 ucx_test_register(suite, test_ucx_list_equals);
universe@122 144 ucx_test_register(suite, test_ucx_list_concat);
universe@122 145 ucx_test_register(suite, test_ucx_list_size);
universe@122 146 ucx_test_register(suite, test_ucx_list_first);
universe@122 147 ucx_test_register(suite, test_ucx_list_last);
universe@122 148 ucx_test_register(suite, test_ucx_list_get);
universe@123 149 ucx_test_register(suite, test_ucx_list_indexof);
universe@123 150 ucx_test_register(suite, test_ucx_list_find);
universe@122 151 ucx_test_register(suite, test_ucx_list_contains);
universe@122 152 ucx_test_register(suite, test_ucx_list_remove);
universe@122 153 ucx_test_register(suite, test_ucx_list_clone);
universe@122 154 ucx_test_register(suite, test_ucx_list_sort);
universe@27 155
universe@28 156 /* UcxMemPool Tests */
universe@28 157 ucx_test_register(suite, test_ucx_mempool_new);
universe@28 158 ucx_test_register(suite, test_ucx_mempool_malloc);
universe@28 159 ucx_test_register(suite, test_ucx_mempool_malloc_with_chcap);
universe@28 160 ucx_test_register(suite, test_ucx_mempool_calloc);
olaf@113 161 ucx_test_register(suite, test_ucx_mempool_free);
universe@28 162 ucx_test_register(suite, test_ucx_mempool_set_destr);
universe@28 163 ucx_test_register(suite, test_ucx_mempool_reg_destr);
universe@28 164 ucx_test_register(suite, test_ucx_mempool_realloc);
universe@185 165
universe@185 166 /* UcxStack Tests */
universe@185 167 ucx_test_register(suite, test_ucx_stack_init);
universe@185 168 ucx_test_register(suite, test_ucx_stack_malloc);
universe@185 169 ucx_test_register(suite, test_ucx_stack_calloc);
universe@185 170 ucx_test_register(suite, test_ucx_stack_free);
universe@185 171 ucx_test_register(suite, test_ucx_stack_realloc);
universe@185 172 ucx_test_register(suite, test_ucx_stack_pop);
universe@26 173
universe@29 174 /* UcxMap Tests */
universe@29 175 ucx_test_register(suite, test_ucx_map_new);
universe@29 176 ucx_test_register(suite, test_ucx_key);
universe@29 177 ucx_test_register(suite, test_ucx_map_put);
universe@29 178 ucx_test_register(suite, test_ucx_map_get);
universe@53 179 ucx_test_register(suite, test_ucx_map_remove);
universe@206 180 ucx_test_register(suite, test_ucx_map_clear);
olaf@31 181 ucx_test_register(suite, test_ucx_map_iterator);
universe@33 182 ucx_test_register(suite, test_ucx_map_iterator_chain);
olaf@44 183 ucx_test_register(suite, test_ucx_map_clone);
universe@51 184 ucx_test_register(suite, test_ucx_map_rehash);
olaf@108 185
olaf@108 186 /* UcxPropertiesParser Tests */
olaf@110 187 ucx_test_register(suite, test_ucx_properties_new);
olaf@110 188 ucx_test_register(suite, test_ucx_properties_next);
olaf@110 189 ucx_test_register(suite, test_ucx_properties_next_multi);
olaf@110 190 ucx_test_register(suite, test_ucx_properties_next_part);
olaf@110 191 ucx_test_register(suite, test_ucx_properties_next_long);
olaf@110 192 ucx_test_register(suite, test_ucx_properties2map);
olaf@109 193 ucx_test_register(suite, test_ucx_properties_load);
olaf@109 194 ucx_test_register(suite, test_ucx_properties_store);
olaf@108 195
olaf@108 196 /* UcxBuffer Tests */
universe@166 197 ucx_test_register(suite, test_ucx_buffer_new);
universe@166 198 ucx_test_register(suite, test_ucx_buffer_new_prealloc);
universe@164 199 ucx_test_register(suite, test_ucx_buffer_eof);
universe@164 200 ucx_test_register(suite, test_ucx_buffer_seek_set);
universe@164 201 ucx_test_register(suite, test_ucx_buffer_seek_cur);
universe@164 202 ucx_test_register(suite, test_ucx_buffer_seek_end);
universe@164 203 ucx_test_register(suite, test_ucx_buffer_seek_oob);
universe@164 204 ucx_test_register(suite, test_ucx_buffer_seek_invalid);
universe@164 205 ucx_test_register(suite, test_ucx_buffer_seek_overflow);
universe@60 206 ucx_test_register(suite, test_ucx_buffer_putc);
universe@164 207 ucx_test_register(suite, test_ucx_buffer_putc_ae);
universe@164 208 ucx_test_register(suite, test_ucx_buffer_putc_oob);
universe@164 209 ucx_test_register(suite, test_ucx_buffer_putc_oobae);
universe@164 210 ucx_test_register(suite, test_ucx_buffer_putc_size);
universe@60 211 ucx_test_register(suite, test_ucx_buffer_getc);
universe@166 212 ucx_test_register(suite, test_ucx_buffer_read);
universe@166 213 ucx_test_register(suite, test_ucx_buffer_read_oob);
universe@167 214 ucx_test_register(suite, test_ucx_buffer_extract);
universe@167 215 ucx_test_register(suite, test_ucx_buffer_extract_oob);
universe@167 216 ucx_test_register(suite, test_ucx_buffer_extract_overflow);
universe@168 217 ucx_test_register(suite, test_ucx_buffer_extend);
universe@60 218 ucx_test_register(suite, test_ucx_buffer_write);
universe@168 219 ucx_test_register(suite, test_ucx_buffer_write_oob);
universe@64 220 ucx_test_register(suite, test_ucx_buffer_write_ax);
olaf@142 221
olaf@142 222 /* Utils Tests*/
olaf@142 223 ucx_test_register(suite, test_ucx_fprintf);
olaf@142 224 ucx_test_register(suite, test_ucx_asprintf);
universe@223 225 ucx_test_register(suite, test_ucx_sprintf);
universe@223 226 ucx_test_register(suite, test_ucx_bprintf);
universe@168 227 ucx_test_register(suite, test_ucx_stream_copy);
olaf@198 228
olaf@198 229 /* AVL Tests */
olaf@198 230 ucx_test_register(suite, test_ucx_avl_put);
olaf@200 231 ucx_test_register(suite, test_ucx_avl_remove);
universe@243 232 ucx_test_register(suite, test_ucx_avl_find);
universe@245 233 ucx_test_register(suite, test_ucx_avl_traverse);
universe@56 234
universe@27 235 ucx_test_run(suite, stdout);
universe@55 236 fflush(stdout);
universe@252 237
universe@252 238 int exit_code = suite->failure > 0 ? EXIT_FAILURE: EXIT_SUCCESS;
universe@252 239
universe@27 240 ucx_test_suite_free(suite);
universe@27 241
universe@252 242 return exit_code;
universe@26 243 } else {
universe@26 244 ucx_test_suite_free(suite);
universe@26 245 return EXIT_FAILURE;
olaf@13 246 }
olaf@0 247 }
olaf@0 248

mercurial