test/main.c

Mon, 20 Feb 2012 15:30:45 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 20 Feb 2012 15:30:45 +0100
changeset 28
1666cbeb1db8
parent 27
22644e2572bc
child 29
bce0d7f2912b
permissions
-rw-r--r--

new mempool tests

olaf@0 1 /*
olaf@0 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
olaf@0 3 *
olaf@0 4 * Copyright 2011 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
olaf@9 36 #include "list_tests.h"
universe@27 37 #include "dlist_tests.h"
universe@27 38
olaf@13 39 #include "mpool_tests.h"
olaf@20 40 #include "map_tests.h"
olaf@9 41
universe@27 42 int cmp_string(void* o1, void* o2, void* data) {
universe@27 43 return strcmp((char*)o1, (char*)o2);
universe@27 44 }
universe@27 45
universe@27 46 void* copy_string(void* e, void* data) {
universe@27 47 char *str = (char*) e;
universe@27 48 size_t n = 1+strlen(str);
universe@27 49 char *cpy = (char*) malloc(n);
universe@27 50 memcpy(cpy, str, n);
universe@27 51 return cpy;
universe@27 52 }
universe@27 53
universe@26 54 UCX_TEST_BEGIN(testTestSuitePositive) {
universe@26 55 UCX_TEST_ASSERT(2*2 == 4, "the test framework fails")
universe@26 56 UCX_TEST_END
universe@26 57 }
universe@26 58
universe@26 59 UCX_TEST_BEGIN(testTestSuiteNegative) {
universe@26 60 UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works")
universe@26 61 UCX_TEST_END
universe@26 62 }
universe@26 63
olaf@0 64 int main(int argc, char **argv) {
olaf@13 65 printf("UCX Tests\n---------\n");
olaf@9 66
universe@28 67 printf("\nUcxTestSuite tests (1 failure is intended!)\n");
universe@26 68 UcxTestSuite* suite = ucx_test_suite_new();
universe@26 69 ucx_test_register(suite, testTestSuitePositive);
universe@26 70 ucx_test_register(suite, testTestSuiteNegative);
universe@26 71 ucx_test_run(suite, stdout);
universe@26 72 if (suite->failure == 1 && suite->success == 1) {
universe@26 73 ucx_test_suite_free(suite);
universe@27 74
universe@28 75 printf("\nLibrary function tests\n");
universe@27 76 suite = ucx_test_suite_new();
universe@27 77 /* UcxList Tests */
universe@27 78 ucx_test_register(suite, test_ucx_list_append);
universe@27 79 ucx_test_register(suite, test_ucx_list_prepend);
universe@27 80 ucx_test_register(suite, test_ucx_list_equals);
universe@27 81 ucx_test_register(suite, test_ucx_list_concat);
universe@27 82 ucx_test_register(suite, test_ucx_list_size);
universe@27 83 ucx_test_register(suite, test_ucx_list_last);
universe@27 84 ucx_test_register(suite, test_ucx_list_get);
universe@27 85 ucx_test_register(suite, test_ucx_list_remove);
universe@27 86 ucx_test_register(suite, test_ucx_list_clone);
universe@27 87
universe@27 88 /* UcxDlist Tests */
universe@27 89 ucx_test_register(suite, test_ucx_dlist_append);
universe@27 90 ucx_test_register(suite, test_ucx_dlist_prepend);
universe@27 91 ucx_test_register(suite, test_ucx_dlist_equals);
universe@27 92 ucx_test_register(suite, test_ucx_dlist_concat);
universe@27 93 ucx_test_register(suite, test_ucx_dlist_size);
universe@27 94 ucx_test_register(suite, test_ucx_dlist_first);
universe@27 95 ucx_test_register(suite, test_ucx_dlist_last);
universe@27 96 ucx_test_register(suite, test_ucx_dlist_get);
universe@27 97 ucx_test_register(suite, test_ucx_dlist_remove);
universe@27 98 ucx_test_register(suite, test_ucx_dlist_clone);
universe@27 99
universe@28 100 /* UcxMemPool Tests */
universe@28 101 ucx_test_register(suite, test_ucx_mempool_new);
universe@28 102 ucx_test_register(suite, test_ucx_mempool_malloc);
universe@28 103 ucx_test_register(suite, test_ucx_mempool_malloc_with_chcap);
universe@28 104 ucx_test_register(suite, test_ucx_mempool_calloc);
universe@28 105 ucx_test_register(suite, test_ucx_mempool_set_destr);
universe@28 106 ucx_test_register(suite, test_ucx_mempool_reg_destr);
universe@28 107 ucx_test_register(suite, test_ucx_mempool_realloc);
universe@26 108
universe@26 109 printf("\nUcxMap Tests\n");
universe@26 110 if(map_tests()) {
universe@26 111 fprintf(stderr, "map_tests failed\n");
universe@26 112 }
universe@26 113
universe@27 114 ucx_test_run(suite, stdout);
universe@27 115 ucx_test_suite_free(suite);
universe@27 116
universe@26 117 return EXIT_SUCCESS;
universe@26 118 } else {
universe@26 119 ucx_test_suite_free(suite);
universe@26 120 return EXIT_FAILURE;
olaf@13 121 }
olaf@0 122 }
olaf@0 123

mercurial