File: queryserializationtest.cpp

package info (click to toggle)
baloo-kf5 5.103.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,880 kB
  • sloc: cpp: 25,143; sh: 23; xml: 15; makefile: 9
file content (114 lines) | stat: -rw-r--r-- 2,522 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
    This file is part of the KDE Baloo Project
    SPDX-FileCopyrightText: 2013-2015 Vishesh Handa <vhanda@kde.org>

    SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "query.h"
#include "term.h"

#include <QTest>

using namespace Baloo;

class QuerySerializationTest : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void testBasic();
    void testTerm();
    void testAndTerm();
    void testDateTerm();
    void testDateTimeTerm();

    void testCustomOptions();
};

// Test a simple query with no terms
void QuerySerializationTest::testBasic()
{
    Query query;
    query.setLimit(5);
    query.setOffset(1);
    query.setSearchString(QStringLiteral("Bookie"));
    query.addType(QStringLiteral("File/Audio"));

    QByteArray json = query.toJSON();
    Query q = Query::fromJSON(json);

    QCOMPARE(q.limit(), static_cast<uint>(5));
    QCOMPARE(q.offset(), static_cast<uint>(1));
    QCOMPARE(q.searchString(), QLatin1String("Bookie"));
    QCOMPARE(q.types().size(), 2);
    QVERIFY(q.types().contains(QLatin1String("File")));
    QVERIFY(q.types().contains(QLatin1String("Audio")));

    QCOMPARE(q, query);
}

void QuerySerializationTest::testTerm()
{
    Query query;
    query.setSearchString(QStringLiteral("prop:value"));

    QByteArray json = query.toJSON();
    Query q = Query::fromJSON(json);

    QCOMPARE(q, query);
}

void QuerySerializationTest::testAndTerm()
{
    Query query;
    query.setSearchString(QStringLiteral("prop1:1 AND prop2:2"));

    QByteArray json = query.toJSON();
    Query q = Query::fromJSON(json);

    QCOMPARE(q, query);
}

void QuerySerializationTest::testDateTerm()
{
    Query query;
    query.setSearchString(QStringLiteral("prop:2015-05-01"));

    QByteArray json = query.toJSON();
    Query q = Query::fromJSON(json);

    QCOMPARE(q, query);
}

void QuerySerializationTest::testDateTimeTerm()
{
    Query query;
    query.setSearchString(QStringLiteral("prop:2015-05-01T23:44:11"));

    QByteArray json = query.toJSON();
    Query q = Query::fromJSON(json);

    QCOMPARE(q, query);
}


void QuerySerializationTest::testCustomOptions()
{
    Query query;
    query.addType(QStringLiteral("File"));
    query.setIncludeFolder(QStringLiteral("/home/vishesh"));

    QByteArray json = query.toJSON();
    Query q = Query::fromJSON(json);

    QString includeFolder = q.includeFolder();
    QCOMPARE(includeFolder, QStringLiteral("/home/vishesh"));

    QCOMPARE(query, q);
}


QTEST_MAIN(QuerySerializationTest)

#include "queryserializationtest.moc"