2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
lib/vfs - test vfs_s_get_path() function
|
2011-04-26 15:24:17 +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 15:24:17 +04:00
|
|
|
|
|
|
|
Written by:
|
2013-01-19 17:42:26 +04:00
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2011, 2013
|
2011-04-26 15:24:17 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
2011-04-26 15:24:17 +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 15:24:17 +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 15:24:17 +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 15:24:17 +04:00
|
|
|
|
|
|
|
#define TEST_SUITE_NAME "/lib/vfs"
|
|
|
|
|
2013-01-19 17:42:26 +04:00
|
|
|
#include "tests/mctest.h"
|
2011-04-26 15:24:17 +04:00
|
|
|
|
|
|
|
#include "lib/strutil.h"
|
2013-01-19 16:05:19 +04:00
|
|
|
#include "lib/vfs/direntry.c" /* for testing static methods */
|
2011-04-26 15:24:17 +04:00
|
|
|
|
|
|
|
#include "src/vfs/local/local.c"
|
|
|
|
|
|
|
|
#define ARCH_NAME "/path/to/some/file.ext"
|
|
|
|
#define ETALON_PATH "path/to/test1_file.ext"
|
|
|
|
#define ETALON_VFS_NAME "#test2:user:pass@host.net"
|
2011-06-14 16:09:59 +04:00
|
|
|
#define ETALON_VFS_URL_NAME "test2://user:pass@host.net"
|
2011-04-26 15:24:17 +04:00
|
|
|
|
|
|
|
struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
|
2016-08-17 11:27:57 +03:00
|
|
|
static struct vfs_class *vfs_test_ops1 = (struct vfs_class *) &test_subclass1;
|
|
|
|
static struct vfs_class *vfs_test_ops2 = (struct vfs_class *) &test_subclass2;
|
|
|
|
static struct vfs_class *vfs_test_ops3 = (struct vfs_class *) &test_subclass3;
|
2011-04-26 15:24:17 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-04-26 15:24:17 +04:00
|
|
|
static int
|
2013-01-19 16:05:19 +04:00
|
|
|
test1_mock_open_archive (struct vfs_s_super *super, const vfs_path_t * vpath,
|
|
|
|
const vfs_path_element_t * vpath_element)
|
2011-04-26 15:24:17 +04:00
|
|
|
{
|
|
|
|
struct vfs_s_inode *root;
|
|
|
|
|
2013-04-14 17:38:37 +04:00
|
|
|
mctest_assert_str_eq (vfs_path_as_str (vpath), "/" ETALON_VFS_URL_NAME ARCH_NAME);
|
2011-04-26 15:24:17 +04:00
|
|
|
|
2013-04-14 17:38:37 +04:00
|
|
|
super->name = g_strdup (vfs_path_as_str (vpath));
|
2011-04-26 15:24:17 +04:00
|
|
|
super->data = g_new (char *, 1);
|
2011-06-13 15:44:25 +04:00
|
|
|
root = vfs_s_new_inode (vpath_element->class, super, NULL);
|
2011-04-26 15:24:17 +04:00
|
|
|
super->root = root;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-04-26 15:24:17 +04:00
|
|
|
static int
|
2013-01-19 16:05:19 +04:00
|
|
|
test1_mock_archive_same (const vfs_path_element_t * vpath_element, struct vfs_s_super *super,
|
|
|
|
const vfs_path_t * vpath, void *cookie)
|
2011-04-26 15:24:17 +04:00
|
|
|
{
|
2012-01-03 13:35:57 +04:00
|
|
|
const vfs_path_element_t *path_element;
|
2011-06-08 17:40:36 +04:00
|
|
|
|
2011-06-13 15:44:25 +04:00
|
|
|
(void) vpath_element;
|
2011-04-26 15:24:17 +04:00
|
|
|
(void) super;
|
|
|
|
(void) cookie;
|
|
|
|
|
2013-01-19 16:05:19 +04:00
|
|
|
path_element = vfs_path_get_by_index (vpath, -1);
|
|
|
|
if (strcmp (ARCH_NAME, path_element->path) != 0)
|
2011-04-26 15:24:17 +04:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* @Before */
|
2011-04-26 15:24:17 +04:00
|
|
|
static void
|
|
|
|
setup (void)
|
|
|
|
{
|
|
|
|
str_init_strings (NULL);
|
|
|
|
|
|
|
|
vfs_init ();
|
|
|
|
init_localfs ();
|
|
|
|
vfs_setup_work_dir ();
|
|
|
|
|
2016-08-17 11:27:57 +03:00
|
|
|
memset (&test_subclass1, 0, sizeof (test_subclass1));
|
2018-09-11 14:54:28 +03:00
|
|
|
vfs_test_ops1->flags = VFS_NOLINKS | VFS_REMOTE;
|
2011-04-26 15:24:17 +04:00
|
|
|
test_subclass1.open_archive = test1_mock_open_archive;
|
|
|
|
test_subclass1.archive_same = test1_mock_archive_same;
|
|
|
|
test_subclass1.archive_check = NULL;
|
2016-08-17 11:27:57 +03:00
|
|
|
vfs_s_init_class (&test_subclass1);
|
|
|
|
vfs_test_ops1->name = "testfs1";
|
|
|
|
vfs_test_ops1->prefix = "test1:";
|
|
|
|
vfs_register_class (vfs_test_ops1);
|
|
|
|
|
|
|
|
memset (&test_subclass2, 0, sizeof (test_subclass2));
|
|
|
|
vfs_s_init_class (&test_subclass2);
|
|
|
|
vfs_test_ops2->name = "testfs2";
|
|
|
|
vfs_test_ops2->prefix = "test2:";
|
|
|
|
vfs_register_class (vfs_test_ops2);
|
|
|
|
|
|
|
|
memset (&test_subclass3, 0, sizeof (test_subclass3));
|
|
|
|
vfs_s_init_class (&test_subclass3);
|
|
|
|
vfs_test_ops3->name = "testfs3";
|
|
|
|
vfs_test_ops3->prefix = "test3:";
|
|
|
|
vfs_register_class (vfs_test_ops3);
|
2011-04-26 15:24:17 +04:00
|
|
|
}
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* @After */
|
2011-04-26 15:24:17 +04:00
|
|
|
static void
|
|
|
|
teardown (void)
|
|
|
|
{
|
|
|
|
vfs_shut ();
|
2011-06-04 16:12:24 +04:00
|
|
|
str_uninit_strings ();
|
2011-04-26 15:24:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_die (const char *m)
|
|
|
|
{
|
2013-01-19 16:05:19 +04:00
|
|
|
printf ("VFS_DIE: '%s'\n", m);
|
2011-04-26 15:24:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @Test */
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2011-06-19 14:32:07 +04:00
|
|
|
START_TEST (test_vfs_s_get_path)
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-04-26 15:24:17 +04:00
|
|
|
{
|
2013-01-19 19:56:40 +04:00
|
|
|
/* given */
|
2011-04-26 15:24:17 +04:00
|
|
|
struct vfs_s_super *archive;
|
|
|
|
const char *result;
|
2013-01-19 19:56:40 +04:00
|
|
|
|
|
|
|
/* when */
|
2013-01-19 16:05:19 +04:00
|
|
|
vfs_path_t *vpath =
|
|
|
|
vfs_path_from_str_flags ("/" ETALON_VFS_NAME ARCH_NAME "#test1:/" ETALON_PATH,
|
|
|
|
VPF_USE_DEPRECATED_PARSER);
|
2011-04-26 15:24:17 +04:00
|
|
|
|
2011-06-19 14:32:07 +04:00
|
|
|
result = vfs_s_get_path (vpath, &archive, 0);
|
2011-04-26 15:24:17 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* then */
|
|
|
|
mctest_assert_str_eq (result, ETALON_PATH);
|
|
|
|
mctest_assert_str_eq (archive->name, "/" ETALON_VFS_URL_NAME ARCH_NAME);
|
2011-04-26 15:24:17 +04:00
|
|
|
|
2013-01-19 16:05:19 +04:00
|
|
|
g_free (vpath);
|
2011-04-26 15:24:17 +04:00
|
|
|
|
|
|
|
}
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2011-04-26 15:24:17 +04:00
|
|
|
END_TEST
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-04-26 15:24:17 +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: *************** */
|
2011-06-19 14:32:07 +04:00
|
|
|
tcase_add_test (tc_core, test_vfs_s_get_path);
|
2011-04-26 15:24:17 +04:00
|
|
|
/* *********************************** */
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_core);
|
|
|
|
sr = srunner_create (s);
|
2011-06-19 14:32:07 +04:00
|
|
|
srunner_set_log (sr, "vfs_s_get_path.log");
|
2015-04-07 11:52:58 +03:00
|
|
|
srunner_run_all (sr, CK_ENV);
|
2011-04-26 15:24:17 +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 15:24:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|