2014-03-20 00:02:12 +04:00
|
|
|
/*
|
|
|
|
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"
|
2014-10-27 15:14:41 +03:00
|
|
|
#include "csync_private.h"
|
2014-03-20 00:02:12 +04:00
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
|
|
|
|
class TestCSyncSqlite : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2017-09-04 20:06:13 +03:00
|
|
|
CSYNC *_ctx;
|
2014-03-20 00:02:12 +04:00
|
|
|
private slots:
|
|
|
|
void initTestCase() {
|
|
|
|
int rc;
|
|
|
|
|
2017-06-22 16:11:27 +03:00
|
|
|
QString db = QCoreApplication::applicationDirPath() + "/test_journal.db";
|
2017-09-04 20:06:13 +03:00
|
|
|
_ctx = new CSYNC("/tmp/check_csync1", db.toLocal8Bit());
|
2014-03-20 00:02:12 +04:00
|
|
|
|
2017-09-04 20:06:13 +03:00
|
|
|
rc = csync_statedb_load(_ctx, _ctx->statedb.file, &(_ctx->statedb.db));
|
2017-06-22 16:11:27 +03:00
|
|
|
QVERIFY(rc == 0);
|
2014-03-20 00:02:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void testFullResult() {
|
2017-09-04 20:06:13 +03:00
|
|
|
std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_hash( _ctx, 2081025720555645157 );
|
2017-08-17 11:06:14 +03:00
|
|
|
QVERIFY(st.get());
|
2014-03-20 00:02:12 +04:00
|
|
|
QCOMPARE( QString::number(st->phash), QString::number(2081025720555645157) );
|
|
|
|
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() {
|
2017-09-04 20:06:13 +03:00
|
|
|
std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_hash(_ctx, -7147279406142960289);
|
2017-08-17 11:06:14 +03:00
|
|
|
QVERIFY(st.get());
|
2014-03-20 00:02:12 +04:00
|
|
|
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1"));
|
|
|
|
|
2017-09-04 20:06:13 +03:00
|
|
|
st = csync_statedb_get_stat_by_hash(_ctx, 5426481156826978940);
|
2017-08-17 11:06:14 +03:00
|
|
|
QVERIFY(st.get());
|
2014-03-20 00:02:12 +04:00
|
|
|
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1/c2"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void testByInode() {
|
2017-09-04 20:06:13 +03:00
|
|
|
std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_inode(_ctx, 1709555);
|
2017-08-17 11:06:14 +03:00
|
|
|
QVERIFY(st.get());
|
2014-03-20 00:02:12 +04:00
|
|
|
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu/zuzuzu"));
|
|
|
|
|
2017-09-04 20:06:13 +03:00
|
|
|
st = csync_statedb_get_stat_by_inode(_ctx, 1706571);
|
2017-08-17 11:06:14 +03:00
|
|
|
QVERIFY(st.get());
|
2014-03-20 00:02:12 +04:00
|
|
|
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("Shared/for_kf/a2"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void testByFileId() {
|
2017-09-04 20:06:13 +03:00
|
|
|
std::unique_ptr<csync_file_stat_t> st = csync_statedb_get_stat_by_file_id(_ctx, "00000556525d5af3d9625");
|
2017-08-17 11:06:14 +03:00
|
|
|
QVERIFY(st.get());
|
2014-03-20 00:02:12 +04:00
|
|
|
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu"));
|
|
|
|
|
2017-09-04 20:06:13 +03:00
|
|
|
st = csync_statedb_get_stat_by_file_id(_ctx, "-0000001525d5af3d9625");
|
2017-08-17 11:06:14 +03:00
|
|
|
QVERIFY(st.get());
|
2014-03-20 00:02:12 +04:00
|
|
|
QCOMPARE(QString::fromUtf8(st->path), QLatin1String("Shared"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanupTestCase() {
|
2017-09-04 20:06:13 +03:00
|
|
|
csync_statedb_close(_ctx);
|
|
|
|
delete _ctx;
|
|
|
|
_ctx = nullptr;
|
2014-03-20 00:02:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-06-22 16:11:27 +03:00
|
|
|
QTEST_GUILESS_MAIN(TestCSyncSqlite)
|
2016-03-30 18:58:15 +03:00
|
|
|
#include "testcsyncsqlite.moc"
|