LCOV - code coverage report
Current view: top level - test - suite_sclist.c (source / functions) Hit Total Coverage
Test: mkernel.info Lines: 129 129 100.0 %
Date: 2024-11-16 16:45:48 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-16 16:33
       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           1 : 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           1 :     forktest_only;
      40             : 
      41           1 :     abort();
      42             : }
      43             : END_TEST
      44             : 
      45           1 : START_TEST(sclist_scenarized_test) {
      46             :     sclist_t* sclist;
      47             :     sclistrecord_t* sclistrecord;
      48           1 :     char* txt_a="a";
      49           1 :     char* txt_b="b";
      50             : 
      51           1 :     sclist = sclist_new();
      52           1 :     ck_assert(sclist);
      53           1 :     ck_assert(NULL==sclist->first);
      54           1 :     ck_assert(NULL==sclist->last);
      55             : 
      56           1 :     sclistrecord = sclist_addrecord(sclist,txt_a);
      57           1 :     ck_assert(sclistrecord!=NULL);
      58           1 :     ck_assert(sclist->last==sclistrecord);
      59           1 :     ck_assert(sclist->first==sclistrecord);
      60           1 :     ck_assert(sclist->first->value==txt_a);
      61           1 :     ck_assert(sclist->first->next==NULL);
      62             : 
      63           1 :     sclistrecord = sclist_addrecord(sclist,txt_b);
      64           1 :     ck_assert(sclistrecord!=NULL);
      65           1 :     ck_assert(sclist->last==sclistrecord);
      66           1 :     ck_assert(sclist->first!=sclistrecord);
      67           1 :     ck_assert(sclist->first->value==txt_a);
      68           1 :     ck_assert(sclist->first->next==sclistrecord);
      69           1 :     ck_assert(sclist->first->next->next==NULL);
      70           1 :     ck_assert(sclist->first->next->value==txt_b);
      71             : 
      72             :     /* Duplicate */
      73           1 :     sclistrecord = sclist_addrecord(sclist,txt_a);
      74           1 :     ck_assert(sclistrecord!=NULL);
      75           1 :     ck_assert(sclist->last==sclistrecord);
      76           1 :     ck_assert(sclist->first!=sclistrecord);
      77           1 :     ck_assert(sclist->first->value==txt_a);
      78           1 :     ck_assert(sclist->first->next!=sclistrecord);
      79           1 :     ck_assert(sclist->first->next->value==txt_b);
      80           1 :     ck_assert(sclist->first->next->next==sclistrecord);
      81           1 :     ck_assert(sclist->first->next->next->value==txt_a);
      82           1 :     ck_assert(sclist->first->next->next->next==NULL);
      83             : 
      84           1 :     sclistrecord = sclist_firstrecord(sclist);
      85           1 :     ck_assert(sclistrecord = sclist->first);
      86           1 :     ck_assert(sclistrecord->value = txt_a);
      87           1 :     ck_assert(sclist_getvalue(sclistrecord)==txt_a);
      88           1 :     ck_assert(sclistrecord->next != NULL);
      89             : 
      90           1 :     sclistrecord = sclist_nextrecord(sclistrecord);
      91           1 :     ck_assert(sclistrecord = sclist->first->next);
      92           1 :     ck_assert(sclistrecord->value = txt_b);
      93           1 :     ck_assert(sclist_getvalue(sclistrecord)==txt_b);
      94           1 :     ck_assert(sclistrecord->next != NULL);
      95             : 
      96           1 :     sclistrecord = sclist_nextrecord(sclistrecord);
      97           1 :     ck_assert(sclistrecord = sclist->first->next->next);
      98           1 :     ck_assert(sclistrecord->value = txt_a);
      99           1 :     ck_assert(sclist_getvalue(sclistrecord)==txt_a);
     100           1 :     ck_assert(sclistrecord->next == NULL);
     101             : 
     102           1 :     sclistrecord = sclist_nextrecord(sclistrecord);
     103           1 :     ck_assert(sclistrecord == sclist->first->next->next->next);
     104           1 :     ck_assert(sclistrecord == NULL);
     105             : 
     106           1 :     sclistrecord = sclist->last;
     107           1 :     sclist_remrecord(sclist, sclistrecord);
     108           1 :     ck_assert(sclist->first!=NULL);
     109           1 :     ck_assert(sclist->first->value==txt_a);
     110           1 :     ck_assert(sclist->first->next!=NULL);
     111           1 :     ck_assert(sclist->first->next->value==txt_b);
     112           1 :     ck_assert(sclist->first->next->next==NULL);
     113           1 :     ck_assert(sclist->last!=NULL);
     114           1 :     ck_assert(sclist->last->value==txt_b);
     115           1 :     ck_assert(sclist->last->next==NULL);
     116             : 
     117           1 :     sclistrecord = sclist->first->next;
     118           1 :     sclist_remrecord(sclist, sclistrecord);
     119           1 :     ck_assert(sclist->first!=NULL);
     120           1 :     ck_assert(sclist->first->value==txt_a);
     121           1 :     ck_assert(sclist->first->next==NULL);
     122           1 :     ck_assert(sclist->last!=NULL);
     123           1 :     ck_assert(sclist->last->value==txt_a);
     124           1 :     ck_assert(sclist->last->next==NULL);
     125             : 
     126           1 :     sclistrecord = sclist->first;
     127           1 :     sclist_remrecord(sclist, sclistrecord);
     128           1 :     ck_assert(sclist->first==NULL);
     129           1 :     ck_assert(sclist->last==NULL);
     130           1 : }
     131             : END_TEST
     132             : 
     133           1 : START_TEST(sclist_remrecord_notfound) {
     134           1 :     forktest_only;
     135             : 
     136             :     sclist_t* sclist;
     137             :     sclistrecord_t* sclistrecord;
     138           1 :     char* txt_a="a";
     139           1 :     char* txt_b="b";
     140             : 
     141           1 :     sclist = sclist_new();
     142           1 :     sclistrecord = sclist_addrecord(sclist,txt_a);
     143           1 :     sclistrecord = sclist_addrecord(sclist,txt_b);
     144           1 :     sclist_remrecord(sclist, sclistrecord);
     145             : 
     146             :     /* Failure expected, record not found */
     147           1 :     sclist_remrecord(sclist, sclistrecord);
     148             : }
     149             : END_TEST
     150             : 
     151           1 : START_TEST(sclist_remrecord_notfound_empty) {
     152           1 :     forktest_only;
     153             : 
     154             :     sclist_t* sclist;
     155             :     sclistrecord_t* sclistrecord;
     156           1 :     char* txt_a="a";
     157             : 
     158           1 :     sclist = sclist_new();
     159           1 :     sclistrecord = sclist_addrecord(sclist,txt_a);
     160           1 :     sclist_remrecord(sclist, sclistrecord);
     161             : 
     162             :     /* Failure expected, record not found */
     163           1 :     sclist_remrecord(sclist, sclistrecord);
     164             : }
     165             : END_TEST
     166             : 
     167           1 : START_TEST(sclist_del_test) {
     168             :     sclist_t* sclist;
     169           1 :     char* txt_a="a";
     170           1 :     char* txt_b="b";
     171             : 
     172           1 :     sclist = sclist_new();
     173           1 :     sclist_addrecord(sclist,txt_a);
     174           1 :     sclist_addrecord(sclist,txt_b);
     175           1 :     sclist_del(sclist);
     176           1 : }
     177             : END_TEST
     178             : 
     179           1 : START_TEST(sclist_del_empty) {
     180             :     sclist_t* sclist;
     181             : 
     182           1 :     sclist = sclist_new();
     183           1 :     sclist_del(sclist);
     184           1 : }
     185             : END_TEST
     186             : 
     187             : /************************************************************************/
     188             : /* Begining of test (potentially in child) */
     189           6 : void sclist_checked_uninitialized_setup() {
     190           6 :     signals_catch();
     191           6 :     forktest_gprofdir();
     192           6 : }
     193             : 
     194             : /* End of test (potentially in child) */
     195           3 : void sclist_checked_uninitialized_teardown() {
     196           3 :     signals_release();
     197           3 : }
     198             : /************************************************************************/
     199           7 : void sclist_unchecked_common_setup() {
     200           7 :     forktest_init();
     201           7 : }
     202           1 : void sclist_unchecked_common_teardown() {
     203           1 : }
     204             : /************************************************************************/
     205           7 : Suite* sclist_suite() {
     206             :     Suite *s;
     207             :     TCase *tc;
     208             : 
     209           7 :     s = suite_create("SCListSuite");
     210             : 
     211           7 :     tc = tcase_create("SCListCase");
     212           7 :     tcase_set_tags(tc,"SCListTag SCListTag2");
     213             :     /* tcase_set_timeout(tc,5); */ /* seconds */
     214           7 :     tcase_add_checked_fixture(tc, sclist_checked_uninitialized_setup, sclist_checked_uninitialized_teardown);
     215           7 :     tcase_add_unchecked_fixture(tc, sclist_unchecked_common_setup, sclist_unchecked_common_teardown);
     216           7 :     suite_add_tcase(s, tc);
     217           7 :     tcase_add_test_raise_signal(tc, sclist_test,6);
     218           7 :     tcase_add_test(tc, sclist_scenarized_test);
     219           7 :     tcase_add_test_raise_signal(tc, sclist_remrecord_notfound,6);
     220           7 :     tcase_add_test_raise_signal(tc, sclist_remrecord_notfound_empty,6);
     221           7 :     tcase_add_test(tc, sclist_del_test);
     222           7 :     tcase_add_test(tc, sclist_del_empty);
     223             : 
     224           7 :     return s;
     225             : }
     226             : /* vim: set tw=80: */

Generated by: LCOV version 1.16