From 4e5898efd76201b104112154be8eca6b2c36a39f Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Mon, 14 Aug 2017 16:19:52 +0200 Subject: [PATCH] Compile almost all of csync as C++ This will allow us to unify data structures between csync and libsync. Utility functions like csync_time and c_std are still compiled as C since we won't need to be coupled with Qt in the short term. --- .../tests/csync_tests/check_csync_update.cpp | 460 ++++++++++++++++++ src/csync/CMakeLists.txt | 24 +- src/csync/{csync.c => csync.cpp} | 4 +- src/csync/csync.h | 10 +- .../{csync_exclude.c => csync_exclude.cpp} | 9 +- src/csync/{csync_log.c => csync_log.cpp} | 0 src/csync/{csync_misc.c => csync_misc.cpp} | 2 +- src/csync/csync_private.h | 2 +- ...{csync_reconcile.c => csync_reconcile.cpp} | 2 + src/csync/csync_rename.cpp | 5 - src/csync/csync_rename.h | 8 - .../{csync_statedb.c => csync_statedb.cpp} | 9 +- src/csync/csync_statedb.h | 8 - src/csync/csync_time.c | 2 + src/csync/csync_time.h | 8 + .../{csync_update.c => csync_update.cpp} | 17 +- src/csync/csync_update.h | 5 +- src/csync/{csync_util.c => csync_util.cpp} | 1 + src/csync/csync_version.h.in | 8 - src/csync/std/asprintf.h | 8 + src/csync/std/c_alloc.h | 9 + src/csync/std/c_path.h | 9 + src/csync/std/c_rbtree.h | 9 + src/csync/std/c_string.h | 9 + src/csync/std/c_time.c | 4 - src/csync/std/c_time.h | 12 + src/csync/vio/{csync_vio.c => csync_vio.cpp} | 0 ...io_file_stat.c => csync_vio_file_stat.cpp} | 0 ..._local_unix.c => csync_vio_local_unix.cpp} | 5 +- ...io_local_win.c => csync_vio_local_win.cpp} | 4 +- src/libsync/excludedfiles.cpp | 2 - src/libsync/excludedfiles.h | 2 - src/libsync/filesystem.cpp | 3 - src/libsync/owncloudpropagator.h | 3 +- src/libsync/syncjournaldb.cpp | 2 - test/csync/CMakeLists.txt | 30 +- ..._csync_commit.c => check_csync_commit.cpp} | 6 +- ..._csync_create.c => check_csync_create.cpp} | 0 ...sync_exclude.c => check_csync_exclude.cpp} | 18 +- ...heck_csync_init.c => check_csync_init.cpp} | 4 +- ...{check_csync_log.c => check_csync_log.cpp} | 4 +- ...heck_csync_misc.c => check_csync_misc.cpp} | 0 ...db_load.c => check_csync_statedb_load.cpp} | 8 +- ..._query.c => check_csync_statedb_query.cpp} | 20 +- ..._csync_update.c => check_csync_update.cpp} | 35 +- ...heck_csync_util.c => check_csync_util.cpp} | 2 +- .../{check_encoding.c => check_encoding.cpp} | 0 .../log_tests/{check_log.c => check_log.cpp} | 0 test/csync/torture.h | 8 + .../vio_tests/{check_vio.c => check_vio.cpp} | 11 +- .../{check_vio_ext.c => check_vio_ext.cpp} | 10 +- ...io_file_stat.c => check_vio_file_stat.cpp} | 0 52 files changed, 654 insertions(+), 167 deletions(-) create mode 100644 csync/tests/csync_tests/check_csync_update.cpp rename src/csync/{csync.c => csync.cpp} (99%) rename src/csync/{csync_exclude.c => csync_exclude.cpp} (98%) rename src/csync/{csync_log.c => csync_log.cpp} (100%) rename src/csync/{csync_misc.c => csync_misc.cpp} (99%) rename src/csync/{csync_reconcile.c => csync_reconcile.cpp} (99%) rename src/csync/{csync_statedb.c => csync_statedb.cpp} (98%) rename src/csync/{csync_update.c => csync_update.cpp} (99%) rename src/csync/{csync_util.c => csync_util.cpp} (99%) rename src/csync/vio/{csync_vio.c => csync_vio.cpp} (100%) rename src/csync/vio/{csync_vio_file_stat.c => csync_vio_file_stat.cpp} (100%) rename src/csync/vio/{csync_vio_local_unix.c => csync_vio_local_unix.cpp} (99%) rename src/csync/vio/{csync_vio_local_win.c => csync_vio_local_win.cpp} (98%) rename test/csync/csync_tests/{check_csync_commit.c => check_csync_commit.cpp} (95%) rename test/csync/csync_tests/{check_csync_create.c => check_csync_create.cpp} (100%) rename test/csync/csync_tests/{check_csync_exclude.c => check_csync_exclude.cpp} (98%) rename test/csync/csync_tests/{check_csync_init.c => check_csync_init.cpp} (96%) rename test/csync/csync_tests/{check_csync_log.c => check_csync_log.cpp} (98%) rename test/csync/csync_tests/{check_csync_misc.c => check_csync_misc.cpp} (100%) rename test/csync/csync_tests/{check_csync_statedb_load.c => check_csync_statedb_load.cpp} (95%) rename test/csync/csync_tests/{check_csync_statedb_query.c => check_csync_statedb_query.cpp} (93%) rename test/csync/csync_tests/{check_csync_update.c => check_csync_update.cpp} (94%) rename test/csync/csync_tests/{check_csync_util.c => check_csync_util.cpp} (95%) rename test/csync/encoding_tests/{check_encoding.c => check_encoding.cpp} (100%) rename test/csync/log_tests/{check_log.c => check_log.cpp} (100%) rename test/csync/vio_tests/{check_vio.c => check_vio.cpp} (95%) rename test/csync/vio_tests/{check_vio_ext.c => check_vio_ext.cpp} (98%) rename test/csync/vio_tests/{check_vio_file_stat.c => check_vio_file_stat.cpp} (100%) diff --git a/csync/tests/csync_tests/check_csync_update.cpp b/csync/tests/csync_tests/check_csync_update.cpp new file mode 100644 index 000000000..cc11bad83 --- /dev/null +++ b/csync/tests/csync_tests/check_csync_update.cpp @@ -0,0 +1,460 @@ +/* + * libcsync -- a library to sync a directory with another + * + * Copyright (c) 2008-2013 by Andreas Schneider + * + * 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 "csync_update.cpp" + +extern "C" { + +#include "torture.h" + +#define TESTDB "/tmp/check_csync/journal.db" + +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)," + "fileid VARCHAR(128)," + "remotePerm VARCHAR(128)," + "filesize BIGINT," + "ignoredChildrenRemote INT," + "contentChecksum TEXT," + "contentChecksumTypeId INTEGER," + "PRIMARY KEY(phash));"; + + rc = sqlite3_exec(db, sql, NULL, NULL, NULL); + //const char *msg = sqlite3_errmsg(db); + assert_int_equal( rc, SQLITE_OK ); + + sql = "CREATE TABLE IF NOT EXISTS checksumtype(" + "id INTEGER PRIMARY KEY," + "name TEXT UNIQUE" + ");"; + rc = sqlite3_exec(db, sql, NULL, NULL, NULL); + 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 ); + } +} + +static int setup(void **state) +{ + CSYNC *csync; + int rc; + + unlink(TESTDB); + rc = system("mkdir -p /tmp/check_csync"); + assert_int_equal(rc, 0); + rc = system("mkdir -p /tmp/check_csync1"); + assert_int_equal(rc, 0); + csync_create(&csync, "/tmp/check_csync1"); + csync_init(csync, TESTDB); + + /* 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); + + rc = csync_statedb_load(csync, TESTDB, &csync->statedb.db); + assert_int_equal(rc, 0); + + *state = csync; + + return 0; +} + +static int 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); + csync_create(&csync, "/tmp"); + csync_init(csync, TESTDB); + + 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); + rc = sqlite3_close(db); + assert_int_equal(rc, SQLITE_OK); + + rc = csync_statedb_load(csync, TESTDB, &csync->statedb.db); + assert_int_equal(rc, 0); + + csync->statedb.file = c_strdup( TESTDB ); + *state = csync; + + return 0; +} + +static int teardown(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + int rc; + + unlink( csync->statedb.file); + rc = csync_destroy(csync); + assert_int_equal(rc, 0); + + *state = NULL; + + return 0; +} + +static int teardown_rm(void **state) { + int rc; + + teardown(state); + + rc = system("rm -rf /tmp/check_csync"); + assert_int_equal(rc, 0); + rc = system("rm -rf /tmp/check_csync1"); + assert_int_equal(rc, 0); + + return 0; +} + +/* 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->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; +} + +static int failing_fn(CSYNC *ctx, + const char *file, + const csync_vio_file_stat_t *fs, + int flag) +{ + (void) ctx; + (void) file; + (void) fs; + (void) flag; + + return -1; +} + +/* detect a new file */ +static void check_csync_detect_update(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + csync_file_stat_t *st; + csync_vio_file_stat_t *fs; + int rc; + + fs = create_fstat("file.txt", 0, 1217597845); + assert_non_null(fs); + + rc = _csync_detect_update(csync, + "/tmp/check_csync1/file.txt", + fs, + CSYNC_FTW_TYPE_FILE); + assert_int_equal(rc, 0); + + /* the instruction should be set to new */ + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); + assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW); + + /* create a statedb */ + csync_set_status(csync, 0xFFFF); + + csync_vio_file_stat_destroy(fs); +} + +/* Test behaviour in case no db is there. For that its important that the + * test before this one uses teardown_rm. + */ +static void check_csync_detect_update_db_none(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + csync_file_stat_t *st; + csync_vio_file_stat_t *fs; + int rc; + + fs = create_fstat("file.txt", 0, 1217597845); + assert_non_null(fs); + + rc = _csync_detect_update(csync, + "/tmp/check_csync1/file.txt", + fs, + CSYNC_FTW_TYPE_FILE); + assert_int_equal(rc, 0); + + /* the instruction should be set to new */ + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); + assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW); + + + /* create a statedb */ + csync_set_status(csync, 0xFFFF); + + csync_vio_file_stat_destroy(fs); +} + +static void check_csync_detect_update_db_eval(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + csync_file_stat_t *st; + csync_vio_file_stat_t *fs; + int rc; + + fs = create_fstat("file.txt", 0, 42); + assert_non_null(fs); + + rc = _csync_detect_update(csync, + "/tmp/check_csync1/file.txt", + fs, + CSYNC_FTW_TYPE_FILE); + assert_int_equal(rc, 0); + + /* the instruction should be set to new */ + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); + assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW); + + /* create a statedb */ + csync_set_status(csync, 0xFFFF); + + csync_vio_file_stat_destroy(fs); +} + + +static void check_csync_detect_update_db_rename(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + // csync_file_stat_t *st; + + csync_vio_file_stat_t *fs; + int rc = 0; + + fs = create_fstat("wurst.txt", 0, 42); + assert_non_null(fs); + csync_set_statedb_exists(csync, 1); + + rc = _csync_detect_update(csync, + "/tmp/check_csync1/wurst.txt", + fs, + CSYNC_FTW_TYPE_FILE); + assert_int_equal(rc, 0); + + /* the instruction should be set to rename */ + /* + * temporarily broken. + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); + assert_int_equal(st->instruction, CSYNC_INSTRUCTION_RENAME); + + st->instruction = CSYNC_INSTRUCTION_UPDATED; + */ + /* create a statedb */ + csync_set_status(csync, 0xFFFF); + + csync_vio_file_stat_destroy(fs); +} + +static void check_csync_detect_update_db_new(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + csync_file_stat_t *st; + csync_vio_file_stat_t *fs; + int rc; + + fs = create_fstat("file.txt", 42000, 0); + assert_non_null(fs); + + rc = _csync_detect_update(csync, + "/tmp/check_csync1/file.txt", + fs, + CSYNC_FTW_TYPE_FILE); + assert_int_equal(rc, 0); + + /* the instruction should be set to new */ + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); + assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW); + + + /* create a statedb */ + csync_set_status(csync, 0xFFFF); + + csync_vio_file_stat_destroy(fs); +} + +static void check_csync_detect_update_null(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + csync_vio_file_stat_t *fs; + int rc; + + fs = create_fstat("file.txt", 0, 0); + assert_non_null(fs); + + rc = _csync_detect_update(csync, + NULL, + fs, + CSYNC_FTW_TYPE_FILE); + assert_int_equal(rc, -1); + + rc = _csync_detect_update(csync, + "/tmp/check_csync1/file.txt", + NULL, + CSYNC_FTW_TYPE_FILE); + assert_int_equal(rc, -1); + + csync_vio_file_stat_destroy(fs); +} + +static void check_csync_ftw(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + int rc; + + rc = csync_ftw(csync, "/tmp", csync_walker, MAX_DEPTH); + assert_int_equal(rc, 0); +} + +static void check_csync_ftw_empty_uri(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + int rc; + + rc = csync_ftw(csync, "", csync_walker, MAX_DEPTH); + assert_int_equal(rc, -1); +} + +static void check_csync_ftw_failing_fn(void **state) +{ + CSYNC *csync = (CSYNC*)*state; + int rc; + + rc = csync_ftw(csync, "/tmp", failing_fn, MAX_DEPTH); + assert_int_equal(rc, -1); +} + +int torture_run_tests(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(check_csync_detect_update, setup, teardown_rm), + cmocka_unit_test_setup_teardown(check_csync_detect_update_db_none, setup, teardown), + cmocka_unit_test_setup_teardown(check_csync_detect_update_db_eval, setup, teardown), + cmocka_unit_test_setup_teardown(check_csync_detect_update_db_rename, setup, teardown), + cmocka_unit_test_setup_teardown(check_csync_detect_update_db_new, setup, teardown_rm), + cmocka_unit_test_setup_teardown(check_csync_detect_update_null, setup, teardown_rm), + + cmocka_unit_test_setup_teardown(check_csync_ftw, setup_ftw, teardown_rm), + cmocka_unit_test_setup_teardown(check_csync_ftw_empty_uri, setup_ftw, teardown_rm), + cmocka_unit_test_setup_teardown(check_csync_ftw_failing_fn, setup_ftw, teardown_rm), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} + +} diff --git a/src/csync/CMakeLists.txt b/src/csync/CMakeLists.txt index 2bd60e572..09f320202 100644 --- a/src/csync/CMakeLists.txt +++ b/src/csync/CMakeLists.txt @@ -62,30 +62,30 @@ if(NO_RENAME_EXTENSION) endif() set(csync_SRCS - csync.c - csync_exclude.c - csync_log.c - csync_statedb.c + csync.cpp + csync_exclude.cpp + csync_log.cpp + csync_statedb.cpp csync_time.c - csync_util.c - csync_misc.c + csync_util.cpp + csync_misc.cpp - csync_update.c - csync_reconcile.c + csync_update.cpp + csync_reconcile.cpp csync_rename.cpp - vio/csync_vio.c - vio/csync_vio_file_stat.c + vio/csync_vio.cpp + vio/csync_vio_file_stat.cpp ) if (WIN32) list(APPEND csync_SRCS - vio/csync_vio_local_win.c + vio/csync_vio_local_win.cpp ) else() list(APPEND csync_SRCS - vio/csync_vio_local_unix.c + vio/csync_vio_local_unix.cpp ) endif() diff --git a/src/csync/csync.c b/src/csync/csync.cpp similarity index 99% rename from src/csync/csync.c rename to src/csync/csync.cpp index 1f75ac3bd..6ef3d0d1d 100644 --- a/src/csync/csync.c +++ b/src/csync/csync.cpp @@ -86,7 +86,7 @@ void csync_create(CSYNC **csync, const char *local) { CSYNC *ctx; size_t len = 0; - ctx = c_malloc(sizeof(CSYNC)); + ctx = (CSYNC*)c_malloc(sizeof(CSYNC)); ctx->status_code = CSYNC_STATUS_OK; @@ -604,7 +604,7 @@ int csync_set_status(CSYNC *ctx, int status) { CSYNC_STATUS csync_get_status(CSYNC *ctx) { if (ctx == NULL) { - return -1; + return CSYNC_STATUS_ERROR; } return ctx->status_code; diff --git a/src/csync/csync.h b/src/csync/csync.h index daf778c24..73eb5790a 100644 --- a/src/csync/csync.h +++ b/src/csync/csync.h @@ -40,10 +40,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - enum csync_status_codes_e { CSYNC_STATUS_OK = 0, @@ -221,7 +217,7 @@ struct csync_vio_file_stat_s { int fields; // actually enum csync_vio_file_stat_fields_e fields; enum csync_vio_file_type_e type; - enum csync_vio_file_flags_e flags; + int flags; char *original_name; // only set if locale conversion fails @@ -504,10 +500,6 @@ int OCSYNC_EXPORT csync_abort_requested(CSYNC *ctx); char OCSYNC_EXPORT *csync_normalize_etag(const char *); time_t OCSYNC_EXPORT oc_httpdate_parse( const char *date ); -#ifdef __cplusplus -} -#endif - /** * }@ */ diff --git a/src/csync/csync_exclude.c b/src/csync/csync_exclude.cpp similarity index 98% rename from src/csync/csync_exclude.c rename to src/csync/csync_exclude.cpp index fea662504..9ab187e71 100644 --- a/src/csync/csync_exclude.c +++ b/src/csync/csync_exclude.cpp @@ -71,7 +71,7 @@ int _csync_exclude_add(c_strlist_t **inList, const char *string) { static const char *csync_exclude_expand_escapes(const char * input) { size_t i_len = strlen(input) + 1; - char *out = c_malloc(i_len); // out can only be shorter + char *out = (char*)c_malloc(i_len); // out can only be shorter size_t i = 0; size_t o = 0; @@ -141,7 +141,7 @@ int csync_exclude_load(const char *fname, c_strlist_t **list) { rc = 0; goto out; } - buf = c_malloc(size + 1); + buf = (char*)c_malloc(size + 1); if (read(fd, buf, size) != size) { rc = -1; goto out; @@ -220,6 +220,7 @@ static CSYNC_EXCLUDE_TYPE _csync_excluded_common(c_strlist_t *excludes, const ch int rc = -1; CSYNC_EXCLUDE_TYPE match = CSYNC_NOT_EXCLUDED; CSYNC_EXCLUDE_TYPE type = CSYNC_NOT_EXCLUDED; + c_strlist_t *path_components = NULL; /* split up the path */ bname = strrchr(path, '/'); @@ -274,8 +275,7 @@ static CSYNC_EXCLUDE_TYPE _csync_excluded_common(c_strlist_t *excludes, const ch } // Filter out characters not allowed in a filename on windows - const char *p = NULL; - for (p = path; *p; p++) { + for (const char *p = path; *p; p++) { switch (*p) { case '\\': case ':': @@ -331,7 +331,6 @@ static CSYNC_EXCLUDE_TYPE _csync_excluded_common(c_strlist_t *excludes, const ch goto out; } - c_strlist_t *path_components = NULL; if (check_leading_dirs) { /* Build a list of path components to check. */ path_components = c_strlist_new(32); diff --git a/src/csync/csync_log.c b/src/csync/csync_log.cpp similarity index 100% rename from src/csync/csync_log.c rename to src/csync/csync_log.cpp diff --git a/src/csync/csync_misc.c b/src/csync/csync_misc.cpp similarity index 99% rename from src/csync/csync_misc.c rename to src/csync/csync_misc.cpp index d23236113..cf719439f 100644 --- a/src/csync/csync_misc.c +++ b/src/csync/csync_misc.cpp @@ -198,7 +198,7 @@ char *csync_normalize_etag(const char *etag) len -= 2; } - buf = c_malloc( len+1 ); + buf = (char*)c_malloc( len+1 ); strncpy( buf, etag, len ); buf[len] = '\0'; return buf; diff --git a/src/csync/csync_private.h b/src/csync/csync_private.h index 2edc26019..3d1632e41 100644 --- a/src/csync/csync_private.h +++ b/src/csync/csync_private.h @@ -163,7 +163,7 @@ struct csync_file_stat_s { size_t pathlen; /* u64 */ uint64_t inode; /* u64 */ mode_t mode; /* u32 */ - unsigned int type : 4; + enum csync_ftw_type_e type : 4; unsigned int child_modified : 1; unsigned int has_ignored_files : 1; /* specify that a directory, or child directory contains ignored files */ diff --git a/src/csync/csync_reconcile.c b/src/csync/csync_reconcile.cpp similarity index 99% rename from src/csync/csync_reconcile.c rename to src/csync/csync_reconcile.cpp index 59156e800..3b02398fc 100644 --- a/src/csync/csync_reconcile.c +++ b/src/csync/csync_reconcile.cpp @@ -31,6 +31,8 @@ #define CSYNC_LOG_CATEGORY_NAME "csync.reconciler" #include "csync_log.h" +// Needed for PRIu64 on MinGW in C++ mode. +#define __STDC_FORMAT_MACROS #include "inttypes.h" /* Check if a file is ignored because one parent is ignored. diff --git a/src/csync/csync_rename.cpp b/src/csync/csync_rename.cpp index 5cc43ce22..79bb78e34 100644 --- a/src/csync/csync_rename.cpp +++ b/src/csync/csync_rename.cpp @@ -18,10 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -extern "C" { #include "csync_private.h" #include "csync_rename.h" -} #include #include @@ -55,7 +53,6 @@ struct csync_rename_s { std::vector todo; }; -extern "C" { void csync_rename_destroy(CSYNC* ctx) { delete reinterpret_cast(ctx->rename_info); @@ -98,5 +95,3 @@ bool csync_rename_count(CSYNC *ctx) { csync_rename_s* d = csync_rename_s::get(ctx); return d->folder_renamed_from.size(); } - -} diff --git a/src/csync/csync_rename.h b/src/csync/csync_rename.h index 53968324c..7702a1376 100644 --- a/src/csync/csync_rename.h +++ b/src/csync/csync_rename.h @@ -22,10 +22,6 @@ #include "csync.h" -#ifdef __cplusplus -extern "C" { -#endif - /* Return the final destination path of a given patch in case of renames */ char OCSYNC_EXPORT *csync_rename_adjust_path(CSYNC *ctx, const char *path); /* Return the source of a given path in case of renames */ @@ -34,7 +30,3 @@ void OCSYNC_EXPORT csync_rename_destroy(CSYNC *ctx); void OCSYNC_EXPORT csync_rename_record(CSYNC *ctx, const char *from, const char *to); /* Return the amount of renamed item recorded */ bool OCSYNC_EXPORT csync_rename_count(CSYNC *ctx); - -#ifdef __cplusplus -} -#endif diff --git a/src/csync/csync_statedb.c b/src/csync/csync_statedb.cpp similarity index 98% rename from src/csync/csync_statedb.c rename to src/csync/csync_statedb.cpp index 056ca48dd..63eb813e7 100644 --- a/src/csync/csync_statedb.c +++ b/src/csync/csync_statedb.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include "c_lib.h" #include "csync_private.h" @@ -48,6 +47,10 @@ #include "csync_log.h" #include "csync_rename.h" +// Needed for PRIu64 on MinGW in C++ mode. +#define __STDC_FORMAT_MACROS +#include + #define BUF_SIZE 16 #define sqlite_open(A, B) sqlite3_open_v2(A,B, SQLITE_OPEN_READONLY+SQLITE_OPEN_NOMUTEX, NULL) @@ -257,7 +260,7 @@ static int _csync_file_stat_from_metadata_table( csync_file_stat_t **st, sqlite3 /* phash, pathlen, path, inode, uid, gid, mode, modtime */ len = sqlite3_column_int(stmt, 1); - *st = c_malloc(sizeof(csync_file_stat_t) + len + 1); + *st = (csync_file_stat_t*)c_malloc(sizeof(csync_file_stat_t) + len + 1); /* clear the whole structure */ ZERO_STRUCTP(*st); @@ -272,7 +275,7 @@ static int _csync_file_stat_from_metadata_table( csync_file_stat_t **st, sqlite3 (*st)->modtime = strtoul((char*)sqlite3_column_text(stmt, 7), NULL, 10); if(*st && column_count > 8 ) { - (*st)->type = sqlite3_column_int(stmt, 8); + (*st)->type = static_cast(sqlite3_column_int(stmt, 8)); } if(column_count > 9 && sqlite3_column_text(stmt, 9)) { diff --git a/src/csync/csync_statedb.h b/src/csync/csync_statedb.h index 601e34a1b..dc58a9b08 100644 --- a/src/csync/csync_statedb.h +++ b/src/csync/csync_statedb.h @@ -33,10 +33,6 @@ #ifndef _CSYNC_STATEDB_H #define _CSYNC_STATEDB_H -#ifdef __cplusplus -extern "C" { -#endif - #include "c_lib.h" #include "csync_private.h" @@ -96,10 +92,6 @@ int csync_statedb_get_below_path(CSYNC *ctx, const char *path); */ c_strlist_t *csync_statedb_query(sqlite3 *db, const char *statement); -#ifdef __cplusplus -} -#endif - /** * }@ */ diff --git a/src/csync/csync_time.c b/src/csync/csync_time.c index 85bdd5ff4..3092819a3 100644 --- a/src/csync/csync_time.c +++ b/src/csync/csync_time.c @@ -34,6 +34,8 @@ #ifndef _WIN32 #include #include +#else +#include #endif #define CSYNC_LOG_CATEGORY_NAME "csync.time" diff --git a/src/csync/csync_time.h b/src/csync/csync_time.h index 1492bef8d..55aa09841 100644 --- a/src/csync/csync_time.h +++ b/src/csync/csync_time.h @@ -21,6 +21,10 @@ #ifndef _CSYNC_TIME_H #define _CSYNC_TIME_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include "csync_private.h" @@ -28,4 +32,8 @@ int csync_gettime(struct timespec *tp); void csync_sleep(unsigned int msecs); +#ifdef __cplusplus +} +#endif + #endif /* _CSYNC_TIME_H */ diff --git a/src/csync/csync_update.c b/src/csync/csync_update.cpp similarity index 99% rename from src/csync/csync_update.c rename to src/csync/csync_update.cpp index 1a069442e..927290b1a 100644 --- a/src/csync/csync_update.c +++ b/src/csync/csync_update.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -48,6 +47,10 @@ #include "csync_log.h" #include "csync_rename.h" +// Needed for PRIu64 on MinGW in C++ mode. +#define __STDC_FORMAT_MACROS +#include + /* calculate the hash of a given uri */ static uint64_t _hash_of_file(CSYNC *ctx, const char *file) { const char *path; @@ -159,7 +162,7 @@ static bool _csync_mtime_equal(time_t a, time_t b) * See doc/dev/sync-algorithm.md for an overview. */ static int _csync_detect_update(CSYNC *ctx, const char *file, - const csync_vio_file_stat_t *fs, const int type) { + const csync_vio_file_stat_t *fs, enum csync_ftw_type_e type) { uint64_t h = 0; size_t len = 0; size_t size = 0; @@ -224,7 +227,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, } size = sizeof(csync_file_stat_t) + len + 1; - st = c_malloc(size); + st = static_cast(c_malloc(size)); /* Set instruction by default to none */ st->instruction = CSYNC_INSTRUCTION_NONE; @@ -540,9 +543,9 @@ out: } int csync_walker(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs, - enum csync_ftw_flags_e flag) { + int flag) { int rc = -1; - int type = CSYNC_FTW_TYPE_SKIP; + enum csync_ftw_type_e type = CSYNC_FTW_TYPE_SKIP; csync_file_stat_t *st = NULL; uint64_t h; @@ -648,13 +651,13 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, int rc = 0; int res = 0; + bool do_read_from_db = (ctx->current == REMOTE_REPLICA && ctx->remote.read_from_db); + if (!depth) { mark_current_item_ignored(ctx, previous_fs, CSYNC_STATUS_INDIVIDUAL_TOO_DEEP); goto done; } - bool do_read_from_db = (ctx->current == REMOTE_REPLICA && ctx->remote.read_from_db); - read_from_db = ctx->remote.read_from_db; // if the etag of this dir is still the same, its content is restored from the diff --git a/src/csync/csync_update.h b/src/csync/csync_update.h index 4a7495e3a..d83ee91e8 100644 --- a/src/csync/csync_update.h +++ b/src/csync/csync_update.h @@ -53,7 +53,7 @@ enum csync_ftw_flags_e { }; typedef int (*csync_walker_fn) (CSYNC *ctx, const char *file, - const csync_vio_file_stat_t *fs, enum csync_ftw_flags_e flag); + const csync_vio_file_stat_t *fs, int flag); /** * @brief The walker function to use in the file tree walker. @@ -68,8 +68,7 @@ typedef int (*csync_walker_fn) (CSYNC *ctx, const char *file, * * @return 0 on success, < 0 on error. */ -int csync_walker(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs, - enum csync_ftw_flags_e flag); +int csync_walker(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs, int flag); /** * @brief The file tree walker. diff --git a/src/csync/csync_util.c b/src/csync/csync_util.cpp similarity index 99% rename from src/csync/csync_util.c rename to src/csync/csync_util.cpp index 1bc09c35c..4fc13a471 100644 --- a/src/csync/csync_util.c +++ b/src/csync/csync_util.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "c_jhash.h" #include "csync_util.h" diff --git a/src/csync/csync_version.h.in b/src/csync/csync_version.h.in index 9471734b8..3bf379db9 100644 --- a/src/csync/csync_version.h.in +++ b/src/csync/csync_version.h.in @@ -21,17 +21,9 @@ #ifndef _CSYNC_VERSION_H #define _CSYNC_VERSION_H -#ifdef __cplusplus -extern "C" { -#endif - #define CSYNC_STRINGIFY(s) CSYNC_TOSTRING(s) #define CSYNC_TOSTRING(s) #s #define MIRALL_VERSION @MIRALL_VERSION@ -#ifdef __cplusplus -} -#endif - #endif // _CSYNC_VERSION_H diff --git a/src/csync/std/asprintf.h b/src/csync/std/asprintf.h index d6dd2e859..21693ca89 100644 --- a/src/csync/std/asprintf.h +++ b/src/csync/std/asprintf.h @@ -34,6 +34,10 @@ #ifndef ASPRINTF_H #define ASPRINTF_H 1 +#ifdef __cplusplus +extern "C" { +#endif + #include /** @@ -56,5 +60,9 @@ vasprintf (char **, const char *, va_list); int asprintf (char **, const char *, ...); +#ifdef __cplusplus +} +#endif + #endif #endif diff --git a/src/csync/std/c_alloc.h b/src/csync/std/c_alloc.h index 6eeccd69d..8ff2eb08b 100644 --- a/src/csync/std/c_alloc.h +++ b/src/csync/std/c_alloc.h @@ -34,6 +34,10 @@ #ifndef _C_ALLOC_H #define _C_ALLOC_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include "c_macro.h" @@ -113,4 +117,9 @@ char *c_strndup(const char *str, size_t size); /** * }@ */ + +#ifdef __cplusplus +} +#endif + #endif /* _C_ALLOC_H */ diff --git a/src/csync/std/c_path.h b/src/csync/std/c_path.h index 291b1b8d3..f17c5f480 100644 --- a/src/csync/std/c_path.h +++ b/src/csync/std/c_path.h @@ -32,6 +32,10 @@ #ifndef _C_PATH_H #define _C_PATH_H +#ifdef __cplusplus +extern "C" { +#endif + #include "c_macro.h" #include "c_private.h" @@ -139,4 +143,9 @@ mbchar_t* c_utf8_path_to_locale(const char *str); /** * }@ */ + +#ifdef __cplusplus +} +#endif + #endif /* _C_PATH_H */ diff --git a/src/csync/std/c_rbtree.h b/src/csync/std/c_rbtree.h index 635458fd2..69b4c0d73 100644 --- a/src/csync/std/c_rbtree.h +++ b/src/csync/std/c_rbtree.h @@ -66,6 +66,10 @@ #ifndef _C_RBTREE_H #define _C_RBTREE_H +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct c_rbtree_s; typedef struct c_rbtree_s c_rbtree_t; struct c_rbnode_s; typedef struct c_rbnode_s c_rbnode_t; @@ -306,4 +310,9 @@ int c_rbtree_check_sanity(c_rbtree_t *tree); /** * }@ */ + +#ifdef __cplusplus +} +#endif + #endif /* _C_RBTREE_H */ diff --git a/src/csync/std/c_string.h b/src/csync/std/c_string.h index 304c598a2..4d7d9b599 100644 --- a/src/csync/std/c_string.h +++ b/src/csync/std/c_string.h @@ -32,6 +32,10 @@ #ifndef _C_STR_H #define _C_STR_H +#ifdef __cplusplus +extern "C" { +#endif + #include "c_private.h" #include "c_macro.h" @@ -217,5 +221,10 @@ mbchar_t* c_utf8_string_to_locale(const char *wstr); /** * }@ */ + +#ifdef __cplusplus +} +#endif + #endif /* _C_STR_H */ diff --git a/src/csync/std/c_time.c b/src/csync/std/c_time.c index ad43fed02..561cd4763 100644 --- a/src/csync/std/c_time.c +++ b/src/csync/std/c_time.c @@ -25,10 +25,6 @@ #include "c_path.h" #include "c_time.h" -#ifndef _WIN32 -#include -#endif - struct timespec c_tspecdiff(struct timespec time1, struct timespec time0) { struct timespec ret; int xsec = 0; diff --git a/src/csync/std/c_time.h b/src/csync/std/c_time.h index aa8ef2f16..67e7fcbad 100644 --- a/src/csync/std/c_time.h +++ b/src/csync/std/c_time.h @@ -21,7 +21,15 @@ #ifndef _C_TIME_H #define _C_TIME_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _WIN32 #include +#else +#include +#endif /** * @brief Calculate time difference @@ -52,4 +60,8 @@ double c_secdiff(struct timespec clock1, struct timespec clock0); int c_utimes(const char *uri, const struct timeval *times); +#ifdef __cplusplus +} +#endif + #endif /* _C_TIME_H */ diff --git a/src/csync/vio/csync_vio.c b/src/csync/vio/csync_vio.cpp similarity index 100% rename from src/csync/vio/csync_vio.c rename to src/csync/vio/csync_vio.cpp diff --git a/src/csync/vio/csync_vio_file_stat.c b/src/csync/vio/csync_vio_file_stat.cpp similarity index 100% rename from src/csync/vio/csync_vio_file_stat.c rename to src/csync/vio/csync_vio_file_stat.cpp diff --git a/src/csync/vio/csync_vio_local_unix.c b/src/csync/vio/csync_vio_local_unix.cpp similarity index 99% rename from src/csync/vio/csync_vio_local_unix.c rename to src/csync/vio/csync_vio_local_unix.cpp index 5d5666688..40e4794c3 100644 --- a/src/csync/vio/csync_vio_local_unix.c +++ b/src/csync/vio/csync_vio_local_unix.cpp @@ -48,7 +48,7 @@ csync_vio_handle_t *csync_vio_local_opendir(const char *name) { dhandle_t *handle = NULL; mbchar_t *dirname = NULL; - handle = c_malloc(sizeof(dhandle_t)); + handle = (dhandle_t*)c_malloc(sizeof(dhandle_t)); dirname = c_utf8_path_to_locale(name); @@ -89,6 +89,7 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle) { csync_vio_file_stat_t *file_stat = NULL; handle = (dhandle_t *) dhandle; + struct _tdirent *dirent = NULL; errno = 0; file_stat = csync_vio_file_stat_new(); @@ -97,8 +98,6 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle) { } file_stat->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE; - struct _tdirent *dirent = NULL; - dirent = _treaddir(handle->dh); if (dirent == NULL) { goto err; diff --git a/src/csync/vio/csync_vio_local_win.c b/src/csync/vio/csync_vio_local_win.cpp similarity index 98% rename from src/csync/vio/csync_vio_local_win.c rename to src/csync/vio/csync_vio_local_win.cpp index fc4eea512..e9d2ba566 100644 --- a/src/csync/vio/csync_vio_local_win.c +++ b/src/csync/vio/csync_vio_local_win.cpp @@ -52,7 +52,7 @@ csync_vio_handle_t *csync_vio_local_opendir(const char *name) { dhandle_t *handle = NULL; mbchar_t *dirname = NULL; - handle = c_malloc(sizeof(dhandle_t)); + handle = (dhandle_t*)c_malloc(sizeof(dhandle_t)); // the file wildcard has to be attached int len_name = strlen(name); @@ -60,7 +60,7 @@ csync_vio_handle_t *csync_vio_local_opendir(const char *name) { char *h = NULL; // alloc an enough large buffer to take the name + '/*' + the closing zero. - h = c_malloc(len_name+3); + h = (char*)c_malloc(len_name+3); strncpy( h, name, 1+len_name); strncat(h, "/*", 2); diff --git a/src/libsync/excludedfiles.cpp b/src/libsync/excludedfiles.cpp index 074494ff8..289164efb 100644 --- a/src/libsync/excludedfiles.cpp +++ b/src/libsync/excludedfiles.cpp @@ -18,11 +18,9 @@ #include -extern "C" { #include "std/c_string.h" #include "csync.h" #include "csync_exclude.h" -} using namespace OCC; diff --git a/src/libsync/excludedfiles.h b/src/libsync/excludedfiles.h index f8a18cd8d..d090f8aa6 100644 --- a/src/libsync/excludedfiles.h +++ b/src/libsync/excludedfiles.h @@ -20,11 +20,9 @@ #include #include -extern "C" { #include "std/c_string.h" #include "csync.h" #include "csync_exclude.h" // for CSYNC_EXCLUDE_TYPE -} namespace OCC { diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index 18e6f800f..8299fcc04 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -39,14 +39,11 @@ // We use some internals of csync: extern "C" int c_utimes(const char *, const struct timeval *); -extern "C" void csync_win32_set_file_hidden(const char *file, bool h); -extern "C" { #include "csync.h" #include "vio/csync_vio_local.h" #include "std/c_path.h" #include "std/c_string.h" -} namespace OCC { diff --git a/src/libsync/owncloudpropagator.h b/src/libsync/owncloudpropagator.h index 02145fa19..b9b60034f 100644 --- a/src/libsync/owncloudpropagator.h +++ b/src/libsync/owncloudpropagator.h @@ -25,6 +25,7 @@ #include #include +#include "csync_util.h" #include "syncfileitem.h" #include "syncjournaldb.h" #include "bandwidthmanager.h" @@ -35,8 +36,6 @@ namespace OCC { Q_DECLARE_LOGGING_CATEGORY(lcPropagator) -extern "C" const char *csync_instruction_str(enum csync_instructions_e instr); - /** Free disk space threshold below which syncs will abort and not even start. */ qint64 criticalFreeSpaceLimit(); diff --git a/src/libsync/syncjournaldb.cpp b/src/libsync/syncjournaldb.cpp index 203c14988..e46d35db6 100644 --- a/src/libsync/syncjournaldb.cpp +++ b/src/libsync/syncjournaldb.cpp @@ -21,8 +21,6 @@ #include "ownsql.h" -#include - #include "syncjournaldb.h" #include "syncjournalfilerecord.h" #include "utility.h" diff --git a/test/csync/CMakeLists.txt b/test/csync/CMakeLists.txt index e92c15e2d..a27505d12 100644 --- a/test/csync/CMakeLists.txt +++ b/test/csync/CMakeLists.txt @@ -29,28 +29,28 @@ add_cmocka_test(check_std_c_time std_tests/check_std_c_time.c ${TEST_TARGET_LIBR # csync tests # This will be rewritten soon anyway. -#add_cmocka_test(check_logger log_tests/check_log.c ${TEST_TARGET_LIBRARIES}) +#add_cmocka_test(check_logger log_tests/check_log.cpp ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_csync_create csync_tests/check_csync_create.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_csync_log csync_tests/check_csync_log.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_csync_exclude csync_tests/check_csync_exclude.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_csync_statedb_load csync_tests/check_csync_statedb_load.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_csync_util csync_tests/check_csync_util.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_csync_misc csync_tests/check_csync_misc.c ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_create csync_tests/check_csync_create.cpp ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_log csync_tests/check_csync_log.cpp ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_exclude csync_tests/check_csync_exclude.cpp ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_statedb_load csync_tests/check_csync_statedb_load.cpp ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_util csync_tests/check_csync_util.cpp ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_misc csync_tests/check_csync_misc.cpp ${TEST_TARGET_LIBRARIES}) # csync tests which require init -add_cmocka_test(check_csync_init csync_tests/check_csync_init.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_csync_statedb_query csync_tests/check_csync_statedb_query.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_csync_commit csync_tests/check_csync_commit.c ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_init csync_tests/check_csync_init.cpp ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_statedb_query csync_tests/check_csync_statedb_query.cpp ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_commit csync_tests/check_csync_commit.cpp ${TEST_TARGET_LIBRARIES}) # vio -add_cmocka_test(check_vio_file_stat vio_tests/check_vio_file_stat.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_vio vio_tests/check_vio.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_vio_ext vio_tests/check_vio_ext.c ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_vio_file_stat vio_tests/check_vio_file_stat.cpp ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_vio vio_tests/check_vio.cpp ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_vio_ext vio_tests/check_vio_ext.cpp ${TEST_TARGET_LIBRARIES}) # sync -add_cmocka_test(check_csync_update csync_tests/check_csync_update.c ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_csync_update csync_tests/check_csync_update.cpp ${TEST_TARGET_LIBRARIES}) # encoding -add_cmocka_test(check_encoding_functions encoding_tests/check_encoding.c ${TEST_TARGET_LIBRARIES}) +add_cmocka_test(check_encoding_functions encoding_tests/check_encoding.cpp ${TEST_TARGET_LIBRARIES}) diff --git a/test/csync/csync_tests/check_csync_commit.c b/test/csync/csync_tests/check_csync_commit.cpp similarity index 95% rename from test/csync/csync_tests/check_csync_commit.c rename to test/csync/csync_tests/check_csync_commit.cpp index 16c89bf9e..b3d77913b 100644 --- a/test/csync/csync_tests/check_csync_commit.c +++ b/test/csync/csync_tests/check_csync_commit.cpp @@ -53,7 +53,7 @@ static int setup_module(void **state) { } static int teardown(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_destroy(csync); @@ -71,7 +71,7 @@ static int teardown(void **state) { static void check_csync_commit(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_commit(csync); @@ -82,7 +82,7 @@ static void check_csync_commit(void **state) static void check_csync_commit_dummy(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_commit(csync); diff --git a/test/csync/csync_tests/check_csync_create.c b/test/csync/csync_tests/check_csync_create.cpp similarity index 100% rename from test/csync/csync_tests/check_csync_create.c rename to test/csync/csync_tests/check_csync_create.cpp diff --git a/test/csync/csync_tests/check_csync_exclude.c b/test/csync/csync_tests/check_csync_exclude.cpp similarity index 98% rename from test/csync/csync_tests/check_csync_exclude.c rename to test/csync/csync_tests/check_csync_exclude.cpp index 1d145b240..5841eddf0 100644 --- a/test/csync/csync_tests/check_csync_exclude.c +++ b/test/csync/csync_tests/check_csync_exclude.cpp @@ -25,7 +25,7 @@ #include "torture.h" #define CSYNC_TEST 1 -#include "csync_exclude.c" +#include "csync_exclude.cpp" #define EXCLUDE_LIST_FILE SOURCEDIR"/../../sync-exclude.lst" @@ -64,7 +64,7 @@ static int setup_init(void **state) { } static int teardown(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_destroy(csync); @@ -82,14 +82,14 @@ static int teardown(void **state) { static void check_csync_exclude_add(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; _csync_exclude_add(&(csync->excludes), "/tmp/check_csync1/*"); assert_string_equal(csync->excludes->vector[0], "/tmp/check_csync1/*"); } static void check_csync_exclude_load(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_exclude_load(EXCLUDE_LIST_FILE, &(csync->excludes) ); @@ -101,7 +101,7 @@ static void check_csync_exclude_load(void **state) static void check_csync_excluded(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_excluded_no_ctx(csync->excludes, "", CSYNC_FTW_TYPE_FILE); @@ -221,7 +221,7 @@ static void check_csync_excluded(void **state) static void check_csync_excluded_traversal(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; _csync_exclude_add( &(csync->excludes), "/exclude" ); @@ -271,7 +271,7 @@ static void check_csync_excluded_traversal(void **state) static void check_csync_pathes(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; _csync_exclude_add( &(csync->excludes), "/exclude" ); @@ -319,7 +319,7 @@ static void check_csync_pathes(void **state) assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST); } -static void check_csync_is_windows_reserved_word() { +static void check_csync_is_windows_reserved_word(void **) { assert_true(csync_is_windows_reserved_word("CON")); assert_true(csync_is_windows_reserved_word("con")); assert_true(csync_is_windows_reserved_word("CON.")); @@ -339,7 +339,7 @@ static void check_csync_is_windows_reserved_word() { static void check_csync_excluded_performance(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; const int N = 10000; int totalRc = 0; diff --git a/test/csync/csync_tests/check_csync_init.c b/test/csync/csync_tests/check_csync_init.cpp similarity index 96% rename from test/csync/csync_tests/check_csync_init.c rename to test/csync/csync_tests/check_csync_init.cpp index 41876d638..c0b4cdd6b 100644 --- a/test/csync/csync_tests/check_csync_init.c +++ b/test/csync/csync_tests/check_csync_init.cpp @@ -50,7 +50,7 @@ static int setup_module(void **state) { } static int teardown(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_destroy(csync); @@ -68,7 +68,7 @@ static int teardown(void **state) { static void check_csync_init(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_init(csync, ""); diff --git a/test/csync/csync_tests/check_csync_log.c b/test/csync/csync_tests/check_csync_log.cpp similarity index 98% rename from test/csync/csync_tests/check_csync_log.c rename to test/csync/csync_tests/check_csync_log.cpp index 9523d9627..c5f312ff5 100644 --- a/test/csync/csync_tests/check_csync_log.c +++ b/test/csync/csync_tests/check_csync_log.cpp @@ -23,7 +23,7 @@ #include "torture.h" #include "csync.h" -#include "csync_log.c" +#include "csync_log.cpp" #include "c_private.h" static int setup(void **state) { @@ -41,7 +41,7 @@ static int setup(void **state) { } static int teardown(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_destroy(csync); diff --git a/test/csync/csync_tests/check_csync_misc.c b/test/csync/csync_tests/check_csync_misc.cpp similarity index 100% rename from test/csync/csync_tests/check_csync_misc.c rename to test/csync/csync_tests/check_csync_misc.cpp diff --git a/test/csync/csync_tests/check_csync_statedb_load.c b/test/csync/csync_tests/check_csync_statedb_load.cpp similarity index 95% rename from test/csync/csync_tests/check_csync_statedb_load.c rename to test/csync/csync_tests/check_csync_statedb_load.cpp index c4b34b500..a7bccd7ea 100644 --- a/test/csync/csync_tests/check_csync_statedb_load.c +++ b/test/csync/csync_tests/check_csync_statedb_load.cpp @@ -22,7 +22,7 @@ #include "torture.h" #define CSYNC_TEST 1 -#include "csync_statedb.c" +#include "csync_statedb.cpp" #define TESTDB "/tmp/check_csync1/test.db" @@ -52,7 +52,7 @@ static int setup(void **state) { } static int teardown(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_destroy(csync); @@ -68,7 +68,7 @@ static int teardown(void **state) { static void check_csync_statedb_load(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_statedb_load(csync, TESTDB, &csync->statedb.db); @@ -79,7 +79,7 @@ static void check_csync_statedb_load(void **state) static void check_csync_statedb_close(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_stat_t sb; time_t modtime; mbchar_t *testdb = c_utf8_path_to_locale(TESTDB); diff --git a/test/csync/csync_tests/check_csync_statedb_query.c b/test/csync/csync_tests/check_csync_statedb_query.cpp similarity index 93% rename from test/csync/csync_tests/check_csync_statedb_query.c rename to test/csync/csync_tests/check_csync_statedb_query.cpp index 603195e8c..843900ec2 100644 --- a/test/csync/csync_tests/check_csync_statedb_query.c +++ b/test/csync/csync_tests/check_csync_statedb_query.cpp @@ -20,7 +20,7 @@ #include "torture.h" #define CSYNC_TEST 1 -#include "csync_statedb.c" +#include "csync_statedb.cpp" #define TESTDB "/tmp/check_csync1/test.db" #define TESTDBTMP "/tmp/check_csync1/test.db.ctmp" @@ -97,7 +97,7 @@ static int setup_db(void **state) } static int teardown(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc = 0; rc = csync_destroy(csync); @@ -115,7 +115,7 @@ static int teardown(void **state) { static void check_csync_statedb_query_statement(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; c_strlist_t *result; result = csync_statedb_query(csync->statedb.db, ""); @@ -133,7 +133,7 @@ static void check_csync_statedb_query_statement(void **state) static void check_csync_statedb_drop_tables(void **state) { - // CSYNC *csync = *state; + // CSYNC *csync = (CSYNC*)*state; int rc = 0; (void) state; @@ -147,7 +147,7 @@ static void check_csync_statedb_drop_tables(void **state) static void check_csync_statedb_insert_metadata(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_file_stat_t *st; int i, rc = 0; @@ -155,7 +155,7 @@ static void check_csync_statedb_insert_metadata(void **state) assert_int_equal(rc, 0); for (i = 0; i < 100; i++) { - st = c_malloc(sizeof(csync_file_stat_t) + 30 ); + st = (csync_file_stat_t*)c_malloc(sizeof(csync_file_stat_t) + 30 ); snprintf(st->path, 29, "file_%d" , i ); st->phash = i; @@ -169,12 +169,12 @@ static void check_csync_statedb_insert_metadata(void **state) static void check_csync_statedb_write(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_file_stat_t *st; int i, rc; for (i = 0; i < 100; i++) { - st = c_malloc(sizeof(csync_file_stat_t) + 30); + st = (csync_file_stat_t*)c_malloc(sizeof(csync_file_stat_t) + 30); snprintf(st->path, 29, "file_%d" , i ); st->phash = i; @@ -189,7 +189,7 @@ static void check_csync_statedb_write(void **state) static void check_csync_statedb_get_stat_by_hash_not_found(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_file_stat_t *tmp; tmp = csync_statedb_get_stat_by_hash(csync, (uint64_t) 666); @@ -201,7 +201,7 @@ static void check_csync_statedb_get_stat_by_hash_not_found(void **state) static void check_csync_statedb_get_stat_by_inode_not_found(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_file_stat_t *tmp; tmp = csync_statedb_get_stat_by_inode(csync, (ino_t) 666); diff --git a/test/csync/csync_tests/check_csync_update.c b/test/csync/csync_tests/check_csync_update.cpp similarity index 94% rename from test/csync/csync_tests/check_csync_update.c rename to test/csync/csync_tests/check_csync_update.cpp index 695616b2c..237687e4c 100644 --- a/test/csync/csync_tests/check_csync_update.c +++ b/test/csync/csync_tests/check_csync_update.cpp @@ -19,7 +19,7 @@ */ #include "torture.h" -#include "csync_update.c" +#include "csync_update.cpp" #define TESTDB "/tmp/check_csync/journal.db" @@ -150,7 +150,7 @@ static int setup_ftw(void **state) static int teardown(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; unlink( csync->statedb.file); @@ -233,7 +233,7 @@ static csync_vio_file_stat_t* create_fstat(const char *name, static int failing_fn(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs, - enum csync_ftw_flags_e flag) + int flag) { (void) ctx; (void) file; @@ -246,7 +246,7 @@ static int failing_fn(CSYNC *ctx, /* detect a new file */ static void check_csync_detect_update(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_file_stat_t *st; csync_vio_file_stat_t *fs; int rc; @@ -261,7 +261,7 @@ static void check_csync_detect_update(void **state) assert_int_equal(rc, 0); /* the instruction should be set to new */ - st = c_rbtree_node_data(csync->local.tree->root); + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW); /* create a statedb */ @@ -275,7 +275,7 @@ static void check_csync_detect_update(void **state) */ static void check_csync_detect_update_db_none(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_file_stat_t *st; csync_vio_file_stat_t *fs; int rc; @@ -290,7 +290,7 @@ static void check_csync_detect_update_db_none(void **state) assert_int_equal(rc, 0); /* the instruction should be set to new */ - st = c_rbtree_node_data(csync->local.tree->root); + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW); @@ -302,7 +302,7 @@ static void check_csync_detect_update_db_none(void **state) static void check_csync_detect_update_db_eval(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_file_stat_t *st; csync_vio_file_stat_t *fs; int rc; @@ -317,7 +317,7 @@ static void check_csync_detect_update_db_eval(void **state) assert_int_equal(rc, 0); /* the instruction should be set to new */ - st = c_rbtree_node_data(csync->local.tree->root); + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW); /* create a statedb */ @@ -329,7 +329,7 @@ static void check_csync_detect_update_db_eval(void **state) static void check_csync_detect_update_db_rename(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; // csync_file_stat_t *st; csync_vio_file_stat_t *fs; @@ -348,7 +348,7 @@ static void check_csync_detect_update_db_rename(void **state) /* the instruction should be set to rename */ /* * temporarily broken. - st = c_rbtree_node_data(csync->local.tree->root); + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); assert_int_equal(st->instruction, CSYNC_INSTRUCTION_RENAME); st->instruction = CSYNC_INSTRUCTION_UPDATED; @@ -361,7 +361,7 @@ static void check_csync_detect_update_db_rename(void **state) static void check_csync_detect_update_db_new(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_file_stat_t *st; csync_vio_file_stat_t *fs; int rc; @@ -376,7 +376,7 @@ static void check_csync_detect_update_db_new(void **state) assert_int_equal(rc, 0); /* the instruction should be set to new */ - st = c_rbtree_node_data(csync->local.tree->root); + st = (csync_file_stat_t*)c_rbtree_node_data(csync->local.tree->root); assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW); @@ -388,7 +388,7 @@ static void check_csync_detect_update_db_new(void **state) static void check_csync_detect_update_null(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_vio_file_stat_t *fs; int rc; @@ -412,7 +412,7 @@ static void check_csync_detect_update_null(void **state) static void check_csync_ftw(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_ftw(csync, "/tmp", csync_walker, MAX_DEPTH); @@ -421,7 +421,7 @@ static void check_csync_ftw(void **state) static void check_csync_ftw_empty_uri(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_ftw(csync, "", csync_walker, MAX_DEPTH); @@ -430,7 +430,7 @@ static void check_csync_ftw_empty_uri(void **state) static void check_csync_ftw_failing_fn(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_ftw(csync, "/tmp", failing_fn, MAX_DEPTH); @@ -454,4 +454,3 @@ int torture_run_tests(void) return cmocka_run_group_tests(tests, NULL, NULL); } - diff --git a/test/csync/csync_tests/check_csync_util.c b/test/csync/csync_tests/check_csync_util.cpp similarity index 95% rename from test/csync/csync_tests/check_csync_util.c rename to test/csync/csync_tests/check_csync_util.cpp index e55c4ce77..0df637741 100644 --- a/test/csync/csync_tests/check_csync_util.c +++ b/test/csync/csync_tests/check_csync_util.cpp @@ -30,7 +30,7 @@ static void check_csync_instruction_str(void **state) str = csync_instruction_str(CSYNC_INSTRUCTION_ERROR); assert_string_equal(str, "INSTRUCTION_ERROR"); - str = csync_instruction_str(0xFFFF); + str = csync_instruction_str((enum csync_instructions_e)0xFFFF); assert_string_equal(str, "ERROR!"); } diff --git a/test/csync/encoding_tests/check_encoding.c b/test/csync/encoding_tests/check_encoding.cpp similarity index 100% rename from test/csync/encoding_tests/check_encoding.c rename to test/csync/encoding_tests/check_encoding.cpp diff --git a/test/csync/log_tests/check_log.c b/test/csync/log_tests/check_log.cpp similarity index 100% rename from test/csync/log_tests/check_log.c rename to test/csync/log_tests/check_log.cpp diff --git a/test/csync/torture.h b/test/csync/torture.h index b3272b8c1..045518ecc 100644 --- a/test/csync/torture.h +++ b/test/csync/torture.h @@ -20,6 +20,10 @@ #ifndef _TORTURE_H #define _TORTURE_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -41,4 +45,8 @@ int torture_csync_verbosity(void); */ int torture_run_tests(void); +#ifdef __cplusplus +} +#endif + #endif /* _TORTURE_H */ diff --git a/test/csync/vio_tests/check_vio.c b/test/csync/vio_tests/check_vio.cpp similarity index 95% rename from test/csync/vio_tests/check_vio.c rename to test/csync/vio_tests/check_vio.cpp index 6d4afd7ef..a57637e85 100644 --- a/test/csync/vio_tests/check_vio.c +++ b/test/csync/vio_tests/check_vio.cpp @@ -72,7 +72,7 @@ static void setup_dir(void **state) { } static void teardown(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_destroy(csync); @@ -94,7 +94,7 @@ static void teardown(void **state) { static void check_csync_vio_opendir(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_vio_handle_t *dh; int rc; @@ -107,7 +107,7 @@ static void check_csync_vio_opendir(void **state) static void check_csync_vio_opendir_perm(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_vio_handle_t *dh; int rc; mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR); @@ -127,7 +127,7 @@ static void check_csync_vio_opendir_perm(void **state) static void check_csync_vio_closedir_null(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; int rc; rc = csync_vio_closedir(csync, NULL); @@ -136,7 +136,7 @@ static void check_csync_vio_closedir_null(void **state) static void check_csync_vio_readdir(void **state) { - CSYNC *csync = *state; + CSYNC *csync = (CSYNC*)*state; csync_vio_handle_t *dh; csync_vio_file_stat_t *dirent; int rc; @@ -164,4 +164,3 @@ int torture_run_tests(void) return run_tests(tests); } - diff --git a/test/csync/vio_tests/check_vio_ext.c b/test/csync/vio_tests/check_vio_ext.cpp similarity index 98% rename from test/csync/vio_tests/check_vio_ext.c rename to test/csync/vio_tests/check_vio_ext.cpp index c34e708c0..efa37a5d0 100644 --- a/test/csync/vio_tests/check_vio_ext.c +++ b/test/csync/vio_tests/check_vio_ext.cpp @@ -93,7 +93,7 @@ static void setup_testenv(void **state) { c_free_locale_string(dir); /* --- initialize csync */ - statevar *mystate = malloc( sizeof(statevar) ); + statevar *mystate = (statevar*)malloc( sizeof(statevar) ); mystate->result = NULL; csync_create(&(mystate->csync), "/tmp/csync1"); @@ -140,7 +140,7 @@ static void teardown(void **state) { static void create_dirs( const char *path ) { int rc; - char *mypath = c_malloc( 2+strlen(CSYNC_TEST_DIR)+strlen(path)); + char *mypath = (char*)c_malloc( 2+strlen(CSYNC_TEST_DIR)+strlen(path)); *mypath = '\0'; strcat(mypath, CSYNC_TEST_DIR); strcat(mypath, "/"); @@ -229,7 +229,7 @@ static void traverse_dir(void **state, const char *dir, int *cnt) } else { int newlen = 1+strlen(sv->result)+strlen(subdir_out); char *tmp = sv->result; - sv->result = c_malloc(newlen); + sv->result = (char*)c_malloc(newlen); strcpy( sv->result, tmp); SAFE_FREE(tmp); @@ -284,7 +284,7 @@ static void create_file( const char *path, const char *name, const char *content SAFE_FREE(dst); c_free_locale_string(w_fname); #else - char *filepath = c_malloc( 1+strlen(path) + strlen(name) ); + char *filepath = (char*)c_malloc( 1+strlen(path) + strlen(name) ); *filepath = '\0'; strcpy(filepath, path); @@ -406,7 +406,7 @@ static void check_readdir_longtree(void **state) /* assemble the result string ... */ int overall_len = 1+strlen(r1)+strlen(r2)+strlen(r3); int files_cnt = 0; - char *result = c_malloc(overall_len); + char *result = (char*)c_malloc(overall_len); *result = '\0'; strcat(result, r1); diff --git a/test/csync/vio_tests/check_vio_file_stat.c b/test/csync/vio_tests/check_vio_file_stat.cpp similarity index 100% rename from test/csync/vio_tests/check_vio_file_stat.c rename to test/csync/vio_tests/check_vio_file_stat.cpp -- 2.30.2