Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJocelyn Turcotte <jturcotte@woboq.com>2017-09-14 16:50:13 +0300
committerOlivier Goffart <olivier@woboq.com>2017-09-26 12:03:23 +0300
commita034ee894ccfbab5164ed2800e511fbb7c0fbe70 (patch)
treef11b0733aa8f70e5f4bcb19c9bae2623378ac77b /test
parent6f46764daa59460a4cbdc7327255a6dc4d631590 (diff)
Use SyncJournalDb in csync
This gets rid of the csync_statedb sqlite layer and use the same code and same connection as the rest of the SyncEngine. Missing functions are added to SyncJournalDb and change a few minor things (like changing SyncJournalFileRecord::_modtime to be an int64 instead of a QDateTime, like it was in csync).
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/csync/CMakeLists.txt4
-rw-r--r--test/csync/csync_tests/check_csync_exclude.cpp6
-rw-r--r--test/csync/csync_tests/check_csync_statedb_load.cpp127
-rw-r--r--test/csync/csync_tests/check_csync_statedb_query.cpp217
-rw-r--r--test/csync/csync_tests/check_csync_update.cpp20
-rw-r--r--test/csync/vio_tests/check_vio.cpp4
-rw-r--r--test/csync/vio_tests/check_vio_ext.cpp4
-rw-r--r--test/testcsyncsqlite.cpp80
-rw-r--r--test/testsyncengine.cpp36
-rw-r--r--test/testsyncjournaldb.cpp24
-rw-r--r--test/testuploadreset.cpp2
12 files changed, 51 insertions, 474 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d6b68cb5c..d5cc8615f 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -33,7 +33,6 @@ IF( APPLE )
list(APPEND FolderWatcher_SRC ../src/gui/folderwatcher_mac.cpp)
list(APPEND FolderWatcher_SRC ../src/gui/socketapisocket_mac.mm)
ENDIF()
-owncloud_add_test(CSyncSqlite "")
owncloud_add_test(NetrcParser ../src/cmd/netrcparser.cpp)
owncloud_add_test(OwnSql "")
owncloud_add_test(SyncJournalDB "")
diff --git a/test/csync/CMakeLists.txt b/test/csync/CMakeLists.txt
index 237c52e27..5cb0590e4 100644
--- a/test/csync/CMakeLists.txt
+++ b/test/csync/CMakeLists.txt
@@ -32,13 +32,9 @@ add_cmocka_test(check_std_c_time std_tests/check_std_c_time.c ${TEST_TARGET_LIBR
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_statedb_query csync_tests/check_csync_statedb_query.cpp ${TEST_TARGET_LIBRARIES})
-
# vio
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})
diff --git a/test/csync/csync_tests/check_csync_exclude.cpp b/test/csync/csync_tests/check_csync_exclude.cpp
index 0525942ac..3f0180e42 100644
--- a/test/csync/csync_tests/check_csync_exclude.cpp
+++ b/test/csync/csync_tests/check_csync_exclude.cpp
@@ -32,7 +32,7 @@
static int setup(void **state) {
CSYNC *csync;
- csync = new CSYNC("/tmp/check_csync1", "");
+ csync = new CSYNC("/tmp/check_csync1", new OCC::SyncJournalDb(""));
*state = csync;
return 0;
@@ -42,7 +42,7 @@ static int setup_init(void **state) {
CSYNC *csync;
int rc;
- csync = new CSYNC("/tmp/check_csync1", "");
+ csync = new CSYNC("/tmp/check_csync1", new OCC::SyncJournalDb(""));
rc = csync_exclude_load(EXCLUDE_LIST_FILE, &(csync->excludes));
assert_int_equal(rc, 0);
@@ -67,7 +67,9 @@ static int teardown(void **state) {
CSYNC *csync = (CSYNC*)*state;
int rc;
+ auto statedb = csync->statedb;
delete csync;
+ delete statedb;
rc = system("rm -rf /tmp/check_csync1");
assert_int_equal(rc, 0);
diff --git a/test/csync/csync_tests/check_csync_statedb_load.cpp b/test/csync/csync_tests/check_csync_statedb_load.cpp
deleted file mode 100644
index f5761f9ff..000000000
--- a/test/csync/csync_tests/check_csync_statedb_load.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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>
-
-#define CSYNC_TEST 1
-#include "csync_statedb.cpp"
-
-#include "torture.h"
-
-#define TESTDB "/tmp/check_csync1/test.db"
-
-static int setup(void **state) {
- CSYNC *csync;
- int rc;
-
- 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 = new CSYNC("/tmp/check_csync1", TESTDB);
- *state = csync;
-
- sqlite3 *db = NULL;
- rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
- assert_int_equal(rc, SQLITE_OK);
-
- rc = sqlite3_close(db);
- assert_int_equal(rc, SQLITE_OK);
-
- return 0;
-}
-
-static int teardown(void **state) {
- CSYNC *csync = (CSYNC*)*state;
- int rc;
-
- delete csync;
-
- rc = system("rm -rf /tmp/check_csync1");
- assert_int_equal(rc, 0);
-
- *state = NULL;
-
- return 0;
-}
-
-static void check_csync_statedb_load(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
- int rc;
-
- rc = csync_statedb_load(csync, TESTDB, &csync->statedb.db);
- assert_int_equal(rc, 0);
-
- sqlite3_close(csync->statedb.db);
-}
-
-static void check_csync_statedb_close(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
- csync_stat_t sb;
- time_t modtime;
- mbchar_t *testdb = c_utf8_path_to_locale(TESTDB);
- int rc;
-
- /* statedb not written */
- csync_statedb_load(csync, TESTDB, &csync->statedb.db);
-
- rc = _tstat(testdb, &sb);
- assert_int_equal(rc, 0);
- modtime = sb.st_mtime;
-
- rc = csync_statedb_close(csync);
- assert_int_equal(rc, 0);
-
- rc = _tstat(testdb, &sb);
- assert_int_equal(rc, 0);
- assert_int_equal(modtime, sb.st_mtime);
-
- csync_statedb_load(csync, TESTDB, &csync->statedb.db);
-
- rc = _tstat(testdb, &sb);
- assert_int_equal(rc, 0);
- modtime = sb.st_mtime;
-
- /* wait a sec or the modtime will be the same */
- sleep(1);
-
- /* statedb written */
- rc = csync_statedb_close(csync);
- assert_int_equal(rc, 0);
-
- rc = _tstat(testdb, &sb);
- assert_int_equal(rc, 0);
-
- c_free_locale_string(testdb);
-}
-
-int torture_run_tests(void)
-{
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(check_csync_statedb_load, setup, teardown),
- cmocka_unit_test_setup_teardown(check_csync_statedb_close, setup, teardown),
- };
-
- return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
diff --git a/test/csync/csync_tests/check_csync_statedb_query.cpp b/test/csync/csync_tests/check_csync_statedb_query.cpp
deleted file mode 100644
index 7f3988a71..000000000
--- a/test/csync/csync_tests/check_csync_statedb_query.cpp
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * 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
- */
-
-#define CSYNC_TEST 1
-#include "csync_statedb.cpp"
-
-#include "torture.h"
-
-#define TESTDB "/tmp/check_csync1/test.db"
-#define TESTDBTMP "/tmp/check_csync1/test.db.ctmp"
-
-
-static int setup(void **state)
-{
- CSYNC *csync;
- int 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);
- rc = system("mkdir -p /tmp/check_csync");
- assert_int_equal(rc, 0);
- csync = new CSYNC("/tmp/check_csync1", TESTDB);
-
- sqlite3 *db = NULL;
- rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
- assert_int_equal(rc, SQLITE_OK);
- rc = sqlite3_close(db);
- assert_int_equal(rc, SQLITE_OK);
-
- rc = csync_statedb_load(csync, TESTDB, &csync->statedb.db);
- assert_int_equal(rc, 0);
-
- *state = csync;
-
- return 0;
-}
-
-static int setup_db(void **state)
-{
- char *errmsg;
- int rc = 0;
- sqlite3 *db = NULL;
-
- 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),"
- "PRIMARY KEY(phash)"
- ");";
-
- const char *sql2 = "INSERT INTO metadata"
- "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5) VALUES"
- "(42, 42, 'Its funny stuff', 23, 42, 43, 55, 66, 2, 54);";
-
-
- setup(state);
- rc = sqlite3_open( TESTDB, &db);
- assert_int_equal(rc, SQLITE_OK);
-
- rc = sqlite3_exec( db, sql, NULL, NULL, &errmsg );
- assert_int_equal(rc, SQLITE_OK);
-
- rc = sqlite3_exec( db, sql2, NULL, NULL, &errmsg );
- assert_int_equal(rc, SQLITE_OK);
-
- sqlite3_close(db);
-
- return 0;
-
-}
-
-static int teardown(void **state) {
- CSYNC *csync = (CSYNC*)*state;
- int 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);
-
- *state = NULL;
-
- return 0;
-}
-
-
-static void check_csync_statedb_query_statement(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
- c_strlist_t *result;
-
- result = csync_statedb_query(csync->statedb.db, "");
- assert_null(result);
- if (result != NULL) {
- c_strlist_destroy(result);
- }
-
- result = csync_statedb_query(csync->statedb.db, "SELECT;");
- assert_null(result);
- if (result != NULL) {
- c_strlist_destroy(result);
- }
-}
-
-static void check_csync_statedb_drop_tables(void **state)
-{
- // CSYNC *csync = (CSYNC*)*state;
- int rc = 0;
- (void) state;
-
- // rc = csync_statedb_drop_tables(csync->statedb.db);
- assert_int_equal(rc, 0);
- // rc = csync_statedb_create_tables(csync->statedb.db);
- assert_int_equal(rc, 0);
- // rc = csync_statedb_drop_tables(csync->statedb.db);
- assert_int_equal(rc, 0);
-}
-
-static void check_csync_statedb_insert_metadata(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
- std::unique_ptr<csync_file_stat_t> st;
- int i, rc = 0;
-
- // rc = csync_statedb_create_tables(csync->statedb.db);
- assert_int_equal(rc, 0);
-
- for (i = 0; i < 100; i++) {
- st.reset(new csync_file_stat_t);
- st->path = QString("file_%1").arg(i).toUtf8();
-
- csync->local.files[st->path] = std::move(st);
- }
-
- // rc = csync_statedb_insert_metadata(csync, csync->statedb.db);
- assert_int_equal(rc, 0);
-}
-
-static void check_csync_statedb_write(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
- std::unique_ptr<csync_file_stat_t> st;
- int i, rc = 0;
-
- for (i = 0; i < 100; i++) {
- st.reset(new csync_file_stat_t);
- st->path = QString("file_%1").arg(i).toUtf8();
-
- csync->local.files[st->path] = std::move(st);
- assert_int_equal(rc, 0);
- }
-
- // rc = csync_statedb_write(csync, csync->statedb.db);
- assert_int_equal(rc, 0);
-}
-
-
-static void check_csync_statedb_get_stat_by_path_not_found(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
- std::unique_ptr<csync_file_stat_t> tmp;
-
- tmp = csync_statedb_get_stat_by_path(csync, "666");
- assert_null(tmp.get());
-}
-
-
-static void check_csync_statedb_get_stat_by_inode_not_found(void **state)
-{
- CSYNC *csync = (CSYNC*)*state;
- std::unique_ptr<csync_file_stat_t> tmp;
-
- tmp = csync_statedb_get_stat_by_inode(csync, (ino_t) 666);
- assert_null(tmp.get());
-}
-
-int torture_run_tests(void)
-{
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(check_csync_statedb_query_statement, setup, teardown),
- cmocka_unit_test_setup_teardown(check_csync_statedb_drop_tables, setup, teardown),
- cmocka_unit_test_setup_teardown(check_csync_statedb_insert_metadata, setup, teardown),
- cmocka_unit_test_setup_teardown(check_csync_statedb_write, setup, teardown),
- cmocka_unit_test_setup_teardown(check_csync_statedb_get_stat_by_path_not_found, setup_db, teardown),
- cmocka_unit_test_setup_teardown(check_csync_statedb_get_stat_by_inode_not_found, setup_db, teardown),
- };
-
- return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
diff --git a/test/csync/csync_tests/check_csync_update.cpp b/test/csync/csync_tests/check_csync_update.cpp
index 4fae4e1a7..db6819907 100644
--- a/test/csync/csync_tests/check_csync_update.cpp
+++ b/test/csync/csync_tests/check_csync_update.cpp
@@ -98,12 +98,10 @@ static int setup(void **state)
assert_int_equal(rc, 0);
rc = system("mkdir -p /tmp/check_csync1");
assert_int_equal(rc, 0);
- csync = new CSYNC("/tmp/check_csync1", TESTDB);
/* Create a new db with metadata */
sqlite3 *db;
- // csync->statedb.file = c_strdup(TESTDB);
- rc = sqlite3_open(csync->statedb.file, &db);
+ rc = sqlite3_open(TESTDB, &db);
statedb_create_metadata_table(db);
if( firstrun ) {
statedb_insert_metadata(db);
@@ -111,8 +109,8 @@ static int setup(void **state)
}
sqlite3_close(db);
- rc = csync_statedb_load(csync, TESTDB, &csync->statedb.db);
- assert_int_equal(rc, 0);
+ csync = new CSYNC("/tmp/check_csync1", new OCC::SyncJournalDb(TESTDB));
+ assert_true(csync->statedb->isConnected());
*state = csync;
@@ -128,7 +126,7 @@ static int setup_ftw(void **state)
assert_int_equal(rc, 0);
rc = system("mkdir -p /tmp/check_csync1");
assert_int_equal(rc, 0);
- csync = new CSYNC("/tmp", TESTDB);
+ csync = new CSYNC("/tmp", new OCC::SyncJournalDb(TESTDB));
sqlite3 *db = NULL;
rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
@@ -137,10 +135,9 @@ static int setup_ftw(void **state)
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 = new CSYNC("/tmp", new OCC::SyncJournalDb(TESTDB));
+ assert_true(csync->statedb->isConnected());
- csync->statedb.file = c_strdup( TESTDB );
*state = csync;
return 0;
@@ -150,8 +147,10 @@ static int teardown(void **state)
{
CSYNC *csync = (CSYNC*)*state;
- unlink( csync->statedb.file);
+ unlink(TESTDB);
+ auto statedb = csync->statedb;
delete csync;
+ delete statedb;
*state = NULL;
@@ -288,7 +287,6 @@ static void check_csync_detect_update_db_rename(void **state)
int rc = 0;
fs = create_fstat("wurst.txt", 0, 42);
- csync_set_statedb_exists(csync, 1);
rc = _csync_detect_update(csync, std::move(fs));
assert_int_equal(rc, 0);
diff --git a/test/csync/vio_tests/check_vio.cpp b/test/csync/vio_tests/check_vio.cpp
index 0607dcaa8..884accf43 100644
--- a/test/csync/vio_tests/check_vio.cpp
+++ b/test/csync/vio_tests/check_vio.cpp
@@ -49,7 +49,7 @@ static int setup(void **state)
rc = system("rm -rf /tmp/csync_test");
assert_int_equal(rc, 0);
- csync = new CSYNC("/tmp/check_csync1", "");
+ csync = new CSYNC("/tmp/check_csync1", new OCC::SyncJournalDb(""));
csync->current = LOCAL_REPLICA;
@@ -78,7 +78,9 @@ static int teardown(void **state) {
CSYNC *csync = (CSYNC*)*state;
int rc;
+ auto statedb = csync->statedb;
delete csync;
+ delete statedb;
rc = chdir(wd_buffer);
assert_int_equal(rc, 0);
diff --git a/test/csync/vio_tests/check_vio_ext.cpp b/test/csync/vio_tests/check_vio_ext.cpp
index 625285ce0..f86ce9591 100644
--- a/test/csync/vio_tests/check_vio_ext.cpp
+++ b/test/csync/vio_tests/check_vio_ext.cpp
@@ -97,7 +97,7 @@ static int setup_testenv(void **state) {
statevar *mystate = (statevar*)malloc( sizeof(statevar) );
mystate->result = NULL;
- mystate->csync = new CSYNC("/tmp/check_csync1", "");
+ mystate->csync = new CSYNC("/tmp/check_csync1", new OCC::SyncJournalDb(""));
mystate->csync->current = LOCAL_REPLICA;
@@ -124,7 +124,9 @@ static int teardown(void **state) {
output("================== Tearing down!\n");
+ auto statedb = csync->statedb;
delete csync;
+ delete statedb;
rc = _tchdir(wd_buffer);
assert_int_equal(rc, 0);
diff --git a/test/testcsyncsqlite.cpp b/test/testcsyncsqlite.cpp
deleted file mode 100644
index 093ee43cb..000000000
--- a/test/testcsyncsqlite.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- This software is in the public domain, furnished "as is", without technical
- support, and with no warranty, express or implied, as to its usefulness for
- any purpose.
-*/
-
-#include "csync_statedb.h"
-#include "csync_private.h"
-#include <QtTest>
-
-
-class TestCSyncSqlite : public QObject
-{
- Q_OBJECT
-
-private:
- CSYNC *_ctx;
-private slots:
- void initTestCase() {
- int rc;
-
- QString db = QCoreApplication::applicationDirPath() + "/test_journal.db";
- _ctx = new CSYNC("/tmp/check_csync1", db.toLocal8Bit());
-
- 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_path( _ctx, "test2/zu/zuzu" );
- QVERIFY(st.get());
- QCOMPARE( QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu") );
- QCOMPARE( QString::number(st->inode), QString::number(1709554));
- QCOMPARE( QString::number(st->modtime), QString::number(1384415006));
- QCOMPARE( QString::number(st->type), QString::number(2));
- QCOMPARE( QString::fromUtf8(st->etag), QLatin1String("52847f2090665"));
- QCOMPARE( QString::fromUtf8(st->file_id), QLatin1String("00000557525d5af3d9625"));
-
- }
-
- void testByHash() {
- std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_path(_ctx, "documents/c1");
- QVERIFY(st.get());
- QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1"));
-
- st = csync_statedb_get_stat_by_path(_ctx, "documents/c1/c2");
- 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(_ctx, 1709555);
- QVERIFY(st.get());
- QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu/zuzuzu"));
-
- 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(_ctx, "00000556525d5af3d9625");
- QVERIFY(st.get());
- QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu"));
-
- st = csync_statedb_get_stat_by_file_id(_ctx, "-0000001525d5af3d9625");
- QVERIFY(st.get());
- QCOMPARE(QString::fromUtf8(st->path), QLatin1String("Shared"));
- }
-
- void cleanupTestCase() {
- csync_statedb_close(_ctx);
- delete _ctx;
- _ctx = nullptr;
- }
-
-};
-
-QTEST_GUILESS_MAIN(TestCSyncSqlite)
-#include "testcsyncsqlite.moc"
diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp
index 032937b62..a4c4c5be4 100644
--- a/test/testsyncengine.cpp
+++ b/test/testsyncengine.cpp
@@ -183,7 +183,7 @@ private slots:
// Remove subFolderA with selectiveSync:
fakeFolder.syncEngine().journal()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
{"parentFolder/subFolderA/"});
- fakeFolder.syncEngine().journal()->avoidReadFromDbOnNextSync("parentFolder/subFolderA/");
+ fakeFolder.syncEngine().journal()->avoidReadFromDbOnNextSync(QByteArrayLiteral("parentFolder/subFolderA/"));
fakeFolder.syncOnce();
@@ -238,7 +238,7 @@ private slots:
// folders are uploaded anyway is some circumstances.
FakeFolder fakeFolder{FileInfo{ QString(), {
FileInfo { QStringLiteral("parentFolder"), {
- FileInfo{ QStringLiteral("subFolder"), {
+ FileInfo{ QStringLiteral("subFolderA"), {
{ QStringLiteral("fileA.txt"), 400 },
{ QStringLiteral("fileB.txt"), 400, 'o' },
FileInfo { QStringLiteral("subsubFolder"), {
@@ -252,23 +252,24 @@ private slots:
{ QStringLiteral("fileF.txt"), 400, 'o' }
}}
}}
- }}
+ }},
+ FileInfo{ QStringLiteral("subFolderB"), {} }
}}
}}};
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
auto expectedServerState = fakeFolder.currentRemoteState();
- // Remove subFolder with selectiveSync:
+ // Remove subFolderA with selectiveSync:
fakeFolder.syncEngine().journal()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
- {"parentFolder/subFolder/"});
- fakeFolder.syncEngine().journal()->avoidReadFromDbOnNextSync("parentFolder/subFolder/");
+ {"parentFolder/subFolderA/"});
+ fakeFolder.syncEngine().journal()->avoidReadFromDbOnNextSync(QByteArrayLiteral("parentFolder/subFolderA/"));
// But touch local file before the next sync, such that the local folder
// can't be removed
- fakeFolder.localModifier().setContents("parentFolder/subFolder/fileB.txt", 'n');
- fakeFolder.localModifier().setContents("parentFolder/subFolder/subsubFolder/fileD.txt", 'n');
- fakeFolder.localModifier().setContents("parentFolder/subFolder/anotherFolder/subsubFolder/fileF.txt", 'n');
+ fakeFolder.localModifier().setContents("parentFolder/subFolderA/fileB.txt", 'n');
+ fakeFolder.localModifier().setContents("parentFolder/subFolderA/subsubFolder/fileD.txt", 'n');
+ fakeFolder.localModifier().setContents("parentFolder/subFolderA/anotherFolder/subsubFolder/fileF.txt", 'n');
// Several follow-up syncs don't change the state at all,
// in particular the remote state doesn't change and fileB.txt
@@ -282,14 +283,15 @@ private slots:
QCOMPARE(fakeFolder.currentRemoteState(), expectedServerState);
// The local state should still have subFolderA
auto local = fakeFolder.currentLocalState();
- QVERIFY(local.find("parentFolder/subFolder"));
- QVERIFY(!local.find("parentFolder/subFolder/fileA.txt"));
- QVERIFY(local.find("parentFolder/subFolder/fileB.txt"));
- QVERIFY(!local.find("parentFolder/subFolder/subsubFolder/fileC.txt"));
- QVERIFY(local.find("parentFolder/subFolder/subsubFolder/fileD.txt"));
- QVERIFY(!local.find("parentFolder/subFolder/anotherFolder/subsubFolder/fileE.txt"));
- QVERIFY(local.find("parentFolder/subFolder/anotherFolder/subsubFolder/fileF.txt"));
- QVERIFY(!local.find("parentFolder/subFolder/anotherFolder/emptyFolder"));
+ QVERIFY(local.find("parentFolder/subFolderA"));
+ QVERIFY(!local.find("parentFolder/subFolderA/fileA.txt"));
+ QVERIFY(local.find("parentFolder/subFolderA/fileB.txt"));
+ QVERIFY(!local.find("parentFolder/subFolderA/subsubFolder/fileC.txt"));
+ QVERIFY(local.find("parentFolder/subFolderA/subsubFolder/fileD.txt"));
+ QVERIFY(!local.find("parentFolder/subFolderA/anotherFolder/subsubFolder/fileE.txt"));
+ QVERIFY(local.find("parentFolder/subFolderA/anotherFolder/subsubFolder/fileF.txt"));
+ QVERIFY(!local.find("parentFolder/subFolderA/anotherFolder/emptyFolder"));
+ QVERIFY(local.find("parentFolder/subFolderB"));
}
}
}
diff --git a/test/testsyncjournaldb.cpp b/test/testsyncjournaldb.cpp
index 5219dd8cf..0575c0ed5 100644
--- a/test/testsyncjournaldb.cpp
+++ b/test/testsyncjournaldb.cpp
@@ -26,9 +26,9 @@ public:
QVERIFY(_tempDir.isValid());
}
- QDateTime dropMsecs(QDateTime time)
+ qint64 dropMsecs(QDateTime time)
{
- return Utility::qDateTimeFromTime_t(Utility::qDateTimeToTime_t(time));
+ return Utility::qDateTimeToTime_t(time);
}
private slots:
@@ -46,7 +46,7 @@ private slots:
void testFileRecord()
{
SyncJournalFileRecord record;
- QVERIFY(_db.getFileRecord("nonexistant", &record));
+ QVERIFY(_db.getFileRecord(QByteArrayLiteral("nonexistant"), &record));
QVERIFY(!record.isValid());
record._path = "foo";
@@ -61,13 +61,13 @@ private slots:
QVERIFY(_db.setFileRecord(record));
SyncJournalFileRecord storedRecord;
- QVERIFY(_db.getFileRecord("foo", &storedRecord));
+ QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo"), &storedRecord));
QVERIFY(storedRecord == record);
// Update checksum
record._checksumHeader = "Adler32:newchecksum";
_db.updateFileRecordChecksum("foo", "newchecksum", "Adler32");
- QVERIFY(_db.getFileRecord("foo", &storedRecord));
+ QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo"), &storedRecord));
QVERIFY(storedRecord == record);
// Update metadata
@@ -79,11 +79,11 @@ private slots:
record._remotePerm = RemotePermissions("NV");
record._fileSize = 289055;
_db.setFileRecordMetadata(record);
- QVERIFY(_db.getFileRecord("foo", &storedRecord));
+ QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo"), &storedRecord));
QVERIFY(storedRecord == record);
QVERIFY(_db.deleteFileRecord("foo"));
- QVERIFY(_db.getFileRecord("foo", &record));
+ QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo"), &record));
QVERIFY(!record.isValid());
}
@@ -95,11 +95,11 @@ private slots:
record._path = "foo-checksum";
record._remotePerm = RemotePermissions("RW");
record._checksumHeader = "MD5:mychecksum";
- record._modtime = QDateTime::currentDateTimeUtc();
+ record._modtime = Utility::qDateTimeToTime_t(QDateTime::currentDateTimeUtc());
QVERIFY(_db.setFileRecord(record));
SyncJournalFileRecord storedRecord;
- QVERIFY(_db.getFileRecord("foo-checksum", &storedRecord));
+ QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo-checksum"), &storedRecord));
QVERIFY(storedRecord._path == record._path);
QVERIFY(storedRecord._remotePerm == record._remotePerm);
QVERIFY(storedRecord._checksumHeader == record._checksumHeader);
@@ -108,19 +108,19 @@ private slots:
// Attention: compare time_t types here, as QDateTime seem to maintain
// milliseconds internally, which disappear in sqlite. Go for full seconds here.
- QVERIFY(storedRecord._modtime.toTime_t() == record._modtime.toTime_t());
+ QVERIFY(storedRecord._modtime == record._modtime);
QVERIFY(storedRecord == record);
}
{
SyncJournalFileRecord record;
record._path = "foo-nochecksum";
record._remotePerm = RemotePermissions("RWN");
- record._modtime = QDateTime::currentDateTimeUtc();
+ record._modtime = Utility::qDateTimeToTime_t(QDateTime::currentDateTimeUtc());
QVERIFY(_db.setFileRecord(record));
SyncJournalFileRecord storedRecord;
- QVERIFY(_db.getFileRecord("foo-nochecksum", &storedRecord));
+ QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo-nochecksum"), &storedRecord));
QVERIFY(storedRecord == record);
}
}
diff --git a/test/testuploadreset.cpp b/test/testuploadreset.cpp
index 9c92d9a1d..ba5489c3a 100644
--- a/test/testuploadreset.cpp
+++ b/test/testuploadreset.cpp
@@ -35,7 +35,7 @@ private slots:
SyncJournalDb::UploadInfo uploadInfo;
uploadInfo._transferid = 1;
uploadInfo._valid = true;
- uploadInfo._modtime = modTime;
+ uploadInfo._modtime = Utility::qDateTimeToTime_t(modTime);
fakeFolder.syncEngine().journal()->setUploadInfo("A/a0", uploadInfo);
fakeFolder.uploadState().mkdir("1");