test/test_allocator.c

changeset 511
a32e6a6b1ca7
parent 510
133ac0f8f3fc
child 512
096d206b63f9
     1.1 --- a/test/test_allocator.c	Fri Apr 15 21:28:51 2022 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,101 +0,0 @@
     1.4 -/*
     1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 - *
     1.7 - * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
     1.8 - *
     1.9 - * Redistribution and use in source and binary forms, with or without
    1.10 - * modification, are permitted provided that the following conditions are met:
    1.11 - *
    1.12 - *   1. Redistributions of source code must retain the above copyright
    1.13 - *      notice, this list of conditions and the following disclaimer.
    1.14 - *
    1.15 - *   2. Redistributions in binary form must reproduce the above copyright
    1.16 - *      notice, this list of conditions and the following disclaimer in the
    1.17 - *      documentation and/or other materials provided with the distribution.
    1.18 - *
    1.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    1.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.29 - * POSSIBILITY OF SUCH DAMAGE.
    1.30 - */
    1.31 -
    1.32 -#include "cx/allocator.h"
    1.33 -#include "test_config.h"
    1.34 -#include <errno.h>
    1.35 -
    1.36 -void test_default_allocator_available(void) {
    1.37 -    cx_allocator_class *clazz = cxDefaultAllocator->cl;
    1.38 -    CU_ASSERT_PTR_NOT_NULL(clazz)
    1.39 -}
    1.40 -
    1.41 -void test_default_malloc(void) {
    1.42 -    void *test = cxMalloc(cxDefaultAllocator, 16);
    1.43 -    CU_ASSERT_PTR_NOT_NULL(test);
    1.44 -    free(test);
    1.45 -}
    1.46 -
    1.47 -void test_default_realloc(void) {
    1.48 -    void *test = calloc(8, 1);
    1.49 -    memcpy(test, "Test", 5);
    1.50 -    test = cxRealloc(cxDefaultAllocator, test, 16);
    1.51 -    CU_ASSERT_PTR_NOT_NULL(test)
    1.52 -    CU_ASSERT_STRING_EQUAL("Test", test)
    1.53 -    free(test);
    1.54 -}
    1.55 -
    1.56 -void test_default_reallocate(void) {
    1.57 -    void *test = calloc(8, 1);
    1.58 -    memcpy(test, "Test", 5);
    1.59 -    int rval = cxReallocate(cxDefaultAllocator, &test, 16);
    1.60 -    CU_ASSERT_EQUAL(rval, 0);
    1.61 -    CU_ASSERT_PTR_NOT_NULL(test)
    1.62 -    CU_ASSERT_STRING_EQUAL("Test", test)
    1.63 -    free(test);
    1.64 -}
    1.65 -
    1.66 -void test_default_calloc(void) {
    1.67 -    void *test = cxCalloc(cxDefaultAllocator, 8, 2);
    1.68 -    CU_ASSERT_PTR_NOT_NULL(test)
    1.69 -    free(test);
    1.70 -}
    1.71 -
    1.72 -void test_default_free(void) {
    1.73 -    void *test = malloc(16);
    1.74 -    cxFree(cxDefaultAllocator, test);
    1.75 -    CU_PASS("Testing standard free is not possible.")
    1.76 -}
    1.77 -
    1.78 -int main() {
    1.79 -    CU_pSuite suite = NULL;
    1.80 -
    1.81 -    if (CUE_SUCCESS != CU_initialize_registry()) {
    1.82 -        return CU_get_error();
    1.83 -    }
    1.84 -
    1.85 -    suite = CU_add_suite("default allocator", NULL, NULL);
    1.86 -
    1.87 -    CU_add_test(suite, "default allocator available", test_default_allocator_available);
    1.88 -    CU_add_test(suite, "test of malloc()", test_default_malloc);
    1.89 -    CU_add_test(suite, "test of realloc()", test_default_realloc);
    1.90 -    CU_add_test(suite, "test of realloc() via cxReallocate", test_default_reallocate);
    1.91 -    CU_add_test(suite, "test of calloc()", test_default_calloc);
    1.92 -    CU_add_test(suite, "test of free()", test_default_free);
    1.93 -
    1.94 -    CU_basic_set_mode(UCX_CU_BRM);
    1.95 -
    1.96 -    int exitcode;
    1.97 -    if (CU_basic_run_tests()) {
    1.98 -        exitcode = CU_get_error();
    1.99 -    } else {
   1.100 -        exitcode = CU_get_number_of_failures() == 0 ? 0 : 1;
   1.101 -    }
   1.102 -    CU_cleanup_registry();
   1.103 -    return exitcode;
   1.104 -}

mercurial