Manual pages: mcmcdiffmceditmcview

root/tests/src/file_history.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. START_TEST
  2. START_TEST
  3. main

   1 /*
   2    src/file_history - tests for file_history
   3 
   4    Copyright (C) 2025
   5    Free Software Foundation, Inc.
   6 
   7    This file is part of the Midnight Commander.
   8 
   9    The Midnight Commander is free software: you can redistribute it
  10    and/or modify it under the terms of the GNU General Public License as
  11    published by the Free Software Foundation, either version 3 of the License,
  12    or (at your option) any later version.
  13 
  14    The Midnight Commander is distributed in the hope that it will be useful,
  15    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17    GNU General Public License for more details.
  18 
  19    You should have received a copy of the GNU General Public License
  20    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  21  */
  22 
  23 #define TEST_SUITE_NAME "/src/file_history"
  24 
  25 #include "tests/mctest.h"
  26 
  27 #include "src/file_history.c"
  28 
  29 /* --------------------------------------------------------------------------------------------- */
  30 
  31 START_TEST (test_file_history_parse_entry)
     /* [previous][next][first][last][top][bottom][index][help]  */
  32 {
  33     GList *file_list = NULL;
  34 
  35     const char *mock_entries[] = {
  36         "/home/codespace/tmp/foo\n", "\n", "bar quux 2;0;5\n", "ba\\nz 1;0;5\n", "",
  37     };
  38     const size_t entries_count = G_N_ELEMENTS (mock_entries);
  39 
  40     for (size_t i = 0; i < entries_count; i++)
  41         file_history_parse_entry (mock_entries[i], &file_list);
  42 
  43     ck_assert_uint_eq (g_list_length (file_list), 2);
  44 
  45     const file_history_data_t *e1 = g_list_nth_data (file_list, 0);
  46     const file_history_data_t *e2 = g_list_nth_data (file_list, 1);
  47 
  48     ck_assert_str_eq (e1->file_name, "ba\nz");
  49     ck_assert_str_eq (e2->file_name, "bar quux");
  50 
  51     g_list_free_full (file_list, file_history_free_item);
  52 }
  53 END_TEST
  54 
  55 /* --------------------------------------------------------------------------------------------- */
  56 
  57 START_TEST (test_file_history_write_entry)
     /* [previous][next][first][last][top][bottom][index][help]  */
  58 {
  59     const file_history_data_t fhd = {
  60         .file_name = g_strdup ("ba\nz"),
  61         .file_pos = g_strdup ("1;0;5"),
  62     };
  63 
  64     GString *s = g_string_new ("");
  65     file_history_write_entry (&fhd, s);
  66 
  67     ck_assert_str_eq (s->str, "ba\\nz 1;0;5");
  68 
  69     g_string_free (s, TRUE);
  70 }
  71 END_TEST
  72 /* --------------------------------------------------------------------------------------------- */
  73 
  74 int
  75 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  76 {
  77     TCase *tc_core;
  78 
  79     tc_core = tcase_create ("Core");
  80 
  81     // Add new tests here: ***************
  82     tcase_add_test (tc_core, test_file_history_parse_entry);
  83     tcase_add_test (tc_core, test_file_history_write_entry);
  84     // ***********************************
  85 
  86     return mctest_run_all (tc_core);
  87 }
  88 
  89 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */