root/tests/lib/terminal.c

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. START_TEST
  4. START_TEST
  5. main

   1 /*
   2    lib/terminal - tests for terminal emulation functions
   3 
   4    Copyright (C) 2013-2025
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Johannes Altmanninger, 2025
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "/lib/terminal"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include <string.h>
  31 
  32 #include "lib/global.h"  // include <glib.h>
  33 #include "lib/terminal.h"
  34 #include "lib/strutil.h"
  35 
  36 /* --------------------------------------------------------------------------------------------- */
  37 
  38 static void
  39 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  40 {
  41     str_init_strings (NULL);
  42 }
  43 
  44 static void
  45 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  46 {
  47     str_uninit_strings ();
  48 }
  49 
  50 /* --------------------------------------------------------------------------------------------- */
  51 
  52 START_TEST (test_parse_csi)
     /* [previous][next][first][last][top][bottom][index][help]  */
  53 {
  54     const char *s = &"\x1b[=5uRest"[2];
  55     const char *end = s + strlen (s);
  56     gboolean ok = parse_csi (NULL, &s, end);
  57     ck_assert_msg (ok, "failed to parse CSI");
  58     ck_assert_str_eq (s, "Rest");
  59 }
  60 END_TEST
  61 
  62 /* --------------------------------------------------------------------------------------------- */
  63 
  64 START_TEST (test_strip_ctrl_codes)
     /* [previous][next][first][last][top][bottom][index][help]  */
  65 {
  66     char *s = strdup (
  67         "\033]0;~\a\033[30m\033(B\033[m\033]133;A;special_key=1\a$ "
  68         "\033[K\033[?2004h\033[>4;1m\033[=5u\033=\033[?2004l\033[>4;0m\033[=0u\033>\033[?2004h"
  69         "\033[>4;1m\033[=5u\033=\033[?2004l\033[>4;0m\033[=0u\033>\033[?2004h\033[>4;1m\033[=5u"
  70         "\033=");
  71     char *actual = strip_ctrl_codes (s);
  72     const char *expected = "$ ";
  73     ck_assert_str_eq (actual, expected);
  74     free (s);
  75 }
  76 END_TEST
  77 
  78 /* --------------------------------------------------------------------------------------------- */
  79 
  80 int
  81 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  82 {
  83     TCase *tc_core;
  84 
  85     tc_core = tcase_create ("Core");
  86 
  87     tcase_add_checked_fixture (tc_core, setup, teardown);
  88 
  89     // Add new tests here: ***************
  90     tcase_add_test (tc_core, test_parse_csi);
  91     tcase_add_test (tc_core, test_strip_ctrl_codes);
  92     // ***********************************
  93 
  94     return mctest_run_all (tc_core);
  95 }
  96 
  97 /* --------------------------------------------------------------------------------------------- */

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