[Pkg-owncloud-commits] [owncloud-client] 176/333: Add new test to test the csync database code.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Apr 17 23:16:50 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 39924d79cbbb125708880d9ee2b1ee1642df1b5e
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Wed Mar 19 21:02:12 2014 +0100

    Add new test to test the csync database code.
---
 test/CMakeLists.txt    |   3 ++
 test/test_journal.db   | Bin 0 -> 57344 bytes
 test/testcsyncsqlite.h | 123 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 126 insertions(+)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index f5ded29..3521be1 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,11 +1,14 @@
 include_directories(${CMAKE_BINARY_DIR}/csync ${CMAKE_BINARY_DIR}/csync/src ${CMAKE_BINARY_DIR}/src)
 include_directories(${CMAKE_SOURCE_DIR}/csync/src/ ${CMAKE_SOURCE_DIR}/csync/src/httpbf/src)
+include_directories(${CMAKE_SOURCE_DIR}/csync/src/std)
+
 include(owncloud_add_test.cmake)
 
 owncloud_add_test(OwncloudPropagator)
 owncloud_add_test(Utility)
 owncloud_add_test(Updater)
 owncloud_add_test(FolderWatcher)
+owncloud_add_test(CSyncSqlite)
 
 if( UNIX AND NOT APPLE )
 	owncloud_add_test(InotifyWatcher)
diff --git a/test/test_journal.db b/test/test_journal.db
new file mode 100644
index 0000000..30905b6
Binary files /dev/null and b/test/test_journal.db differ
diff --git a/test/testcsyncsqlite.h b/test/testcsyncsqlite.h
new file mode 100644
index 0000000..7f44da3
--- /dev/null
+++ b/test/testcsyncsqlite.h
@@ -0,0 +1,123 @@
+/*
+   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.
+*/
+
+#ifndef MIRALL_TESTCSYNCSQLITE_H
+#define MIRALL_TESTCSYNCSQLITE_H
+
+#include "csync_statedb.h"
+#include <QtTest>
+
+
+class TestCSyncSqlite : public QObject
+{
+    Q_OBJECT
+
+private:
+    typedef struct {
+        struct {
+            csync_auth_callback auth_function;
+            csync_progress_callback progress_cb;
+            void *userdata;
+        } callbacks;
+        c_strlist_t *excludes;
+
+        struct {
+            char *file;
+            sqlite3 *db;
+            int exists;
+            int disabled;
+
+            sqlite3_stmt* by_hash_stmt;
+            sqlite3_stmt* by_fileid_stmt;
+            sqlite3_stmt* by_inode_stmt;
+        } statedb;
+    } MY_CSYNC;
+
+    MY_CSYNC _ctx;
+    int      _written;
+private slots:
+    void initTestCase() {
+        int rc;
+        _written = 0;
+
+        memset(&_ctx, 0, sizeof(MY_CSYNC));
+
+        _ctx.statedb.file = "./test_journal.db";
+
+        rc = csync_statedb_load((CSYNC*)(&_ctx), _ctx.statedb.file, &(_ctx.statedb.db));
+        Q_ASSERT(rc == 0);
+    }
+
+    void testFullResult() {
+        csync_file_stat_t *st = csync_statedb_get_stat_by_hash((CSYNC*)(&_ctx), 2081025720555645157 );
+        QVERIFY(st);
+        QCOMPARE( QString::number(st->phash), QString::number(2081025720555645157) );
+        QCOMPARE( QString::number(st->pathlen), QString::number(13));
+        QCOMPARE( QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu") );
+        QCOMPARE( QString::number(st->inode), QString::number(1709554));
+        QCOMPARE( QString::number(st->uid), QString::number(0));
+        QCOMPARE( QString::number(st->gid), QString::number(0));
+        QCOMPARE( QString::number(st->mode), QString::number(0));
+        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() {
+        csync_file_stat_t *st = csync_statedb_get_stat_by_hash((CSYNC*)(&_ctx), -7147279406142960289);
+        QVERIFY(st);
+        QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1"));
+        csync_file_stat_free(st);
+
+        st = csync_statedb_get_stat_by_hash((CSYNC*)(&_ctx), 5426481156826978940);
+        QVERIFY(st);
+        QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1/c2"));
+        csync_file_stat_free(st);
+    }
+
+    void testByInode() {
+        csync_file_stat_t *st = csync_statedb_get_stat_by_inode((CSYNC*)(&_ctx), 1709555);
+        QVERIFY(st);
+        QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu/zuzuzu"));
+        csync_file_stat_free(st);
+
+        st = csync_statedb_get_stat_by_inode((CSYNC*)(&_ctx), 1706571);
+        QVERIFY(st);
+        QCOMPARE(QString::fromUtf8(st->path), QLatin1String("Shared/for_kf/a2"));
+        csync_file_stat_free(st);
+    }
+
+    void testByFileId() {
+        csync_file_stat_t *st = csync_statedb_get_stat_by_file_id((CSYNC*)(&_ctx), "00000556525d5af3d9625");
+        QVERIFY(st);
+        QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu"));
+        csync_file_stat_free(st);
+
+        st = csync_statedb_get_stat_by_file_id((CSYNC*)(&_ctx), "-0000001525d5af3d9625");
+        QVERIFY(st);
+        QCOMPARE(QString::fromUtf8(st->path), QLatin1String("Shared"));
+        csync_file_stat_free(st);
+    }
+
+    void testEtag() {
+        char *etag = csync_statedb_get_etag((CSYNC*)(&_ctx), 7145399680328529363 );
+        QCOMPARE( QString::fromUtf8(etag), QLatin1String("52847f208be09"));
+        SAFE_FREE(etag);
+
+        etag = csync_statedb_get_etag((CSYNC*)(&_ctx), -8148768149813301136);
+        QCOMPARE( QString::fromUtf8(etag), QLatin1String("530d148493894"));
+        SAFE_FREE(etag);
+    }
+
+    void cleanupTestCase() {
+        csync_statedb_close((CSYNC*)(&_ctx), _written);
+    }
+
+};
+
+#endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list