2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
lib/vfs - mc_build_filename() function testing
|
2011-06-17 21:17:16 +04:00
|
|
|
|
2019-01-01 08:48:53 +03:00
|
|
|
Copyright (C) 2011-2019
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2011-06-17 21:17:16 +04:00
|
|
|
|
|
|
|
Written by:
|
2013-01-19 17:42:26 +04:00
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2011, 2013
|
2011-06-17 21:17:16 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
2011-06-17 21:17:16 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
2011-06-17 21:17:16 +04:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-10-15 14:56:47 +04:00
|
|
|
GNU General Public License for more details.
|
2011-06-17 21:17:16 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-01-19 16:05:19 +04:00
|
|
|
*/
|
2011-06-17 21:17:16 +04:00
|
|
|
|
|
|
|
#define TEST_SUITE_NAME "/lib"
|
|
|
|
|
2013-01-19 17:42:26 +04:00
|
|
|
#include "tests/mctest.h"
|
2011-06-17 21:17:16 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "lib/strutil.h"
|
|
|
|
#include "lib/util.h"
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-06-17 21:17:16 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @Before */
|
2011-06-17 21:17:16 +04:00
|
|
|
static void
|
|
|
|
setup (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* @After */
|
2011-06-17 21:17:16 +04:00
|
|
|
static void
|
|
|
|
teardown (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2013-01-19 19:56:40 +04:00
|
|
|
|
|
|
|
static char *
|
|
|
|
run_mc_build_filename (int iteration)
|
|
|
|
{
|
|
|
|
switch (iteration)
|
|
|
|
{
|
|
|
|
case 0:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("test", "path", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 1:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("/test", "path/", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 2:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("/test", "pa/th", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 3:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("/test", "#vfsprefix:", "path ", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 4:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("/test", "vfsprefix://", "path ", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 5:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("/test", "vfs/../prefix:///", "p\\///ath", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 6:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("/test", "path", "..", "/test", "path/", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 7:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("", "path", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 8:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("", "/path", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 9:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("path", "", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 10:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("/path", "", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 11:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("pa", "", "th", (char *) NULL);
|
2013-01-19 19:56:40 +04:00
|
|
|
case 12:
|
2016-03-25 21:33:44 +03:00
|
|
|
return mc_build_filename ("/pa", "", "/th", (char *) NULL);
|
2015-04-19 13:57:38 +03:00
|
|
|
default:
|
|
|
|
return NULL;
|
2013-01-19 19:56:40 +04:00
|
|
|
}
|
2011-06-17 21:17:16 +04:00
|
|
|
}
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @DataSource("test_mc_build_filename_ds") */
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2013-01-19 19:56:40 +04:00
|
|
|
static const struct test_mc_build_filename_ds
|
2011-06-17 21:17:16 +04:00
|
|
|
{
|
2013-01-19 19:56:40 +04:00
|
|
|
const char *expected_result;
|
|
|
|
} test_mc_build_filename_ds[] =
|
|
|
|
{
|
|
|
|
{"test/path"},
|
|
|
|
{"/test/path"},
|
|
|
|
{"/test/pa/th"},
|
|
|
|
{"/test/#vfsprefix:/path "},
|
|
|
|
{"/test/vfsprefix://path "},
|
|
|
|
{"/test/prefix://p\\/ath"},
|
|
|
|
{"/test/test/path"},
|
|
|
|
{"path"},
|
|
|
|
{"path"},
|
|
|
|
{"path"},
|
|
|
|
{"/path"},
|
|
|
|
{"pa/th"},
|
|
|
|
{"/pa/th"},
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
2011-09-20 09:21:11 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @Test(dataSource = "test_mc_build_filename_ds") */
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
START_PARAMETRIZED_TEST (test_mc_build_filename, test_mc_build_filename_ds)
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
{
|
|
|
|
/* given */
|
|
|
|
char *actual_result;
|
2011-09-20 09:21:11 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* when */
|
|
|
|
actual_result = run_mc_build_filename (_i);
|
2011-09-20 09:21:11 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* then */
|
|
|
|
mctest_assert_str_eq (actual_result, data->expected_result);
|
2011-09-20 09:21:11 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
g_free (actual_result);
|
2011-06-17 21:17:16 +04:00
|
|
|
}
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2013-01-19 19:56:40 +04:00
|
|
|
END_PARAMETRIZED_TEST
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-06-17 21:17:16 +04:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
int number_failed;
|
|
|
|
|
|
|
|
Suite *s = suite_create (TEST_SUITE_NAME);
|
|
|
|
TCase *tc_core = tcase_create ("Core");
|
|
|
|
SRunner *sr;
|
|
|
|
|
|
|
|
tcase_add_checked_fixture (tc_core, setup, teardown);
|
|
|
|
|
|
|
|
/* Add new tests here: *************** */
|
2013-01-19 19:56:40 +04:00
|
|
|
mctest_add_parameterized_test (tc_core, test_mc_build_filename, test_mc_build_filename_ds);
|
2011-06-17 21:17:16 +04:00
|
|
|
/* *********************************** */
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_core);
|
|
|
|
sr = srunner_create (s);
|
|
|
|
srunner_set_log (sr, "mc_build_filename.log");
|
2015-04-07 11:52:58 +03:00
|
|
|
srunner_run_all (sr, CK_ENV);
|
2011-06-17 21:17:16 +04:00
|
|
|
number_failed = srunner_ntests_failed (sr);
|
|
|
|
srunner_free (sr);
|
2015-04-07 11:52:58 +03:00
|
|
|
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
2011-06-17 21:17:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|