LCOV - code coverage report
Current view: top level - tests/src - test0020.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 99 99
Test Date: 2026-10-20 14:27:43 Functions: 100.0 % 8 8
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  *
       5                 :             :  * Testing database creation attempt in missing directory
       6                 :             :  *
       7                 :             :  */
       8                 :           2 : Return test0020_1(void)
       9                 :             : {
      10                 :           2 :         INITTEST;
      11                 :             : 
      12                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      13                 :             : 
      14                 :           2 :         const char *arguments = "--update --database=nonexistent_directory/database1.db "
      15                 :             :                 "tests/fixtures/diffs/diff1";
      16                 :             : 
      17                 :           2 :         const struct argument_test_case cases[] = {
      18                 :             :                 {arguments,FAILURE,"templates/0020_001.txt",STDERR_MUST_BE_EMPTY},
      19                 :             :                 {0}
      20                 :             :         };
      21                 :             : 
      22                 :             :         // Match the result against the pattern
      23                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
      24                 :             : 
      25                 :           2 :         RETURN_STATUS;
      26                 :             : }
      27                 :             : 
      28                 :             : /**
      29                 :             :  * @brief Reject updating a missing database through CLI and configuration
      30                 :             :  *
      31                 :             :  * Both runs use the same full output template and must fail without creating
      32                 :             :  * the database
      33                 :             :  *
      34                 :             :  * @return Return status for equivalent update failures
      35                 :             :  */
      36                 :           2 : Return test0020_2(void)
      37                 :             : {
      38                 :           2 :         INITTEST;
      39                 :             : 
      40                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      41                 :             : 
      42                 :           2 :         const char *arguments = "--update --database=nonexistent_database1.db "
      43                 :             :                 "tests/fixtures/diffs/diff1";
      44                 :             : 
      45                 :           2 :         const struct argument_test_case cases[] = {
      46                 :             :                 {arguments,FAILURE,"templates/0020_002.txt",STDERR_MUST_BE_EMPTY},
      47                 :             :                 {0}
      48                 :             :         };
      49                 :             : 
      50                 :             :         // Match the result against the pattern
      51                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
      52                 :             : 
      53                 :             :         /* Repeat the failure through configuration while the database is still absent */
      54                 :           2 :         ASSERT(SUCCESS == copy_path("tests/templates/0020_002.conf","0020_002.conf"));
      55                 :           2 :         const struct argument_test_case file_cases[] = {
      56                 :             :                 {"--config=0020_002.conf",FAILURE,"templates/0020_002.txt",STDERR_MUST_BE_EMPTY},
      57                 :             :                 {0}
      58                 :             :         };
      59                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(file_cases,NULL,NULL));
      60                 :           2 :         call(delete_path_if_present("0020_002.conf"));
      61                 :             : 
      62                 :           2 :         RETURN_STATUS;
      63                 :             : }
      64                 :             : 
      65                 :             : /**
      66                 :             :  * @brief Reject database creation in a write-protected directory through CLI and configuration
      67                 :             :  *
      68                 :             :  * Both runs use the same directory permissions and full output template
      69                 :             :  *
      70                 :             :  * @return Return status for equivalent database creation failures
      71                 :             :  */
      72                 :           2 : Return test0020_3(void)
      73                 :             : {
      74                 :           2 :         INITTEST;
      75                 :             : 
      76                 :           2 :         ASSERT(SUCCESS == create_directory("write_protected_directory"));
      77                 :           2 :         ASSERT(SUCCESS == change_mode("write_protected_directory",0000));
      78                 :             : 
      79                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      80                 :             : 
      81                 :           2 :         const char *arguments = "--database=write_protected_directory/database1.db "
      82                 :             :                 "tests/fixtures/diffs/diff1";
      83                 :             : 
      84                 :           2 :         const struct argument_test_case cases[] = {
      85                 :             :                 {arguments,FAILURE,"templates/0020_003.txt",STDERR_MUST_BE_EMPTY},
      86                 :             :                 {0}
      87                 :             :         };
      88                 :             : 
      89                 :             :         // Match the result against the pattern
      90                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
      91                 :             : 
      92                 :             :         /* Repeat the failure before restoring permissions on the database directory */
      93                 :           2 :         ASSERT(SUCCESS == copy_from_origin("tests/templates/0020_003.conf","0020_003.conf",REQUIRE_SOURCE_EXISTS));
      94                 :           2 :         const struct argument_test_case file_cases[] = {
      95                 :             :                 {"--config=0020_003.conf",FAILURE,"templates/0020_003.txt",STDERR_MUST_BE_EMPTY},
      96                 :             :                 {0}
      97                 :             :         };
      98                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(file_cases,NULL,NULL));
      99                 :             : 
     100                 :           2 :         call(delete_path_if_present("0020_003.conf"));
     101                 :             : 
     102                 :           2 :         ASSERT(SUCCESS == change_mode("write_protected_directory",0777));
     103                 :           2 :         ASSERT(SUCCESS == delete_path("write_protected_directory"));
     104                 :             : 
     105                 :           2 :         RETURN_STATUS;
     106                 :             : }
     107                 :             : 
     108                 :             : /**
     109                 :             :  *
     110                 :             :  * Testing attempt to open DB with write protected database file
     111                 :             :  *
     112                 :             :  */
     113                 :           2 : Return test0020_4(void)
     114                 :             : {
     115                 :           2 :         INITTEST;
     116                 :             : 
     117                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     118                 :             : 
     119                 :           2 :         const char *arguments = "--database=write_protected_database1.db "
     120                 :             :                 "tests/fixtures/diffs/diff1";
     121                 :             : 
     122                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     123                 :             : 
     124                 :           2 :         arguments = "--database=database2.db tests/fixtures/diffs/diff2";
     125                 :             : 
     126                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     127                 :             : 
     128                 :           2 :         ASSERT(SUCCESS == change_mode("write_protected_database1.db",0000));
     129                 :             : 
     130                 :           2 :         arguments = "--compare write_protected_database1.db database2.db";
     131                 :             : 
     132                 :           2 :         const struct argument_test_case cases[] = {
     133                 :             :                 {arguments,FAILURE,"templates/0020_004.txt",STDERR_MUST_BE_EMPTY},
     134                 :             :                 {0}
     135                 :             :         };
     136                 :             : 
     137                 :             :         // Match the result against the pattern
     138                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
     139                 :             : 
     140                 :           2 :         ASSERT(SUCCESS == delete_path("database2.db"));
     141                 :             : 
     142                 :           2 :         RETURN_STATUS;
     143                 :             : }
     144                 :             : 
     145                 :             : /**
     146                 :             :  *
     147                 :             :  * Testing attempt to update DB with --update when database file is write protected
     148                 :             :  *
     149                 :             :  */
     150                 :           2 : Return test0020_5(void)
     151                 :             : {
     152                 :           2 :         INITTEST;
     153                 :             : 
     154                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     155                 :             : 
     156                 :           2 :         const char *arguments = "--update --database=write_protected_database1.db "
     157                 :             :                 "tests/fixtures/diffs/diff1";
     158                 :             : 
     159                 :           2 :         const struct argument_test_case cases[] = {
     160                 :             :                 {arguments,FAILURE,"templates/0020_005.txt",STDERR_MUST_BE_EMPTY},
     161                 :             :                 {0}
     162                 :             :         };
     163                 :             : 
     164                 :             :         // Match the result against the pattern
     165                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
     166                 :             : 
     167                 :           2 :         ASSERT(SUCCESS == change_mode("write_protected_database1.db",0666));
     168                 :           2 :         ASSERT(SUCCESS == delete_path("write_protected_database1.db"));
     169                 :             : 
     170                 :           2 :         RETURN_STATUS;
     171                 :             : }
     172                 :             : 
     173                 :             : /**
     174                 :             :  * @brief Reject changing the primary path without force through CLI and configuration
     175                 :             :  *
     176                 :             :  * Both runs use the same prepared database and full output template. The warning
     177                 :             :  * leaves the database unchanged for the following test
     178                 :             :  *
     179                 :             :  * @return Return status for equivalent path mismatch warnings
     180                 :             :  */
     181                 :           2 : Return test0020_6(void)
     182                 :             : {
     183                 :           2 :         INITTEST;
     184                 :             : 
     185                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     186                 :             : 
     187                 :           2 :         const char *arguments = "--database=database1.db tests/fixtures/diffs/diff1";
     188                 :             : 
     189                 :           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     190                 :             : 
     191                 :           2 :         arguments = "--check-level=QUICK --update --database=database1.db tests/fixtures/diffs/diff2";
     192                 :             : 
     193                 :           2 :         const struct argument_test_case cases[] = {
     194                 :             :                 {arguments,WARNING,"templates/0020_006.txt",STDERR_MUST_BE_EMPTY},
     195                 :             :                 {0}
     196                 :             :         };
     197                 :             : 
     198                 :             :         // Match the result against the pattern
     199                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
     200                 :             : 
     201                 :             :         /* Repeat the warning with force disabled in the configuration file */
     202                 :           2 :         ASSERT(SUCCESS == copy_path("tests/templates/0020_006.conf","0020_006.conf"));
     203                 :           2 :         const struct argument_test_case file_cases[] = {
     204                 :             :                 {"--config=0020_006.conf",WARNING,"templates/0020_006.txt",STDERR_MUST_BE_EMPTY},
     205                 :             :                 {0}
     206                 :             :         };
     207                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(file_cases,NULL,NULL));
     208                 :           2 :         call(delete_path_if_present("0020_006.conf"));
     209                 :             : 
     210                 :           2 :         RETURN_STATUS;
     211                 :             : }
     212                 :             : 
     213                 :             : /**
     214                 :             :  * @brief Replace the primary path with force through CLI and configuration
     215                 :             :  *
     216                 :             :  * Both updates start from the same saved database and use the same full output
     217                 :             :  * template. File timestamps are prepared once before either update
     218                 :             :  *
     219                 :             :  * @return Return status for equivalent forced path replacements
     220                 :             :  */
     221                 :           2 : Return test0020_7(void)
     222                 :             : {
     223                 :           2 :         INITTEST;
     224                 :             : 
     225                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     226                 :             : 
     227                 :             :         // Match mtime for files with identical content in diff1 and diff2.
     228                 :             :         // Setting the timestamp updates ctime, so --update --force can refresh
     229                 :             :         // their metadata without rehashing when --watch-timestamps is not used
     230                 :           2 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/1/AAA/BCB/CCC/a.txt","tests/fixtures/diffs/diff2/1/AAA/BCB/CCC/a.txt",0));
     231                 :           2 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/1/AAA/ZAW/A/b/c/a_file.txt","tests/fixtures/diffs/diff2/1/AAA/ZAW/A/b/c/a_file.txt",0));
     232                 :           2 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt","tests/fixtures/diffs/diff2/1/AAA/ZAW/D/e/f/b_file.txt",0));
     233                 :           2 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/path1/AAA/BCB/CCC/a.txt","tests/fixtures/diffs/diff2/path1/AAA/BCB/CCC/a.txt",0));
     234                 :           2 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/path1/AAA/ZAW/A/b/c/a_file.txt","tests/fixtures/diffs/diff2/path1/AAA/ZAW/A/b/c/a_file.txt",0));
     235                 :           2 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/path2/AAA/ZAW/A/b/c/a_file.txt","tests/fixtures/diffs/diff2/path2/AAA/ZAW/A/b/c/a_file.txt",0));
     236                 :             : 
     237                 :             :         /* Save the database before either update replaces its stored paths and records */
     238                 :           2 :         ASSERT(SUCCESS == copy_path("database1.db","0020_007.db"));
     239                 :             : 
     240                 :           2 :         const char *arguments = "--check-level=QUICK --update --force --database=database1.db "
     241                 :             :                 "tests/fixtures/diffs/diff2";
     242                 :             : 
     243                 :           2 :         const struct argument_test_case cases[] = {
     244                 :             :                 {arguments,COMPLETED,"templates/0020_007.txt",STDERR_MUST_BE_EMPTY},
     245                 :             :                 {0}
     246                 :             :         };
     247                 :             : 
     248                 :             :         // Match the result against the pattern
     249                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
     250                 :             : 
     251                 :             :         /* Restore only the database so configuration processes the same prepared files */
     252                 :           2 :         ASSERT(SUCCESS == copy_path("0020_007.db","database1.db"));
     253                 :           2 :         ASSERT(SUCCESS == copy_path("tests/templates/0020_007.conf","0020_007.conf"));
     254                 :           2 :         const struct argument_test_case file_cases[] = {
     255                 :             :                 {"--config=0020_007.conf",COMPLETED,"templates/0020_007.txt",STDERR_MUST_BE_EMPTY},
     256                 :             :                 {0}
     257                 :             :         };
     258                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(file_cases,NULL,NULL));
     259                 :           2 :         call(delete_path_if_present("0020_007.conf"));
     260                 :           2 :         call(delete_path_if_present("0020_007.db"));
     261                 :             : 
     262                 :           2 :         ASSERT(SUCCESS == delete_path("database1.db"));
     263                 :             : 
     264                 :           2 :         RETURN_STATUS;
     265                 :             : }
     266                 :             : 
     267                 :           2 : Return test0020(void)
     268                 :             : {
     269                 :           2 :         INITTEST;
     270                 :             : 
     271                 :           2 :         TEST(test0020_1,"DB creation in missing directory")
     272                 :           2 :         TEST(test0020_2,"Attempt to open DB with --update when database is missing")
     273                 :           2 :         TEST(test0020_3,"DB creation in write protected directory")
     274                 :           2 :         TEST(test0020_4,"Attempt to open DB with write protected database file")
     275                 :           2 :         TEST(test0020_5,"Attempt to update DB with --update when database file is write protected")
     276                 :           2 :         TEST(test0020_6,"Attempt to change the primary path in the database")
     277                 :           2 :         TEST(test0020_7,"Replace the primary path in the database")
     278                 :             : 
     279                 :           2 :         RETURN_STATUS;
     280                 :             : }
        

Generated by: LCOV version 2.0-1