2014-02-24 14:08:58 +04:00
|
|
|
/*
|
|
|
|
* libcsync -- a library to sync a directory with another
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2014-01-15 15:20:03 +04:00
|
|
|
#include "config_csync.h"
|
2008-03-25 18:13:44 +03:00
|
|
|
#include <string.h>
|
2015-08-21 15:20:27 +03:00
|
|
|
#include <time.h>
|
2016-09-14 16:31:05 +03:00
|
|
|
#include <sys/time.h>
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2008-04-25 12:56:23 +04:00
|
|
|
#define CSYNC_TEST 1
|
2017-08-14 17:19:52 +03:00
|
|
|
#include "csync_exclude.cpp"
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2017-09-07 12:02:05 +03:00
|
|
|
#include "torture.h"
|
|
|
|
|
2017-08-14 20:19:52 +03:00
|
|
|
#define EXCLUDE_LIST_FILE SOURCEDIR"/../../sync-exclude.lst"
|
2014-08-21 15:12:05 +04:00
|
|
|
|
2016-09-02 16:49:54 +03:00
|
|
|
static int setup(void **state) {
|
2012-10-18 17:17:24 +04:00
|
|
|
CSYNC *csync;
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2017-09-14 16:50:13 +03:00
|
|
|
csync = new CSYNC("/tmp/check_csync1", new OCC::SyncJournalDb(""));
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2012-10-18 17:17:24 +04:00
|
|
|
*state = csync;
|
2016-09-02 16:49:54 +03:00
|
|
|
return 0;
|
2008-03-25 18:13:44 +03:00
|
|
|
}
|
|
|
|
|
2016-09-02 16:49:54 +03:00
|
|
|
static int setup_init(void **state) {
|
2012-10-18 17:17:24 +04:00
|
|
|
CSYNC *csync;
|
|
|
|
int rc;
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2017-09-14 16:50:13 +03:00
|
|
|
csync = new CSYNC("/tmp/check_csync1", new OCC::SyncJournalDb(""));
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2014-08-21 15:12:05 +04:00
|
|
|
rc = csync_exclude_load(EXCLUDE_LIST_FILE, &(csync->excludes));
|
2012-10-18 17:17:24 +04:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2015-10-20 18:06:32 +03:00
|
|
|
/* and add some unicode stuff */
|
|
|
|
rc = _csync_exclude_add(&(csync->excludes), "*.💩");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = _csync_exclude_add(&(csync->excludes), "пятницы.*");
|
|
|
|
assert_int_equal(rc, 0);
|
2016-01-10 14:03:28 +03:00
|
|
|
rc = _csync_exclude_add(&(csync->excludes), "*/*.out");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = _csync_exclude_add(&(csync->excludes), "latex*/*.run.xml");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = _csync_exclude_add(&(csync->excludes), "latex/*/*.tex.tmp");
|
|
|
|
assert_int_equal(rc, 0);
|
2015-10-20 18:06:32 +03:00
|
|
|
|
2012-10-18 17:17:24 +04:00
|
|
|
*state = csync;
|
2016-09-02 16:49:54 +03:00
|
|
|
return 0;
|
2008-03-25 18:13:44 +03:00
|
|
|
}
|
|
|
|
|
2016-09-02 16:49:54 +03:00
|
|
|
static int teardown(void **state) {
|
2017-08-14 17:19:52 +03:00
|
|
|
CSYNC *csync = (CSYNC*)*state;
|
2012-10-18 17:17:24 +04:00
|
|
|
int rc;
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2017-09-14 16:50:13 +03:00
|
|
|
auto statedb = csync->statedb;
|
2017-09-04 20:06:13 +03:00
|
|
|
delete csync;
|
2017-09-14 16:50:13 +03:00
|
|
|
delete statedb;
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2012-10-18 17:17:24 +04:00
|
|
|
rc = system("rm -rf /tmp/check_csync1");
|
|
|
|
assert_int_equal(rc, 0);
|
2012-11-23 14:43:39 +04:00
|
|
|
rc = system("rm -rf /tmp/check_csync2");
|
|
|
|
assert_int_equal(rc, 0);
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2012-10-18 17:17:24 +04:00
|
|
|
*state = NULL;
|
2016-09-02 16:49:54 +03:00
|
|
|
|
|
|
|
return 0;
|
2008-03-25 18:13:44 +03:00
|
|
|
}
|
|
|
|
|
2012-10-18 17:17:24 +04:00
|
|
|
static void check_csync_exclude_add(void **state)
|
|
|
|
{
|
2017-08-14 17:19:52 +03:00
|
|
|
CSYNC *csync = (CSYNC*)*state;
|
2014-08-21 15:12:05 +04:00
|
|
|
_csync_exclude_add(&(csync->excludes), "/tmp/check_csync1/*");
|
2012-10-27 21:27:14 +04:00
|
|
|
assert_string_equal(csync->excludes->vector[0], "/tmp/check_csync1/*");
|
2012-10-18 17:17:24 +04:00
|
|
|
}
|
2008-05-07 13:09:56 +04:00
|
|
|
|
2012-10-18 17:17:24 +04:00
|
|
|
static void check_csync_exclude_load(void **state)
|
|
|
|
{
|
2017-08-14 17:19:52 +03:00
|
|
|
CSYNC *csync = (CSYNC*)*state;
|
2012-10-18 17:17:24 +04:00
|
|
|
int rc;
|
2008-05-07 13:09:56 +04:00
|
|
|
|
2014-08-21 15:12:05 +04:00
|
|
|
rc = csync_exclude_load(EXCLUDE_LIST_FILE, &(csync->excludes) );
|
2012-10-18 17:17:24 +04:00
|
|
|
assert_int_equal(rc, 0);
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2015-11-11 11:38:39 +03:00
|
|
|
assert_string_equal(csync->excludes->vector[0], "*~");
|
2014-08-21 15:12:05 +04:00
|
|
|
assert_int_not_equal(csync->excludes->count, 0);
|
2012-10-18 17:17:24 +04:00
|
|
|
}
|
2008-03-25 18:13:44 +03:00
|
|
|
|
2012-10-18 17:17:24 +04:00
|
|
|
static void check_csync_excluded(void **state)
|
|
|
|
{
|
2017-08-14 17:19:52 +03:00
|
|
|
CSYNC *csync = (CSYNC*)*state;
|
2012-10-18 17:17:24 +04:00
|
|
|
int rc;
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "", CSYNC_FTW_TYPE_FILE);
|
2015-08-24 12:09:34 +03:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/", CSYNC_FTW_TYPE_FILE);
|
2015-08-24 12:09:34 +03:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "krawel_krawel", CSYNC_FTW_TYPE_FILE);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".kde/share/config/kwin.eventsrc", CSYNC_FTW_TYPE_FILE);
|
2013-09-12 16:47:06 +04:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
2017-07-03 17:42:31 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".directory/cache-maximegalon/cache1.txt", CSYNC_FTW_TYPE_FILE);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
2017-07-03 17:42:31 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "mozilla/.directory", CSYNC_FTW_TYPE_DIR);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
2012-09-25 16:41:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test for patterns in subdirs. '.beagle' is defined as a pattern and has
|
|
|
|
* to be found in top dir as well as in directories underneath.
|
|
|
|
*/
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".apdisk", CSYNC_FTW_TYPE_DIR);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "foo/.apdisk", CSYNC_FTW_TYPE_DIR);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "foo/bar/.apdisk", CSYNC_FTW_TYPE_DIR);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
2012-10-22 17:13:52 +04:00
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".java", CSYNC_FTW_TYPE_FILE);
|
2013-09-12 16:47:06 +04:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
2014-08-21 15:12:05 +04:00
|
|
|
|
2013-09-12 16:47:06 +04:00
|
|
|
/* Files in the ignored dir .java will also be ignored. */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".apdisk/totally_amazing.jar", CSYNC_FTW_TYPE_FILE);
|
2013-09-12 16:47:06 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
|
|
|
/* and also in subdirs */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "projects/.apdisk/totally_amazing.jar", CSYNC_FTW_TYPE_FILE);
|
2013-09-12 16:47:06 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
|
|
|
/* csync-journal is ignored in general silently. */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".csync_journal.db", CSYNC_FTW_TYPE_FILE);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".csync_journal.db.ctmp", CSYNC_FTW_TYPE_FILE);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "subdir/.csync_journal.db", CSYNC_FTW_TYPE_FILE);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
2016-09-02 16:49:54 +03:00
|
|
|
|
|
|
|
/* also the new form of the database name */
|
2016-11-22 15:17:04 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "._sync_5bdd60bdfcfa.db", CSYNC_FTW_TYPE_FILE);
|
2016-09-02 16:49:54 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
2016-11-22 15:17:04 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "._sync_5bdd60bdfcfa.db.ctmp", CSYNC_FTW_TYPE_FILE);
|
2016-09-02 16:49:54 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
2016-11-22 15:17:04 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "._sync_5bdd60bdfcfa.db-shm", CSYNC_FTW_TYPE_FILE);
|
2016-09-02 16:49:54 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
2016-11-22 15:17:04 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "subdir/._sync_5bdd60bdfcfa.db", CSYNC_FTW_TYPE_FILE);
|
2016-09-02 16:49:54 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
2017-06-16 16:43:21 +03:00
|
|
|
|
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".sync_5bdd60bdfcfa.db", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".sync_5bdd60bdfcfa.db.ctmp", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".sync_5bdd60bdfcfa.db-shm", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "subdir/.sync_5bdd60bdfcfa.db", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
|
|
|
|
|
2013-09-03 17:15:14 +04:00
|
|
|
|
2013-09-12 16:47:06 +04:00
|
|
|
/* pattern ]*.directory - ignore and remove */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "my.~directory", CSYNC_FTW_TYPE_FILE);
|
2013-09-03 17:15:14 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_AND_REMOVE);
|
2013-09-12 16:47:06 +04:00
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/a_folder/my.~directory", CSYNC_FTW_TYPE_FILE);
|
2013-09-12 16:47:06 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_AND_REMOVE);
|
|
|
|
|
|
|
|
/* Not excluded because the pattern .netscape/cache requires directory. */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, ".netscape/cache", CSYNC_FTW_TYPE_FILE);
|
2013-09-12 16:47:06 +04:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
2015-10-20 18:06:32 +03:00
|
|
|
/* Not excluded */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "unicode/中文.hé", CSYNC_FTW_TYPE_FILE);
|
2015-10-20 18:06:32 +03:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
/* excluded */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "unicode/пятницы.txt", CSYNC_FTW_TYPE_FILE);
|
2015-10-20 18:06:32 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "unicode/中文.💩", CSYNC_FTW_TYPE_FILE);
|
2015-10-20 18:06:32 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
2016-01-10 14:03:28 +03:00
|
|
|
/* path wildcards */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "foobar/my_manuscript.out", CSYNC_FTW_TYPE_FILE);
|
2016-01-10 14:03:28 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "latex_tmp/my_manuscript.run.xml", CSYNC_FTW_TYPE_FILE);
|
2016-01-10 14:03:28 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
2015-10-20 18:06:32 +03:00
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "word_tmp/my_manuscript.run.xml", CSYNC_FTW_TYPE_FILE);
|
2016-01-10 14:03:28 +03:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "latex/my_manuscript.tex.tmp", CSYNC_FTW_TYPE_FILE);
|
2016-01-10 14:03:28 +03:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "latex/songbook/my_manuscript.tex.tmp", CSYNC_FTW_TYPE_FILE);
|
2016-01-10 14:03:28 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
2016-07-19 16:38:57 +03:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "file_trailing_space ", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_TRAILING_SPACE);
|
|
|
|
|
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "file_trailing_dot.", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_INVALID_CHAR);
|
|
|
|
|
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "AUX", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_INVALID_CHAR);
|
|
|
|
|
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "file_invalid_char<", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_INVALID_CHAR);
|
|
|
|
#endif
|
2008-03-25 18:13:44 +03:00
|
|
|
}
|
|
|
|
|
2015-08-24 10:44:54 +03:00
|
|
|
static void check_csync_excluded_traversal(void **state)
|
|
|
|
{
|
2017-08-14 17:19:52 +03:00
|
|
|
CSYNC *csync = (CSYNC*)*state;
|
2015-08-24 10:44:54 +03:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
_csync_exclude_add( &(csync->excludes), "/exclude" );
|
|
|
|
|
|
|
|
/* Check toplevel dir, the pattern only works for toplevel dir. */
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/exclude", CSYNC_FTW_TYPE_DIR);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/foo/exclude", CSYNC_FTW_TYPE_DIR);
|
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
|
|
|
/* check for a file called exclude. Must still work */
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/exclude", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/foo/exclude", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
|
|
|
/* Add an exclude for directories only: excl/ */
|
|
|
|
_csync_exclude_add( &(csync->excludes), "excl/" );
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/excl", CSYNC_FTW_TYPE_DIR);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "meep/excl", CSYNC_FTW_TYPE_DIR);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "meep/excl/file", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED); // because leading dirs aren't checked!
|
|
|
|
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/excl", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
|
|
|
_csync_exclude_add(&csync->excludes, "/excludepath/withsubdir");
|
|
|
|
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/excludepath/withsubdir", CSYNC_FTW_TYPE_DIR);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/excludepath/withsubdir", CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/excludepath/withsubdir2", CSYNC_FTW_TYPE_DIR);
|
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
|
|
|
rc = csync_excluded_traversal(csync->excludes, "/excludepath/withsubdir/foo", CSYNC_FTW_TYPE_DIR);
|
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED); // because leading dirs aren't checked!
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:33:44 +04:00
|
|
|
static void check_csync_pathes(void **state)
|
|
|
|
{
|
2017-08-14 17:19:52 +03:00
|
|
|
CSYNC *csync = (CSYNC*)*state;
|
2014-09-18 17:33:44 +04:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
_csync_exclude_add( &(csync->excludes), "/exclude" );
|
|
|
|
|
|
|
|
/* Check toplevel dir, the pattern only works for toplevel dir. */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/exclude", CSYNC_FTW_TYPE_DIR);
|
2014-09-18 17:33:44 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/foo/exclude", CSYNC_FTW_TYPE_DIR);
|
2014-09-18 17:33:44 +04:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
|
|
|
/* check for a file called exclude. Must still work */
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/exclude", CSYNC_FTW_TYPE_FILE);
|
2014-09-18 17:33:44 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/foo/exclude", CSYNC_FTW_TYPE_FILE);
|
2014-09-18 17:33:44 +04:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
|
|
|
/* Add an exclude for directories only: excl/ */
|
|
|
|
_csync_exclude_add( &(csync->excludes), "excl/" );
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/excl", CSYNC_FTW_TYPE_DIR);
|
2014-09-18 17:33:44 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "meep/excl", CSYNC_FTW_TYPE_DIR);
|
2014-09-18 17:33:44 +04:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "meep/excl/file", CSYNC_FTW_TYPE_FILE);
|
2015-08-21 15:20:27 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/excl", CSYNC_FTW_TYPE_FILE);
|
2014-09-18 17:33:44 +04:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
2015-08-21 15:20:27 +03:00
|
|
|
|
|
|
|
_csync_exclude_add(&csync->excludes, "/excludepath/withsubdir");
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/excludepath/withsubdir", CSYNC_FTW_TYPE_DIR);
|
2015-08-21 15:20:27 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/excludepath/withsubdir", CSYNC_FTW_TYPE_FILE);
|
2015-08-21 15:20:27 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/excludepath/withsubdir2", CSYNC_FTW_TYPE_DIR);
|
2015-08-21 15:20:27 +03:00
|
|
|
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
|
|
|
|
|
2016-02-10 23:55:16 +03:00
|
|
|
rc = csync_excluded_no_ctx(csync->excludes, "/excludepath/withsubdir/foo", CSYNC_FTW_TYPE_DIR);
|
2015-08-21 15:20:27 +03:00
|
|
|
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
|
2014-09-18 17:33:44 +04:00
|
|
|
}
|
2013-09-12 16:47:06 +04:00
|
|
|
|
2017-08-14 17:19:52 +03:00
|
|
|
static void check_csync_is_windows_reserved_word(void **) {
|
2014-10-24 21:18:57 +04:00
|
|
|
assert_true(csync_is_windows_reserved_word("CON"));
|
|
|
|
assert_true(csync_is_windows_reserved_word("con"));
|
|
|
|
assert_true(csync_is_windows_reserved_word("CON."));
|
|
|
|
assert_true(csync_is_windows_reserved_word("con."));
|
|
|
|
assert_true(csync_is_windows_reserved_word("CON.ference"));
|
|
|
|
assert_false(csync_is_windows_reserved_word("CONference"));
|
|
|
|
assert_false(csync_is_windows_reserved_word("conference"));
|
|
|
|
assert_false(csync_is_windows_reserved_word("conf.erence"));
|
|
|
|
assert_false(csync_is_windows_reserved_word("co"));
|
|
|
|
assert_true(csync_is_windows_reserved_word("A:"));
|
|
|
|
assert_true(csync_is_windows_reserved_word("a:"));
|
|
|
|
assert_true(csync_is_windows_reserved_word("z:"));
|
|
|
|
assert_true(csync_is_windows_reserved_word("Z:"));
|
|
|
|
assert_true(csync_is_windows_reserved_word("M:"));
|
|
|
|
assert_true(csync_is_windows_reserved_word("m:"));
|
2015-08-21 15:20:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_csync_excluded_performance(void **state)
|
|
|
|
{
|
2017-08-14 17:19:52 +03:00
|
|
|
CSYNC *csync = (CSYNC*)*state;
|
2015-08-21 15:20:27 +03:00
|
|
|
|
|
|
|
const int N = 10000;
|
|
|
|
int totalRc = 0;
|
2016-07-19 16:38:57 +03:00
|
|
|
int i = 0;
|
2015-08-21 15:20:27 +03:00
|
|
|
|
|
|
|
// Being able to use QElapsedTimer for measurement would be nice...
|
2015-08-24 10:44:54 +03:00
|
|
|
{
|
|
|
|
struct timeval before, after;
|
|
|
|
gettimeofday(&before, 0);
|
|
|
|
|
2016-07-19 16:38:57 +03:00
|
|
|
for (i = 0; i < N; ++i) {
|
2016-02-10 23:55:16 +03:00
|
|
|
totalRc += csync_excluded_no_ctx(csync->excludes, "/this/is/quite/a/long/path/with/many/components", CSYNC_FTW_TYPE_DIR);
|
|
|
|
totalRc += csync_excluded_no_ctx(csync->excludes, "/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/29", CSYNC_FTW_TYPE_FILE);
|
2015-08-24 10:44:54 +03:00
|
|
|
}
|
|
|
|
assert_int_equal(totalRc, CSYNC_NOT_EXCLUDED); // mainly to avoid optimization
|
|
|
|
|
|
|
|
gettimeofday(&after, 0);
|
|
|
|
|
|
|
|
const double total = (after.tv_sec - before.tv_sec)
|
|
|
|
+ (after.tv_usec - before.tv_usec) / 1.0e6;
|
|
|
|
const double perCallMs = total / 2 / N * 1000;
|
|
|
|
printf("csync_excluded: %f ms per call\n", perCallMs);
|
2015-08-21 15:20:27 +03:00
|
|
|
}
|
|
|
|
|
2015-08-24 10:44:54 +03:00
|
|
|
{
|
|
|
|
struct timeval before, after;
|
|
|
|
gettimeofday(&before, 0);
|
|
|
|
|
2016-07-19 16:38:57 +03:00
|
|
|
for (i = 0; i < N; ++i) {
|
2015-08-24 10:44:54 +03:00
|
|
|
totalRc += csync_excluded_traversal(csync->excludes, "/this/is/quite/a/long/path/with/many/components", CSYNC_FTW_TYPE_DIR);
|
|
|
|
totalRc += csync_excluded_traversal(csync->excludes, "/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/29", CSYNC_FTW_TYPE_FILE);
|
|
|
|
}
|
|
|
|
assert_int_equal(totalRc, CSYNC_NOT_EXCLUDED); // mainly to avoid optimization
|
2014-10-24 21:18:57 +04:00
|
|
|
|
2015-08-24 10:44:54 +03:00
|
|
|
gettimeofday(&after, 0);
|
|
|
|
|
|
|
|
const double total = (after.tv_sec - before.tv_sec)
|
|
|
|
+ (after.tv_usec - before.tv_usec) / 1.0e6;
|
|
|
|
const double perCallMs = total / 2 / N * 1000;
|
|
|
|
printf("csync_excluded_traversal: %f ms per call\n", perCallMs);
|
|
|
|
}
|
2014-10-24 21:18:57 +04:00
|
|
|
}
|
|
|
|
|
2016-03-17 16:25:18 +03:00
|
|
|
static void check_csync_exclude_expand_escapes(void **state)
|
|
|
|
{
|
|
|
|
(void)state;
|
|
|
|
|
|
|
|
const char *str = csync_exclude_expand_escapes(
|
2017-09-13 14:03:40 +03:00
|
|
|
"keep \\' \\\" \\? \\\\ \\a \\b \\f \\n \\r \\t \\v \\z \\#");
|
2016-03-17 16:25:18 +03:00
|
|
|
assert_true(0 == strcmp(
|
2017-09-13 14:03:40 +03:00
|
|
|
str, "keep ' \" ? \\ \a \b \f \n \r \t \v \\z #"));
|
2016-03-17 16:25:18 +03:00
|
|
|
SAFE_FREE(str);
|
|
|
|
|
|
|
|
str = csync_exclude_expand_escapes("");
|
|
|
|
assert_true(0 == strcmp(str, ""));
|
|
|
|
SAFE_FREE(str);
|
|
|
|
|
|
|
|
str = csync_exclude_expand_escapes("\\");
|
|
|
|
assert_true(0 == strcmp(str, "\\"));
|
|
|
|
SAFE_FREE(str);
|
|
|
|
}
|
|
|
|
|
2012-10-18 17:17:24 +04:00
|
|
|
int torture_run_tests(void)
|
|
|
|
{
|
2016-09-02 16:49:54 +03:00
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(check_csync_exclude_add, setup, teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(check_csync_exclude_load, setup, teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(check_csync_excluded, setup_init, teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(check_csync_excluded_traversal, setup_init, teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(check_csync_pathes, setup_init, teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(check_csync_is_windows_reserved_word, setup_init, teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(check_csync_excluded_performance, setup_init, teardown),
|
|
|
|
cmocka_unit_test(check_csync_exclude_expand_escapes),
|
2012-10-18 17:17:24 +04:00
|
|
|
};
|
|
|
|
|
2016-09-02 16:49:54 +03:00
|
|
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
2012-10-18 17:17:24 +04:00
|
|
|
}
|