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

Generated by: LCOV version 1.16