Ticket #2980: Add missing doc/hints french translation
[midnight-commander.git] / tests / src / filemanager / cmd__get_random_hint.c
blob5213ed9a506b1dadeb93b0fa86d3b669f73d6668
1 /*
2 src/filemanager - filemanager functions.
3 Tests for getting random hints.
5 Copyright (C) 2013
6 The 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/cmd.h"
37 /* --------------------------------------------------------------------------------------------- */
38 /* mocked functions */
40 /* @Mock */
41 char *
42 guess_message_value (void)
44 return g_strdup ("not_exists");
47 /* --------------------------------------------------------------------------------------------- */
48 int rand (void);
50 /* @ThenReturnValue */
51 static gboolean rand__return_value = 0;
53 /* @Mock */
54 int
55 rand (void)
57 return rand__return_value;
60 /* --------------------------------------------------------------------------------------------- */
62 static void
63 setup (void)
65 mc_global.share_data_dir = (char *) TEST_SHARE_DIR;
66 str_init_strings (NULL);
69 static void
70 teardown (void)
72 str_uninit_strings ();
75 /* --------------------------------------------------------------------------------------------- */
77 /* *INDENT-OFF* */
78 START_TEST (test_not_force)
79 /* *INDENT-ON* */
81 // given
82 char *first_hint_for_ignore;
83 char *actual_hint1;
84 char *actual_hint2;
85 char *actual_hint3;
87 // when
88 first_hint_for_ignore = get_random_hint (FALSE);
89 actual_hint1 = get_random_hint (FALSE);
90 actual_hint2 = get_random_hint (FALSE);
91 actual_hint3 = get_random_hint (FALSE);
93 // then
94 mctest_assert_ptr_ne (first_hint_for_ignore, NULL);
95 mctest_assert_str_eq (actual_hint1, "");
96 mctest_assert_str_eq (actual_hint2, "");
97 mctest_assert_str_eq (actual_hint3, "");
99 g_free (actual_hint3);
100 g_free (actual_hint2);
101 g_free (actual_hint1);
102 g_free (first_hint_for_ignore);
104 /* *INDENT-OFF* */
105 END_TEST
106 /* *INDENT-ON* */
108 /* --------------------------------------------------------------------------------------------- */
109 #define MC_HINT_FILE_SIZE 58
110 /* @DataSource("get_random_ds") */
111 /* *INDENT-OFF* */
112 static const struct get_random_ds
114 int input_random_value;
116 const char *expected_value;
117 } get_random_ds[] =
119 { /* 0. */
120 MC_HINT_FILE_SIZE + 2,
121 "Para_1",
123 { /* 1. */
124 MC_HINT_FILE_SIZE + 10,
125 "Para_2_line_1 Para_2_line_2",
127 { /* 2. */
128 MC_HINT_FILE_SIZE + 25,
129 "Para_2_line_1 Para_2_line_2",
131 { /* 3. */
132 MC_HINT_FILE_SIZE + 40,
133 "Para_3",
135 { /* 4. */
136 MC_HINT_FILE_SIZE + 50,
137 "P A R A _ 4 ", /* the trailing space it's a bug, but not critical and may be ommited */
140 /* *INDENT-ON* */
141 /* @Test(dataSource = "get_random_ds") */
142 /* *INDENT-OFF* */
143 START_PARAMETRIZED_TEST (get_random, get_random_ds)
144 /* *INDENT-ON* */
146 /* given */
147 char *actual_value;
149 rand__return_value = data->input_random_value;
151 /* when */
152 actual_value = get_random_hint (TRUE);
154 /* then */
155 mctest_assert_str_eq (actual_value, data->expected_value);
156 g_free (actual_value);
158 /* *INDENT-OFF* */
159 END_PARAMETRIZED_TEST
160 /* *INDENT-ON* */
162 /* --------------------------------------------------------------------------------------------- */
165 main (void)
167 int number_failed;
169 Suite *s = suite_create (TEST_SUITE_NAME);
170 TCase *tc_core = tcase_create ("Core");
171 SRunner *sr;
173 tcase_add_checked_fixture (tc_core, setup, teardown);
175 /* Add new tests here: *************** */
176 tcase_add_test (tc_core, test_not_force);
177 mctest_add_parameterized_test (tc_core, get_random, get_random_ds);
178 /* *********************************** */
180 suite_add_tcase (s, tc_core);
181 sr = srunner_create (s);
182 srunner_set_log (sr, "cmd__get_random_hint.log");
183 srunner_run_all (sr, CK_NORMAL);
184 number_failed = srunner_ntests_failed (sr);
185 srunner_free (sr);
186 return (number_failed == 0) ? 0 : 1;
189 /* --------------------------------------------------------------------------------------------- */