Merge branch '4549_subshell_execl_argv0'
[midnight-commander.git] / tests / src / filemanager / get_random_hint.c
blob8370619f597a06d5c826feaa034de05d280d7425
1 /*
2 src/filemanager - filemanager functions.
3 Tests for getting random hints.
5 Copyright (C) 2013-2024
6 Free Software Foundation, Inc.
8 Written by:
9 Slava Zanko <slavazanko@gmail.com>, 2013
11 This file is part of the Midnight Commander.
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.
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.
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/>.
27 #define TEST_SUITE_NAME "/src/filemanager"
29 #include "tests/mctest.h"
31 #include "lib/strutil.h"
32 #include "lib/util.h"
34 #include "src/filemanager/filemanager.h"
37 /* --------------------------------------------------------------------------------------------- */
38 /* mocked functions */
40 /* @Mock */
41 char *
42 guess_message_value (void)
44 return g_strdup ("not_exists");
47 /* --------------------------------------------------------------------------------------------- */
49 /* @ThenReturnValue */
50 static gboolean rand__return_value = 0;
52 /* @Mock */
53 int
54 rand (void)
56 return rand__return_value;
59 /* --------------------------------------------------------------------------------------------- */
61 static void
62 setup (void)
64 mc_global.share_data_dir = (char *) TEST_SHARE_DIR;
65 str_init_strings (NULL);
68 static void
69 teardown (void)
71 str_uninit_strings ();
74 /* --------------------------------------------------------------------------------------------- */
76 /* *INDENT-OFF* */
77 START_TEST (test_not_force)
78 /* *INDENT-ON* */
80 // given
81 char *first_hint_for_ignore;
82 char *actual_hint1;
83 char *actual_hint2;
84 char *actual_hint3;
86 // when
87 first_hint_for_ignore = get_random_hint (FALSE);
88 actual_hint1 = get_random_hint (FALSE);
89 actual_hint2 = get_random_hint (FALSE);
90 actual_hint3 = get_random_hint (FALSE);
92 // then
93 mctest_assert_ptr_ne (first_hint_for_ignore, NULL);
94 mctest_assert_str_eq (actual_hint1, "");
95 mctest_assert_str_eq (actual_hint2, "");
96 mctest_assert_str_eq (actual_hint3, "");
98 g_free (actual_hint3);
99 g_free (actual_hint2);
100 g_free (actual_hint1);
101 g_free (first_hint_for_ignore);
103 /* *INDENT-OFF* */
104 END_TEST
105 /* *INDENT-ON* */
107 /* --------------------------------------------------------------------------------------------- */
108 #define MC_HINT_FILE_SIZE 58
109 /* @DataSource("get_random_ds") */
110 /* *INDENT-OFF* */
111 static const struct get_random_ds
113 int input_random_value;
115 const char *expected_value;
116 } get_random_ds[] =
118 { /* 0. */
119 MC_HINT_FILE_SIZE + 2,
120 "Para_1",
122 { /* 1. */
123 MC_HINT_FILE_SIZE + 10,
124 "Para_2_line_1 Para_2_line_2",
126 { /* 2. */
127 MC_HINT_FILE_SIZE + 25,
128 "Para_2_line_1 Para_2_line_2",
130 { /* 3. */
131 MC_HINT_FILE_SIZE + 40,
132 "Para_3",
134 { /* 4. */
135 MC_HINT_FILE_SIZE + 50,
136 "P A R A _ 4 ", /* the trailing space it's a bug, but not critical and may be omitted */
139 /* *INDENT-ON* */
140 /* @Test(dataSource = "get_random_ds") */
141 /* *INDENT-OFF* */
142 START_PARAMETRIZED_TEST (get_random, get_random_ds)
143 /* *INDENT-ON* */
145 /* given */
146 char *actual_value;
148 rand__return_value = data->input_random_value;
150 /* when */
151 actual_value = get_random_hint (TRUE);
153 /* then */
154 mctest_assert_str_eq (actual_value, data->expected_value);
155 g_free (actual_value);
157 /* *INDENT-OFF* */
158 END_PARAMETRIZED_TEST
159 /* *INDENT-ON* */
161 /* --------------------------------------------------------------------------------------------- */
164 main (void)
166 TCase *tc_core;
168 tc_core = tcase_create ("Core");
170 tcase_add_checked_fixture (tc_core, setup, teardown);
172 /* Add new tests here: *************** */
173 tcase_add_test (tc_core, test_not_force);
174 mctest_add_parameterized_test (tc_core, get_random, get_random_ds);
175 /* *********************************** */
177 return mctest_run_all (tc_core);
180 /* --------------------------------------------------------------------------------------------- */