2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
lib/vfs - test vfs_parse_ls_lga() functionality
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2016-01-01 09:53:15 +03:00
|
|
|
Copyright (C) 2011-2016
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2011-06-24 22:09:12 +04:00
|
|
|
|
|
|
|
Written by:
|
2013-01-19 17:42:26 +04:00
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2011, 2013
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
2011-06-24 22:09:12 +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-24 22:09:12 +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-24 22:09:12 +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-24 22:09:12 +04:00
|
|
|
|
|
|
|
#define TEST_SUITE_NAME "/lib/vfs"
|
|
|
|
|
2013-01-19 17:42:26 +04:00
|
|
|
#include "tests/mctest.h"
|
2011-10-17 16:15:15 +04:00
|
|
|
|
2011-06-24 22:09:12 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "lib/vfs/utilvfs.h"
|
|
|
|
#include "lib/vfs/xdirentry.h"
|
|
|
|
#include "lib/strutil.h"
|
|
|
|
|
|
|
|
#include "src/vfs/local/local.c"
|
|
|
|
|
|
|
|
|
|
|
|
struct vfs_s_subclass test_subclass1;
|
|
|
|
struct vfs_class vfs_test_ops1;
|
|
|
|
|
|
|
|
struct vfs_s_entry *vfs_root_entry;
|
|
|
|
static struct vfs_s_inode *vfs_root_inode;
|
|
|
|
static struct vfs_s_super *vfs_test_super;
|
|
|
|
|
2015-08-25 15:28:01 +03:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
void message (int flags, const char *title, const char *text, ...) G_GNUC_PRINTF (3, 4);
|
|
|
|
/* *INDENT-ON* */
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @Before */
|
2011-06-24 22:09:12 +04:00
|
|
|
static void
|
|
|
|
setup (void)
|
|
|
|
{
|
|
|
|
static struct stat initstat;
|
|
|
|
|
|
|
|
str_init_strings (NULL);
|
|
|
|
|
|
|
|
vfs_init ();
|
|
|
|
init_localfs ();
|
|
|
|
vfs_setup_work_dir ();
|
|
|
|
|
|
|
|
test_subclass1.flags = VFS_S_REMOTE;
|
|
|
|
vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
|
|
|
|
vfs_test_ops1.name = "testfs1";
|
|
|
|
vfs_test_ops1.flags = VFSF_NOLINKS;
|
|
|
|
vfs_test_ops1.prefix = "test1:";
|
|
|
|
vfs_register_class (&vfs_test_ops1);
|
|
|
|
|
|
|
|
vfs_test_super = g_new0 (struct vfs_s_super, 1);
|
|
|
|
vfs_test_super->me = &vfs_test_ops1;
|
|
|
|
|
|
|
|
vfs_root_inode = vfs_s_new_inode (&vfs_test_ops1, vfs_test_super, &initstat);
|
|
|
|
vfs_root_entry = vfs_s_new_entry (&vfs_test_ops1, "/", vfs_root_inode);
|
|
|
|
}
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* @After */
|
2011-06-24 22:09:12 +04:00
|
|
|
static void
|
|
|
|
teardown (void)
|
|
|
|
{
|
|
|
|
vfs_s_free_entry (&vfs_test_ops1, vfs_root_entry);
|
|
|
|
vfs_shut ();
|
|
|
|
str_uninit_strings ();
|
|
|
|
}
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @Mock */
|
2011-06-24 22:09:12 +04:00
|
|
|
void
|
|
|
|
message (int flags, const char *title, const char *text, ...)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
(void) flags;
|
|
|
|
(void) title;
|
|
|
|
|
|
|
|
va_start (ap, text);
|
|
|
|
p = g_strdup_vprintf (text, ap);
|
|
|
|
va_end (ap);
|
2013-01-19 16:05:19 +04:00
|
|
|
printf ("message(): %s\n", p);
|
|
|
|
g_free (p);
|
2011-06-24 22:09:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2013-01-19 16:05:19 +04:00
|
|
|
static void
|
2013-01-19 19:56:40 +04:00
|
|
|
fill_stat_struct (struct stat *etalon_stat, int iterator)
|
2011-06-24 22:09:12 +04:00
|
|
|
{
|
2013-01-19 19:56:40 +04:00
|
|
|
switch (iterator)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
etalon_stat->st_dev = 0;
|
|
|
|
etalon_stat->st_ino = 0;
|
|
|
|
etalon_stat->st_mode = 0x41fd;
|
|
|
|
etalon_stat->st_nlink = 10;
|
|
|
|
etalon_stat->st_uid = 500;
|
|
|
|
etalon_stat->st_gid = 500;
|
2017-01-02 10:55:26 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_rdev = 0;
|
2017-01-02 10:55:26 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_size = 4096;
|
2016-12-30 11:13:17 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_blksize = 512;
|
2016-12-30 11:13:17 +03:00
|
|
|
#endif
|
2016-12-30 11:23:23 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_blocks = 8;
|
2016-12-30 11:23:23 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_atime = 1308838140;
|
|
|
|
etalon_stat->st_mtime = 1308838140;
|
|
|
|
etalon_stat->st_ctime = 1308838140;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
etalon_stat->st_dev = 0;
|
|
|
|
etalon_stat->st_ino = 0;
|
|
|
|
etalon_stat->st_mode = 0xa1ff;
|
|
|
|
etalon_stat->st_nlink = 10;
|
|
|
|
etalon_stat->st_uid = 500;
|
|
|
|
etalon_stat->st_gid = 500;
|
2017-01-02 10:55:26 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_rdev = 0;
|
2017-01-02 10:55:26 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_size = 11;
|
2016-12-30 11:13:17 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_blksize = 512;
|
2016-12-30 11:13:17 +03:00
|
|
|
#endif
|
2016-12-30 11:23:23 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_blocks = 1;
|
2016-12-30 11:23:23 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_atime = 1268431200;
|
|
|
|
etalon_stat->st_mtime = 1268431200;
|
|
|
|
etalon_stat->st_ctime = 1268431200;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
etalon_stat->st_dev = 0;
|
|
|
|
etalon_stat->st_ino = 0;
|
|
|
|
etalon_stat->st_mode = 0x41fd;
|
|
|
|
etalon_stat->st_nlink = 10;
|
|
|
|
etalon_stat->st_uid = 500;
|
|
|
|
etalon_stat->st_gid = 500;
|
2017-01-02 10:55:26 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_rdev = 0;
|
2017-01-02 10:55:26 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_size = 4096;
|
2016-12-30 11:13:17 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_blksize = 512;
|
2016-12-30 11:13:17 +03:00
|
|
|
#endif
|
2016-12-30 11:23:23 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_blocks = 8;
|
2016-12-30 11:23:23 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_atime = 1308838140;
|
|
|
|
etalon_stat->st_mtime = 1308838140;
|
|
|
|
etalon_stat->st_ctime = 1308838140;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
etalon_stat->st_dev = 0;
|
|
|
|
etalon_stat->st_ino = 0;
|
|
|
|
etalon_stat->st_mode = 0x41fd;
|
|
|
|
etalon_stat->st_nlink = 10;
|
|
|
|
etalon_stat->st_uid = 500;
|
|
|
|
etalon_stat->st_gid = 500;
|
2017-01-02 10:55:26 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_rdev = 0;
|
2017-01-02 10:55:26 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_size = 4096;
|
2016-12-30 11:13:17 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_blksize = 512;
|
2016-12-30 11:13:17 +03:00
|
|
|
#endif
|
2016-12-30 11:23:23 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_blocks = 8;
|
2016-12-30 11:23:23 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat->st_atime = 1308838140;
|
|
|
|
etalon_stat->st_mtime = 1308838140;
|
|
|
|
etalon_stat->st_ctime = 1308838140;
|
|
|
|
break;
|
2015-04-19 13:57:38 +03:00
|
|
|
default:
|
|
|
|
break;
|
2013-01-19 19:56:40 +04:00
|
|
|
}
|
|
|
|
}
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @DataSource("test_vfs_parse_ls_lga_ds") */
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
static const struct test_vfs_parse_ls_lga_ds
|
|
|
|
{
|
|
|
|
const char *input_string;
|
|
|
|
int expected_result;
|
|
|
|
const char *expected_filename;
|
|
|
|
const char *expected_linkname;
|
|
|
|
const size_t expected_filepos;
|
|
|
|
} test_vfs_parse_ls_lga_ds[] =
|
|
|
|
{
|
|
|
|
{ /* 0. */
|
|
|
|
"drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root",
|
|
|
|
1,
|
|
|
|
"build_root",
|
|
|
|
NULL,
|
|
|
|
0
|
|
|
|
},
|
|
|
|
{ /* 1. */
|
|
|
|
"lrwxrwxrwx 1 500 500 11 Mar 13 2010 COPYING -> doc/COPYING",
|
|
|
|
1,
|
|
|
|
"COPYING",
|
|
|
|
"doc/COPYING",
|
|
|
|
0
|
|
|
|
},
|
|
|
|
{ /* 2. */
|
|
|
|
"drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..",
|
|
|
|
1,
|
|
|
|
"..",
|
|
|
|
NULL,
|
|
|
|
0
|
|
|
|
},
|
|
|
|
{ /* 3. */
|
|
|
|
"drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root",
|
|
|
|
1,
|
|
|
|
"build_root",
|
|
|
|
NULL,
|
|
|
|
0
|
|
|
|
},
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @Test(dataSource = "test_vfs_parse_ls_lga_ds") */
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2013-01-19 19:56:40 +04:00
|
|
|
START_PARAMETRIZED_TEST (test_vfs_parse_ls_lga, test_vfs_parse_ls_lga_ds)
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2011-06-24 22:09:12 +04:00
|
|
|
{
|
2013-01-19 19:56:40 +04:00
|
|
|
/* given */
|
2011-06-24 22:09:12 +04:00
|
|
|
size_t filepos = 0;
|
2012-02-13 15:14:50 +04:00
|
|
|
struct stat etalon_stat;
|
2013-01-19 19:56:40 +04:00
|
|
|
static struct stat test_stat;
|
|
|
|
char *filename = NULL;
|
|
|
|
char *linkname = NULL;
|
|
|
|
gboolean actual_result;
|
2012-02-13 15:14:50 +04:00
|
|
|
|
2013-01-19 16:05:19 +04:00
|
|
|
vfs_parse_ls_lga_init ();
|
2011-08-27 21:22:41 +04:00
|
|
|
|
2016-12-30 11:23:23 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat.st_blocks = 0;
|
2016-12-30 11:23:23 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
etalon_stat.st_size = 0;
|
|
|
|
etalon_stat.st_mode = 0;
|
|
|
|
fill_stat_struct (&etalon_stat, _i);
|
|
|
|
|
|
|
|
/* when */
|
|
|
|
actual_result =
|
|
|
|
vfs_parse_ls_lga (data->input_string, &test_stat, &filename, &linkname, &filepos);
|
|
|
|
|
|
|
|
/* then */
|
|
|
|
mctest_assert_int_eq (actual_result, data->expected_result);
|
|
|
|
|
|
|
|
mctest_assert_str_eq (filename, data->expected_filename);
|
|
|
|
mctest_assert_str_eq (linkname, data->expected_linkname);
|
|
|
|
|
|
|
|
mctest_assert_int_eq (etalon_stat.st_dev, test_stat.st_dev);
|
|
|
|
mctest_assert_int_eq (etalon_stat.st_ino, test_stat.st_ino);
|
|
|
|
mctest_assert_int_eq (etalon_stat.st_mode, test_stat.st_mode);
|
|
|
|
mctest_assert_int_eq (etalon_stat.st_uid, test_stat.st_uid);
|
|
|
|
mctest_assert_int_eq (etalon_stat.st_gid, test_stat.st_gid);
|
2017-01-02 10:55:26 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
2013-01-19 19:56:40 +04:00
|
|
|
mctest_assert_int_eq (etalon_stat.st_rdev, test_stat.st_rdev);
|
2017-01-02 10:55:26 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
mctest_assert_int_eq (etalon_stat.st_size, test_stat.st_size);
|
2016-12-30 11:13:17 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
2013-01-19 19:56:40 +04:00
|
|
|
mctest_assert_int_eq (etalon_stat.st_blksize, test_stat.st_blksize);
|
2016-12-30 11:13:17 +03:00
|
|
|
#endif
|
2016-12-30 11:23:23 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
2013-01-19 19:56:40 +04:00
|
|
|
mctest_assert_int_eq (etalon_stat.st_blocks, test_stat.st_blocks);
|
2016-12-30 11:23:23 +03:00
|
|
|
#endif
|
2013-01-19 19:56:40 +04:00
|
|
|
|
|
|
|
/* FIXME: these commented checks are related to time zone!
|
|
|
|
mctest_assert_int_eq (etalon_stat.st_atime, test_stat.st_atime);
|
|
|
|
mctest_assert_int_eq (etalon_stat.st_mtime, test_stat.st_mtime);
|
|
|
|
mctest_assert_int_eq (etalon_stat.st_ctime, test_stat.st_ctime);
|
|
|
|
*/
|
2011-06-24 22:09:12 +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-24 22:09:12 +04:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @Test */
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2011-06-24 22:09:12 +04:00
|
|
|
START_TEST (test_vfs_parse_ls_lga_reorder)
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-06-24 22:09:12 +04:00
|
|
|
{
|
2013-01-19 19:56:40 +04:00
|
|
|
/* given */
|
2011-06-24 22:09:12 +04:00
|
|
|
size_t filepos = 0;
|
|
|
|
struct vfs_s_entry *ent1, *ent2, *ent3;
|
|
|
|
|
2013-01-19 16:05:19 +04:00
|
|
|
vfs_parse_ls_lga_init ();
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* init ent1 */
|
2011-06-24 22:09:12 +04:00
|
|
|
ent1 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);
|
2013-01-19 19:56:40 +04:00
|
|
|
vfs_parse_ls_lga
|
2013-01-19 16:05:19 +04:00
|
|
|
("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root1", &ent1->ino->st,
|
2013-01-19 19:56:40 +04:00
|
|
|
&ent1->name, &ent1->ino->linkname, &filepos);
|
2011-08-27 21:22:41 +04:00
|
|
|
vfs_s_store_filename_leading_spaces (ent1, filepos);
|
2011-06-24 22:09:12 +04:00
|
|
|
vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent1);
|
|
|
|
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* init ent2 */
|
2011-06-24 22:09:12 +04:00
|
|
|
ent2 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);
|
2013-01-19 19:56:40 +04:00
|
|
|
vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root2",
|
|
|
|
&ent2->ino->st, &ent2->name, &ent2->ino->linkname, &filepos);
|
2011-08-27 21:22:41 +04:00
|
|
|
vfs_s_store_filename_leading_spaces (ent2, filepos);
|
2011-06-24 22:09:12 +04:00
|
|
|
vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent2);
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* init ent3 */
|
2011-06-24 22:09:12 +04:00
|
|
|
ent3 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);
|
2013-01-19 19:56:40 +04:00
|
|
|
vfs_parse_ls_lga ("drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..",
|
|
|
|
&ent3->ino->st, &ent3->name, &ent3->ino->linkname, &filepos);
|
2011-08-27 21:22:41 +04:00
|
|
|
vfs_s_store_filename_leading_spaces (ent3, filepos);
|
2011-06-24 22:09:12 +04:00
|
|
|
vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent3);
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* when */
|
2011-08-27 21:22:41 +04:00
|
|
|
vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ());
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* then */
|
|
|
|
mctest_assert_str_eq (ent1->name, " build_root1");
|
|
|
|
mctest_assert_str_eq (ent2->name, " build_root2");
|
2011-06-24 22:09:12 +04:00
|
|
|
}
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2011-06-24 22:09:12 +04:00
|
|
|
END_TEST
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-06-24 22:09:12 +04:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-08-27 21:22:41 +04:00
|
|
|
#define parce_one_line(ent_index, ls_output) {\
|
|
|
|
ent[ent_index] = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);\
|
|
|
|
if (! vfs_parse_ls_lga (ls_output,\
|
|
|
|
&ent[ent_index]->ino->st, &ent[ent_index]->name, &ent[ent_index]->ino->linkname, &filepos))\
|
|
|
|
{\
|
2013-01-23 15:49:37 +04:00
|
|
|
fail ("An error occurred while parse ls output");\
|
2011-08-27 21:22:41 +04:00
|
|
|
return;\
|
|
|
|
}\
|
|
|
|
vfs_s_store_filename_leading_spaces (ent[ent_index], filepos);\
|
|
|
|
vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent[ent_index]);\
|
|
|
|
\
|
|
|
|
}
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* @Test */
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2011-08-27 21:22:41 +04:00
|
|
|
START_TEST (test_vfs_parse_ls_lga_unaligned)
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-08-27 21:22:41 +04:00
|
|
|
{
|
2013-01-19 19:56:40 +04:00
|
|
|
/* given */
|
2011-08-27 21:22:41 +04:00
|
|
|
size_t filepos = 0;
|
|
|
|
struct vfs_s_entry *ent[4];
|
|
|
|
|
2013-01-19 16:05:19 +04:00
|
|
|
vfs_parse_ls_lga_init ();
|
2011-08-27 21:22:41 +04:00
|
|
|
|
2013-01-19 16:05:19 +04:00
|
|
|
parce_one_line (0, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root1");
|
|
|
|
parce_one_line (1, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root2");
|
|
|
|
parce_one_line (2, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09 ..");
|
|
|
|
parce_one_line (3,
|
|
|
|
"drwxrwxr-x 10 500 500 4096 Jun 23 17:09 build_root 0");
|
2011-08-27 21:22:41 +04:00
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* when */
|
2011-08-27 21:22:41 +04:00
|
|
|
vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ());
|
|
|
|
|
2013-01-19 19:56:40 +04:00
|
|
|
/* then */
|
|
|
|
mctest_assert_str_eq (ent[0]->name, "build_root1");
|
|
|
|
mctest_assert_str_eq (ent[0]->name, "build_root1");
|
|
|
|
mctest_assert_str_eq (ent[1]->name, " build_root2");
|
|
|
|
mctest_assert_str_eq (ent[3]->name, " build_root 0");
|
2011-08-27 21:22:41 +04:00
|
|
|
}
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2011-08-27 21:22:41 +04:00
|
|
|
END_TEST
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-08-27 21:22:41 +04:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-06-24 22:09:12 +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_parse_ls_lga, test_vfs_parse_ls_lga_ds);
|
2011-06-24 22:09:12 +04:00
|
|
|
tcase_add_test (tc_core, test_vfs_parse_ls_lga_reorder);
|
2011-08-27 21:22:41 +04:00
|
|
|
tcase_add_test (tc_core, test_vfs_parse_ls_lga_unaligned);
|
2011-06-24 22:09:12 +04:00
|
|
|
/* *********************************** */
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_core);
|
|
|
|
sr = srunner_create (s);
|
|
|
|
srunner_set_log (sr, "vfs_parse_ls_lga.log");
|
2015-04-07 11:52:58 +03:00
|
|
|
srunner_run_all (sr, CK_ENV);
|
2011-06-24 22:09:12 +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-24 22:09:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|