Manual pages: mcmcdiffmceditmcview

root/tests/lib/tty.c

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

DEFINITIONS

This source file includes following definitions.
  1. my_exit
  2. START_TEST
  3. START_TEST
  4. START_TEST
  5. START_TEST
  6. main

   1 /*
   2    lib - tty function testing
   3 
   4    Copyright (C) 2011-2026
   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 "/lib"
  24 
  25 #include "tests/mctest.h"
  26 
  27 #include <stdio.h>
  28 
  29 #include "lib/strutil.h"
  30 #include "lib/util.h"
  31 
  32 #include "lib/tty/tty.h"
  33 
  34 /* --------------------------------------------------------------------------------------------- */
  35 /* @CapturedValue */
  36 static int my_exit__status__captured;
  37 
  38 /* @Mock */
  39 void
  40 my_exit (int status)
     /* [previous][next][first][last][top][bottom][index][help]  */
  41 {
  42     my_exit__status__captured = status;
  43 }
  44 
  45 /* --------------------------------------------------------------------------------------------- */
  46 
  47 START_TEST (test_tty_check_term_unset)
     /* [previous][next][first][last][top][bottom][index][help]  */
  48 {
  49     // given
  50     g_unsetenv ("TERM");
  51 
  52     // when
  53     tty_check_xterm_compat (FALSE);
  54 
  55     // then
  56     ck_assert_int_eq (my_exit__status__captured, 1);
  57 }
  58 END_TEST
  59 
  60 /* --------------------------------------------------------------------------------------------- */
  61 
  62 START_TEST (test_tty_check_term_set_empty)
     /* [previous][next][first][last][top][bottom][index][help]  */
  63 {
  64     // given
  65     g_setenv ("TERM", "", TRUE);
  66 
  67     // when
  68     tty_check_xterm_compat (FALSE);
  69 
  70     // then
  71     ck_assert_int_eq (my_exit__status__captured, 1);
  72 }
  73 END_TEST
  74 
  75 /* --------------------------------------------------------------------------------------------- */
  76 
  77 START_TEST (test_tty_check_term_non_xterm)
     /* [previous][next][first][last][top][bottom][index][help]  */
  78 {
  79     // given
  80     g_setenv ("TERM", "gnome-terminal", TRUE);
  81 
  82     // when
  83     const gboolean actual_result_force_false = tty_check_xterm_compat (FALSE);
  84     const gboolean actual_result_force_true = tty_check_xterm_compat (TRUE);
  85 
  86     // then
  87     ck_assert_int_eq (my_exit__status__captured, 0);
  88     mctest_assert_false (actual_result_force_false);
  89     mctest_assert_true (actual_result_force_true);
  90 }
  91 END_TEST
  92 /* --------------------------------------------------------------------------------------------- */
  93 
  94 START_TEST (test_tty_check_term_xterm_like)
     /* [previous][next][first][last][top][bottom][index][help]  */
  95 {
  96     // given
  97     g_setenv ("TERM", "alacritty-terminal", TRUE);
  98 
  99     // when
 100     const gboolean actual_result_force_false = tty_check_xterm_compat (FALSE);
 101     const gboolean actual_result_force_true = tty_check_xterm_compat (TRUE);
 102 
 103     // then
 104     ck_assert_int_eq (my_exit__status__captured, 0);
 105     mctest_assert_true (actual_result_force_false);
 106     mctest_assert_true (actual_result_force_true);
 107 }
 108 END_TEST
 109 
 110 /* --------------------------------------------------------------------------------------------- */
 111 
 112 int
 113 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 114 {
 115     TCase *tc_core;
 116 
 117     tc_core = tcase_create ("Core");
 118 
 119     // Add new tests here: ***************
 120     tcase_add_test (tc_core, test_tty_check_term_unset);
 121     tcase_add_test (tc_core, test_tty_check_term_set_empty);
 122     tcase_add_test (tc_core, test_tty_check_term_non_xterm);
 123     tcase_add_test (tc_core, test_tty_check_term_xterm_like);
 124     // ***********************************
 125 
 126     return mctest_run_all (tc_core);
 127 }
 128 
 129 /* --------------------------------------------------------------------------------------------- */

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