test/main.c

Mon, 28 Jul 2014 14:36:25 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 28 Jul 2014 14:36:25 +0200
changeset 185
a48428642b4e
parent 180
2185f19dcc45
child 192
1e51558b9d09
permissions
-rw-r--r--

added stack implementation + added g++ config and added some fixes for C++

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

mercurial