LCOV - code coverage report
Current view: top level - test - suite_sclist.c (source / functions) Hit Total Coverage
Test: mkernel.info Lines: 135 135 100.0 %
Date: 2024-12-05 21:00:54 Functions: 11 11 100.0 %

          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-25 09:01
       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 :     ck_assert(sclist==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 :     ck_assert(sclist==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 :     ck_assert(sclist==sclist_remrecord(sclist, sclistrecord));
     131           3 :     ck_assert(sclist->first==NULL);
     132           3 :     ck_assert(sclist->last==NULL);
     133             : 
     134           3 :     sclist_del(sclist);
     135           3 : }
     136             : END_TEST
     137             : 
     138           3 : START_TEST(sclist_remrecord_notfound) {
     139             :     sclist_t* sclist;
     140             :     sclistrecord_t* sclistrecord;
     141           3 :     char* txt_a="a";
     142           3 :     char* txt_b="b";
     143             : 
     144           3 :     sclist = sclist_new();
     145           3 :     sclist_addrecord(sclist,txt_a);
     146           3 :     sclistrecord = sclist_addrecord(sclist,txt_b);
     147           3 :     ck_assert(sclist==sclist_remrecord(sclist, sclistrecord));
     148             : 
     149             :     /* Failure expected, record not found */
     150           3 :     ck_assert(NULL==sclist_remrecord(sclist, sclistrecord));
     151             : 
     152           3 :     sclist_del(sclist);
     153           3 : }
     154             : END_TEST
     155             : 
     156           3 : START_TEST(sclist_remrecord_notfound_empty) {
     157           3 :     forktest_only;
     158             : 
     159             :     sclist_t* sclist;
     160             :     sclistrecord_t* sclistrecord;
     161           2 :     char* txt_a="a";
     162             : 
     163           2 :     sclist = sclist_new();
     164           2 :     sclistrecord = sclist_addrecord(sclist,txt_a);
     165           2 :     ck_assert(sclist==sclist_remrecord(sclist, sclistrecord));
     166             : 
     167             :     /* Failure expected, record not found */
     168           2 :     ck_assert(NULL==sclist_remrecord(sclist, sclistrecord));
     169             : 
     170           2 :     sclist_del(sclist);
     171             : }
     172             : END_TEST
     173             : 
     174           3 : START_TEST(sclist_del_test) {
     175             :     sclist_t* sclist;
     176           3 :     char* txt_a="a";
     177           3 :     char* txt_b="b";
     178             : 
     179           3 :     sclist = sclist_new();
     180           3 :     sclist_addrecord(sclist,txt_a);
     181           3 :     sclist_addrecord(sclist,txt_b);
     182           3 :     sclist_del(sclist);
     183           3 : }
     184             : END_TEST
     185             : 
     186           3 : START_TEST(sclist_del_empty) {
     187             :     sclist_t* sclist;
     188             : 
     189           3 :     sclist = sclist_new();
     190           3 :     sclist_del(sclist);
     191           3 : }
     192             : END_TEST
     193             : 
     194             : /************************************************************************/
     195             : /* Begining of test (potentially in child) */
     196          18 : void sclist_checked_uninitialized_setup() {
     197          18 :     signals_catch();
     198          18 :     forktest_gprofdir();
     199          18 : }
     200             : 
     201             : /* End of test (potentially in child) */
     202          16 : void sclist_checked_uninitialized_teardown() {
     203          16 :     signals_release();
     204          16 : }
     205             : /************************************************************************/
     206          15 : void sclist_unchecked_common_setup() {
     207          15 :     forktest_init();
     208          15 : }
     209           3 : void sclist_unchecked_common_teardown() {
     210           3 : }
     211             : /************************************************************************/
     212          16 : Suite* sclist_suite() {
     213             :     Suite *s;
     214             :     TCase *tc;
     215             : 
     216          16 :     s = suite_create("SCListSuite");
     217             : 
     218          16 :     tc = tcase_create("SCListCase");
     219          16 :     tcase_set_tags(tc,"SCListTag SCListTag2");
     220             :     /* tcase_set_timeout(tc,5); */ /* seconds */
     221          16 :     tcase_add_checked_fixture(tc, sclist_checked_uninitialized_setup, sclist_checked_uninitialized_teardown);
     222          16 :     tcase_add_unchecked_fixture(tc, sclist_unchecked_common_setup, sclist_unchecked_common_teardown);
     223          16 :     suite_add_tcase(s, tc);
     224          16 :     tcase_add_test_raise_signal(tc, sclist_test,6);
     225          16 :     tcase_add_test(tc, sclist_scenarized_test);
     226          16 :     tcase_add_test(tc, sclist_remrecord_notfound);
     227          16 :     tcase_add_test(tc, sclist_remrecord_notfound_empty);
     228          16 :     tcase_add_test(tc, sclist_del_test);
     229          16 :     tcase_add_test(tc, sclist_del_empty);
     230             : 
     231          16 :     return s;
     232             : }
     233             : /* vim: set tw=80: */

Generated by: LCOV version 1.16