root/tests/src/filemanager/get_random_hint.c

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

DEFINITIONS

This source file includes following definitions.
  1. guess_message_value
  2. rand
  3. setup
  4. teardown
  5. START_TEST
  6. START_PARAMETRIZED_TEST
  7. main

   1 /*
   2    src/filemanager - filemanager functions.
   3    Tests for getting random hints.
   4 
   5    Copyright (C) 2013-2019
   6    Free Software Foundation, Inc.
   7 
   8    Written by:
   9    Slava Zanko <slavazanko@gmail.com>, 2013
  10 
  11    This file is part of the Midnight Commander.
  12 
  13    The Midnight Commander is free software: you can redistribute it
  14    and/or modify it under the terms of the GNU General Public License as
  15    published by the Free Software Foundation, either version 3 of the License,
  16    or (at your option) any later version.
  17 
  18    The Midnight Commander is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22 
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  25  */
  26 
  27 #define TEST_SUITE_NAME "/src/filemanager"
  28 
  29 #include "tests/mctest.h"
  30 
  31 #include "lib/strutil.h"
  32 #include "lib/util.h"
  33 #include "lib/timer.h"
  34 
  35 #include "src/filemanager/midnight.h"
  36 
  37 
  38 /* --------------------------------------------------------------------------------------------- */
  39 /* mocked functions */
  40 
  41 /* @Mock */
  42 char *
  43 guess_message_value (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  44 {
  45     return g_strdup ("not_exists");
  46 }
  47 
  48 /* --------------------------------------------------------------------------------------------- */
  49 
  50 /* @ThenReturnValue */
  51 static gboolean rand__return_value = 0;
  52 
  53 /* @Mock */
  54 int
  55 rand (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  56 {
  57     return rand__return_value;
  58 }
  59 
  60 /* --------------------------------------------------------------------------------------------- */
  61 
  62 static void
  63 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  64 {
  65     mc_global.timer = mc_timer_new ();
  66     mc_global.share_data_dir = (char *) TEST_SHARE_DIR;
  67     str_init_strings (NULL);
  68 }
  69 
  70 static void
  71 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  72 {
  73     str_uninit_strings ();
  74     mc_timer_destroy (mc_global.timer);
  75 }
  76 
  77 /* --------------------------------------------------------------------------------------------- */
  78 
  79 /* *INDENT-OFF* */
  80 START_TEST (test_not_force)
     /* [previous][next][first][last][top][bottom][index][help]  */
  81 /* *INDENT-ON* */
  82 {
  83     // given
  84     char *first_hint_for_ignore;
  85     char *actual_hint1;
  86     char *actual_hint2;
  87     char *actual_hint3;
  88 
  89     // when
  90     first_hint_for_ignore = get_random_hint (FALSE);
  91     actual_hint1 = get_random_hint (FALSE);
  92     actual_hint2 = get_random_hint (FALSE);
  93     actual_hint3 = get_random_hint (FALSE);
  94 
  95     // then
  96     mctest_assert_ptr_ne (first_hint_for_ignore, NULL);
  97     mctest_assert_str_eq (actual_hint1, "");
  98     mctest_assert_str_eq (actual_hint2, "");
  99     mctest_assert_str_eq (actual_hint3, "");
 100 
 101     g_free (actual_hint3);
 102     g_free (actual_hint2);
 103     g_free (actual_hint1);
 104     g_free (first_hint_for_ignore);
 105 }
 106 /* *INDENT-OFF* */
 107 END_TEST
 108 /* *INDENT-ON* */
 109 
 110 /* --------------------------------------------------------------------------------------------- */
 111 #define MC_HINT_FILE_SIZE 58
 112 /* @DataSource("get_random_ds") */
 113 /* *INDENT-OFF* */
 114 static const struct get_random_ds
 115 {
 116     int input_random_value;
 117 
 118     const char *expected_value;
 119 } get_random_ds[] =
 120 {
 121     { /* 0. */
 122         MC_HINT_FILE_SIZE + 2,
 123         "Para_1",
 124     },
 125     { /* 1. */
 126         MC_HINT_FILE_SIZE + 10,
 127         "Para_2_line_1 Para_2_line_2",
 128     },
 129     { /* 2. */
 130         MC_HINT_FILE_SIZE + 25,
 131         "Para_2_line_1 Para_2_line_2",
 132     },
 133     { /* 3. */
 134         MC_HINT_FILE_SIZE + 40,
 135         "Para_3",
 136     },
 137     { /* 4. */
 138         MC_HINT_FILE_SIZE + 50,
 139         "P A R A _ 4 ", /* the trailing space it's a bug, but not critical and may be ommited */
 140     },
 141 };
 142 /* *INDENT-ON* */
 143     /* @Test(dataSource = "get_random_ds") */
 144 /* *INDENT-OFF* */
 145 START_PARAMETRIZED_TEST (get_random, get_random_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 146 /* *INDENT-ON* */
 147 {
 148     /* given */
 149     char *actual_value;
 150 
 151     rand__return_value = data->input_random_value;
 152 
 153     /* when */
 154     actual_value = get_random_hint (TRUE);
 155 
 156     /* then */
 157     mctest_assert_str_eq (actual_value, data->expected_value);
 158     g_free (actual_value);
 159 }
 160 /* *INDENT-OFF* */
 161 END_PARAMETRIZED_TEST
 162 /* *INDENT-ON* */
 163 
 164 /* --------------------------------------------------------------------------------------------- */
 165 
 166 int
 167 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 168 {
 169     int number_failed;
 170 
 171     Suite *s = suite_create (TEST_SUITE_NAME);
 172     TCase *tc_core = tcase_create ("Core");
 173     SRunner *sr;
 174 
 175     tcase_add_checked_fixture (tc_core, setup, teardown);
 176 
 177     /* Add new tests here: *************** */
 178     tcase_add_test (tc_core, test_not_force);
 179     mctest_add_parameterized_test (tc_core, get_random, get_random_ds);
 180     /* *********************************** */
 181 
 182     suite_add_tcase (s, tc_core);
 183     sr = srunner_create (s);
 184     srunner_set_log (sr, "get_random_hint.log");
 185     srunner_run_all (sr, CK_ENV);
 186     number_failed = srunner_ntests_failed (sr);
 187     srunner_free (sr);
 188     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 189 }
 190 
 191 /* --------------------------------------------------------------------------------------------- */

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