test/main.c

Fri, 09 Aug 2013 11:32:10 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 09 Aug 2013 11:32:10 +0200
changeset 134
4d320dc3a7af
parent 131
fc3af16818a3
child 140
15f871f50bfd
permissions
-rw-r--r--

documented test.h and removed duplicated implement/declare macros for UCX_TEST

olaf@0 1 /*
olaf@0 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
olaf@0 3 *
universe@103 4 * Copyright 2013 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@54 36 #include "logging_tests.h"
universe@122 37 #include "list_tests.h"
universe@39 38 #include "string_tests.h"
olaf@13 39 #include "mpool_tests.h"
olaf@20 40 #include "map_tests.h"
olaf@108 41 #include "prop_tests.h"
universe@60 42 #include "buffer_tests.h"
olaf@9 43
universe@134 44 UCX_EXTERN UCX_TEST(testTestSuitePositive) {
universe@33 45 UCX_TEST_BEGIN
universe@40 46 UCX_TEST_ASSERT(2*2 == 4, "the test framework fails");
universe@26 47 UCX_TEST_END
universe@26 48 }
universe@26 49
universe@134 50 UCX_EXTERN UCX_TEST(testTestSuiteNegative) {
universe@33 51 UCX_TEST_BEGIN
universe@40 52 UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works");
universe@26 53 UCX_TEST_END
universe@26 54 }
universe@26 55
olaf@131 56 UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) {
universe@88 57 UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails");
universe@88 58 }
universe@88 59
olaf@131 60 UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) {
universe@88 61 UCX_TEST_ASSERT(i == 42, "two parameter routine fails");
universe@88 62 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f);
universe@88 63 }
universe@88 64
olaf@131 65 UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) {
universe@33 66 *i += 2;
universe@33 67 UCX_TEST_ASSERT(*i==4, "the test framework fails");
universe@33 68 }
universe@33 69
olaf@131 70 UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) {
universe@33 71 *i += 2;
universe@88 72 // Next test shall fail!
universe@33 73 UCX_TEST_ASSERT(*i==4, "the test framework works");
universe@33 74 }
universe@33 75
universe@134 76 UCX_EXTERN UCX_TEST(testTestSuiteRoutinePositive) {
universe@33 77 int i = 2;
universe@33 78 UCX_TEST_BEGIN
universe@33 79 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i);
universe@33 80 UCX_TEST_ASSERT(i==4, "the test framework fails");
universe@33 81 UCX_TEST_END
universe@33 82 }
universe@33 83
universe@134 84 UCX_EXTERN UCX_TEST(testTestSuiteRoutineNegative) {
universe@33 85 int i = 0;
universe@33 86 UCX_TEST_BEGIN
universe@33 87 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i);
universe@33 88 UCX_TEST_ASSERT(1, "the test framework fails");
universe@33 89 UCX_TEST_END
universe@33 90 }
universe@33 91
universe@134 92 UCX_EXTERN UCX_TEST(testTestSuiteRoutineMultiparam) {
universe@88 93 UCX_TEST_BEGIN
universe@88 94 UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f);
universe@88 95 UCX_TEST_END
universe@88 96 }
universe@88 97
olaf@0 98 int main(int argc, char **argv) {
olaf@13 99 printf("UCX Tests\n---------\n");
olaf@9 100
universe@33 101 printf("\nUcxTestSuite tests (2 failures are intended!)\n");
universe@26 102 UcxTestSuite* suite = ucx_test_suite_new();
universe@26 103 ucx_test_register(suite, testTestSuitePositive);
universe@26 104 ucx_test_register(suite, testTestSuiteNegative);
universe@33 105 ucx_test_register(suite, testTestSuiteRoutinePositive);
universe@33 106 ucx_test_register(suite, testTestSuiteRoutineNegative);
universe@88 107 ucx_test_register(suite, testTestSuiteRoutineMultiparam);
universe@26 108 ucx_test_run(suite, stdout);
universe@88 109 if (suite->failure == 2 && suite->success == 3) {
universe@26 110 ucx_test_suite_free(suite);
universe@27 111
universe@28 112 printf("\nLibrary function tests\n");
universe@27 113 suite = ucx_test_suite_new();
universe@97 114 /* sstring Tests */
universe@97 115 ucx_test_register(suite, test_sstr);
universe@97 116 ucx_test_register(suite, test_sstr_len_cat);
universe@97 117 ucx_test_register(suite, test_sstrsplit);
universe@97 118 ucx_test_register(suite, test_sstrtrim);
universe@97 119
universe@54 120 /* UcxLogger Tests */
universe@54 121 ucx_test_register(suite, test_ucx_logger_log);
universe@27 122
universe@123 123 /* UcxList Tests */
universe@122 124 ucx_test_register(suite, test_ucx_list_append);
universe@122 125 ucx_test_register(suite, test_ucx_list_prepend);
universe@122 126 ucx_test_register(suite, test_ucx_list_equals);
universe@122 127 ucx_test_register(suite, test_ucx_list_concat);
universe@122 128 ucx_test_register(suite, test_ucx_list_size);
universe@122 129 ucx_test_register(suite, test_ucx_list_first);
universe@122 130 ucx_test_register(suite, test_ucx_list_last);
universe@122 131 ucx_test_register(suite, test_ucx_list_get);
universe@123 132 ucx_test_register(suite, test_ucx_list_indexof);
universe@123 133 ucx_test_register(suite, test_ucx_list_find);
universe@122 134 ucx_test_register(suite, test_ucx_list_contains);
universe@122 135 ucx_test_register(suite, test_ucx_list_remove);
universe@122 136 ucx_test_register(suite, test_ucx_list_clone);
universe@122 137 ucx_test_register(suite, test_ucx_list_sort);
universe@27 138
universe@28 139 /* UcxMemPool Tests */
universe@28 140 ucx_test_register(suite, test_ucx_mempool_new);
universe@28 141 ucx_test_register(suite, test_ucx_mempool_malloc);
universe@28 142 ucx_test_register(suite, test_ucx_mempool_malloc_with_chcap);
universe@28 143 ucx_test_register(suite, test_ucx_mempool_calloc);
olaf@113 144 ucx_test_register(suite, test_ucx_mempool_free);
universe@28 145 ucx_test_register(suite, test_ucx_mempool_set_destr);
universe@28 146 ucx_test_register(suite, test_ucx_mempool_reg_destr);
universe@28 147 ucx_test_register(suite, test_ucx_mempool_realloc);
universe@26 148
universe@29 149 /* UcxMap Tests */
universe@29 150 ucx_test_register(suite, test_ucx_map_new);
universe@29 151 ucx_test_register(suite, test_ucx_key);
universe@29 152 ucx_test_register(suite, test_ucx_map_put);
universe@29 153 ucx_test_register(suite, test_ucx_map_get);
universe@53 154 ucx_test_register(suite, test_ucx_map_remove);
olaf@31 155 ucx_test_register(suite, test_ucx_map_iterator);
universe@33 156 ucx_test_register(suite, test_ucx_map_iterator_chain);
olaf@44 157 ucx_test_register(suite, test_ucx_map_clone);
universe@51 158 ucx_test_register(suite, test_ucx_map_rehash);
olaf@108 159
olaf@108 160 /* UcxPropertiesParser Tests */
olaf@110 161 ucx_test_register(suite, test_ucx_properties_new);
olaf@110 162 ucx_test_register(suite, test_ucx_properties_next);
olaf@110 163 ucx_test_register(suite, test_ucx_properties_next_multi);
olaf@110 164 ucx_test_register(suite, test_ucx_properties_next_part);
olaf@110 165 ucx_test_register(suite, test_ucx_properties_next_long);
olaf@110 166 ucx_test_register(suite, test_ucx_properties2map);
olaf@109 167 ucx_test_register(suite, test_ucx_properties_load);
olaf@109 168 ucx_test_register(suite, test_ucx_properties_store);
olaf@108 169
olaf@108 170 /* UcxBuffer Tests */
universe@60 171 ucx_test_register(suite, test_ucx_buffer_seektell);
universe@60 172 ucx_test_register(suite, test_ucx_buffer_putc);
olaf@76 173 ucx_test_register(suite, test_ucx_buffer_putc_ax);
universe@60 174 ucx_test_register(suite, test_ucx_buffer_getc);
universe@60 175 ucx_test_register(suite, test_ucx_buffer_write);
universe@64 176 ucx_test_register(suite, test_ucx_buffer_write_ax);
universe@60 177 ucx_test_register(suite, test_ucx_buffer_read);
universe@62 178 ucx_test_register(suite, test_ucx_buffer_extract);
olaf@76 179 ucx_test_register(suite, test_ucx_buffer_generic_copy);
universe@56 180
universe@27 181 ucx_test_run(suite, stdout);
universe@55 182 fflush(stdout);
universe@27 183 ucx_test_suite_free(suite);
universe@27 184
universe@26 185 return EXIT_SUCCESS;
universe@26 186 } else {
universe@26 187 ucx_test_suite_free(suite);
universe@26 188 return EXIT_FAILURE;
olaf@13 189 }
olaf@0 190 }
olaf@0 191

mercurial