test/main.c

Fri, 09 Aug 2013 15:29:26 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 09 Aug 2013 15:29:26 +0200
changeset 136
b798f2eed26a
parent 134
4d320dc3a7af
child 140
15f871f50bfd
permissions
-rw-r--r--

started documentation of map.h + renamed allocator version of ucx_map_new

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2013 Olaf Wintermann. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <stdlib.h>

#include "ucx/test.h"

#include "main.h"

#include "logging_tests.h"
#include "list_tests.h"
#include "string_tests.h"
#include "mpool_tests.h"
#include "map_tests.h"
#include "prop_tests.h"
#include "buffer_tests.h"

UCX_EXTERN UCX_TEST(testTestSuitePositive) {
    UCX_TEST_BEGIN
    UCX_TEST_ASSERT(2*2 == 4, "the test framework fails");
    UCX_TEST_END
}

UCX_EXTERN UCX_TEST(testTestSuiteNegative) {
    UCX_TEST_BEGIN
    UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works");
    UCX_TEST_END
}

UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) {
    UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails");
}

UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) {
    UCX_TEST_ASSERT(i == 42, "two parameter routine fails");
    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f);
}

UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) {
    *i += 2;
    UCX_TEST_ASSERT(*i==4, "the test framework fails");
}

UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) {
    *i += 2;
    // Next test shall fail!
    UCX_TEST_ASSERT(*i==4, "the test framework works");
}

UCX_EXTERN UCX_TEST(testTestSuiteRoutinePositive) {
    int i = 2;
    UCX_TEST_BEGIN
    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i);
    UCX_TEST_ASSERT(i==4, "the test framework fails");
    UCX_TEST_END
}

UCX_EXTERN UCX_TEST(testTestSuiteRoutineNegative) {
    int i = 0;
    UCX_TEST_BEGIN
    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i);
    UCX_TEST_ASSERT(1, "the test framework fails");
    UCX_TEST_END
}

UCX_EXTERN UCX_TEST(testTestSuiteRoutineMultiparam) {
    UCX_TEST_BEGIN
    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f);
    UCX_TEST_END
}

int main(int argc, char **argv) {
    printf("UCX Tests\n---------\n");

    printf("\nUcxTestSuite tests (2 failures are intended!)\n");
    UcxTestSuite* suite = ucx_test_suite_new();
    ucx_test_register(suite, testTestSuitePositive);
    ucx_test_register(suite, testTestSuiteNegative);
    ucx_test_register(suite, testTestSuiteRoutinePositive);
    ucx_test_register(suite, testTestSuiteRoutineNegative);
    ucx_test_register(suite, testTestSuiteRoutineMultiparam);
    ucx_test_run(suite, stdout);
    if (suite->failure == 2 && suite->success == 3) {
        ucx_test_suite_free(suite);

        printf("\nLibrary function tests\n");
        suite = ucx_test_suite_new();
        /* sstring Tests */
        ucx_test_register(suite, test_sstr);
        ucx_test_register(suite, test_sstr_len_cat);
        ucx_test_register(suite, test_sstrsplit);
        ucx_test_register(suite, test_sstrtrim);
        
        /* UcxLogger Tests */
        ucx_test_register(suite, test_ucx_logger_log);
        
        /* UcxList Tests */
        ucx_test_register(suite, test_ucx_list_append);
        ucx_test_register(suite, test_ucx_list_prepend);
        ucx_test_register(suite, test_ucx_list_equals);
        ucx_test_register(suite, test_ucx_list_concat);
        ucx_test_register(suite, test_ucx_list_size);
        ucx_test_register(suite, test_ucx_list_first);
        ucx_test_register(suite, test_ucx_list_last);
        ucx_test_register(suite, test_ucx_list_get);
        ucx_test_register(suite, test_ucx_list_indexof);
        ucx_test_register(suite, test_ucx_list_find);
        ucx_test_register(suite, test_ucx_list_contains);
        ucx_test_register(suite, test_ucx_list_remove);
        ucx_test_register(suite, test_ucx_list_clone);
        ucx_test_register(suite, test_ucx_list_sort);

        /* UcxMemPool Tests */
        ucx_test_register(suite, test_ucx_mempool_new);
        ucx_test_register(suite, test_ucx_mempool_malloc);
        ucx_test_register(suite, test_ucx_mempool_malloc_with_chcap);
        ucx_test_register(suite, test_ucx_mempool_calloc);
        ucx_test_register(suite, test_ucx_mempool_free);
        ucx_test_register(suite, test_ucx_mempool_set_destr);
        ucx_test_register(suite, test_ucx_mempool_reg_destr);
        ucx_test_register(suite, test_ucx_mempool_realloc);

        /* UcxMap Tests */
        ucx_test_register(suite, test_ucx_map_new);
        ucx_test_register(suite, test_ucx_key);
        ucx_test_register(suite, test_ucx_map_put);
        ucx_test_register(suite, test_ucx_map_get);
        ucx_test_register(suite, test_ucx_map_remove);
        ucx_test_register(suite, test_ucx_map_iterator);
        ucx_test_register(suite, test_ucx_map_iterator_chain);
        ucx_test_register(suite, test_ucx_map_clone);
        ucx_test_register(suite, test_ucx_map_rehash);
        
        /* UcxPropertiesParser Tests */
        ucx_test_register(suite, test_ucx_properties_new);
        ucx_test_register(suite, test_ucx_properties_next);
        ucx_test_register(suite, test_ucx_properties_next_multi);
        ucx_test_register(suite, test_ucx_properties_next_part);
        ucx_test_register(suite, test_ucx_properties_next_long);
        ucx_test_register(suite, test_ucx_properties2map);
        ucx_test_register(suite, test_ucx_properties_load);
        ucx_test_register(suite, test_ucx_properties_store);
        
        /* UcxBuffer Tests */
        ucx_test_register(suite, test_ucx_buffer_seektell);
        ucx_test_register(suite, test_ucx_buffer_putc);
        ucx_test_register(suite, test_ucx_buffer_putc_ax);
        ucx_test_register(suite, test_ucx_buffer_getc);
        ucx_test_register(suite, test_ucx_buffer_write);
        ucx_test_register(suite, test_ucx_buffer_write_ax);
        ucx_test_register(suite, test_ucx_buffer_read);
        ucx_test_register(suite, test_ucx_buffer_extract);
        ucx_test_register(suite, test_ucx_buffer_generic_copy);

        ucx_test_run(suite, stdout);
        fflush(stdout);
        ucx_test_suite_free(suite);
        
        return EXIT_SUCCESS;
    } else {
        ucx_test_suite_free(suite);
        return EXIT_FAILURE;
    }
}

mercurial