test/main.c

Wed, 24 Jul 2013 14:26:17 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 24 Jul 2013 14:26:17 +0200
changeset 129
61edec666928
parent 123
7fb0f74517c5
child 131
fc3af16818a3
permissions
-rw-r--r--

documentation for UcxLogger

/*
 * 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_TEST_IMPLEMENT(testTestSuitePositive) {
    UCX_TEST_BEGIN
    UCX_TEST_ASSERT(2*2 == 4, "the test framework fails");
    UCX_TEST_END
}

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

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

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

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

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

UCX_TEST_IMPLEMENT(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_TEST_IMPLEMENT(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_TEST_IMPLEMENT(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