diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/modelinteractivitytest.cpp | 101 |
2 files changed, 103 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5d64511..1e0f6b5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -50,11 +50,13 @@ auto_tests ( | |||
50 | querytest | 50 | querytest |
51 | databasepopulationandfacadequerybenchmark | 51 | databasepopulationandfacadequerybenchmark |
52 | dummyresourcewritebenchmark | 52 | dummyresourcewritebenchmark |
53 | modelinteractivitytest | ||
53 | ) | 54 | ) |
54 | target_link_libraries(dummyresourcetest akonadi2_resource_dummy) | 55 | target_link_libraries(dummyresourcetest akonadi2_resource_dummy) |
55 | target_link_libraries(dummyresourcebenchmark akonadi2_resource_dummy) | 56 | target_link_libraries(dummyresourcebenchmark akonadi2_resource_dummy) |
56 | target_link_libraries(dummyresourcewritebenchmark akonadi2_resource_dummy) | 57 | target_link_libraries(dummyresourcewritebenchmark akonadi2_resource_dummy) |
57 | target_link_libraries(querytest akonadi2_resource_dummy) | 58 | target_link_libraries(querytest akonadi2_resource_dummy) |
59 | target_link_libraries(modelinteractivitytest akonadi2_resource_dummy) | ||
58 | 60 | ||
59 | if (BUILD_MAILDIR) | 61 | if (BUILD_MAILDIR) |
60 | auto_tests ( | 62 | auto_tests ( |
diff --git a/tests/modelinteractivitytest.cpp b/tests/modelinteractivitytest.cpp new file mode 100644 index 0000000..52db932 --- /dev/null +++ b/tests/modelinteractivitytest.cpp | |||
@@ -0,0 +1,101 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | #include <iostream> | ||
5 | |||
6 | #include "dummyresource/resourcefactory.h" | ||
7 | #include "clientapi.h" | ||
8 | #include "commands.h" | ||
9 | #include "resourceconfig.h" | ||
10 | #include "log.h" | ||
11 | #include "modelresult.h" | ||
12 | |||
13 | static int blockingTime; | ||
14 | |||
15 | class TimeMeasuringApplication : public QCoreApplication | ||
16 | { | ||
17 | QElapsedTimer t; | ||
18 | public: | ||
19 | TimeMeasuringApplication(int& argc, char ** argv) : QCoreApplication(argc, argv) { } | ||
20 | virtual ~TimeMeasuringApplication() { } | ||
21 | |||
22 | virtual bool notify(QObject* receiver, QEvent* event) | ||
23 | { | ||
24 | t.start(); | ||
25 | const bool ret = QCoreApplication::notify(receiver, event); | ||
26 | if(t.elapsed() > 1) | ||
27 | std::cout << QString("processing event type %1 for object %2 took %3ms") | ||
28 | .arg((int)event->type()) | ||
29 | .arg(""/* receiver->objectName().toLocal8Bit().data()*/) | ||
30 | .arg((int)t.elapsed()) | ||
31 | .toStdString() << std::endl; | ||
32 | blockingTime += t.elapsed(); | ||
33 | return ret; | ||
34 | } | ||
35 | }; | ||
36 | |||
37 | /** | ||
38 | * Ensure that queries don't block the system for an extended period of time. | ||
39 | * | ||
40 | * This is done by ensuring that the event loop is never blocked. | ||
41 | */ | ||
42 | class ModelinteractivityTest : public QObject | ||
43 | { | ||
44 | Q_OBJECT | ||
45 | private Q_SLOTS: | ||
46 | void initTestCase() | ||
47 | { | ||
48 | Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); | ||
49 | DummyResource::removeFromDisk("org.kde.dummy.instance1"); | ||
50 | ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); | ||
51 | } | ||
52 | |||
53 | void cleanup() | ||
54 | { | ||
55 | Akonadi2::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); | ||
56 | DummyResource::removeFromDisk("org.kde.dummy.instance1"); | ||
57 | Akonadi2::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); | ||
58 | } | ||
59 | |||
60 | void init() | ||
61 | { | ||
62 | } | ||
63 | |||
64 | void testSingle() | ||
65 | { | ||
66 | //Setup | ||
67 | { | ||
68 | Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); | ||
69 | for (int i = 0; i < 1000; i++) { | ||
70 | Akonadi2::Store::create<Akonadi2::ApplicationDomain::Mail>(mail).exec().waitForFinished(); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | Akonadi2::Query query; | ||
75 | query.resources << "org.kde.dummy.instance1"; | ||
76 | query.syncOnDemand = false; | ||
77 | query.processAll = true; | ||
78 | query.liveQuery = true; | ||
79 | |||
80 | Akonadi2::Store::synchronize(query).exec().waitForFinished(); | ||
81 | |||
82 | //Test | ||
83 | QTime time; | ||
84 | time.start(); | ||
85 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query); | ||
86 | blockingTime += time.elapsed(); | ||
87 | QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); | ||
88 | //Never block longer than 10 ms | ||
89 | QVERIFY2(blockingTime < 10, QString("Total blocking time: %1").arg(blockingTime).toLatin1().data()); | ||
90 | } | ||
91 | }; | ||
92 | |||
93 | int main(int argc, char *argv[]) | ||
94 | { | ||
95 | blockingTime = 0; | ||
96 | TimeMeasuringApplication app(argc, argv); | ||
97 | ModelinteractivityTest tc; | ||
98 | return QTest::qExec(&tc, argc, argv); | ||
99 | } | ||
100 | |||
101 | #include "modelinteractivitytest.moc" | ||