testcsyncsqlite.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. This software is in the public domain, furnished "as is", without technical
  3. support, and with no warranty, express or implied, as to its usefulness for
  4. any purpose.
  5. */
  6. #ifndef MIRALL_TESTCSYNCSQLITE_H
  7. #define MIRALL_TESTCSYNCSQLITE_H
  8. #include "csync_statedb.h"
  9. #include "csync_private.h"
  10. #include <QtTest>
  11. class TestCSyncSqlite : public QObject
  12. {
  13. Q_OBJECT
  14. private:
  15. CSYNC _ctx;
  16. private slots:
  17. void initTestCase() {
  18. int rc;
  19. memset(&_ctx, 0, sizeof(CSYNC));
  20. _ctx.statedb.file = c_strdup("./test_journal.db");
  21. rc = csync_statedb_load((CSYNC*)(&_ctx), _ctx.statedb.file, &(_ctx.statedb.db));
  22. Q_ASSERT(rc == 0);
  23. }
  24. void testFullResult() {
  25. csync_file_stat_t *st = csync_statedb_get_stat_by_hash((CSYNC*)(&_ctx), 2081025720555645157 );
  26. QVERIFY(st);
  27. QCOMPARE( QString::number(st->phash), QString::number(2081025720555645157) );
  28. QCOMPARE( QString::number(st->pathlen), QString::number(13));
  29. QCOMPARE( QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu") );
  30. QCOMPARE( QString::number(st->inode), QString::number(1709554));
  31. QCOMPARE( QString::number(st->mode), QString::number(0));
  32. QCOMPARE( QString::number(st->modtime), QString::number(1384415006));
  33. QCOMPARE( QString::number(st->type), QString::number(2));
  34. QCOMPARE( QString::fromUtf8(st->etag), QLatin1String("52847f2090665"));
  35. QCOMPARE( QString::fromUtf8(st->file_id), QLatin1String("00000557525d5af3d9625"));
  36. }
  37. void testByHash() {
  38. csync_file_stat_t *st = csync_statedb_get_stat_by_hash((CSYNC*)(&_ctx), -7147279406142960289);
  39. QVERIFY(st);
  40. QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1"));
  41. csync_file_stat_free(st);
  42. st = csync_statedb_get_stat_by_hash((CSYNC*)(&_ctx), 5426481156826978940);
  43. QVERIFY(st);
  44. QCOMPARE(QString::fromUtf8(st->path), QLatin1String("documents/c1/c2"));
  45. csync_file_stat_free(st);
  46. }
  47. void testByInode() {
  48. csync_file_stat_t *st = csync_statedb_get_stat_by_inode((CSYNC*)(&_ctx), 1709555);
  49. QVERIFY(st);
  50. QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu/zuzu/zuzuzu"));
  51. csync_file_stat_free(st);
  52. st = csync_statedb_get_stat_by_inode((CSYNC*)(&_ctx), 1706571);
  53. QVERIFY(st);
  54. QCOMPARE(QString::fromUtf8(st->path), QLatin1String("Shared/for_kf/a2"));
  55. csync_file_stat_free(st);
  56. }
  57. void testByFileId() {
  58. csync_file_stat_t *st = csync_statedb_get_stat_by_file_id((CSYNC*)(&_ctx), "00000556525d5af3d9625");
  59. QVERIFY(st);
  60. QCOMPARE(QString::fromUtf8(st->path), QLatin1String("test2/zu"));
  61. csync_file_stat_free(st);
  62. st = csync_statedb_get_stat_by_file_id((CSYNC*)(&_ctx), "-0000001525d5af3d9625");
  63. QVERIFY(st);
  64. QCOMPARE(QString::fromUtf8(st->path), QLatin1String("Shared"));
  65. csync_file_stat_free(st);
  66. }
  67. void testEtag() {
  68. char *etag = csync_statedb_get_etag((CSYNC*)(&_ctx), 7145399680328529363 );
  69. QCOMPARE( QString::fromUtf8(etag), QLatin1String("52847f208be09"));
  70. SAFE_FREE(etag);
  71. etag = csync_statedb_get_etag((CSYNC*)(&_ctx), -8148768149813301136);
  72. QCOMPARE( QString::fromUtf8(etag), QLatin1String("530d148493894"));
  73. SAFE_FREE(etag);
  74. }
  75. void cleanupTestCase() {
  76. SAFE_FREE(_ctx.statedb.file);
  77. csync_statedb_close((CSYNC*)(&_ctx));
  78. }
  79. };
  80. #endif