nextcloud-desktop/tests/csync_tests/check_csync_treewalk.c
Olivier Goffart b5ed352aa3 Merge remote-tracking branch 'origin/master' into ocsync
Only confluct resolution, do not compile or works

Conflicts:
	CMakeLists.txt
	CPackConfig.cmake
	ConfigureChecks.cmake
	client/csync_client.c
	cmake/Modules/DefineCompilerFlags.cmake
	cmake/Modules/DefineInstallationPaths.cmake
	cmake/Modules/FindIconv.cmake
	cmake/Modules/FindIniparser.cmake
	cmake/Modules/FindNeon.cmake
	config.h.cmake
	config/CMakeLists.txt
	config/ocsync.conf
	doc/CMakeLists.txt
	modules/csync_owncloud.c
	modules/csync_sftp2.c
	src/CMakeLists.txt
	src/csync.c
	src/csync.h
	src/csync_config.c
	src/csync_exclude.c
	src/csync_lock.c
	src/csync_macros.h
	src/csync_misc.c
	src/csync_misc.h
	src/csync_private.h
	src/csync_propagate.c
	src/csync_statedb.c
	src/csync_statedb.h
	src/csync_update.c
	src/csync_util.c
	src/csync_util.h
	src/std/c_dir.c
	src/std/c_file.c
	src/std/c_private.h
	src/std/c_string.c
	src/std/c_string.h
	src/std/c_time.c
	src/vio/csync_vio.c
	src/vio/csync_vio.h
	src/vio/csync_vio_file_stat.h
	src/vio/csync_vio_local.c
	src/vio/csync_vio_method.h
	tests/CMakeLists.txt
	tests/csync_tests/check_csync_statedb_load.c
	tests/csync_tests/check_csync_statedb_query.c
	tests/csync_tests/check_csync_treewalk.c
	tests/csync_tests/check_csync_update.c
	tests/ownCloud/HTTP/DAV.pm
	tests/ownCloud/ownCloud/Test.pm
	tests/std_tests/check_std_c_str.c
	tests/vio_tests/check_vio.c
2013-08-18 16:21:18 +02:00

194 lines
4.7 KiB
C

#define _GNU_SOURCE /* asprintf */
#include <string.h>
#include "support.h"
#include "torture.h"
#define CSYNC_TEST 1
#include "csync_config.c"
static void setup_local(void **state) {
CSYNC *csync;
int rc;
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 = system("mkdir -p /tmp/check_csync");
assert_int_equal(rc, 0);
rc = system("echo \"This is test data\" > /tmp/check_csync1/testfile1.txt");
assert_int_equal(rc, 0);
rc = system("echo \"This is also test data\" > /tmp/check_csync1/testfile2.txt");
assert_int_equal(rc, 0);
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
assert_int_equal(rc, 0);
rc = csync_set_config_dir(csync, "/tmp/check_csync/");
assert_int_equal(rc, 0);
rc = csync_init(csync);
assert_int_equal(rc, 0);
*state = csync;
}
static void teardown_local(void **state) {
CSYNC *csync = (CSYNC *)*state;
csync_destroy(csync);
system("rm -rf /tmp/check_csync1");
system("rm -rf /tmp/check_csync2");
system("rm -rf /tmp/check_csync");
}
static void setup_remote(void **state) {
CSYNC *csync = (CSYNC *)*state;
int rc;
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 = system("echo \"This is test data\" > /tmp/check_csync1/testfile1.txt");
assert_int_equal(rc, 0);
rc = system("echo \"This is also test data\" > /tmp/check_csync1/testfile2.txt");
assert_int_equal(rc, 0);
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
assert_int_equal(rc, 0);
rc = csync_set_config_dir(csync, "/tmp/check_csync/");
assert_int_equal(rc, 0);
rc = csync_init(csync);
assert_int_equal(rc, 0);
rc = csync_update(csync);
assert_int_equal(rc, 0);
rc = csync_reconcile(csync);
assert_int_equal(rc, 0);
rc = csync_propagate(csync);
assert_int_equal(rc, 0);
*state = csync;
}
static void teardown_remote(void **state) {
CSYNC *csync = (CSYNC *)*state;
csync_destroy(csync);
system("rm -rf /tmp/check_csync1");
system("rm -rf /tmp/check_csync2");
}
static int visitor(TREE_WALK_FILE* file, void *userdata)
{
int *file_count;
assert_non_null(userdata);
assert_non_null(file);
file_count = (int *)userdata;
(*file_count)++;
return 0;
}
static void check_csync_treewalk_local(void **state)
{
CSYNC *csync = (CSYNC *)*state;
int file_count = 0;
int rc;
csync_set_userdata(csync, (void *)&file_count);
rc = csync_walk_local_tree(csync, &visitor, 0);
assert_int_equal(rc, 0);
assert_int_equal(file_count, 0);
rc = csync_update(csync);
assert_int_equal(rc, 0);
rc = csync_walk_local_tree(csync, &visitor, 0);
assert_int_equal(rc, 0);
assert_int_equal(file_count, 2);
}
static void check_csync_treewalk_remote(void **state)
{
CSYNC *csync = (CSYNC *)*state;
int file_count = 0;
int rc;
csync_set_userdata(csync, &file_count);
assert_non_null(csync->remote.tree);
rc = csync_walk_remote_tree(csync, &visitor, 0);
assert_int_equal(rc, 0);
assert_int_equal(file_count, 0);
/* reconcile doesn't update the tree */
rc = csync_update(csync);
assert_int_equal(rc, 0);
rc = csync_walk_remote_tree(csync, &visitor, 0);
assert_int_equal(rc, 0);
assert_int_equal(file_count, 2);
}
static void check_csync_treewalk_local_with_filter(void **state)
{
CSYNC *csync = (CSYNC *)*state;
int file_count = 0;
int rc;
csync_set_userdata(csync, &file_count);
rc = csync_walk_local_tree(csync, &visitor, 0);
assert_int_equal(rc, 0);
assert_int_equal(file_count, 0);
rc = csync_update(csync);
assert_int_equal(rc, 0);
rc = csync_walk_local_tree(csync, &visitor, CSYNC_INSTRUCTION_NEW);
assert_int_equal(rc, 0);
assert_int_equal(file_count, 2 );
file_count = 0;
rc = csync_walk_local_tree(csync,
&visitor,
CSYNC_INSTRUCTION_NEW|CSYNC_INSTRUCTION_REMOVE);
assert_int_equal(rc, 0);
assert_int_equal(file_count, 2);
file_count = 0;
rc = csync_walk_local_tree(csync, &visitor, CSYNC_INSTRUCTION_RENAME);
assert_int_equal(rc, 0);
assert_int_equal(file_count, 0);
}
int torture_run_tests(void)
{
const UnitTest tests[] = {
unit_test_setup_teardown(check_csync_treewalk_local, setup_local, teardown_local ),
unit_test_setup_teardown(check_csync_treewalk_remote, setup_remote, teardown_remote),
unit_test_setup_teardown(check_csync_treewalk_local_with_filter, setup_local, teardown_local)
};
return run_tests(tests);
}