File indexing completed on 2024-10-27 04:52:51
0001 /* 0002 * SPDX-FileCopyrightText: 2019 David Barchiesi <david@barchie.si> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include <QObject> 0008 #include <QTest> 0009 0010 #include "drivessearchquery.h" 0011 0012 using namespace KGAPI2; 0013 using namespace KGAPI2::Drive; 0014 0015 Q_DECLARE_METATYPE(KGAPI2::Drive::DrivesSearchQuery) 0016 0017 class DrivesSearchQueryTest : public QObject 0018 { 0019 Q_OBJECT 0020 public: 0021 explicit DrivesSearchQueryTest() 0022 { 0023 } 0024 0025 ~DrivesSearchQueryTest() override 0026 { 0027 } 0028 0029 private Q_SLOTS: 0030 void testDrivesSearchQuery_data() 0031 { 0032 QTest::addColumn<DrivesSearchQuery>("query"); 0033 QTest::addColumn<QString>("expected"); 0034 0035 { 0036 DrivesSearchQuery query; 0037 query.addQuery(DrivesSearchQuery::CreatedDate, DrivesSearchQuery::Equals, QDateTime(QDate(2019, 6, 16), QTime(6, 36, 0), QTimeZone::UTC)); 0038 QTest::newRow("serialize time") << query << "((createdDate = '2019-06-16T06:36:00'))"; 0039 } 0040 0041 { 0042 DrivesSearchQuery query; 0043 query.addQuery(DrivesSearchQuery::Name, DrivesSearchQuery::Contains, QLatin1StringView("Some String")); 0044 QTest::newRow("contains") << query << "((name contains 'Some String'))"; 0045 } 0046 0047 { 0048 DrivesSearchQuery query; 0049 query.addQuery(DrivesSearchQuery::Hidden, DrivesSearchQuery::Equals, true); 0050 QTest::newRow("contains") << query << "((hidden = true))"; 0051 } 0052 0053 { 0054 DrivesSearchQuery query; 0055 query.addQuery(DrivesSearchQuery::Name, DrivesSearchQuery::Contains, QLatin1StringView("Name")); 0056 query.addQuery(DrivesSearchQuery::MemberCount, DrivesSearchQuery::Equals, 5); 0057 QTest::newRow("A and B") << query << "((name contains 'Name') and (memberCount = 5))"; 0058 } 0059 0060 { 0061 DrivesSearchQuery query(DrivesSearchQuery::Or); 0062 query.addQuery(DrivesSearchQuery::Name, DrivesSearchQuery::Contains, QLatin1StringView("Name")); 0063 query.addQuery(DrivesSearchQuery::OrganizerCount, DrivesSearchQuery::Equals, 5); 0064 QTest::newRow("A or B") << query << "((name contains 'Name') or (organizerCount = 5))"; 0065 } 0066 0067 { 0068 DrivesSearchQuery query(DrivesSearchQuery::Or); 0069 query.addQuery(DrivesSearchQuery::CreatedDate, DrivesSearchQuery::Equals, QDateTime(QDate(2019, 3, 5), QTime(6, 36, 0), QTimeZone::UTC)); 0070 DrivesSearchQuery subquery; 0071 subquery.addQuery(DrivesSearchQuery::Name, DrivesSearchQuery::Equals, QLatin1StringView("Test")); 0072 subquery.addQuery(DrivesSearchQuery::MemberCount, DrivesSearchQuery::LessOrEqual, 10); 0073 query.addQuery(subquery); 0074 QTest::newRow("A or (B and C)") << query << "((createdDate = '2019-03-05T06:36:00') or ((name = 'Test') and (memberCount <= 10)))"; 0075 } 0076 } 0077 0078 void testDrivesSearchQuery() 0079 { 0080 QFETCH(DrivesSearchQuery, query); 0081 QFETCH(QString, expected); 0082 0083 const QString serialized = query.serialize(); 0084 QCOMPARE(serialized, expected); 0085 } 0086 }; 0087 0088 QTEST_GUILESS_MAIN(DrivesSearchQueryTest) 0089 0090 #include "drivessearchquerytest.moc"