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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
* 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
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "torture.h"
#include "csync.h"
#include "csync_log.c"
#include "c_private.h"
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);
csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
*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;
}
static void check_log_callback(int verbosity,
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);
}
static void check_set_log_level(void **state)
{
int rc;
(void) state;
rc = csync_set_log_level(-5);
assert_int_equal(rc, -1);
rc = csync_set_log_level(5);
assert_int_equal(rc, 0);
rc = csync_get_log_level();
assert_int_equal(rc, 5);
}
static void check_set_auth_callback(void **state)
{
csync_log_callback log_fn;
int rc;
(void) state;
rc = csync_set_log_callback(NULL);
assert_int_equal(rc, -1);
rc = csync_set_log_callback(check_log_callback);
assert_int_equal(rc, 0);
log_fn = csync_get_log_callback();
assert_non_null(log_fn);
assert_true(log_fn == &check_log_callback);
}
static void check_logging(void **state)
{
int rc;
csync_stat_t sb;
mbchar_t *path;
path = c_utf8_path_to_locale("/tmp/check_csync1/cb_called");
(void) state; /* unused */
assert_non_null(path);
rc = csync_set_log_level(1);
assert_int_equal(rc, 0);
rc = csync_set_log_callback(check_log_callback);
assert_int_equal(rc, 0);
csync_log(1, __func__, "rc = %d", rc);
rc = _tstat(path, &sb);
c_free_locale_string(path);
assert_int_equal(rc, 0);
}
int torture_run_tests(void)
{
const UnitTest tests[] = {
unit_test(check_set_log_level),
unit_test(check_set_auth_callback),
unit_test_setup_teardown(check_logging, setup, teardown),
};
return run_tests(tests);
}
|