2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
lib/vfs - test vfs_split() functionality
|
2011-04-26 12:00:46 +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-04-26 12:00:46 +04:00
|
|
|
|
|
|
|
Written by:
|
2013-01-19 17:42:26 +04:00
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2011, 2013
|
2011-04-26 12:00:46 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
2011-04-26 12:00:46 +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-04-26 12:00:46 +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-04-26 12:00:46 +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-04-26 12:00:46 +04:00
|
|
|
|
|
|
|
#define TEST_SUITE_NAME "/lib/vfs"
|
|
|
|
|
2013-01-19 17:42:26 +04:00
|
|
|
#include "tests/mctest.h"
|
2011-04-26 12:00:46 +04:00
|
|
|
|
|
|
|
#include "lib/strutil.h"
|
|
|
|
#include "lib/vfs/xdirentry.h"
|
2013-01-19 16:05:19 +04:00
|
|
|
#include "lib/vfs/path.c" /* for testing static methods */
|
2011-04-26 12:00:46 +04:00
|
|
|
|
|
|
|
#include "src/vfs/local/local.c"
|
|
|
|
|
2018-09-14 13:24:17 +03:00
|
|
|
static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
|
2011-04-26 12:00:46 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* @Before */
|
2011-04-26 12:00:46 +04:00
|
|
|
static void
|
|
|
|
setup (void)
|
|
|
|
{
|
|
|
|
str_init_strings (NULL);
|
|
|
|
|
|
|
|
vfs_init ();
|
2019-05-12 19:35:20 +03:00
|
|
|
vfs_init_localfs ();
|
2011-04-26 12:00:46 +04:00
|
|
|
vfs_setup_work_dir ();
|
|
|
|
|
2018-09-14 13:24:17 +03:00
|
|
|
vfs_init_class (&vfs_test_ops1, "testfs1", VFS_NOLINKS | VFS_REMOTE, "test1");
|
|
|
|
vfs_register_class (&vfs_test_ops1);
|
|
|
|
|
|
|
|
vfs_init_class (&vfs_test_ops2, "testfs2", VFS_UNKNOWN, "test2");
|
|
|
|
vfs_register_class (&vfs_test_ops2);
|
|
|
|
|
|
|
|
vfs_init_class (&vfs_test_ops3, "testfs3", VFS_UNKNOWN, "test3");
|
|
|
|
vfs_register_class (&vfs_test_ops3);
|
2011-04-26 12:00:46 +04:00
|
|
|
}
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* @After */
|
2011-04-26 12:00:46 +04:00
|
|
|
static void
|
|
|
|
teardown (void)
|
|
|
|
{
|
|
|
|
vfs_shut ();
|
2011-06-04 16:12:24 +04:00
|
|
|
str_uninit_strings ();
|
2011-04-26 12:00:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @DataSource("test_vfs_split_ds") */
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2013-01-19 19:56:40 +04:00
|
|
|
static const struct test_vfs_split_ds
|
2011-04-26 12:00:46 +04:00
|
|
|
{
|
2013-01-19 19:56:40 +04:00
|
|
|
const char *input_string;
|
|
|
|
const char *expected_path;
|
|
|
|
const char *expected_local;
|
|
|
|
const char *expected_op;
|
|
|
|
const struct vfs_class *expected_result;
|
|
|
|
} test_vfs_split_ds[] =
|
2011-04-26 12:00:46 +04:00
|
|
|
{
|
2013-01-19 19:56:40 +04:00
|
|
|
{ /* 0. */
|
|
|
|
"#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/#test3:/qqq/www/eee.rr",
|
|
|
|
"#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
|
|
|
|
"qqq/www/eee.rr",
|
|
|
|
"test3:",
|
2018-09-14 13:24:17 +03:00
|
|
|
&vfs_test_ops3
|
2013-01-19 19:56:40 +04:00
|
|
|
},
|
|
|
|
{ /* 1. */
|
|
|
|
"#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
|
|
|
|
"#test1:/bla-bla/some/path/",
|
|
|
|
"bla-bla/some/path2/",
|
|
|
|
"test2:",
|
2018-09-14 13:24:17 +03:00
|
|
|
&vfs_test_ops2
|
2013-01-19 19:56:40 +04:00
|
|
|
},
|
|
|
|
{ /* 2. */
|
|
|
|
"#test1:/bla-bla/some/path/",
|
|
|
|
"",
|
|
|
|
"bla-bla/some/path/",
|
|
|
|
"test1:",
|
2018-09-14 13:24:17 +03:00
|
|
|
&vfs_test_ops1
|
2013-01-19 19:56:40 +04:00
|
|
|
},
|
|
|
|
{ /* 3. */
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{ /* 4. split with local */
|
|
|
|
"/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2#test3:/qqq/www/eee.rr",
|
|
|
|
"/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
|
|
|
|
"qqq/www/eee.rr",
|
|
|
|
"test3:",
|
2018-09-14 13:24:17 +03:00
|
|
|
&vfs_test_ops3
|
2013-01-19 19:56:40 +04:00
|
|
|
},
|
|
|
|
{ /* 5. split with local */
|
|
|
|
"/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
|
|
|
|
"/local/path/#test1:/bla-bla/some/path/",
|
|
|
|
"bla-bla/some/path2",
|
|
|
|
"test2:",
|
2018-09-14 13:24:17 +03:00
|
|
|
&vfs_test_ops2
|
2013-01-19 19:56:40 +04:00
|
|
|
},
|
|
|
|
{ /* 6. split with local */
|
|
|
|
"/local/path/#test1:/bla-bla/some/path/",
|
|
|
|
"/local/path/",
|
|
|
|
"bla-bla/some/path/",
|
|
|
|
"test1:",
|
2018-09-14 13:24:17 +03:00
|
|
|
&vfs_test_ops1
|
2013-01-19 19:56:40 +04:00
|
|
|
},
|
|
|
|
{ /* 7. split with local */
|
|
|
|
"/local/path/",
|
|
|
|
"/local/path/",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{ /* 8. split with URL */
|
|
|
|
"#test2:username:passwd@somehost.net/bla-bla/some/path2",
|
|
|
|
"",
|
|
|
|
"bla-bla/some/path2",
|
|
|
|
"test2:username:passwd@somehost.net",
|
2018-09-14 13:24:17 +03:00
|
|
|
&vfs_test_ops2
|
2013-01-19 19:56:40 +04:00
|
|
|
},
|
|
|
|
{ /* 9. split URL with semi */
|
|
|
|
"/local/path/#test1:/bla-bla/some/path/#test2:username:p!a@s#s$w%d@somehost.net/bla-bla/some/path2",
|
|
|
|
"/local/path/#test1:/bla-bla/some/path/",
|
|
|
|
"bla-bla/some/path2",
|
|
|
|
"test2:username:p!a@s#s$w%d@somehost.net",
|
2018-09-14 13:24:17 +03:00
|
|
|
&vfs_test_ops2
|
2013-01-19 19:56:40 +04:00
|
|
|
},
|
|
|
|
{ /* 10. split with semi in path */
|
|
|
|
"#test2:/bl#a-bl#a/so#me/pa#th2",
|
|
|
|
"",
|
|
|
|
"bl#a-bl#a/so#me/pa#th2",
|
|
|
|
"test2:",
|
2018-09-14 13:24:17 +03:00
|
|
|
&vfs_test_ops2
|
2016-08-17 11:27:57 +03:00
|
|
|
}
|
2013-01-19 19:56:40 +04:00
|
|
|
};
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-04-26 12:00:46 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @Test(dataSource = "test_vfs_split_ds") */
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2013-01-19 19:56:40 +04:00
|
|
|
START_PARAMETRIZED_TEST (test_vfs_split, test_vfs_split_ds)
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-04-26 12:00:46 +04:00
|
|
|
{
|
2013-01-19 19:56:40 +04:00
|
|
|
/* given */
|
|
|
|
const char *local = NULL, *op = NULL;
|
|
|
|
struct vfs_class *actual_result;
|
2011-04-28 15:39:59 +04:00
|
|
|
char *path;
|
2013-01-19 16:05:19 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
path = g_strdup (data->input_string);
|
2011-04-26 12:00:46 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* when */
|
|
|
|
actual_result = _vfs_split_with_semi_skip_count (path, &local, &op, 0);
|
2013-01-19 16:05:19 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* then */
|
|
|
|
mctest_assert_ptr_eq (actual_result, data->expected_result);
|
|
|
|
mctest_assert_str_eq (path, data->expected_path);
|
|
|
|
mctest_assert_str_eq (local, data->expected_local);
|
|
|
|
mctest_assert_str_eq (op, data->expected_op);
|
2013-01-19 16:05:19 +04:00
|
|
|
g_free (path);
|
2011-04-26 12:00:46 +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-04-26 12:00:46 +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_vfs_split, test_vfs_split_ds);
|
2011-04-26 12:00:46 +04:00
|
|
|
/* *********************************** */
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_core);
|
|
|
|
sr = srunner_create (s);
|
2011-06-02 14:20:31 +04:00
|
|
|
srunner_set_log (sr, "vfs_split.log");
|
2015-04-07 11:52:58 +03:00
|
|
|
srunner_run_all (sr, CK_ENV);
|
2011-04-26 12:00:46 +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-04-26 12:00:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|