1.1 --- a/test/list_tests.c Sat Jul 20 11:13:26 2013 +0200 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,229 +0,0 @@ 1.4 -/* 1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 1.6 - * 1.7 - * Copyright 2013 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 "list_tests.h" 1.33 -#include "ucx/utils.h" 1.34 - 1.35 -UCX_TEST_IMPLEMENT(test_ucx_list_append) { 1.36 - UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 1.37 - UCX_TEST_BEGIN 1.38 - UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 1.39 - "failed"); 1.40 - 1.41 - list = ucx_list_append(list, (void*)" World!"); 1.42 - 1.43 - UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, 1.44 - "failed"); 1.45 - UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 1.46 - 1.47 - UCX_TEST_END 1.48 - ucx_list_free(list); 1.49 -} 1.50 - 1.51 -UCX_TEST_IMPLEMENT(test_ucx_list_prepend) { 1.52 - UcxList *list = ucx_list_prepend(NULL, (void*)" World!"); 1.53 - UCX_TEST_BEGIN 1.54 - list = ucx_list_prepend(list, (void*)"Hello"); 1.55 - 1.56 - UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 1.57 - "failed"); 1.58 - UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, 1.59 - "failed"); 1.60 - UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 1.61 - 1.62 - UCX_TEST_END 1.63 - ucx_list_free(list); 1.64 -} 1.65 - 1.66 -UCX_TEST_IMPLEMENT(test_ucx_list_equals) { 1.67 - UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 1.68 - list = ucx_list_append(list, (void*)" World!"); 1.69 - UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!"); 1.70 - list2 = ucx_list_prepend(list2, (void*)"Hello"); 1.71 - UcxList *list3 = ucx_list_prepend(NULL, (void*)" Welt!"); 1.72 - list3 = ucx_list_prepend(list3, (void*)"Hallo"); 1.73 - 1.74 - UCX_TEST_BEGIN 1.75 - UCX_TEST_ASSERT(ucx_list_equals(list, list2, ucx_strcmp, NULL), "failed"); 1.76 - UCX_TEST_ASSERT(!ucx_list_equals(list, list3, ucx_strcmp, NULL), "failed"); 1.77 - UCX_TEST_END 1.78 - 1.79 - ucx_list_free(list3); 1.80 - ucx_list_free(list2); 1.81 - ucx_list_free(list); 1.82 -} 1.83 - 1.84 -UCX_TEST_IMPLEMENT(test_ucx_list_concat) { 1.85 - UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 1.86 - UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!"); 1.87 - 1.88 - list = ucx_list_concat(list, list2); 1.89 - UCX_TEST_BEGIN 1.90 - 1.91 - UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 1.92 - "failed"); 1.93 - UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, 1.94 - "failed"); 1.95 - UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 1.96 - 1.97 - UCX_TEST_END 1.98 - if (list->next == NULL) { 1.99 - ucx_list_free(list2); 1.100 - } 1.101 - ucx_list_free(list); 1.102 -} 1.103 - 1.104 -UCX_TEST_IMPLEMENT(test_ucx_list_size) { 1.105 - UcxList *list = ucx_list_append(NULL, (void*)"This "); 1.106 - UCX_TEST_BEGIN 1.107 - list = ucx_list_append(list, (void*)"list "); 1.108 - list = ucx_list_append(list, (void*)"has "); 1.109 - list = ucx_list_append(list, (void*)"size "); 1.110 - list = ucx_list_append(list, (void*)"5!"); 1.111 - 1.112 - UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed"); 1.113 - 1.114 - UCX_TEST_END 1.115 - ucx_list_free(list); 1.116 -} 1.117 - 1.118 -UCX_TEST_IMPLEMENT(test_ucx_list_last) { 1.119 - UcxList *list = ucx_list_append(NULL, (void*)"Find "); 1.120 - UCX_TEST_BEGIN 1.121 - list = ucx_list_append(list, (void*)"the "); 1.122 - list = ucx_list_append(list, (void*)"last!"); 1.123 - 1.124 - const char* last = (const char*) (ucx_list_last(list)->data); 1.125 - 1.126 - UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); 1.127 - 1.128 - UCX_TEST_END 1.129 - ucx_list_free(list); 1.130 - 1.131 -} 1.132 - 1.133 -UCX_TEST_IMPLEMENT(test_ucx_list_get) { 1.134 - UcxList *list = ucx_list_append(NULL, (void*)"Find "); 1.135 - UCX_TEST_BEGIN 1.136 - list = ucx_list_append(list, (void*)"the "); 1.137 - list = ucx_list_append(list, (void*)"mid!"); 1.138 - 1.139 - const char* mid = (const char*) (ucx_list_get(list, 1)->data); 1.140 - 1.141 - UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); 1.142 - 1.143 - UCX_TEST_END 1.144 - ucx_list_free(list); 1.145 -} 1.146 - 1.147 -UCX_TEST_IMPLEMENT(test_ucx_list_contains) { 1.148 - UcxList *l = ucx_list_append(NULL, (void*)"Contains "); 1.149 - UCX_TEST_BEGIN 1.150 - l = ucx_list_append(l, (void*)"a "); 1.151 - l = ucx_list_append(l, (void*)"string!"); 1.152 - 1.153 - UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL), "failed"); 1.154 - UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL), "failed"); 1.155 - 1.156 - UCX_TEST_END 1.157 - ucx_list_free(l); 1.158 -} 1.159 - 1.160 -UCX_TEST_IMPLEMENT(test_ucx_list_remove) { 1.161 - UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 1.162 - UCX_TEST_BEGIN 1.163 - list = ucx_list_append(list, (void*)" fucking"); 1.164 - list = ucx_list_append(list, (void*)" World!"); 1.165 - 1.166 - list = ucx_list_remove(list, ucx_list_get(list, 1)); 1.167 - 1.168 - UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 1.169 - "failed"); 1.170 - UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, 1.171 - "failed"); 1.172 - UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 1.173 - UCX_TEST_END 1.174 - 1.175 - ucx_list_free(list); 1.176 -} 1.177 - 1.178 -UCX_TEST_IMPLEMENT(test_ucx_list_clone) { 1.179 - 1.180 - char *hello = (char*)malloc(6); 1.181 - char *world = (char*)malloc(8); 1.182 - 1.183 - memcpy(hello, "Hello", 6); 1.184 - memcpy(world, " World!", 8); 1.185 - 1.186 - UcxList *list = ucx_list_append(NULL, hello); 1.187 - list = ucx_list_append(list, world); 1.188 - 1.189 - UcxList *copy = ucx_list_clone(list, ucx_strcpy, NULL); 1.190 - UCX_TEST_BEGIN 1.191 - 1.192 - UCX_TEST_ASSERT(ucx_list_equals(list, copy, ucx_strcmp, NULL), "failed"); 1.193 - UCX_TEST_ASSERT(hello != copy->data, "first element is no copy"); 1.194 - UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy"); 1.195 - 1.196 - UCX_TEST_END 1.197 - free(copy->next->data); 1.198 - free(copy->data); 1.199 - 1.200 - free(world); 1.201 - free(hello); 1.202 - ucx_list_free(list); 1.203 - ucx_list_free(copy); 1.204 -} 1.205 - 1.206 -UCX_TEST_IMPLEMENT(test_ucx_list_sort) { 1.207 - UcxList *list = ucx_list_append(NULL, (void*)"this"); 1.208 - list = ucx_list_append(list, (void*)"is"); 1.209 - list = ucx_list_append(list, (void*)"a"); 1.210 - list = ucx_list_append(list, (void*)"test"); 1.211 - list = ucx_list_append(list, (void*)"for"); 1.212 - list = ucx_list_append(list, (void*)"partial"); 1.213 - list = ucx_list_append(list, (void*)"correctness"); 1.214 - 1.215 - UcxList *expected = ucx_list_append(NULL, (void*)"a"); 1.216 - expected = ucx_list_append(expected, (void*)"correctness"); 1.217 - expected = ucx_list_append(expected, (void*)"for"); 1.218 - expected = ucx_list_append(expected, (void*)"is"); 1.219 - expected = ucx_list_append(expected, (void*)"partial"); 1.220 - expected = ucx_list_append(expected, (void*)"test"); 1.221 - expected = ucx_list_append(expected, (void*)"this"); 1.222 - 1.223 - list = ucx_list_sort(list, ucx_strcmp, NULL); 1.224 - 1.225 - UCX_TEST_BEGIN 1.226 - UCX_TEST_ASSERT( 1.227 - ucx_list_equals(list, expected, ucx_strcmp, NULL), "failed"); 1.228 - UCX_TEST_END 1.229 - 1.230 - ucx_list_free(expected); 1.231 - ucx_list_free(list); 1.232 -}