LCOV - code coverage report
Current view: top level - tests/src - test0037.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.5 % 68 67
Test Date: 2026-07-12 01:01:34 Functions: 100.0 % 6 6
Branches: 50.0 % 2 1

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :           4 : static Return assert_stderr_matches(const char *template_file)
       4                 :             : {
       5                 :             :         /* Status returned by this function through provide()
       6                 :             :            Default value assumes successful completion */
       7                 :           4 :         Return status = SUCCESS;
       8                 :           4 :         m_create(char,pattern,MEMORY_STRING);
       9                 :           4 :         m_create(char,stderr_snapshot,MEMORY_STRING);
      10                 :             : 
      11         [ -  + ]:           4 :         if(template_file == NULL)
      12                 :             :         {
      13                 :           0 :                 status = FAILURE;
      14                 :             :         }
      15                 :             : 
      16                 :           4 :         run(get_file_content(template_file,pattern));
      17                 :           4 :         run(m_copy(stderr_snapshot,STDERR));
      18                 :           4 :         run(match_pattern(stderr_snapshot,pattern,template_file));
      19                 :             : 
      20                 :           4 :         run(m_del(STDERR));
      21                 :             : 
      22                 :           4 :         call(m_del(stderr_snapshot));
      23                 :           4 :         call(m_del(pattern));
      24                 :             : 
      25                 :           4 :         deliver(status);
      26                 :             : }
      27                 :             : 
      28                 :             : /**
      29                 :             :  *
      30                 :             :  * @brief delete_path() should report a NULL input path
      31                 :             :  *
      32                 :             :  */
      33                 :           1 : static Return test0037_1(void)
      34                 :             : {
      35                 :           1 :         INITTEST;
      36                 :             : 
      37                 :           1 :         call(m_del(STDERR));
      38                 :             : 
      39                 :           1 :         ASSERT(FAILURE == delete_path(NULL));
      40                 :           1 :         ASSERT(SUCCESS == assert_stderr_matches("templates/0037_001.txt"));
      41                 :             : 
      42                 :           1 :         RETURN_STATUS;
      43                 :             : }
      44                 :             : 
      45                 :             : /**
      46                 :             :  *
      47                 :             :  * @brief delete_path() should report lstat() failure for a missing path
      48                 :             :  *
      49                 :             :  */
      50                 :           1 : static Return test0037_2(void)
      51                 :             : {
      52                 :           1 :         INITTEST;
      53                 :             : 
      54                 :           1 :         call(m_del(STDERR));
      55                 :             : 
      56                 :           1 :         ASSERT(FAILURE == delete_path("delete_path_missing.txt"));
      57                 :           1 :         ASSERT(SUCCESS == assert_stderr_matches("templates/0037_002.txt"));
      58                 :             : 
      59                 :           1 :         RETURN_STATUS;
      60                 :             : }
      61                 :             : 
      62                 :             : #ifndef EVIL_EMPIRE_OS
      63                 :             : /**
      64                 :             :  *
      65                 :             :  * @brief delete_path() should report remove() failure for a regular file
      66                 :             :  *
      67                 :             :  */
      68                 :           1 : static Return test0037_3(void)
      69                 :             : {
      70                 :           1 :         INITTEST;
      71                 :             : 
      72                 :           1 :         size_t remove_calls = 0;
      73                 :           1 :         const char *file_path = "0037_read_only_dir/file.txt";
      74                 :             : 
      75                 :           1 :         ASSERT(SUCCESS == create_directory("0037_read_only_dir"));
      76                 :           1 :         ASSERT(SUCCESS == truncate_file_to_zero_size(file_path));
      77                 :             : 
      78                 :           1 :         call(m_del(STDERR));
      79                 :           1 :         mocks_remove_reset();
      80                 :           1 :         mocks_remove_set_target_suffix(file_path);
      81                 :           1 :         mocks_remove_set_errno(EACCES);
      82                 :           1 :         mocks_remove_enable(true);
      83                 :             : 
      84                 :           1 :         ASSERT(FAILURE == delete_path(file_path));
      85                 :           1 :         ASSERT(SUCCESS == assert_stderr_matches("templates/0037_003.txt"));
      86                 :           1 :         remove_calls = mocks_remove_call_count();
      87                 :           1 :         mocks_remove_reset();
      88                 :           1 :         ASSERT(remove_calls == 1U);
      89                 :             : 
      90                 :           1 :         ASSERT(SUCCESS == delete_path("0037_read_only_dir"));
      91                 :             : 
      92                 :           1 :         RETURN_STATUS;
      93                 :             : }
      94                 :             : 
      95                 :             : /**
      96                 :             :  *
      97                 :             :  * @brief delete_path() should report callback remove() failure during nftw()
      98                 :             :  *
      99                 :             :  */
     100                 :           1 : static Return test0037_4(void)
     101                 :             : {
     102                 :           1 :         INITTEST;
     103                 :             : 
     104                 :           1 :         size_t remove_calls = 0;
     105                 :           1 :         const char *file_path = "0037_locked_tree/a/b/file.txt";
     106                 :             : 
     107                 :           1 :         ASSERT(SUCCESS == create_directory("0037_locked_tree/a/b"));
     108                 :           1 :         ASSERT(SUCCESS == truncate_file_to_zero_size(file_path));
     109                 :             : 
     110                 :           1 :         call(m_del(STDERR));
     111                 :           1 :         mocks_remove_reset();
     112                 :           1 :         mocks_remove_set_target_suffix(file_path);
     113                 :           1 :         mocks_remove_set_errno(EACCES);
     114                 :           1 :         mocks_remove_enable(true);
     115                 :             : 
     116                 :           1 :         ASSERT(FAILURE == delete_path("0037_locked_tree"));
     117                 :           1 :         ASSERT(SUCCESS == assert_stderr_matches("templates/0037_004.txt"));
     118                 :           1 :         remove_calls = mocks_remove_call_count();
     119                 :           1 :         mocks_remove_reset();
     120                 :           1 :         ASSERT(remove_calls == 1U);
     121                 :             : 
     122                 :           1 :         ASSERT(SUCCESS == delete_path("0037_locked_tree"));
     123                 :             : 
     124                 :           1 :         RETURN_STATUS;
     125                 :             : }
     126                 :             : #endif
     127                 :             : 
     128                 :             : /**
     129                 :             :  * @brief Run delete_path() diagnostics unit tests
     130                 :             :  */
     131                 :           1 : Return test0037(void)
     132                 :             : {
     133                 :           1 :         INITTEST;
     134                 :             : 
     135                 :           1 :         TEST(test0037_1,"delete_path() reports NULL input path");
     136                 :           1 :         TEST(test0037_2,"delete_path() reports missing path lstat() failure");
     137                 :             : #ifndef EVIL_EMPIRE_OS
     138                 :           1 :         TEST(test0037_3,"delete_path() reports remove() failure for a regular file");
     139                 :           1 :         TEST(test0037_4,"delete_path() reports nftw() callback remove() failure");
     140                 :             : #endif
     141                 :             : 
     142                 :           1 :         RETURN_STATUS;
     143                 :             : }
        

Generated by: LCOV version 2.0-1