Merge lp:~boiko/history-service/fix_telepathy_init_on_qml into lp:history-service

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Tiago Salem Herrmann
Approved revision: 227
Merged at revision: 226
Proposed branch: lp:~boiko/history-service/fix_telepathy_init_on_qml
Merge into: lp:history-service
Diff against target: 207 lines (+112/-10)
6 files modified
daemon/main.cpp (+0/-5)
src/telepathyhelper.cpp (+6/-0)
tests/Ubuntu.History/CMakeLists.txt (+8/-0)
tests/Ubuntu.History/HistoryEventModelTest.cpp (+95/-0)
tests/common/telepathytest.cpp (+2/-4)
tests/common/telepathytest.h (+1/-1)
To merge this branch: bzr merge lp:~boiko/history-service/fix_telepathy_init_on_qml
Reviewer Review Type Date Requested Status
Tiago Salem Herrmann (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+292843@code.launchpad.net

Commit message

Make sure Telepathy types are always initialized.

Description of the change

Make sure Telepathy types are always initialized.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tiago Salem Herrmann (tiagosh) wrote :

looks good. thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'daemon/main.cpp'
2--- daemon/main.cpp 2013-09-17 14:41:07 +0000
3+++ daemon/main.cpp 2016-04-25 17:57:17 +0000
4@@ -20,8 +20,6 @@
5 */
6
7 #include "historydaemon.h"
8-#include <TelepathyQt/Types>
9-#include <TelepathyQt/Debug>
10
11 bool checkApplicationRunning()
12 {
13@@ -35,9 +33,6 @@
14 }
15 int main(int argc, char **argv)
16 {
17- Tp::registerTypes();
18- Tp::enableWarnings(true);
19-
20 QCoreApplication app(argc, argv);
21
22 if (checkApplicationRunning()) {
23
24=== modified file 'src/telepathyhelper.cpp'
25--- src/telepathyhelper.cpp 2015-10-06 12:50:14 +0000
26+++ src/telepathyhelper.cpp 2016-04-25 17:57:17 +0000
27@@ -23,6 +23,8 @@
28 #include "telepathyhelper_p.h"
29
30 #include <TelepathyQt/ClientRegistrar>
31+#include <TelepathyQt/Types>
32+#include <TelepathyQt/Debug>
33
34 namespace History
35 {
36@@ -32,6 +34,10 @@
37 mChannelObserver(0),
38 mReady(false)
39 {
40+ // initialize telepathy
41+ Tp::registerTypes();
42+ Tp::enableWarnings(true);
43+
44 mAccountFeatures << Tp::Account::FeatureCore
45 << Tp::Account::FeatureProtocolInfo;
46 mContactFeatures << Tp::Contact::FeatureAlias
47
48=== modified file 'tests/Ubuntu.History/CMakeLists.txt'
49--- tests/Ubuntu.History/CMakeLists.txt 2015-05-19 11:55:20 +0000
50+++ tests/Ubuntu.History/CMakeLists.txt 2016-04-25 17:57:17 +0000
51@@ -2,6 +2,8 @@
52 ${CMAKE_CURRENT_BINARY_DIR}
53 ${CMAKE_SOURCE_DIR}/Ubuntu/History
54 ${CMAKE_SOURCE_DIR}/src
55+ ${CMAKE_SOURCE_DIR}/tests/common
56+ ${TP_QT5_INCLUDE_DIRS}
57 )
58
59 set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/Ubuntu/History)
60@@ -12,3 +14,9 @@
61 USE_XVFB
62 TASKS --task ${CMAKE_BINARY_DIR}/daemon/history-daemon --ignore-return --task-name history-daemon
63 WAIT_FOR com.canonical.HistoryService)
64+generate_telepathy_test(HistoryEventModelTest
65+ SOURCES HistoryEventModelTest.cpp
66+ LIBRARIES ${TP_QT5_LIBRARIES} mockcontroller telepathytest history-qml
67+ USE_XVFB
68+ TASKS --task ${CMAKE_BINARY_DIR}/daemon/history-daemon --ignore-return --task-name history-daemon
69+ WAIT_FOR com.canonical.HistoryService)
70
71=== added file 'tests/Ubuntu.History/HistoryEventModelTest.cpp'
72--- tests/Ubuntu.History/HistoryEventModelTest.cpp 1970-01-01 00:00:00 +0000
73+++ tests/Ubuntu.History/HistoryEventModelTest.cpp 2016-04-25 17:57:17 +0000
74@@ -0,0 +1,95 @@
75+/*
76+ * Copyright (C) 2016 Canonical, Ltd.
77+ *
78+ * This file is part of history-service.
79+ *
80+ * telephony-service is free software; you can redistribute it and/or modify
81+ * it under the terms of the GNU General Public License as published by
82+ * the Free Software Foundation; version 3.
83+ *
84+ * telephony-service is distributed in the hope that it will be useful,
85+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
86+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87+ * GNU General Public License for more details.
88+ *
89+ * You should have received a copy of the GNU General Public License
90+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
91+ */
92+
93+#include <QtTest/QtTest>
94+#include "telepathytest.h"
95+#include "manager.h"
96+#include "textevent.h"
97+#include "historyeventmodel.h"
98+
99+class HistoryEventModelTest : public TelepathyTest
100+{
101+ Q_OBJECT
102+
103+private Q_SLOTS:
104+ void initTestCase();
105+ void testTelepathyInitializedCorrectly();
106+
107+private:
108+ History::Manager *mManager;
109+};
110+
111+void HistoryEventModelTest::initTestCase()
112+{
113+ initialize(0);
114+
115+ mManager = History::Manager::instance();
116+}
117+
118+void HistoryEventModelTest::testTelepathyInitializedCorrectly()
119+{
120+ Tp::AccountPtr account = addAccount("mock", "ofono", "My Account");
121+ QVERIFY(!account.isNull());
122+
123+ // we don't actually test anything on the model other than it having the event
124+ // but if telepathy is not properly initialized, this will crash.
125+ HistoryEventModel model;
126+ QString participant("textParticipant");
127+
128+ // create a temporary thread to populate the model
129+ History::Thread textThread = mManager->threadForParticipants(account->uniqueIdentifier(),
130+ History::EventTypeText,
131+ QStringList() << participant,
132+ History::MatchCaseSensitive, true);
133+
134+ History::TextEvent event(textThread.accountId(),
135+ textThread.threadId(),
136+ "theEventId",
137+ participant,
138+ QDateTime::currentDateTime(),
139+ true,
140+ "Hi there",
141+ History::MessageTypeText,
142+ History::MessageStatusRead,
143+ QDateTime::currentDateTime(),
144+ "The subject",
145+ History::TextEventAttachments(),
146+ textThread.participants());
147+ QVERIFY(mManager->writeEvents(History::Events() << event));
148+
149+ HistoryQmlFilter *filter = new HistoryQmlFilter(this);
150+ filter->setFilterProperty(History::FieldThreadId);
151+ filter->setFilterValue(textThread.threadId());
152+ model.setFilter(filter);
153+
154+ HistoryQmlSort *sort = new HistoryQmlSort(this);
155+ sort->setSortOrder(HistoryQmlSort::DescendingOrder);
156+ sort->setSortField("timestamp");
157+ model.setSort(sort);
158+
159+ QTRY_COMPARE(model.rowCount(), 1);
160+
161+ // this will trigger the crash if tp-qt is not properly initialized
162+ qDebug() << model.index(0).data(HistoryEventModel::SenderRole);
163+
164+ mManager->removeThreads(History::Threads() << textThread);
165+ QTRY_COMPARE(model.rowCount(), 0);
166+}
167+
168+QTEST_MAIN(HistoryEventModelTest)
169+#include "HistoryEventModelTest.moc"
170
171=== modified file 'tests/common/telepathytest.cpp'
172--- tests/common/telepathytest.cpp 2015-10-06 12:50:14 +0000
173+++ tests/common/telepathytest.cpp 2016-04-25 17:57:17 +0000
174@@ -24,10 +24,8 @@
175 #include "telepathytest.h"
176 #include "telepathyhelper_p.h"
177
178-void TelepathyTest::initialize()
179+void TelepathyTest::initialize(int waitTime)
180 {
181- Tp::registerTypes();
182-
183 QSignalSpy spy(History::TelepathyHelper::instance(), SIGNAL(setupReady()));
184 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, DEFAULT_TIMEOUT);
185
186@@ -70,7 +68,7 @@
187 QTRY_VERIFY(mReady);
188
189 // give some time for telepathy stuff to settle
190- QTest::qWait(1000);
191+ QTest::qWait(waitTime);
192 }
193
194 void TelepathyTest::doCleanup()
195
196=== modified file 'tests/common/telepathytest.h'
197--- tests/common/telepathytest.h 2015-04-07 14:40:58 +0000
198+++ tests/common/telepathytest.h 2016-04-25 17:57:17 +0000
199@@ -30,7 +30,7 @@
200 Q_OBJECT
201
202 protected:
203- void initialize();
204+ void initialize(int waitTime = 1000);
205 void doCleanup();
206
207 // helper slots

Subscribers

People subscribed via source and target branches