2008-04-25 19:13:27 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2008-04-21 11:45:55 +04:00
|
|
|
#include <string.h>
|
2008-04-25 19:13:27 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2008-04-21 11:45:55 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
#include "torture.h"
|
2008-04-21 11:45:55 +04:00
|
|
|
|
|
|
|
#include "csync_private.h"
|
|
|
|
#include "vio/csync_vio.h"
|
|
|
|
|
2008-04-25 19:13:27 +04:00
|
|
|
#define CSYNC_TEST_DIR "/tmp/csync/"
|
2008-05-19 19:05:39 +04:00
|
|
|
#define CSYNC_TEST_DIRS "/tmp/csync/this/is/a/mkdirs/test"
|
2008-04-25 19:13:27 +04:00
|
|
|
#define CSYNC_TEST_FILE "/tmp/csync/file.txt"
|
|
|
|
|
2013-03-14 17:29:31 +04:00
|
|
|
#define WD_BUFFER_SIZE 255
|
|
|
|
|
|
|
|
static char wd_buffer[WD_BUFFER_SIZE];
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void setup(void **state)
|
|
|
|
{
|
|
|
|
CSYNC *csync;
|
|
|
|
int rc;
|
2008-04-21 11:45:55 +04:00
|
|
|
|
2013-03-14 17:29:31 +04:00
|
|
|
assert_non_null(getcwd(wd_buffer, WD_BUFFER_SIZE));
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = system("rm -rf /tmp/csync/");
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_create(&csync, "/tmp/csync1", "/tmp/csync2");
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
csync->replica = LOCAL_REPLICA;
|
|
|
|
|
|
|
|
*state = csync;
|
2008-04-21 11:45:55 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void setup_dir(void **state) {
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
setup(state);
|
|
|
|
|
|
|
|
rc = mkdir(CSYNC_TEST_DIR, 0755);
|
|
|
|
assert_int_equal(rc, 0);
|
2013-03-14 17:29:31 +04:00
|
|
|
|
|
|
|
assert_non_null(getcwd(wd_buffer, WD_BUFFER_SIZE));
|
|
|
|
|
|
|
|
rc = chdir(CSYNC_TEST_DIR);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-21 11:45:55 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void setup_file(void **state) {
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
setup_dir(state);
|
|
|
|
|
|
|
|
rc = system("echo \"This is a test\" > /tmp/csync/file.txt");
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void teardown(void **state) {
|
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = csync_destroy(csync);
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2013-03-14 17:29:31 +04:00
|
|
|
rc = chdir(wd_buffer);
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = system("rm -rf /tmp/csync/");
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
*state = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_csync_vio_load(void **state)
|
2008-04-21 11:45:55 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
|
|
|
|
2012-11-23 15:51:01 +04:00
|
|
|
rc = csync_vio_init(csync, "owncloud", NULL);
|
2012-10-19 20:14:28 +04:00
|
|
|
assert_int_equal(rc, 0);
|
2008-04-21 11:45:55 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
csync_vio_shutdown(csync);
|
2008-04-21 11:45:55 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_load_wrong_proto(void **state)
|
2008-08-06 20:14:34 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
2008-08-06 20:14:34 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_init(csync, "wrong", NULL);
|
|
|
|
assert_int_equal(rc, -1);
|
|
|
|
|
|
|
|
csync_vio_shutdown(csync);
|
2008-08-06 20:14:34 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_load_bad_plugin(void **state)
|
2008-08-06 20:14:34 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = csync_vio_init(csync, "bad", NULL);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-08-06 20:14:34 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
csync_vio_shutdown(csync);
|
2008-08-06 20:14:34 +04:00
|
|
|
}
|
|
|
|
|
2008-04-25 19:13:27 +04:00
|
|
|
/*
|
|
|
|
* Test directory function
|
|
|
|
*/
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_mkdir(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
struct stat sb;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_mkdir(csync, CSYNC_TEST_DIR, 0755);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = lstat(CSYNC_TEST_DIR, &sb);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_mkdirs(void **state)
|
2008-05-19 19:05:39 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
struct stat sb;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = csync_vio_mkdirs(csync, CSYNC_TEST_DIRS, 0755);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-05-19 19:05:39 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = lstat(CSYNC_TEST_DIRS, &sb);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-05-19 19:05:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_mkdirs_some_exist(void **state)
|
2008-05-19 19:05:39 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
struct stat sb;
|
|
|
|
int rc;
|
2008-05-19 19:05:39 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = mkdir("/tmp/csync/this", 0755);
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
rc = csync_vio_mkdirs(csync, CSYNC_TEST_DIRS, 0755);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-05-19 19:05:39 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = lstat(CSYNC_TEST_DIRS, &sb);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-05-19 19:05:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_rmdir(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
struct stat sb;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = csync_vio_mkdir(csync, CSYNC_TEST_DIR, 0755);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = lstat(CSYNC_TEST_DIR, &sb);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_rmdir(csync, CSYNC_TEST_DIR);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = lstat(CSYNC_TEST_DIR, &sb);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_opendir(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_method_handle_t *dh;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
dh = csync_vio_opendir(csync, CSYNC_TEST_DIR);
|
|
|
|
assert_non_null(dh);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_closedir(csync, dh);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_opendir_perm(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_method_handle_t *dh;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = mkdir(CSYNC_TEST_DIR, 0200);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
dh = csync_vio_opendir(csync, CSYNC_TEST_DIR);
|
|
|
|
assert_null(dh);
|
|
|
|
assert_int_equal(errno, EACCES);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_closedir_null(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = csync_vio_closedir(csync, NULL);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_readdir(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_method_handle_t *dh;
|
|
|
|
csync_vio_file_stat_t *dirent;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
dh = csync_vio_opendir(csync, CSYNC_TEST_DIR);
|
|
|
|
assert_non_null(dh);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
dirent = csync_vio_readdir(csync, dh);
|
|
|
|
assert_non_null(dirent);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
csync_vio_file_stat_destroy(dirent);
|
|
|
|
rc = csync_vio_closedir(csync, dh);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test file functions (open, read, write, close ...)
|
|
|
|
*/
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_close_null(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = csync_vio_close(csync, NULL);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_creat_close(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_method_handle_t *fh;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
fh = csync_vio_creat(csync, CSYNC_TEST_FILE, 0644);
|
|
|
|
assert_non_null(fh);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_close(csync, fh);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_open_close(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_method_handle_t *fh;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
fh = csync_vio_open(csync, CSYNC_TEST_FILE, O_RDONLY, 0644);
|
|
|
|
assert_non_null(fh);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_close(csync, fh);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_read_null(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
char test[16] = {0};
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_read(csync, NULL, test, 10);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_read(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_method_handle_t *fh;
|
|
|
|
char test[16] = {0};
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
fh = csync_vio_open(csync, CSYNC_TEST_FILE, O_RDONLY, 0644);
|
|
|
|
assert_non_null(fh);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_read(csync, fh, test, 14);
|
|
|
|
assert_int_equal(rc, 14);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
assert_string_equal(test, "This is a test");
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_close(csync, fh);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_read_0(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_method_handle_t *fh = NULL;
|
|
|
|
char test[16] = {0};
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
fh = csync_vio_open(csync, CSYNC_TEST_FILE, O_RDONLY, 0644);
|
|
|
|
assert_non_null(fh);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_read(csync, fh, test, 0);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
assert_true(test[0] == '\0');
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_close(csync, fh);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_write_null(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
char test[16] = {0};
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_write(csync, NULL, test, 10);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_write(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_method_handle_t *fh;
|
|
|
|
char str[] = "This is a test";
|
|
|
|
char test[16] = {0};
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
fh = csync_vio_creat(csync, CSYNC_TEST_FILE, 0644);
|
|
|
|
assert_non_null(fh);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_write(csync, fh, str, sizeof(str));
|
|
|
|
assert_int_equal(rc, sizeof(str));
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_close(csync, fh);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
fh = csync_vio_open(csync, CSYNC_TEST_FILE, O_RDONLY, 0644);
|
|
|
|
assert_non_null(fh);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_read(csync, fh, test, 14);
|
|
|
|
assert_int_equal(rc, 14);
|
|
|
|
|
|
|
|
assert_string_equal(test, "This is a test");
|
|
|
|
|
|
|
|
rc = csync_vio_close(csync, fh);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_lseek(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_method_handle_t *fh;
|
|
|
|
char test[16] = {0};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
fh = csync_vio_open(csync, CSYNC_TEST_FILE, O_RDONLY, 0644);
|
|
|
|
assert_non_null(fh);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_lseek(csync, fh, 10, SEEK_SET);
|
|
|
|
assert_int_equal(rc, 10);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_read(csync, fh, test, 4);
|
|
|
|
assert_int_equal(rc, 4);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
assert_string_equal(test, "test");
|
|
|
|
|
|
|
|
rc = csync_vio_close(csync, fh);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test for general functions (stat, chmod, chown, ...)
|
|
|
|
*/
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_stat_dir(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_file_stat_t *fs;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
fs = csync_vio_file_stat_new();
|
|
|
|
assert_non_null(fs);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_stat(csync, CSYNC_TEST_DIR, fs);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
assert_string_equal(fs->name, "csync");
|
|
|
|
assert_int_equal(fs->type, CSYNC_VIO_FILE_TYPE_DIRECTORY);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
csync_vio_file_stat_destroy(fs);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_stat_file(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
csync_vio_file_stat_t *fs;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
fs = csync_vio_file_stat_new();
|
|
|
|
assert_non_null(fs);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_stat(csync, CSYNC_TEST_FILE, fs);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
assert_string_equal(fs->name, "file.txt");
|
|
|
|
assert_int_equal(fs->type, CSYNC_VIO_FILE_TYPE_REGULAR);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
csync_vio_file_stat_destroy(fs);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_rename_dir(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
struct stat sb;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = mkdir("test", 0755);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_rename(csync, "test", "test2");
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = lstat("test2", &sb);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_rename_file(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
struct stat sb;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_rename(csync, CSYNC_TEST_FILE, CSYNC_TEST_DIR "file2.txt");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
|
|
|
rc = lstat(CSYNC_TEST_DIR "file2.txt", &sb);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_unlink(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
struct stat sb;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_unlink(csync, CSYNC_TEST_FILE);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = lstat(CSYNC_TEST_FILE, &sb);
|
|
|
|
assert_int_equal(rc, -1);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_chmod(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = csync_vio_chmod(csync, CSYNC_TEST_FILE, 0777);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_chown(void **state)
|
2008-04-25 19:13:27 +04:00
|
|
|
{
|
2012-10-19 20:14:28 +04:00
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_chown(csync, CSYNC_TEST_FILE, getuid(), getgid());
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
static void check_csync_vio_utimes(void **state)
|
|
|
|
{
|
|
|
|
CSYNC *csync = *state;
|
|
|
|
struct stat sb;
|
|
|
|
struct timeval times[2];
|
|
|
|
long modtime = 0;
|
|
|
|
int rc;
|
2008-04-21 11:45:55 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = lstat(CSYNC_TEST_FILE, &sb);
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
modtime = sb.st_mtime + 10;
|
2008-04-21 11:45:55 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
times[0].tv_sec = modtime;
|
|
|
|
times[0].tv_usec = 0;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
times[1].tv_sec = modtime;
|
|
|
|
times[1].tv_usec = 0;
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = csync_vio_utimes(csync, CSYNC_TEST_FILE, times);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
rc = lstat(CSYNC_TEST_FILE, &sb);
|
|
|
|
assert_int_equal(rc, 0);
|
2008-04-25 19:13:27 +04:00
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
assert_int_equal(modtime, sb.st_mtime);
|
2008-04-21 11:45:55 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:14:28 +04:00
|
|
|
int torture_run_tests(void)
|
|
|
|
{
|
|
|
|
const UnitTest tests[] = {
|
|
|
|
unit_test_setup_teardown(check_csync_vio_load, setup, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_load_wrong_proto, setup, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_load_bad_plugin, setup, teardown),
|
|
|
|
|
|
|
|
unit_test_setup_teardown(check_csync_vio_mkdir, setup, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_mkdirs, setup, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_mkdirs_some_exist, setup_dir, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_rmdir, setup, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_opendir, setup_dir, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_opendir_perm, setup, teardown),
|
|
|
|
unit_test(check_csync_vio_closedir_null),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_readdir, setup_dir, teardown),
|
|
|
|
|
|
|
|
unit_test_setup_teardown(check_csync_vio_close_null, setup_dir, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_creat_close, setup_dir, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_open_close, setup_file, teardown),
|
|
|
|
unit_test(check_csync_vio_read_null),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_read, setup_file, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_read_0, setup_file, teardown),
|
|
|
|
unit_test(check_csync_vio_write_null),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_write, setup_dir, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_lseek, setup_file, teardown),
|
|
|
|
|
|
|
|
unit_test_setup_teardown(check_csync_vio_stat_dir, setup_dir, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_stat_file, setup_file, teardown),
|
|
|
|
|
|
|
|
unit_test_setup_teardown(check_csync_vio_rename_dir, setup_dir, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_rename_file, setup_file, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_unlink, setup_file, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_chmod, setup_file, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_chown, setup_file, teardown),
|
|
|
|
unit_test_setup_teardown(check_csync_vio_utimes, setup_file, teardown),
|
|
|
|
};
|
|
|
|
|
|
|
|
return run_tests(tests);
|
2008-04-21 11:45:55 +04:00
|
|
|
}
|
|
|
|
|