test/main.c

Sat, 18 Feb 2012 18:36:30 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 18 Feb 2012 18:36:30 +0100
changeset 27
22644e2572bc
parent 26
59f147baea31
child 28
1666cbeb1db8
permissions
-rw-r--r--

removed old foreach + refactored list tests

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2011 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 "list_tests.h"
#include "dlist_tests.h"

#include "mpool_tests.h"
#include "map_tests.h"

int cmp_string(void* o1, void* o2, void* data) {
    return strcmp((char*)o1, (char*)o2);
}

void* copy_string(void* e, void* data) {
    char *str = (char*) e;
    size_t n = 1+strlen(str);
    char *cpy = (char*) malloc(n);
    memcpy(cpy, str, n);
    return cpy;
}

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

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

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

    printf("\nUcxTestSuite Tests (1 failure is intended!)\n");
    UcxTestSuite* suite = ucx_test_suite_new();
    ucx_test_register(suite, testTestSuitePositive);
    ucx_test_register(suite, testTestSuiteNegative);
    ucx_test_run(suite, stdout);
    if (suite->failure == 1 && suite->success == 1) {
        ucx_test_suite_free(suite);

        suite = ucx_test_suite_new();
        /* 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_last);
        ucx_test_register(suite, test_ucx_list_get);
        ucx_test_register(suite, test_ucx_list_remove);
        ucx_test_register(suite, test_ucx_list_clone);
        
        /* UcxDlist Tests */
        ucx_test_register(suite, test_ucx_dlist_append);
        ucx_test_register(suite, test_ucx_dlist_prepend);
        ucx_test_register(suite, test_ucx_dlist_equals);
        ucx_test_register(suite, test_ucx_dlist_concat);
        ucx_test_register(suite, test_ucx_dlist_size);
        ucx_test_register(suite, test_ucx_dlist_first);
        ucx_test_register(suite, test_ucx_dlist_last);
        ucx_test_register(suite, test_ucx_dlist_get);
        ucx_test_register(suite, test_ucx_dlist_remove);
        ucx_test_register(suite, test_ucx_dlist_clone);

        /* TODO: replace these tests with "real" tests */
        printf("\nUcxMemPool Tests\n");
        if(mpool_tests()) {
            fprintf(stderr, "mpool_tests failed\n");
        }

        printf("\nUcxMap Tests\n");
        if(map_tests()) {
            fprintf(stderr, "map_tests failed\n");
        }
        
        ucx_test_run(suite, stdout);
        ucx_test_suite_free(suite);
        
        return EXIT_SUCCESS;
    } else {
        ucx_test_suite_free(suite);
        return EXIT_FAILURE;
    }
}

mercurial