Line data Source code
1 : /** @file suite_sclist.c 2 : * @brief Check testsuite template 3 : * @author François Cerbelle (Fanfan), francois@cerbelle.net 4 : * 5 : * @internal 6 : * Created: 20/03/2022 7 : * Revision: none 8 : * Last modified: 2024-11-20 23:05 9 : * Compiler: gcc 10 : * Organization: Cerbelle.net 11 : * Copyright: Copyright (c) 2024, François Cerbelle 12 : * 13 : * This source code is released for free distribution under the terms of the 14 : * GNU General Public License as published by the Free Software Foundation. 15 : */ 16 : 17 : #ifdef HAVE_CONFIG_H 18 : #include "config.h" 19 : #endif 20 : 21 : #include <check.h> 22 : #include <unistd.h> /* pid_t getpid() */ 23 : #include <sys/stat.h> /* mkdir(), chdir(), mode_t */ 24 : #include <stdio.h> /* fprintf */ 25 : #include <stdlib.h> /* abort() */ 26 : #include "checktools.inc" 27 : 28 : #include "sclist.c" 29 : 30 : /** Dummy test to trigger fixtures 31 : * 32 : * This test is defined and added to all testcases in order to execute at 33 : * least one test test in each testcase of the testsuite, trigger the 34 : * fixtures and have a decent coverage report. 35 : */ 36 3 : START_TEST(sclist_test) { 37 : /* This test is supposed to trigger a SIGABRT(6) and will crash the 38 : * whole testsuite if not caught or not in a child process */ 39 3 : forktest_only; 40 : 41 2 : abort(); 42 : } 43 : END_TEST 44 : 45 3 : START_TEST(sclist_scenarized_test) { 46 3 : sclist_t* sclist=NULL; 47 : sclistrecord_t* sclistrecord; 48 3 : char* txt_a="a"; 49 3 : char* txt_b="b"; 50 : 51 3 : sclist = sclist_new(); 52 3 : ck_assert(sclist); 53 3 : ck_assert(NULL==sclist->first); 54 3 : ck_assert(NULL==sclist->last); 55 : 56 3 : sclistrecord = sclist_firstrecord(sclist); 57 3 : ck_assert(sclistrecord == sclist->first); 58 : 59 3 : sclistrecord = sclist_addrecord(sclist,txt_a); 60 3 : ck_assert(sclistrecord!=NULL); 61 3 : ck_assert(sclist->last==sclistrecord); 62 3 : ck_assert(sclist->first==sclistrecord); 63 3 : ck_assert(sclist->first->value==txt_a); 64 3 : ck_assert(sclist->first->next==NULL); 65 : 66 3 : sclistrecord = sclist_addrecord(sclist,txt_b); 67 3 : ck_assert(sclistrecord!=NULL); 68 3 : ck_assert(sclist->last==sclistrecord); 69 3 : ck_assert(sclist->first!=sclistrecord); 70 3 : ck_assert(sclist->first->value==txt_a); 71 3 : ck_assert(sclist->first->next==sclistrecord); 72 3 : ck_assert(sclist->first->next->next==NULL); 73 3 : ck_assert(sclist->first->next->value==txt_b); 74 : 75 : /* Duplicate */ 76 3 : sclistrecord = sclist_addrecord(sclist,txt_a); 77 3 : ck_assert(sclistrecord!=NULL); 78 3 : ck_assert(sclist->last==sclistrecord); 79 3 : ck_assert(sclist->first!=sclistrecord); 80 3 : ck_assert(sclist->first->value==txt_a); 81 3 : ck_assert(sclist->first->next!=sclistrecord); 82 3 : ck_assert(sclist->first->next->value==txt_b); 83 3 : ck_assert(sclist->first->next->next==sclistrecord); 84 3 : ck_assert(sclist->first->next->next->value==txt_a); 85 3 : ck_assert(sclist->first->next->next->next==NULL); 86 : 87 3 : sclistrecord = sclist_firstrecord(sclist); 88 3 : ck_assert(sclistrecord == sclist->first); 89 3 : ck_assert(sclistrecord->value = txt_a); 90 3 : ck_assert(sclist_getvalue(sclistrecord)==txt_a); 91 3 : ck_assert(sclistrecord->next != NULL); 92 : 93 3 : sclistrecord = sclist_nextrecord(sclistrecord); 94 3 : ck_assert(sclistrecord = sclist->first->next); 95 3 : ck_assert(sclistrecord->value = txt_b); 96 3 : ck_assert(sclist_getvalue(sclistrecord)==txt_b); 97 3 : ck_assert(sclistrecord->next != NULL); 98 : 99 3 : sclistrecord = sclist_nextrecord(sclistrecord); 100 3 : ck_assert(sclistrecord = sclist->first->next->next); 101 3 : ck_assert(sclistrecord->value = txt_a); 102 3 : ck_assert(sclist_getvalue(sclistrecord)==txt_a); 103 3 : ck_assert(sclistrecord->next == NULL); 104 : 105 3 : sclistrecord = sclist_nextrecord(sclistrecord); 106 3 : ck_assert(sclistrecord == sclist->first->next->next->next); 107 3 : ck_assert(sclistrecord == NULL); 108 : 109 3 : sclistrecord = sclist->last; 110 3 : sclist_remrecord(sclist, sclistrecord); 111 3 : ck_assert(sclist->first!=NULL); 112 3 : ck_assert(sclist->first->value==txt_a); 113 3 : ck_assert(sclist->first->next!=NULL); 114 3 : ck_assert(sclist->first->next->value==txt_b); 115 3 : ck_assert(sclist->first->next->next==NULL); 116 3 : ck_assert(sclist->last!=NULL); 117 3 : ck_assert(sclist->last->value==txt_b); 118 3 : ck_assert(sclist->last->next==NULL); 119 : 120 3 : sclistrecord = sclist->first->next; 121 3 : sclist_remrecord(sclist, sclistrecord); 122 3 : ck_assert(sclist->first!=NULL); 123 3 : ck_assert(sclist->first->value==txt_a); 124 3 : ck_assert(sclist->first->next==NULL); 125 3 : ck_assert(sclist->last!=NULL); 126 3 : ck_assert(sclist->last->value==txt_a); 127 3 : ck_assert(sclist->last->next==NULL); 128 : 129 3 : sclistrecord = sclist->first; 130 3 : sclist_remrecord(sclist, sclistrecord); 131 3 : ck_assert(sclist->first==NULL); 132 3 : ck_assert(sclist->last==NULL); 133 3 : } 134 : END_TEST 135 : 136 3 : START_TEST(sclist_remrecord_notfound) { 137 3 : forktest_only; 138 : 139 : sclist_t* sclist; 140 : sclistrecord_t* sclistrecord; 141 2 : char* txt_a="a"; 142 2 : char* txt_b="b"; 143 : 144 2 : sclist = sclist_new(); 145 2 : sclist_addrecord(sclist,txt_a); 146 2 : sclistrecord = sclist_addrecord(sclist,txt_b); 147 2 : sclist_remrecord(sclist, sclistrecord); 148 : 149 : /* Failure expected, record not found */ 150 2 : sclist_remrecord(sclist, sclistrecord); 151 : } 152 : END_TEST 153 : 154 3 : START_TEST(sclist_remrecord_notfound_empty) { 155 3 : forktest_only; 156 : 157 : sclist_t* sclist; 158 : sclistrecord_t* sclistrecord; 159 2 : char* txt_a="a"; 160 : 161 2 : sclist = sclist_new(); 162 2 : sclistrecord = sclist_addrecord(sclist,txt_a); 163 2 : sclist_remrecord(sclist, sclistrecord); 164 : 165 : /* Failure expected, record not found */ 166 2 : sclist_remrecord(sclist, sclistrecord); 167 : } 168 : END_TEST 169 : 170 3 : START_TEST(sclist_del_test) { 171 : sclist_t* sclist; 172 3 : char* txt_a="a"; 173 3 : char* txt_b="b"; 174 : 175 3 : sclist = sclist_new(); 176 3 : sclist_addrecord(sclist,txt_a); 177 3 : sclist_addrecord(sclist,txt_b); 178 3 : sclist_del(sclist); 179 3 : } 180 : END_TEST 181 : 182 3 : START_TEST(sclist_del_empty) { 183 : sclist_t* sclist; 184 : 185 3 : sclist = sclist_new(); 186 3 : sclist_del(sclist); 187 3 : } 188 : END_TEST 189 : 190 : /************************************************************************/ 191 : /* Begining of test (potentially in child) */ 192 18 : void sclist_checked_uninitialized_setup() { 193 18 : signals_catch(); 194 18 : forktest_gprofdir(); 195 18 : } 196 : 197 : /* End of test (potentially in child) */ 198 12 : void sclist_checked_uninitialized_teardown() { 199 12 : signals_release(); 200 12 : } 201 : /************************************************************************/ 202 15 : void sclist_unchecked_common_setup() { 203 15 : forktest_init(); 204 15 : } 205 3 : void sclist_unchecked_common_teardown() { 206 3 : } 207 : /************************************************************************/ 208 16 : Suite* sclist_suite() { 209 : Suite *s; 210 : TCase *tc; 211 : 212 16 : s = suite_create("SCListSuite"); 213 : 214 16 : tc = tcase_create("SCListCase"); 215 16 : tcase_set_tags(tc,"SCListTag SCListTag2"); 216 : /* tcase_set_timeout(tc,5); */ /* seconds */ 217 16 : tcase_add_checked_fixture(tc, sclist_checked_uninitialized_setup, sclist_checked_uninitialized_teardown); 218 16 : tcase_add_unchecked_fixture(tc, sclist_unchecked_common_setup, sclist_unchecked_common_teardown); 219 16 : suite_add_tcase(s, tc); 220 16 : tcase_add_test_raise_signal(tc, sclist_test,6); 221 16 : tcase_add_test(tc, sclist_scenarized_test); 222 16 : tcase_add_test_raise_signal(tc, sclist_remrecord_notfound,6); 223 16 : tcase_add_test_raise_signal(tc, sclist_remrecord_notfound_empty,6); 224 16 : tcase_add_test(tc, sclist_del_test); 225 16 : tcase_add_test(tc, sclist_del_empty); 226 : 227 16 : return s; 228 : } 229 : /* vim: set tw=80: */