return 0;
}
-void csync_create(CSYNC **csync, const char *local) {
- CSYNC *ctx;
+csync_s::csync_s(const char *localUri, const char *db_file) {
size_t len = 0;
- ctx = (CSYNC*)c_malloc(sizeof(CSYNC));
-
- ctx->status_code = CSYNC_STATUS_OK;
-
/* remove trailing slashes */
- len = strlen(local);
- while(len > 0 && local[len - 1] == '/') --len;
-
- ctx->local.uri = c_strndup(local, len);
-
- ctx->status_code = CSYNC_STATUS_OK;
+ len = strlen(localUri);
+ while(len > 0 && localUri[len - 1] == '/') --len;
- ctx->current_fs = NULL;
+ local.uri = c_strndup(localUri, len);
- ctx->abort = false;
+ c_rbtree_create(&local.tree, _key_cmp, _data_cmp);
+ c_rbtree_create(&remote.tree, _key_cmp, _data_cmp);
- ctx->ignore_hidden_files = true;
-
- *csync = ctx;
-}
-
-void csync_init(CSYNC *ctx, const char *db_file) {
- assert(ctx);
- /* Do not initialize twice */
-
- assert(!(ctx->status & CSYNC_STATUS_INIT));
- ctx->status_code = CSYNC_STATUS_OK;
-
- SAFE_FREE(ctx->statedb.file);
- ctx->statedb.file = c_strdup(db_file);
-
- c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp);
- c_rbtree_create(&ctx->remote.tree, _key_cmp, _data_cmp);
-
- ctx->remote.root_perms = 0;
-
- ctx->status = CSYNC_STATUS_INIT;
-
- /* initialize random generator */
- srand(time(NULL));
+ statedb.file = c_strdup(db_file);
}
int csync_update(CSYNC *ctx) {
delete freedata;
}
-/* reset all the list to empty.
- * used by csync_commit and csync_destroy */
-static void _csync_clean_ctx(CSYNC *ctx)
-{
- /* destroy the rbtrees */
- if (c_rbtree_size(ctx->local.tree) > 0) {
- c_rbtree_destroy(ctx->local.tree, _tree_destructor);
- }
-
- if (c_rbtree_size(ctx->remote.tree) > 0) {
- c_rbtree_destroy(ctx->remote.tree, _tree_destructor);
- }
-
- csync_rename_destroy(ctx);
-
- /* free memory */
- c_rbtree_free(ctx->local.tree);
- c_rbtree_free(ctx->remote.tree);
-
- SAFE_FREE(ctx->remote.root_perms);
-}
-
-int csync_commit(CSYNC *ctx) {
+int csync_s::reinitialize() {
int rc = 0;
- if (ctx == NULL) {
- return -1;
- }
-
- ctx->status_code = CSYNC_STATUS_OK;
+ status_code = CSYNC_STATUS_OK;
- if (ctx->statedb.db != NULL
- && csync_statedb_close(ctx) < 0) {
+ if (statedb.db != NULL
+ && csync_statedb_close(this) < 0) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "ERR: closing of statedb failed.");
rc = -1;
}
- ctx->statedb.db = NULL;
+ statedb.db = NULL;
+
+ /* destroy the rbtrees */
+ if (c_rbtree_size(local.tree) > 0) {
+ c_rbtree_destroy(local.tree, _tree_destructor);
+ }
- _csync_clean_ctx(ctx);
+ if (c_rbtree_size(remote.tree) > 0) {
+ c_rbtree_destroy(remote.tree, _tree_destructor);
+ }
- ctx->remote.read_from_db = 0;
- ctx->read_remote_from_db = true;
- ctx->db_is_empty = false;
+ /* free memory */
+ c_rbtree_free(local.tree);
+ c_rbtree_free(remote.tree);
+ remote.read_from_db = 0;
+ read_remote_from_db = true;
+ db_is_empty = false;
/* Create new trees */
- c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp);
- c_rbtree_create(&ctx->remote.tree, _key_cmp, _data_cmp);
-
+ c_rbtree_create(&local.tree, _key_cmp, _data_cmp);
+ c_rbtree_create(&remote.tree, _key_cmp, _data_cmp);
- ctx->status = CSYNC_STATUS_INIT;
- SAFE_FREE(ctx->error_string);
+ status = CSYNC_STATUS_INIT;
+ SAFE_FREE(error_string);
rc = 0;
return rc;
}
-int csync_destroy(CSYNC *ctx) {
- int rc = 0;
-
- if (ctx == NULL) {
- errno = EBADF;
- return -1;
- }
- ctx->status_code = CSYNC_STATUS_OK;
-
- if (ctx->statedb.db != NULL
- && csync_statedb_close(ctx) < 0) {
+csync_s::~csync_s() {
+ if (statedb.db != NULL
+ && csync_statedb_close(this) < 0) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "ERR: closing of statedb failed.");
- rc = -1;
}
- ctx->statedb.db = NULL;
+ statedb.db = NULL;
- _csync_clean_ctx(ctx);
+ /* destroy the rbtrees */
+ if (c_rbtree_size(local.tree) > 0) {
+ c_rbtree_destroy(local.tree, _tree_destructor);
+ }
- SAFE_FREE(ctx->statedb.file);
- SAFE_FREE(ctx->local.uri);
- SAFE_FREE(ctx->error_string);
+ if (c_rbtree_size(remote.tree) > 0) {
+ c_rbtree_destroy(remote.tree, _tree_destructor);
+ }
- SAFE_FREE(ctx);
+ /* free memory */
+ c_rbtree_free(local.tree);
+ c_rbtree_free(remote.tree);
- return rc;
+ SAFE_FREE(statedb.file);
+ SAFE_FREE(local.uri);
+ SAFE_FREE(error_string);
}
void *csync_get_userdata(CSYNC *ctx) {
typedef struct csync_file_stat_s csync_file_stat_t;
-struct csync_file_stat_s {
+struct OCSYNC_EXPORT csync_file_stat_s {
uint64_t phash;
time_t modtime;
int64_t size;
typedef QByteArray (*csync_checksum_hook)(
const QByteArray &path, const QByteArray &otherChecksumHeader, void *userdata);
-/**
- * @brief Allocate a csync context.
- *
- * @param csync The context variable to allocate.
- */
-void OCSYNC_EXPORT csync_create(CSYNC **csync, const char *local);
-
-/**
- * @brief Initialize the file synchronizer.
- *
- * This function loads the configuration
- *
- * @param ctx The context to initialize.
- */
-void OCSYNC_EXPORT csync_init(CSYNC *ctx, const char *db_file);
-
/**
* @brief Update detection
*
*/
int OCSYNC_EXPORT csync_reconcile(CSYNC *ctx);
-/**
- * @brief Re-initializes the csync context
- *
- * @param ctx The context to commit.
- *
- * @return 0 on success, less than 0 if an error occurred.
- */
-int OCSYNC_EXPORT csync_commit(CSYNC *ctx);
-
-/**
- * @brief Destroy the csync context
- *
- * frees the memory.
- *
- * @param ctx The context to destroy.
- *
- * @return 0 on success, less than 0 if an error occurred.
- */
-int OCSYNC_EXPORT csync_destroy(CSYNC *ctx);
-
/**
* @brief Get the userdata saved in the context.
*
#ifndef _CSYNC_PRIVATE_H
#define _CSYNC_PRIVATE_H
+#include <map>
#include <stdint.h>
#include <stdbool.h>
#include <sqlite3.h>
/**
* @brief csync public structure
*/
-struct csync_s {
+struct OCSYNC_EXPORT csync_s {
struct {
- csync_auth_callback auth_function;
- void *userdata;
- csync_update_callback update_callback;
- void *update_callback_userdata;
+ csync_auth_callback auth_function = nullptr;
+ void *userdata = nullptr;
+ csync_update_callback update_callback = nullptr;
+ void *update_callback_userdata = nullptr;
/* hooks for checking the white list (uses the update_callback_userdata) */
- int (*checkSelectiveSyncBlackListHook)(void*, const char*);
- int (*checkSelectiveSyncNewFolderHook)(void*, const char* /* path */, const char* /* remotePerm */);
+ int (*checkSelectiveSyncBlackListHook)(void*, const char*) = nullptr;
+ int (*checkSelectiveSyncNewFolderHook)(void*, const char* /* path */, const char* /* remotePerm */) = nullptr;
- csync_vio_opendir_hook remote_opendir_hook;
- csync_vio_readdir_hook remote_readdir_hook;
- csync_vio_closedir_hook remote_closedir_hook;
- void *vio_userdata;
+ csync_vio_opendir_hook remote_opendir_hook = nullptr;
+ csync_vio_readdir_hook remote_readdir_hook = nullptr;
+ csync_vio_closedir_hook remote_closedir_hook = nullptr;
+ void *vio_userdata = nullptr;
/* hook for comparing checksums of files during discovery */
- csync_checksum_hook checksum_hook;
- void *checksum_userdata;
+ csync_checksum_hook checksum_hook = nullptr;
+ void *checksum_userdata = nullptr;
} callbacks;
- c_strlist_t *excludes;
+ c_strlist_t *excludes = nullptr;
struct {
- char *file;
- sqlite3 *db;
- int exists;
+ char *file = nullptr;
+ sqlite3 *db = nullptr;
+ bool exists = false;
- sqlite3_stmt* by_hash_stmt;
- sqlite3_stmt* by_fileid_stmt;
- sqlite3_stmt* by_inode_stmt;
+ sqlite3_stmt* by_hash_stmt = nullptr;
+ sqlite3_stmt* by_fileid_stmt = nullptr;
+ sqlite3_stmt* by_inode_stmt = nullptr;
int lastReturnValue;
} statedb;
struct {
- char *uri;
- c_rbtree_t *tree;
+ std::map<std::string, std::string> folder_renamed_to; // map from->to
+ std::map<std::string, std::string> folder_renamed_from; // map to->from
+ } renames;
+
+ struct {
+ char *uri = nullptr;
+ c_rbtree_t *tree = nullptr;
} local;
struct {
- c_rbtree_t *tree;
- int read_from_db;
- const char *root_perms; /* Permission of the root folder. (Since the root folder is not in the db tree, we need to keep a separate entry.) */
+ c_rbtree_t *tree = nullptr;
+ bool read_from_db = false;
+ QByteArray root_perms; /* Permission of the root folder. (Since the root folder is not in the db tree, we need to keep a separate entry.) */
} remote;
-
/* replica we are currently walking */
- enum csync_replica_e current;
+ enum csync_replica_e current = LOCAL_REPLICA;
/* Used in the update phase so changes in the sub directories can be notified to
parent directories */
- csync_file_stat_t *current_fs;
+ csync_file_stat_t *current_fs = nullptr;
/* csync error code */
- enum csync_status_codes_e status_code;
+ enum csync_status_codes_e status_code = CSYNC_STATUS_OK;
- char *error_string;
+ char *error_string = nullptr;
- int status;
- volatile int abort;
- void *rename_info;
+ int status = CSYNC_STATUS_INIT;
+ volatile bool abort = false;
/**
* Specify if it is allowed to read the remote tree from the DB (default to enabled)
*/
- bool read_remote_from_db;
+ bool read_remote_from_db = false;
/**
* If true, the DB is considered empty and all reads are skipped. (default is false)
* This is useful during the initial local discovery as it speeds it up significantly.
*/
- bool db_is_empty;
+ bool db_is_empty = false;
+
+ bool ignore_hidden_files = true;
- bool ignore_hidden_files;
+ csync_s(const char *localUri, const char *db_file);
+ ~csync_s();
+ int reinitialize();
};
/*
#include "csync_private.h"
#include "csync_rename.h"
-#include <map>
#include <string>
#include <vector>
#include <algorithm>
return path.substr(0, len);
}
-struct csync_rename_s {
- static csync_rename_s *get(CSYNC *ctx) {
- if (!ctx->rename_info) {
- ctx->rename_info = new csync_rename_s;
- }
- return reinterpret_cast<csync_rename_s *>(ctx->rename_info);
- }
-
- std::map<std::string, std::string> folder_renamed_to; // map from->to
- std::map<std::string, std::string> folder_renamed_from; // map to->from
-};
-
-void csync_rename_destroy(CSYNC* ctx)
-{
- delete reinterpret_cast<csync_rename_s *>(ctx->rename_info);
- ctx->rename_info = 0;
-}
-
void csync_rename_record(CSYNC* ctx, const char* from, const char* to)
{
- csync_rename_s::get(ctx)->folder_renamed_to[from] = to;
- csync_rename_s::get(ctx)->folder_renamed_from[to] = from;
+ ctx->renames.folder_renamed_to[from] = to;
+ ctx->renames.folder_renamed_from[to] = from;
}
char* csync_rename_adjust_path(CSYNC* ctx, const char* path)
{
- csync_rename_s* d = csync_rename_s::get(ctx);
for (std::string p = _parentDir(path); !p.empty(); p = _parentDir(p)) {
- std::map< std::string, std::string >::iterator it = d->folder_renamed_to.find(p);
- if (it != d->folder_renamed_to.end()) {
+ std::map< std::string, std::string >::iterator it = ctx->renames.folder_renamed_to.find(p);
+ if (it != ctx->renames.folder_renamed_to.end()) {
std::string rep = it->second + (path + p.length());
return c_strdup(rep.c_str());
}
char* csync_rename_adjust_path_source(CSYNC* ctx, const char* path)
{
- csync_rename_s* d = csync_rename_s::get(ctx);
for (std::string p = _parentDir(path); !p.empty(); p = _parentDir(p)) {
- std::map< std::string, std::string >::iterator it = d->folder_renamed_from.find(p);
- if (it != d->folder_renamed_from.end()) {
+ std::map< std::string, std::string >::iterator it = ctx->renames.folder_renamed_from.find(p);
+ if (it != ctx->renames.folder_renamed_from.end()) {
std::string rep = it->second + (path + p.length());
return c_strdup(rep.c_str());
}
}
bool csync_rename_count(CSYNC *ctx) {
- csync_rename_s* d = csync_rename_s::get(ctx);
- return d->folder_renamed_from.size();
+ return ctx->renames.folder_renamed_from.size();
}
char OCSYNC_EXPORT *csync_rename_adjust_path(CSYNC *ctx, const char *path);
/* Return the source of a given path in case of renames */
char OCSYNC_EXPORT *csync_rename_adjust_path_source(CSYNC *ctx, const char *path);
-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);
void DiscoveryMainThread::singleDirectoryJobFirstDirectoryPermissionsSlot(const QString &p)
{
// Should be thread safe since the sync thread is blocked
- if (!_discoveryJob->_csync_ctx->remote.root_perms) {
+ if (_discoveryJob->_csync_ctx->remote.root_perms.isEmpty()) {
qCDebug(lcDiscovery) << "Permissions for root dir:" << p;
- _discoveryJob->_csync_ctx->remote.root_perms = strdup(p.toUtf8());
+ _discoveryJob->_csync_ctx->remote.root_perms = p.toUtf8();
}
}
// Everything in the SyncEngine expects a trailing slash for the localPath.
ASSERT(localPath.endsWith(QLatin1Char('/')));
- csync_create(&_csync_ctx, localPath.toUtf8().data());
-
const QString dbFile = _journal->databaseFilePath();
- csync_init(_csync_ctx, dbFile.toUtf8().data());
+ _csync_ctx.reset(new CSYNC(localPath.toUtf8().data(), dbFile.toUtf8().data()));
_excludedFiles.reset(new ExcludedFiles(&_csync_ctx->excludes));
_syncFileStatusTracker.reset(new SyncFileStatusTracker(this));
_thread.quit();
_thread.wait();
_excludedFiles.reset();
- csync_destroy(_csync_ctx);
}
//Convert an error code from csync to a user readable string.
_syncItemMap.clear();
_needsUpdate = false;
- csync_resume(_csync_ctx);
+ csync_resume(_csync_ctx.data());
int fileRecordCount = -1;
if (!_journal->exists()) {
finalize(false);
return;
}
- csync_set_userdata(_csync_ctx, this);
+ csync_set_userdata(_csync_ctx.data(), this);
// Set up checksumming hook
_csync_ctx->callbacks.checksum_hook = &CSyncChecksumHook::hook;
connect(_discoveryMainThread, SIGNAL(etagConcatenation(QString)), this, SLOT(slotRootEtagReceived(QString)));
}
- DiscoveryJob *discoveryJob = new DiscoveryJob(_csync_ctx);
+ DiscoveryJob *discoveryJob = new DiscoveryJob(_csync_ctx.data());
discoveryJob->_selectiveSyncBlackList = selectiveSyncBlackList;
discoveryJob->_selectiveSyncWhiteList =
_journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, &ok);
void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
{
if (discoveryResult < 0) {
- handleSyncError(_csync_ctx, "csync_update");
+ handleSyncError(_csync_ctx.data(), "csync_update");
return;
}
qCInfo(lcEngine) << "#### Discovery end #################################################### " << _stopWatch.addLapTime(QLatin1String("Discovery Finished")) << "ms";
_progressInfo->_status = ProgressInfo::Reconcile;
emit transmissionProgress(*_progressInfo);
- if (csync_reconcile(_csync_ctx) < 0) {
- handleSyncError(_csync_ctx, "csync_reconcile");
+ if (csync_reconcile(_csync_ctx.data()) < 0) {
+ handleSyncError(_csync_ctx.data(), "csync_reconcile");
return;
}
_temporarilyUnavailablePaths.clear();
_renamedFolders.clear();
- if (csync_walk_local_tree(_csync_ctx, &treewalkLocal, 0) < 0) {
+ if (csync_walk_local_tree(_csync_ctx.data(), &treewalkLocal, 0) < 0) {
qCWarning(lcEngine) << "Error in local treewalk.";
walkOk = false;
}
- if (walkOk && csync_walk_remote_tree(_csync_ctx, &treewalkRemote, 0) < 0) {
+ if (walkOk && csync_walk_remote_tree(_csync_ctx.data(), &treewalkRemote, 0) < 0) {
qCWarning(lcEngine) << "Error in remote treewalk.";
}
- if (_csync_ctx->remote.root_perms) {
+ if (!_csync_ctx->remote.root_perms.isEmpty()) {
_remotePerms[QLatin1String("")] = _csync_ctx->remote.root_perms;
qCInfo(lcEngine) << "Permissions of the root folder: " << _remotePerms[QLatin1String("")];
}
// Re-init the csync context to free memory
- csync_commit(_csync_ctx);
+ _csync_ctx->reinitialize();
// The map was used for merging trees, convert it to a list:
SyncFileItemVector syncItems = _syncItemMap.values().toVector();
_thread.quit();
_thread.wait();
- csync_commit(_csync_ctx);
+ _csync_ctx->reinitialize();
_journal->close();
qCInfo(lcEngine) << "CSync run took " << _stopWatch.addLapTime(QLatin1String("Sync Finished")) << "ms";
qCInfo(lcEngine) << "Aborting sync";
// Sets a flag for the update phase
- csync_request_abort(_csync_ctx);
+ csync_request_abort(_csync_ctx.data());
// Aborts the discovery phase job
if (_discoveryMainThread) {
QMap<QString, SyncFileItemPtr> _syncItemMap;
AccountPtr _account;
- CSYNC *_csync_ctx;
+ QScopedPointer<CSYNC> _csync_ctx;
bool _needsUpdate;
bool _syncRunning;
QString _localPath;
# This will be rewritten soon anyway.
#add_cmocka_test(check_logger log_tests/check_log.cpp ${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_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.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 vio_tests/check_vio.cpp ${TEST_TARGET_LIBRARIES})
+++ /dev/null
-/*
- * 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 <string.h>
-
-#include "torture.h"
-
-#include "csync_private.h"
-
-static int setup(void **state) {
- CSYNC *csync;
- int rc;
-
- rc = system("mkdir -p /tmp/check_csync1");
- assert_int_equal(rc, 0);
-
- csync_create(&csync, "/tmp/check_csync1");
-
- *state = csync;
-
- return 0;
-}
-
-static int setup_module(void **state) {
- CSYNC *csync;
- int rc;
-
- rc = system("mkdir -p /tmp/check_csync1");
- assert_int_equal(rc, 0);
-
- csync_create(&csync, "/tmp/check_csync1");
-
- csync_init(csync, "foo");
- *state = csync;
-
- return 0;
-}
-
-static int teardown(void **state) {
- CSYNC *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);
-
- *state = NULL;
-
- return 0;
-}
-
-static void check_csync_commit(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
- int rc;
-
- rc = csync_commit(csync);
- assert_int_equal(rc, 0);
-
- assert_int_equal(csync->status & CSYNC_STATUS_INIT, 1);
-}
-
-static void check_csync_commit_dummy(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
- int rc;
-
- rc = csync_commit(csync);
- assert_int_equal(rc, 0);
-
- assert_int_equal(csync->status & CSYNC_STATUS_INIT, 1);
-
-}
-
-int torture_run_tests(void)
-{
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(check_csync_commit, setup, teardown),
- cmocka_unit_test_setup_teardown(check_csync_commit_dummy, setup_module, teardown),
- };
-
- return cmocka_run_group_tests(tests, NULL, NULL);
-}
+++ /dev/null
-/*
- * 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 <stdlib.h>
-#include <stdio.h>
-
-#include "torture.h"
-
-#include "csync_private.h"
-
-
-static void check_csync_destroy_null(void **state)
-{
- int rc;
-
- (void) state; /* unused */
-
- rc = csync_destroy(NULL);
- assert_int_equal(rc, -1);
-}
-
-static void check_csync_create(void **state)
-{
- CSYNC *csync;
- int rc;
-
- (void) state; /* unused */
-
- csync_create(&csync, "/tmp/csync1");
-
- rc = csync_destroy(csync);
- assert_int_equal(rc, 0);
-}
-
-int torture_run_tests(void)
-{
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(check_csync_destroy_null),
- cmocka_unit_test(check_csync_create),
- };
-
- return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
static int setup(void **state) {
CSYNC *csync;
- csync_create(&csync, "/tmp/check_csync1");
+ csync = new CSYNC("/tmp/check_csync1", "");
*state = csync;
return 0;
CSYNC *csync;
int rc;
- csync_create(&csync, "/tmp/check_csync1");
+ csync = new CSYNC("/tmp/check_csync1", "");
rc = csync_exclude_load(EXCLUDE_LIST_FILE, &(csync->excludes));
assert_int_equal(rc, 0);
CSYNC *csync = (CSYNC*)*state;
int rc;
- rc = csync_destroy(csync);
- assert_int_equal(rc, 0);
+ delete csync;
rc = system("rm -rf /tmp/check_csync1");
assert_int_equal(rc, 0);
+++ /dev/null
-/*
- * 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 <string.h>
-
-#include "torture.h"
-
-#include "csync_private.h"
-
-static int setup(void **state) {
- CSYNC *csync;
- int rc;
-
- rc = system("mkdir -p /tmp/check_csync1");
- assert_int_equal(rc, 0);
-
- csync_create(&csync, "/tmp/check_csync1");
-
- *state = csync;
- return 0;
-}
-
-static int setup_module(void **state) {
- CSYNC *csync;
- int rc;
-
- rc = system("mkdir -p /tmp/check_csync1");
- assert_int_equal(rc, 0);
-
- csync_create(&csync, "/tmp/check_csync1");
-
- *state = csync;
- return 0;
-}
-
-static int teardown(void **state) {
- CSYNC *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);
-
- *state = NULL;
-
- return 0;
-}
-
-static void check_csync_init(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
-
- csync_init(csync, "");
-
- assert_int_equal(csync->status & CSYNC_STATUS_INIT, 1);
-
-}
-
-int torture_run_tests(void)
-{
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(check_csync_init, setup, teardown),
- cmocka_unit_test_setup_teardown(check_csync_init, setup_module, teardown),
- };
-
- return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
#include "std/c_utf8.h"
static int setup(void **state) {
- CSYNC *csync;
int rc;
rc = system("mkdir -p /tmp/check_csync1");
assert_int_equal(rc, 0);
- csync_create(&csync, "/tmp/check_csync1");
+ *state = NULL;
- *state = csync;
-
return 0;
}
static int teardown(void **state) {
- CSYNC *csync = (CSYNC*)*state;
int rc;
- rc = csync_destroy(csync);
-
rc = system("rm -rf /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->statedb.file = c_strdup( TESTDB );
+ csync = new CSYNC("/tmp/check_csync1", TESTDB);
*state = csync;
sqlite3 *db = NULL;
CSYNC *csync = (CSYNC*)*state;
int rc;
- rc = csync_destroy(csync);
- assert_int_equal(rc, 0);
+ delete csync;
rc = system("rm -rf /tmp/check_csync1");
assert_int_equal(rc, 0);
assert_int_equal(rc, 0);
rc = system("mkdir -p /tmp/check_csync");
assert_int_equal(rc, 0);
- csync_create(&csync, "/tmp/check_csync1");
- csync_init(csync, TESTDB);
+ csync = new CSYNC("/tmp/check_csync1", TESTDB);
sqlite3 *db = NULL;
rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
CSYNC *csync = (CSYNC*)*state;
int rc = 0;
- rc = csync_destroy(csync);
- assert_int_equal(rc, 0);
+ delete 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("mkdir -p /tmp/check_csync1");
assert_int_equal(rc, 0);
- csync_create(&csync, "/tmp/check_csync1");
- csync_init(csync, TESTDB);
+ csync = new CSYNC("/tmp/check_csync1", TESTDB);
/* Create a new db with metadata */
sqlite3 *db;
- csync->statedb.file = c_strdup(TESTDB);
+ // csync->statedb.file = c_strdup(TESTDB);
rc = sqlite3_open(csync->statedb.file, &db);
statedb_create_metadata_table(db);
if( firstrun ) {
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);
+ csync = new CSYNC("/tmp", TESTDB);
sqlite3 *db = NULL;
rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
static int teardown(void **state)
{
CSYNC *csync = (CSYNC*)*state;
- int rc;
unlink( csync->statedb.file);
- rc = csync_destroy(csync);
- assert_int_equal(rc, 0);
+ delete csync;
*state = NULL;
rc = system("rm -rf /tmp/csync_test");
assert_int_equal(rc, 0);
- csync_create(&csync, "/tmp/csync1");
+ csync = new CSYNC("/tmp/check_csync1", "");
csync->current = LOCAL_REPLICA;
CSYNC *csync = (CSYNC*)*state;
int rc;
- rc = csync_destroy(csync);
- assert_int_equal(rc, 0);
+ delete csync;
rc = chdir(wd_buffer);
assert_int_equal(rc, 0);
statevar *mystate = (statevar*)malloc( sizeof(statevar) );
mystate->result = NULL;
- csync_create(&(mystate->csync), "/tmp/csync1");
+ mystate->csync = new CSYNC("/tmp/check_csync1", "");
mystate->csync->current = LOCAL_REPLICA;
output("================== Tearing down!\n");
- rc = csync_destroy(csync);
- assert_int_equal(rc, 0);
+ delete csync;
rc = _tchdir(wd_buffer);
assert_int_equal(rc, 0);
Q_OBJECT
private:
- CSYNC _ctx;
+ CSYNC *_ctx;
private slots:
void initTestCase() {
int rc;
- memset(&_ctx, 0, sizeof(CSYNC));
-
QString db = QCoreApplication::applicationDirPath() + "/test_journal.db";
- _ctx.statedb.file = c_strdup(db.toLocal8Bit());
+ _ctx = new CSYNC("/tmp/check_csync1", db.toLocal8Bit());
- rc = csync_statedb_load((CSYNC*)(&_ctx), _ctx.statedb.file, &(_ctx.statedb.db));
+ rc = csync_statedb_load(_ctx, _ctx->statedb.file, &(_ctx->statedb.db));
QVERIFY(rc == 0);
}
void testFullResult() {
- std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_hash((CSYNC*)(&_ctx), 2081025720555645157 );
+ std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_hash( _ctx, 2081025720555645157 );
QVERIFY(st.get());
QCOMPARE( QString::number(st->phash), QString::number(2081025720555645157) );
QCOMPARE( QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu") );
}
void testByHash() {
- std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_hash((CSYNC*)(&_ctx), -7147279406142960289);
+ std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_hash(_ctx, -7147279406142960289);
QVERIFY(st.get());
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1"));
- st = csync_statedb_get_stat_by_hash((CSYNC*)(&_ctx), 5426481156826978940);
+ st = csync_statedb_get_stat_by_hash(_ctx, 5426481156826978940);
QVERIFY(st.get());
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1/c2"));
}
void testByInode() {
- std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_inode((CSYNC*)(&_ctx), 1709555);
+ std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_inode(_ctx, 1709555);
QVERIFY(st.get());
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu/zuzuzu"));
- st = csync_statedb_get_stat_by_inode((CSYNC*)(&_ctx), 1706571);
+ st = csync_statedb_get_stat_by_inode(_ctx, 1706571);
QVERIFY(st.get());
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("Shared/for_kf/a2"));
}
void testByFileId() {
- std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_file_id((CSYNC*)(&_ctx), "00000556525d5af3d9625");
+ std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_file_id(_ctx, "00000556525d5af3d9625");
QVERIFY(st.get());
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu"));
- st = csync_statedb_get_stat_by_file_id((CSYNC*)(&_ctx), "-0000001525d5af3d9625");
+ st = csync_statedb_get_stat_by_file_id(_ctx, "-0000001525d5af3d9625");
QVERIFY(st.get());
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("Shared"));
}
void cleanupTestCase() {
- SAFE_FREE(_ctx.statedb.file);
- csync_statedb_close((CSYNC*)(&_ctx));
+ csync_statedb_close(_ctx);
+ delete _ctx;
+ _ctx = nullptr;
}
};