Warning, file /plasma/milou/lib/test/test.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * This file is part of the KDE Baloo Project
0003  * SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  *
0007  */
0008 
0009 #include <QAbstractItemModelTester>
0010 #include <QCoreApplication>
0011 #include <QDebug>
0012 #include <QTimer>
0013 
0014 #include "../sourcesmodel.h"
0015 
0016 using namespace Milou;
0017 
0018 class TestObject : public QObject
0019 {
0020     Q_OBJECT
0021 public Q_SLOTS:
0022     void fire()
0023     {
0024         i++;
0025         if (i > queryString.size()) {
0026             timer.stop();
0027             QCoreApplication::instance()->exit();
0028             return;
0029         }
0030 
0031         const QString str = queryString.mid(0, i);
0032         qDebug() << "Setting" << str;
0033         qDebug() << "Setting" << str;
0034         qDebug() << "Setting" << str;
0035         qDebug() << "Setting" << str;
0036         qDebug() << "Setting" << str;
0037         qDebug() << "Setting" << str;
0038         model->setQueryString(str);
0039     }
0040 
0041 public:
0042     TestObject(const QString &str)
0043     {
0044         queryString = str;
0045         i = 0;
0046 
0047         timer.setInterval(3000);
0048         connect(&timer, SIGNAL(timeout()), this, SLOT(fire()));
0049     }
0050 
0051     SourcesModel *model;
0052     QString queryString;
0053     int i;
0054 
0055     QTimer timer;
0056 };
0057 
0058 int main(int argc, char **argv)
0059 {
0060     QCoreApplication app(argc, argv);
0061 
0062     SourcesModel *model = new SourcesModel();
0063     auto mt = new QAbstractItemModelTester(model);
0064     Q_UNUSED(mt);
0065     model->setQueryLimit(20);
0066 
0067     TestObject obj(QStringLiteral("Summer"));
0068     obj.model = model;
0069     obj.timer.start();
0070 
0071     return app.exec();
0072 }
0073 
0074 #include "test.moc"