LCOV - code coverage report
Current view: top level - tests/src - test0015.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 200 200
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 14 14

            Line data    Source code
       1              : #include "sute.h"
       2              : 
       3              : /**
       4              :  *
       5              :  * Upgrade a DB from version 0 to the current version as the primary database.
       6              :  * Verify the run fails without the --update parameter and prints the proper error.
       7              :  *
       8              :  */
       9            2 : Return test0015_1_upgrade_db(void)
      10              : {
      11            2 :         INITTEST;
      12              : 
      13            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      14              : 
      15            2 :         const char *command = "cd ${TMPDIR} && "
      16              :                 "cp -a tests/0015_database_v0.db .";
      17              : 
      18            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
      19              : 
      20            2 :         const char *arguments = "--database=./0015_database_v0.db tests/examples/diffs/diff1";
      21              : 
      22            2 :         create(char,result);
      23            2 :         create(char,pattern);
      24              : 
      25            2 :         const char *filename = "templates/0015_001.txt";
      26              : 
      27            2 :         ASSERT(SUCCESS == runit(arguments,result,WARNING,ALLOW_BOTH));
      28              : 
      29            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      30              : 
      31              :         // Match the result against the pattern
      32            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      33              : 
      34              :         // Clean to use it iteratively
      35            2 :         del(pattern);
      36            2 :         del(result);
      37              : 
      38              :         // Clean up test results
      39            2 :         ASSERT(SUCCESS == external_call("rm \"${TMPDIR}/0015_database_v0.db\"",COMPLETED,ALLOW_BOTH));
      40              : 
      41            2 :         RETURN_STATUS;
      42              : }
      43              : 
      44              : /**
      45              :  *
      46              :  * Upgrade a DB from version 0 to the current version as the primary database.
      47              :  * Running the test with the --update parameter to ensure the update
      48              :  * completes successfully
      49              :  *
      50              :  */
      51            2 : Return test0015_2_1_upgrade_db(void)
      52              : {
      53            2 :         INITTEST;
      54              : 
      55            2 :         const char *command = "cd ${TMPDIR} && "
      56              :                 "cp -a tests/0015_database_v0.db .";
      57              : 
      58            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
      59              : 
      60            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      61              : 
      62            2 :         const char *arguments = "--update --database=0015_database_v0.db tests/examples/diffs/diff1";
      63              : 
      64            2 :         create(char,result);
      65            2 :         create(char,pattern);
      66              : 
      67            2 :         const char *filename = "templates/0015_002_1.txt";
      68              : 
      69            2 :         ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
      70              : 
      71            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      72              : 
      73              :         // Match the result against the pattern
      74            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      75              : 
      76              :         // Clean up test results
      77            2 :         ASSERT(SUCCESS == external_call("rm \"${TMPDIR}/0015_database_v0.db\"",COMPLETED,ALLOW_BOTH));
      78              : 
      79              :         // Clean to use it iteratively
      80            2 :         del(pattern);
      81            2 :         del(result);
      82              : 
      83            2 :         RETURN_STATUS;
      84              : }
      85              : 
      86              : /**
      87              :  *
      88              :  * Upgrade a DB from version 0 to the current version as the primary database.
      89              :  * Running the test with the --update and --watch-timestamps parameters to ensure
      90              :  * the update completes successfully with according details in output
      91              :  *
      92              :  */
      93            2 : Return test0015_2_2_upgrade_db(void)
      94              : {
      95            2 :         INITTEST;
      96              : 
      97            2 :         const char *command = "cd ${TMPDIR} && "
      98              :                 "cp -a tests/0015_database_v0.db .";
      99              : 
     100            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
     101              : 
     102            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     103              : 
     104            2 :         const char *arguments = "--watch-timestamps --update --database=0015_database_v0.db tests/examples/diffs/diff1";
     105              : 
     106            2 :         create(char,result);
     107            2 :         create(char,pattern);
     108              : 
     109            2 :         const char *filename = "templates/0015_002_2.txt";
     110              : 
     111            2 :         ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
     112              : 
     113            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     114              : 
     115              :         // Match the result against the pattern
     116            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     117              : 
     118              :         // Clean to use it iteratively
     119            2 :         del(pattern);
     120            2 :         del(result);
     121              : 
     122            2 :         RETURN_STATUS;
     123              : }
     124              : 
     125              : /**
     126              :  *
     127              :  * Run the program again to verify that the database
     128              :  * is actually at the current version
     129              :  *
     130              :  */
     131            2 : Return test0015_3_upgrade_db(void)
     132              : {
     133            2 :         INITTEST;
     134              : 
     135            2 :         create(char,result);
     136            2 :         create(char,pattern);
     137              : 
     138            2 :         const char *filename = "templates/0015_003.txt";
     139              : 
     140            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     141              : 
     142            2 :         ASSERT(SUCCESS == runit("--update --database=./0015_database_v0.db tests/examples/diffs/diff1",result,COMPLETED,ALLOW_BOTH));
     143              : 
     144            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     145              : 
     146              :         // Match the result against the pattern
     147            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     148              : 
     149              :         // Clean to use it iteratively
     150            2 :         del(pattern);
     151            2 :         del(result);
     152              : 
     153              :         // Clean up test results
     154            2 :         ASSERT(SUCCESS == external_call("rm \"${TMPDIR}/0015_database_v0.db\"",COMPLETED,ALLOW_BOTH));
     155              : 
     156            2 :         RETURN_STATUS;
     157              : }
     158              : 
     159              : /**
     160              :  *
     161              :  * Run the program again to verify that the database is actually at the current version
     162              :  * Create a database with the default name
     163              :  *
     164              :  */
     165            2 : Return test0015_4_upgrade_db(void)
     166              : {
     167            2 :         INITTEST;
     168              : 
     169            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     170              : 
     171              :         // Get the output of an external program
     172            2 :         const char *arguments = "tests/examples/diffs/diff1";
     173              : 
     174            2 :         const char *filename = "templates/0015_004.txt";  // File name
     175            2 :         const char *template = "%DB_NAME%";
     176              : 
     177            2 :         const char *replacement = getenv("DBNAME");  // Database name
     178              : 
     179            2 :         ASSERT(replacement != NULL);
     180              : 
     181            2 :         ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
     182              : 
     183            2 :         RETURN_STATUS;
     184              : }
     185              : 
     186              : /**
     187              :  *
     188              :  * Run the program with the --compare parameter to compare databases
     189              :  * when one of them has an older version — this should generate an
     190              :  * appropriate error message
     191              :  *
     192              :  */
     193            2 : Return test0015_5_upgrade_db(void)
     194              : {
     195            2 :         INITTEST;
     196              : 
     197            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     198              : 
     199              :         // Get the output of an external program
     200            2 :         const char *command = "cd ${TMPDIR} && "
     201              :                 "cp -a tests/0015_database_v0.db .";
     202              : 
     203            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
     204              : 
     205            2 :         const char *arguments = "--compare $DBNAME 0015_database_v0.db";
     206              : 
     207            2 :         const char *filename = "templates/0015_005.txt";  // File name
     208            2 :         const char *template = "%DB_NAME%";
     209              : 
     210            2 :         const char *replacement = getenv("DBNAME");  // Database name
     211              : 
     212            2 :         ASSERT(replacement != NULL);
     213              : 
     214            2 :         ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,WARNING));
     215              : 
     216            2 :         RETURN_STATUS;
     217              : }
     218              : 
     219              : /**
     220              :  *
     221              :  * Run the database comparison again using the --compare parameter, but this time with
     222              :  * the --update option. The database should be upgraded accordingly.
     223              :  * Upgrading from 0 to the last version
     224              :  *
     225              :  */
     226            2 : Return test0015_6_upgrade_db(void)
     227              : {
     228            2 :         INITTEST;
     229              : 
     230            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     231              : 
     232              :         // Get the output of an external program
     233            2 :         const char *arguments = "--compare --update $DBNAME 0015_database_v0.db";
     234              : 
     235            2 :         const char *filename = "templates/0015_006.txt";  // File name
     236            2 :         const char *template = "%DB_NAME%";
     237              : 
     238            2 :         const char *replacement = getenv("DBNAME");  // Database name
     239              : 
     240            2 :         ASSERT(replacement != NULL);
     241              : 
     242            2 :         ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
     243              : 
     244              :         // Clean up test results
     245            2 :         ASSERT(SUCCESS == external_call("rm \"${TMPDIR}/0015_database_v0.db\"",COMPLETED,ALLOW_BOTH));
     246              : 
     247            2 :         RETURN_STATUS;
     248              : }
     249              : 
     250              : /**
     251              :  *
     252              :  * Upgrade a DB from version 1 to the current version as the primary database.
     253              :  * Running the test with the --update parameter to ensure the update
     254              :  * completes successfully
     255              :  *
     256              :  */
     257            2 : Return test0015_7_upgrade_db(void)
     258              : {
     259            2 :         INITTEST;
     260              : 
     261            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     262              : 
     263            2 :         const char *command = "cd ${TMPDIR} && "
     264              :                 "cp -a tests/0015_database_v1.db .";
     265              : 
     266            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
     267              : 
     268            2 :         const char *arguments = "--update --database=0015_database_v1.db tests/examples/diffs/diff1";
     269              : 
     270            2 :         create(char,result);
     271            2 :         create(char,pattern);
     272              : 
     273            2 :         const char *filename = "templates/0015_007.txt";
     274              : 
     275            2 :         ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
     276              : 
     277            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     278              : 
     279              :         // Match the result against the pattern
     280            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     281              : 
     282              :         // Clean to use it iteratively
     283            2 :         del(pattern);
     284            2 :         del(result);
     285              : 
     286            2 :         RETURN_STATUS;
     287              : }
     288              : 
     289              : /**
     290              :  *
     291              :  * Run the program again to verify that the database
     292              :  * is actually at the current version
     293              :  *
     294              :  */
     295            2 : Return test0015_8_upgrade_db(void)
     296              : {
     297            2 :         INITTEST;
     298              : 
     299            2 :         create(char,result);
     300            2 :         create(char,pattern);
     301              : 
     302            2 :         const char *filename = "templates/0015_008.txt";
     303              : 
     304            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     305              : 
     306            2 :         ASSERT(SUCCESS == runit("--update --database=./0015_database_v1.db tests/examples/diffs/diff1",result,COMPLETED,ALLOW_BOTH));
     307              : 
     308            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     309              : 
     310              :         // Match the result against the pattern
     311            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     312              : 
     313              :         // Clean to use it iteratively
     314            2 :         del(pattern);
     315            2 :         del(result);
     316              : 
     317              :         // Clean up test results
     318            2 :         ASSERT(SUCCESS == external_call("rm \"${TMPDIR}/0015_database_v1.db\"",COMPLETED,ALLOW_BOTH));
     319              : 
     320            2 :         RETURN_STATUS;
     321              : }
     322              : 
     323              : /**
     324              :  *
     325              :  * Run the database comparison again using the --compare and --update parameters.
     326              :  * Upgrading from 1 to the last version
     327              :  *
     328              :  */
     329            2 : Return test0015_9_upgrade_db(void)
     330              : {
     331            2 :         INITTEST;
     332              : 
     333            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     334              : 
     335              :         // Get the output of an external program
     336            2 :         const char *command = "cd ${TMPDIR} && "
     337              :                 "cp -a tests/0015_database_v1.db .";
     338              : 
     339            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
     340              : 
     341            2 :         const char *arguments = "--compare --update $DBNAME 0015_database_v1.db";
     342              : 
     343            2 :         const char *filename = "templates/0015_009.txt";  // File name
     344            2 :         const char *template = "%DB_NAME%";
     345              : 
     346            2 :         const char *replacement = getenv("DBNAME");  // Database name
     347              : 
     348            2 :         ASSERT(replacement != NULL);
     349              : 
     350            2 :         ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
     351              : 
     352              :         // Clean up test results
     353            2 :         ASSERT(SUCCESS == external_call("rm \"${TMPDIR}/0015_database_v1.db\"",COMPLETED,ALLOW_BOTH));
     354              : 
     355            2 :         RETURN_STATUS;
     356              : }
     357              : 
     358              : /**
     359              :  *
     360              :  * Upgrade a DB from version 2 to the current version as the primary database.
     361              :  * Running the test with the --update parameter to ensure the update
     362              :  * completes successfully
     363              :  *
     364              :  */
     365            2 : Return test0015_10_upgrade_db(void)
     366              : {
     367            2 :         INITTEST;
     368              : 
     369            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
     370              : 
     371            2 :         const char *command = "cd ${TMPDIR} && "
     372              :                 "cp -a tests/0015_database_v2.db .";
     373              : 
     374            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
     375              : 
     376            2 :         const char *arguments = "--update --database=0015_database_v2.db --verbose tests/examples/diffs/diff1";
     377              : 
     378            2 :         create(char,result);
     379            2 :         create(char,pattern);
     380              : 
     381            2 :         ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
     382              : 
     383            2 :         const char *filename = "templates/0015_010.txt";
     384              : 
     385            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     386              : 
     387              :         // Match the result against the pattern
     388            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     389              : 
     390              :         // Clean to use it iteratively
     391            2 :         del(pattern);
     392            2 :         del(result);
     393              : 
     394            2 :         RETURN_STATUS;
     395              : }
     396              : 
     397              : /**
     398              :  *
     399              :  * Run the database comparison again using the --compare and --update parameters.
     400              :  * Upgrading from 2 to the last version
     401              :  *
     402              :  */
     403            2 : Return test0015_11_upgrade_db(void)
     404              : {
     405            2 :         INITTEST;
     406              : 
     407            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     408              : 
     409              :         // Get the output of an external program
     410            2 :         const char *command = "cd ${TMPDIR} && "
     411              :                 "cp -a tests/0015_database_v2.db .";
     412              : 
     413            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
     414              : 
     415            2 :         const char *arguments = "--compare --update $DBNAME 0015_database_v2.db";
     416              : 
     417            2 :         const char *filename = "templates/0015_011.txt";  // File name
     418            2 :         const char *template = "%DB_NAME%";
     419              : 
     420            2 :         const char *replacement = getenv("DBNAME");  // Database name
     421              : 
     422            2 :         ASSERT(replacement != NULL);
     423              : 
     424            2 :         ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
     425              : 
     426              :         // Clean up test results
     427            2 :         ASSERT(SUCCESS == external_call("rm \"${TMPDIR}/${DBNAME}\" && rm \"${TMPDIR}/0015_database_v2.db\"",COMPLETED,ALLOW_BOTH));
     428              : 
     429            2 :         RETURN_STATUS;
     430              : }
     431              : 
     432              : /**
     433              :  * Create a fresh database inside tests/examples/diffs/ with the UTF-8 name
     434              :  * "Это новая база данных.db" and ensure the app can read/write it despite
     435              :  * spaces and non-ASCII characters.
     436              :  * Then compare it against the legacy database
     437              :  * "0015_database_v3 это база данных с пробелами и символами UTF-8.db" that was
     438              :  * produced by a well-tested older release when upgraded to the version 3.
     439              :  * If the files and checksums match, the current checksum calculation is
     440              :  * considered compatible with the legacy well-tested algorithm.
     441              :  */
     442            2 : Return test0015_12_checksum_compare(void)
     443              : {
     444            2 :         INITTEST;
     445              : 
     446            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     447              : 
     448            2 :         const char *command = "cd ${TMPDIR} && "
     449              :                 "cp -a \"$ORIGIN_DIR/tests/templates/0015_database_v3 это база данных с пробелами и символами UTF-8.db\" .";
     450              : 
     451            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
     452              : 
     453            2 :         create(char,pattern);
     454            2 :         create(char,result);
     455            2 :         create(char,chunk);
     456              : 
     457            2 :         const char *arguments = "--database=\"Это новая база данных.db\" tests/examples/diffs/diff1";
     458              : 
     459            2 :         ASSERT(SUCCESS == runit(arguments,chunk,COMPLETED,ALLOW_BOTH));
     460            2 :         ASSERT(SUCCESS == copy(result,chunk));
     461              : 
     462            2 :         arguments = "--compare \"Это новая база данных.db\" \"0015_database_v3 это база данных с пробелами и символами UTF-8.db\"";
     463              : 
     464            2 :         ASSERT(SUCCESS == runit(arguments,chunk,COMPLETED,ALLOW_BOTH));
     465            2 :         ASSERT(SUCCESS == concat_strings(result,chunk));
     466              : 
     467            2 :         const char *filename = "templates/0015_012.txt";
     468              : 
     469            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     470              : 
     471              :         // Match the result against the pattern
     472            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     473              : 
     474              :         // Clean to use it iteratively
     475            2 :         del(pattern);
     476            2 :         del(result);
     477            2 :         del(chunk);
     478              : 
     479              :         // Clean up test results
     480            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR} && "
     481              :                 "rm \"${TMPDIR}/Это новая база данных.db\" \"${TMPDIR}/0015_database_v3 это база данных с пробелами и символами UTF-8.db\"",
     482              :                 COMPLETED,ALLOW_BOTH));
     483              : 
     484            2 :         RETURN_STATUS;
     485              : }
     486              : 
     487              : /**
     488              :  * Testing scenario 15
     489              :  *
     490              :  * Database upgrade testing:
     491              :  * - Upgrade DBs from versions 0, 1, and 2 to the current version as the primary database and verify reruns
     492              :  * - Launch the program without specifying a database to ensure that a new database is created with the correct version
     493              :  * - Compare a current database with outdated versions (0/1/2) without --update and check for the expected errors
     494              :  * - Compare and upgrade outdated databases (0/1/2) using the --compare and --update parameters
     495              :  * - Verify upgraded databases version 1 and 2 directly with --update
     496              :  */
     497            2 : Return test0015(void)
     498              : {
     499            2 :         INITTEST;
     500              : 
     501            2 :         TEST(test0015_1_upgrade_db,"Upgrade a DB from v0 to the current version. Error handling…");
     502            2 :         TEST(test0015_2_1_upgrade_db,"Upgrade a DB from v0 to the current version as the primary database…");
     503            2 :         TEST(test0015_2_2_upgrade_db,"Upgrade a DB from v0 to the current version with --watch-timestamps…");
     504            2 :         TEST(test0015_3_upgrade_db,"Verify that the DB is actually at the current version…");
     505            2 :         TEST(test0015_4_upgrade_db,"Create default name database…");
     506            2 :         TEST(test0015_5_upgrade_db,"Attempting an upgrade with a single --compare parameter…");
     507            2 :         TEST(test0015_6_upgrade_db,"Upgrading from 0 to the last version using the --compare and --update…");
     508            2 :         TEST(test0015_7_upgrade_db,"Upgrade a DB from v1 to the current version as the primary database…");
     509            2 :         TEST(test0015_8_upgrade_db,"Verify that the DB is actually at the current version…");
     510            2 :         TEST(test0015_9_upgrade_db,"Upgrading from 1 to the last version using the --compare and --update…");
     511            2 :         TEST(test0015_10_upgrade_db,"Upgrade a DB from v2 to the current version as the primary database…");
     512            2 :         TEST(test0015_11_upgrade_db,"Upgrading from 2 to the last version using the --compare and --update…");
     513            2 :         TEST(test0015_12_checksum_compare,"Create and compare DBs with UTF-8 names and checksums from legacy DB…");
     514              : 
     515            2 :         RETURN_STATUS;
     516              : }
        

Generated by: LCOV version 2.0-1