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-30 14:26:58 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "torture.h"
|
|
|
|
|
|
|
|
#include "csync.h"
|
|
|
|
#include "csync_log.c"
|
2013-02-07 14:41:46 +04:00
|
|
|
#include "c_private.h"
|
2012-10-30 14:26:58 +04:00
|
|
|
|
|
|
|
static void setup(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 = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
|
|
|
*state = csync;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void teardown(void **state) {
|
|
|
|
CSYNC *csync = *state;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = csync_destroy(csync);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
*state = NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-01 13:06:06 +04:00
|
|
|
static void check_log_callback(int verbosity,
|
2012-10-30 14:26:58 +04:00
|
|
|
const char *function,
|
|
|
|
const char *buffer,
|
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
assert_true(verbosity >= 0);
|
|
|
|
assert_non_null(function);
|
|
|
|
assert_false(function[0] == '\0');
|
|
|
|
assert_non_null(buffer);
|
|
|
|
assert_false(buffer[0] == '\0');
|
|
|
|
|
|
|
|
(void) userdata; /* unused */
|
|
|
|
|
|
|
|
rc = system("touch /tmp/check_csync1/cb_called");
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
}
|
|
|
|
|
2012-12-17 12:40:17 +04:00
|
|
|
static void check_set_log_level(void **state)
|
2012-10-30 14:26:58 +04:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2012-12-17 12:40:17 +04:00
|
|
|
(void) state;
|
2012-10-30 14:26:58 +04:00
|
|
|
|
2012-12-17 12:40:17 +04:00
|
|
|
rc = csync_set_log_level(-5);
|
2012-10-30 14:26:58 +04:00
|
|
|
assert_int_equal(rc, -1);
|
|
|
|
|
2012-12-17 12:40:17 +04:00
|
|
|
rc = csync_set_log_level(5);
|
2012-10-30 14:26:58 +04:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2012-12-17 12:40:17 +04:00
|
|
|
rc = csync_get_log_level();
|
2012-10-30 14:26:58 +04:00
|
|
|
assert_int_equal(rc, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_set_auth_callback(void **state)
|
|
|
|
{
|
|
|
|
csync_log_callback log_fn;
|
|
|
|
int rc;
|
|
|
|
|
2012-12-18 17:25:35 +04:00
|
|
|
(void) state;
|
|
|
|
|
|
|
|
rc = csync_set_log_callback(NULL);
|
2012-10-30 14:26:58 +04:00
|
|
|
assert_int_equal(rc, -1);
|
|
|
|
|
2012-12-18 17:25:35 +04:00
|
|
|
rc = csync_set_log_callback(check_log_callback);
|
2012-10-30 14:26:58 +04:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2012-12-18 17:25:35 +04:00
|
|
|
log_fn = csync_get_log_callback();
|
2012-10-30 14:26:58 +04:00
|
|
|
assert_non_null(log_fn);
|
|
|
|
assert_true(log_fn == &check_log_callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_logging(void **state)
|
|
|
|
{
|
|
|
|
int rc;
|
2013-02-07 14:41:46 +04:00
|
|
|
csync_stat_t sb;
|
|
|
|
mbchar_t *path;
|
|
|
|
path = c_utf8_to_locale("/tmp/check_csync1/cb_called");
|
|
|
|
|
2013-03-01 13:06:06 +04:00
|
|
|
(void) state; /* unused */
|
|
|
|
|
2013-02-07 14:41:46 +04:00
|
|
|
assert_non_null(path);
|
2012-10-30 14:26:58 +04:00
|
|
|
|
2012-12-17 12:40:17 +04:00
|
|
|
rc = csync_set_log_level(1);
|
2012-10-30 14:26:58 +04:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2012-12-18 17:25:35 +04:00
|
|
|
rc = csync_set_log_callback(check_log_callback);
|
2012-10-30 14:26:58 +04:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2013-03-01 13:06:06 +04:00
|
|
|
csync_log(1, __FUNCTION__, "rc = %d", rc);
|
2012-10-30 14:26:58 +04:00
|
|
|
|
2013-02-07 14:41:46 +04:00
|
|
|
rc = _tstat(path, &sb);
|
|
|
|
|
|
|
|
c_free_locale_string(path);
|
|
|
|
|
2012-10-30 14:26:58 +04:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int torture_run_tests(void)
|
|
|
|
{
|
|
|
|
const UnitTest tests[] = {
|
2012-12-17 12:40:17 +04:00
|
|
|
unit_test(check_set_log_level),
|
2012-12-18 17:25:35 +04:00
|
|
|
unit_test(check_set_auth_callback),
|
2012-10-30 14:26:58 +04:00
|
|
|
unit_test_setup_teardown(check_logging, setup, teardown),
|
|
|
|
};
|
|
|
|
|
|
|
|
return run_tests(tests);
|
|
|
|
}
|