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
|
|
|
|
*/
|
2012-10-19 19:25:41 +04:00
|
|
|
#include "torture.h"
|
2008-08-01 17:58:28 +04:00
|
|
|
|
|
|
|
#include "csync_update.c"
|
|
|
|
|
2013-08-07 14:43:32 +04:00
|
|
|
#define TESTDB "/tmp/check_csync/journal.db"
|
|
|
|
|
2014-10-21 13:25:44 +04:00
|
|
|
static int firstrun = 1;
|
|
|
|
|
|
|
|
static void statedb_create_metadata_table(sqlite3 *db)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if( db ) {
|
|
|
|
const char *sql = "CREATE TABLE IF NOT EXISTS metadata("
|
|
|
|
"phash INTEGER(8),"
|
|
|
|
"pathlen INTEGER,"
|
|
|
|
"path VARCHAR(4096),"
|
|
|
|
"inode INTEGER,"
|
|
|
|
"uid INTEGER,"
|
|
|
|
"gid INTEGER,"
|
|
|
|
"mode INTEGER,"
|
|
|
|
"modtime INTEGER(8),"
|
|
|
|
"type INTEGER,"
|
|
|
|
"md5 VARCHAR(32),"
|
|
|
|
"PRIMARY KEY(phash));";
|
|
|
|
|
|
|
|
rc = sqlite3_exec(db, sql, NULL, NULL, NULL);
|
2015-01-14 13:28:53 +03:00
|
|
|
//const char *msg = sqlite3_errmsg(db);
|
2014-10-21 13:25:44 +04:00
|
|
|
assert_int_equal( rc, SQLITE_OK );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void statedb_insert_metadata(sqlite3 *db)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if( db ) {
|
|
|
|
char *stmt = sqlite3_mprintf("INSERT INTO metadata"
|
|
|
|
"(phash, pathlen, path, inode, uid, gid, mode, modtime,type,md5) VALUES"
|
|
|
|
"(%lld, %d, '%q', %d, %d, %d, %d, %lld, %d, '%q');",
|
|
|
|
(long long signed int)42,
|
|
|
|
42,
|
|
|
|
"I_was_wurst_before_I_became_wurstsalat",
|
|
|
|
619070,
|
|
|
|
42,
|
|
|
|
42,
|
|
|
|
42,
|
|
|
|
(long long signed int)42,
|
|
|
|
0,
|
|
|
|
"4711");
|
|
|
|
|
|
|
|
char *errmsg;
|
|
|
|
rc = sqlite3_exec(db, stmt, NULL, NULL, &errmsg);
|
|
|
|
sqlite3_free(stmt);
|
|
|
|
assert_int_equal( rc, SQLITE_OK );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void setup(void **state)
|
|
|
|
{
|
|
|
|
CSYNC *csync;
|
|
|
|
int rc;
|
|
|
|
|
2014-10-21 13:25:44 +04:00
|
|
|
unlink(TESTDB);
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = system("mkdir -p /tmp/check_csync");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = system("mkdir -p /tmp/check_csync1");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = system("mkdir -p /tmp/check_csync2");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = csync_init(csync);
|
|
|
|
assert_int_equal(rc, 0);
|
2014-10-21 13:25:44 +04:00
|
|
|
|
|
|
|
/* Create a new db with metadata */
|
|
|
|
sqlite3 *db;
|
|
|
|
csync->statedb.file = c_strdup(TESTDB);
|
|
|
|
rc = sqlite3_open(csync->statedb.file, &db);
|
|
|
|
statedb_create_metadata_table(db);
|
|
|
|
if( firstrun ) {
|
|
|
|
statedb_insert_metadata(db);
|
|
|
|
firstrun = 0;
|
|
|
|
}
|
|
|
|
sqlite3_close(db);
|
|
|
|
|
2013-08-18 21:11:36 +04:00
|
|
|
rc = csync_statedb_load(csync, TESTDB, &csync->statedb.db);
|
2013-08-07 14:43:32 +04:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
*state = csync;
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void setup_ftw(void **state)
|
|
|
|
{
|
|
|
|
CSYNC *csync;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = system("mkdir -p /tmp/check_csync");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = system("mkdir -p /tmp/check_csync1");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = system("mkdir -p /tmp/check_csync2");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = csync_create(&csync, "/tmp", "/tmp");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = csync_init(csync);
|
|
|
|
assert_int_equal(rc, 0);
|
2014-10-22 13:50:11 +04:00
|
|
|
|
|
|
|
sqlite3 *db = NULL;
|
|
|
|
rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
|
|
|
|
assert_int_equal(rc, SQLITE_OK);
|
|
|
|
statedb_create_metadata_table(db);
|
2014-10-22 14:44:03 +04:00
|
|
|
rc = sqlite3_close(db);
|
2014-10-22 13:50:11 +04:00
|
|
|
assert_int_equal(rc, SQLITE_OK);
|
|
|
|
|
2013-08-18 21:11:36 +04:00
|
|
|
rc = csync_statedb_load(csync, TESTDB, &csync->statedb.db);
|
2013-08-07 17:39:30 +04:00
|
|
|
assert_int_equal(rc, 0);
|
2012-10-19 19:25:41 +04:00
|
|
|
|
2014-10-22 13:50:11 +04:00
|
|
|
csync->statedb.file = c_strdup( TESTDB );
|
2012-10-19 19:25:41 +04:00
|
|
|
*state = csync;
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void teardown(void **state)
|
|
|
|
{
|
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2014-10-21 13:25:44 +04:00
|
|
|
unlink( csync->statedb.file);
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = csync_destroy(csync);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-09-01 16:53:26 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
*state = NULL;
|
|
|
|
}
|
2008-09-01 16:53:26 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void teardown_rm(void **state) {
|
|
|
|
int rc;
|
2008-09-01 16:53:26 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
teardown(state);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = system("rm -rf /tmp/check_csync");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = system("rm -rf /tmp/check_csync1");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = system("rm -rf /tmp/check_csync2");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
}
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* create a file stat, caller must free memory */
|
|
|
|
static csync_vio_file_stat_t* create_fstat(const char *name,
|
|
|
|
ino_t inode,
|
|
|
|
time_t mtime)
|
|
|
|
{
|
|
|
|
csync_vio_file_stat_t *fs = NULL;
|
|
|
|
time_t t;
|
|
|
|
|
|
|
|
fs = csync_vio_file_stat_new();
|
|
|
|
if (fs == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name && *name) {
|
|
|
|
fs->name = c_strdup(name);
|
|
|
|
} else {
|
|
|
|
fs->name = c_strdup("file.txt");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fs->name == NULL) {
|
|
|
|
csync_vio_file_stat_destroy(fs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fs->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;
|
|
|
|
|
|
|
|
fs->type = CSYNC_VIO_FILE_TYPE_REGULAR;
|
|
|
|
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
|
|
|
|
|
|
|
|
|
|
|
|
if (inode == 0) {
|
|
|
|
fs->inode = 619070;
|
|
|
|
} else {
|
|
|
|
fs->inode = inode;
|
|
|
|
}
|
|
|
|
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_INODE;
|
|
|
|
|
|
|
|
fs->device = 0;
|
|
|
|
|
|
|
|
fs->size = 157459;
|
|
|
|
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mtime == 0) {
|
|
|
|
fs->atime = fs->ctime = fs->mtime = time(&t);
|
|
|
|
} else {
|
|
|
|
fs->atime = fs->ctime = fs->mtime = mtime;
|
|
|
|
}
|
|
|
|
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ATIME;
|
|
|
|
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_CTIME;
|
|
|
|
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
|
|
|
|
|
|
|
|
return fs;
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int failing_fn(CSYNC *ctx,
|
2012-10-19 19:25:41 +04:00
|
|
|
const char *file,
|
|
|
|
const csync_vio_file_stat_t *fs,
|
|
|
|
enum csync_ftw_flags_e flag)
|
|
|
|
{
|
2008-08-01 17:58:28 +04:00
|
|
|
(void) ctx;
|
|
|
|
(void) file;
|
|
|
|
(void) fs;
|
|
|
|
(void) flag;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-09-01 16:53:26 +04:00
|
|
|
/* detect a new file */
|
2012-10-19 19:25:41 +04:00
|
|
|
static void check_csync_detect_update(void **state)
|
2008-08-01 17:58:28 +04:00
|
|
|
{
|
2012-10-19 19:25:41 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_file_stat_t *st;
|
|
|
|
csync_vio_file_stat_t *fs;
|
|
|
|
int rc;
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2015-07-02 11:04:20 +03:00
|
|
|
fs = create_fstat("file.txt", 0, 1217597845);
|
2012-10-19 19:25:41 +04:00
|
|
|
assert_non_null(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = _csync_detect_update(csync,
|
|
|
|
"/tmp/check_csync1/file.txt",
|
|
|
|
fs,
|
|
|
|
CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* the instruction should be set to new */
|
|
|
|
st = c_rbtree_node_data(csync->local.tree->root);
|
|
|
|
assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* create a statedb */
|
|
|
|
csync_set_status(csync, 0xFFFF);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
csync_vio_file_stat_destroy(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2013-07-04 11:42:42 +04:00
|
|
|
/* Test behaviour in case no db is there. For that its important that the
|
|
|
|
* test before this one uses teardown_rm.
|
|
|
|
*/
|
2012-10-19 19:25:41 +04:00
|
|
|
static void check_csync_detect_update_db_none(void **state)
|
2008-08-01 17:58:28 +04:00
|
|
|
{
|
2012-10-19 19:25:41 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_file_stat_t *st;
|
|
|
|
csync_vio_file_stat_t *fs;
|
|
|
|
int rc;
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2015-07-02 11:04:20 +03:00
|
|
|
fs = create_fstat("file.txt", 0, 1217597845);
|
2012-10-19 19:25:41 +04:00
|
|
|
assert_non_null(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = _csync_detect_update(csync,
|
|
|
|
"/tmp/check_csync1/file.txt",
|
|
|
|
fs,
|
|
|
|
CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* the instruction should be set to new */
|
|
|
|
st = c_rbtree_node_data(csync->local.tree->root);
|
2013-08-07 14:43:32 +04:00
|
|
|
assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* create a statedb */
|
|
|
|
csync_set_status(csync, 0xFFFF);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
csync_vio_file_stat_destroy(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void check_csync_detect_update_db_eval(void **state)
|
2008-08-01 17:58:28 +04:00
|
|
|
{
|
2012-10-19 19:25:41 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_file_stat_t *st;
|
|
|
|
csync_vio_file_stat_t *fs;
|
|
|
|
int rc;
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2015-07-02 11:04:20 +03:00
|
|
|
fs = create_fstat("file.txt", 0, 42);
|
2012-10-19 19:25:41 +04:00
|
|
|
assert_non_null(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = _csync_detect_update(csync,
|
|
|
|
"/tmp/check_csync1/file.txt",
|
|
|
|
fs,
|
|
|
|
CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* the instruction should be set to new */
|
|
|
|
st = c_rbtree_node_data(csync->local.tree->root);
|
2013-08-07 14:43:32 +04:00
|
|
|
assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* create a statedb */
|
|
|
|
csync_set_status(csync, 0xFFFF);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
csync_vio_file_stat_destroy(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2014-10-21 13:25:44 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void check_csync_detect_update_db_rename(void **state)
|
2008-08-01 17:58:28 +04:00
|
|
|
{
|
2012-10-19 19:25:41 +04:00
|
|
|
CSYNC *csync = *state;
|
2013-10-25 16:43:04 +04:00
|
|
|
// csync_file_stat_t *st;
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
csync_vio_file_stat_t *fs;
|
2013-10-23 19:51:56 +04:00
|
|
|
int rc = 0;
|
2013-06-07 19:15:15 +04:00
|
|
|
|
2015-07-02 11:04:20 +03:00
|
|
|
fs = create_fstat("wurst.txt", 0, 42);
|
2012-10-19 19:25:41 +04:00
|
|
|
assert_non_null(fs);
|
2013-06-07 19:15:15 +04:00
|
|
|
csync_set_statedb_exists(csync, 1);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = _csync_detect_update(csync,
|
|
|
|
"/tmp/check_csync1/wurst.txt",
|
|
|
|
fs,
|
|
|
|
CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* the instruction should be set to rename */
|
2013-10-25 16:43:04 +04:00
|
|
|
/*
|
|
|
|
* temporarily broken.
|
2012-10-19 19:25:41 +04:00
|
|
|
st = c_rbtree_node_data(csync->local.tree->root);
|
|
|
|
assert_int_equal(st->instruction, CSYNC_INSTRUCTION_RENAME);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
st->instruction = CSYNC_INSTRUCTION_UPDATED;
|
2013-10-25 16:43:04 +04:00
|
|
|
*/
|
2012-10-19 19:25:41 +04:00
|
|
|
/* create a statedb */
|
|
|
|
csync_set_status(csync, 0xFFFF);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
csync_vio_file_stat_destroy(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void check_csync_detect_update_db_new(void **state)
|
2008-08-01 17:58:28 +04:00
|
|
|
{
|
2012-10-19 19:25:41 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_file_stat_t *st;
|
|
|
|
csync_vio_file_stat_t *fs;
|
|
|
|
int rc;
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2015-07-02 11:04:20 +03:00
|
|
|
fs = create_fstat("file.txt", 42000, 0);
|
2012-10-19 19:25:41 +04:00
|
|
|
assert_non_null(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = _csync_detect_update(csync,
|
|
|
|
"/tmp/check_csync1/file.txt",
|
|
|
|
fs,
|
|
|
|
CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* the instruction should be set to new */
|
|
|
|
st = c_rbtree_node_data(csync->local.tree->root);
|
|
|
|
assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
/* create a statedb */
|
|
|
|
csync_set_status(csync, 0xFFFF);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
csync_vio_file_stat_destroy(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void check_csync_detect_update_null(void **state)
|
2008-08-01 17:58:28 +04:00
|
|
|
{
|
2012-10-19 19:25:41 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_file_stat_t *fs;
|
|
|
|
int rc;
|
2008-09-01 16:53:26 +04:00
|
|
|
|
2015-07-02 11:04:20 +03:00
|
|
|
fs = create_fstat("file.txt", 0, 0);
|
2012-10-19 19:25:41 +04:00
|
|
|
assert_non_null(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = _csync_detect_update(csync,
|
|
|
|
NULL,
|
|
|
|
fs,
|
|
|
|
CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = _csync_detect_update(csync,
|
|
|
|
"/tmp/check_csync1/file.txt",
|
|
|
|
NULL,
|
|
|
|
CSYNC_FTW_TYPE_FILE);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
csync_vio_file_stat_destroy(fs);
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void check_csync_ftw(void **state)
|
2008-08-01 17:58:28 +04:00
|
|
|
{
|
2012-10-19 19:25:41 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = csync_ftw(csync, "/tmp", csync_walker, MAX_DEPTH);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void check_csync_ftw_empty_uri(void **state)
|
2008-08-01 17:58:28 +04:00
|
|
|
{
|
2012-10-19 19:25:41 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = csync_ftw(csync, "", csync_walker, MAX_DEPTH);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
static void check_csync_ftw_failing_fn(void **state)
|
2008-08-01 17:58:28 +04:00
|
|
|
{
|
2012-10-19 19:25:41 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
rc = csync_ftw(csync, "/tmp", failing_fn, MAX_DEPTH);
|
|
|
|
assert_int_equal(rc, -1);
|
|
|
|
}
|
2008-08-01 17:58:28 +04:00
|
|
|
|
2012-10-19 19:25:41 +04:00
|
|
|
int torture_run_tests(void)
|
|
|
|
{
|
|
|
|
const UnitTest tests[] = {
|
2013-07-04 11:42:42 +04:00
|
|
|
unit_test_setup_teardown(check_csync_detect_update, setup, teardown_rm),
|
2012-10-19 19:25:41 +04:00
|
|
|
unit_test_setup_teardown(check_csync_detect_update_db_none, setup, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_detect_update_db_eval, setup, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_detect_update_db_rename, setup, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_detect_update_db_new, setup, teardown_rm),
|
|
|
|
unit_test_setup_teardown(check_csync_detect_update_null, setup, teardown_rm),
|
|
|
|
|
|
|
|
unit_test_setup_teardown(check_csync_ftw, setup_ftw, teardown_rm),
|
|
|
|
unit_test_setup_teardown(check_csync_ftw_empty_uri, setup_ftw, teardown_rm),
|
2013-07-24 18:02:51 +04:00
|
|
|
unit_test_setup_teardown(check_csync_ftw_failing_fn, setup_ftw, teardown_rm),
|
2012-10-19 19:25:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
return run_tests(tests);
|
2008-08-01 17:58:28 +04:00
|
|
|
}
|
|
|
|
|