on xenial help sign in
Use libusermetrics; consolidate test usage of that library into a single mock
commit4811d692f8efd39f7178e47df63987a04531c38c authorMichael Terry <michael.terry@canonical.com> dateFri 14 Jun 2013, 15:35 (13 years ago) parent5640542
27 files changed+740−631
build+1−1 plugins/LightDM/CMakeLists.txt+4−1 plugins/LightDM/InfographicModel.h−27 plugins/LightDM/plugin.cpp+5−4 run+3−3 tests/autopilot/unity8/tests/__init__.py+2−2 tests/mocks/CMakeLists.txt+1 tests/mocks/LightDM/CMakeLists.txt+3 tests/mocks/LightDM/InfographicModel.cpp−416 tests/mocks/LightDM/InfographicModelPrivate.h−99 tests/mocks/LightDM/demo/CMakeLists.txt+11−2 tests/mocks/LightDM/demo/UsersModelPrivate.cpp+1−1 tests/mocks/LightDM/full/CMakeLists.txt−2 tests/mocks/LightDM/single-passphrase/CMakeLists.txt−2 tests/mocks/LightDM/single-passphrase/UsersModelPrivate.cpp+1−1 tests/mocks/LightDM/single-pin/CMakeLists.txt−2 tests/mocks/LightDM/single-pin/UsersModelPrivate.cpp+1−1 tests/mocks/LightDM/single/CMakeLists.txt−2 tests/mocks/LightDM/single/UsersModelPrivate.cpp+1−1 tests/mocks/libusermetrics/CMakeLists.txt+17 tests/mocks/libusermetrics/ColorTheme.cpp+128 tests/mocks/libusermetrics/ColorTheme.h+68 tests/mocks/libusermetrics/UserMetrics.cpp+465 tests/mocks/LightDM/InfographicModel.h → tests/mocks/libusermetrics/UserMetrics.h+22−60 tests/mocks/libusermetrics/libusermetricsoutput/ColorTheme.h+1 tests/mocks/libusermetrics/libusermetricsoutput/UserMetrics.h+1 tests/qmltests/CMakeLists.txt+4−4
build+1−1
@@ -43,7 +43,7 @@ install_dependencies() {
4343 [ -f /etc/apt/sources.list.d/ubuntu-sdk-team-ppa-${DISTRIB_CODENAME}.list ] || sudo add-apt-repository ppa:ubuntu-sdk-team/ppa || exit 3
4444 sudo apt-get update || exit 4
4545 echo "Installing Unity 8 dependencies.."
46− sudo apt-get install qtdeclarative5-ubuntu-ui-toolkit-plugin qtdeclarative5-dee-plugin indicators-client indicators-client-plugin-* qtbase5-dev qtbase5-private-dev qtdeclarative5-dev qtdeclarative5-dev-tools qtdeclarative5-test-plugin libdee-qt5-dev libpulse-dev qtdeclarative5-xmllistmodel-plugin unity-lens-mock demo-assets ubuntu-mobile-icons || exit 5
46+ sudo apt-get install qtdeclarative5-ubuntu-ui-toolkit-plugin qtdeclarative5-dee-plugin indicators-client indicators-client-plugin-* qtbase5-dev qtbase5-private-dev qtdeclarative5-dev qtdeclarative5-dev-tools qtdeclarative5-test-plugin libdee-qt5-dev libpulse-dev qtdeclarative5-xmllistmodel-plugin unity-lens-mock demo-assets ubuntu-mobile-icons libusermetricsoutput1-dev || exit 5
4747}
4848
4949if [ -f "/usr/bin/ninja" ] ; then
plugins/LightDM/CMakeLists.txt+4−1
@@ -1,6 +1,7 @@
11# Dependencies
2+include(FindPkgConfig)
3+pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
24# TODO: Once we split out a separate greeter process, uncomment these lines
3−#include(FindPkgConfig)
45#pkg_check_modules(LIBLIGHTDM REQUIRED liblightdm-qt5-2)
56
67include_directories(
@@ -8,6 +9,7 @@ include_directories(
89 ${CMAKE_CURRENT_BINARY_DIR}
910 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM
1011 #${LIBLIGHTDM_INCLUDE_DIRS}
12+ ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
1113)
1214
1315set(QMLPLUGIN_SRC
@@ -25,6 +27,7 @@ target_link_libraries(LightDM-qml
2527 MockLightDM-demo
2628# TODO: Once we split out a separate greeter process, uncomment these lines
2729# ${LIBLIGHTDM_LDFLAGS}
30+ ${LIBUSERMETRICSOUTPUT_LDFLAGS}
2831 )
2932
3033qt5_use_modules(LightDM-qml Gui Qml)
plugins/LightDM/InfographicModel.hdeleted−27
@@ -1,27 +0,0 @@
1−/*
2− * Copyright (C) 2012,2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors: Pete Woods <pete.woods@canonical.com>
17− */
18−
19−#ifndef INFOGRAPHICMODEL_H
20−#define INFOGRAPHICMODEL_H
21−
22−#include <QLightDM/InfographicModel>
23−
24−typedef QLightDM::InfographicModel InfographicModel;
25−typedef QLightDM::InfographicColorTheme InfographicColorTheme;
26−
27−#endif
plugins/LightDM/plugin.cpp+5−4
@@ -20,8 +20,9 @@
2020#include "plugin.h"
2121#include "Greeter.h"
2222#include "UsersModel.h"
23+#include <libusermetricsoutput/ColorTheme.h>
24+#include <libusermetricsoutput/UserMetrics.h>
2325#include <QLightDM/UsersModel>
24−#include "InfographicModel.h"
2526
2627#include <QtCore/QAbstractItemModel>
2728#include <QtQml>
@@ -44,17 +45,17 @@ static QObject *infographic_provider(QQmlEngine *engine, QJSEngine *scriptEngine
4445{
4546 Q_UNUSED(engine)
4647 Q_UNUSED(scriptEngine)
47− return InfographicModel::getInstance();
48+ return UserMetricsOutput::UserMetrics::getInstance();
4849}
4950
5051void LightDMPlugin::registerTypes(const char *uri)
5152{
5253 qmlRegisterType<QAbstractItemModel>();
53− qmlRegisterType<InfographicColorTheme>();
54+ qmlRegisterType<UserMetricsOutput::ColorTheme>();
5455
5556 Q_ASSERT(uri == QLatin1String("LightDM"));
5657 qmlRegisterSingletonType<Greeter>(uri, 0, 1, "Greeter", greeter_provider);
5758 qmlRegisterSingletonType<UsersModel>(uri, 0, 1, "Users", users_provider);
5859 qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", "Type is not instantiable");
59− qmlRegisterSingletonType<InfographicModel>(uri, 0, 1, "Infographic", infographic_provider);
60+ qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);
6061}
run+3−3
@@ -42,17 +42,17 @@ done
4242
4343if $FAKE; then
4444 export QML2_IMPORT_PATH=$PWD/builddir/tests/mocks:$PWD/builddir/plugins
45− export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/builddir/tests/mocks/LightDM/single
45+ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/builddir/tests/mocks/libusermetrics:$PWD/builddir/tests/mocks/LightDM/single
4646fi
4747
4848if $PINLOCK; then
4949 export QML2_IMPORT_PATH=$PWD/builddir/tests/mocks:$PWD/builddir/plugins
50− export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/builddir/tests/mocks/LightDM/single-pin
50+ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/builddir/tests/mocks/libusermetrics:$PWD/builddir/tests/mocks/LightDM/single-pin
5151fi
5252
5353if $KEYLOCK; then
5454 export QML2_IMPORT_PATH=$PWD/builddir/tests/mocks:$PWD/builddir/plugins
55− export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/builddir/tests/mocks/LightDM/single-passphrase
55+ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/builddir/tests/mocks/libusermetrics:$PWD/builddir/tests/mocks/LightDM/single-passphrase
5656fi
5757
5858# Force icon theme if running on the desktop, otherwise gnome theme (if running
tests/autopilot/unity8/tests/__init__.py+2−2
@@ -39,7 +39,7 @@ class ShellTestCase(AutopilotTestCase):
3939 self.launch_test_local(geometry)
4040
4141 def launch_test_local(self, geometry):
42− os.environ['LD_LIBRARY_PATH'] = "../../../unity_build/build/lib:../../builddir/tests/mocks/LightDM/" + self.lightdm_mock
42+ os.environ['LD_LIBRARY_PATH'] = "../../../unity_build/build/lib:../../builddir/tests/mocks/libusermetrics:../../builddir/tests/mocks/LightDM/" + self.lightdm_mock
4343 os.environ['QML2_IMPORT_PATH'] = "../../builddir/tests/mocks:../../builddir/plugins"
4444 if geometry != "0x0":
4545 self.app = self.launch_test_application(
@@ -49,7 +49,7 @@ class ShellTestCase(AutopilotTestCase):
4949 "../../builddir/unity8", "-fullscreen", app_type='qt')
5050
5151 def launch_test_installed(self, geometry):
52− os.environ['LD_LIBRARY_PATH'] = "/usr/share/unity8/plugins/mocks/LightDM/" + self.lightdm_mock
52+ os.environ['LD_LIBRARY_PATH'] = "/usr/share/unity8/plugins/mocks/libusermetrics:/usr/share/unity8/plugins/mocks/LightDM/" + self.lightdm_mock
5353 os.environ['QML2_IMPORT_PATH'] = "/usr/share/unity8/plugins/mocks:/usr/share/unity8/plugins"
5454 if model() == 'Desktop' and geometry != "0x0":
5555 self.app = self.launch_test_application(
tests/mocks/CMakeLists.txt+1
@@ -1,2 +1,3 @@
1+add_subdirectory(libusermetrics)
12add_subdirectory(LightDM)
23add_subdirectory(Ubuntu)
tests/mocks/LightDM/CMakeLists.txt+3
@@ -13,6 +13,7 @@ add_subdirectory(single-passphrase)
1313include_directories(
1414 ${CMAKE_CURRENT_SOURCE_DIR}
1515 ${CMAKE_CURRENT_BINARY_DIR}
16+ ${CMAKE_SOURCE_DIR}/tests/mocks/libusermetrics
1617)
1718
1819set(QMLPLUGIN_SRC
@@ -34,6 +35,8 @@ add_dependencies(MockLightDM-qml MockLightDM-full)
3435target_link_libraries(MockLightDM-qml
3536 -L${CMAKE_CURRENT_BINARY_DIR}/full
3637 -llightdm-qt5-2
38+ -L${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics
39+ -lusermetricsoutput
3740 )
3841
3942qt5_use_modules(MockLightDM-qml Gui Qml)
tests/mocks/LightDM/InfographicModel.cppdeleted−416
@@ -1,416 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Author: Pete Woods <pete.woods@canonical.com>
17− */
18−
19−#include "InfographicModelPrivate.h"
20−#include "InfographicModel.h"
21−
22−#include <QtCore/QDir>
23−#include <QtCore/QString>
24−#include <QtGui/QIcon>
25−#include <QMultiMap>
26−
27−using namespace QLightDM;
28−
29−namespace QLightDM
30−{
31−
32−class InfographicColorThemePrivate: QObject
33−{
34−public:
35− explicit InfographicColorThemePrivate(InfographicColorTheme *parent = 0);
36−
37− InfographicColorThemePrivate(const QColor &start, const QColor &main,
38− const QColor &end, InfographicColorTheme *parent = 0);
39−
40− ~InfographicColorThemePrivate();
41−
42− InfographicColorTheme * const q_ptr;
43−
44− QColor m_start;
45−
46− QColor m_main;
47−
48− QColor m_end;
49−
50−protected:
51− int calculateLength();
52−
53−private:
54− Q_DECLARE_PUBLIC(InfographicColorTheme)
55−};
56−
57−class InfographicDataPrivate: QObject
58−{
59−public:
60− explicit InfographicDataPrivate(InfographicData *parent);
61−
62− InfographicDataPrivate(const QString &label,
63− const InfographicColorTheme &firstColor,
64− const QVariantList &firstMonth,
65− const InfographicColorTheme &secondColor,
66− const QVariantList &secondMonth, InfographicData *parent);
67−
68− ~InfographicDataPrivate();
69−
70− InfographicData * const q_ptr;
71− QString m_label;
72− InfographicColorTheme m_firstColor;
73− QVariantList m_firstMonth;
74− InfographicColorTheme m_secondColor;
75− QVariantList m_secondMonth;
76− int m_length;
77−
78−protected:
79− int calculateLength();
80−
81−private:
82− Q_DECLARE_PUBLIC(InfographicData)
83−};
84−
85−}
86−
87−InfographicColorThemePrivate::InfographicColorThemePrivate(
88− InfographicColorTheme *parent) :
89− q_ptr(parent)
90−{
91−}
92−
93−InfographicColorThemePrivate::InfographicColorThemePrivate(const QColor &start,
94− const QColor &main, const QColor &end, InfographicColorTheme *parent) :
95− q_ptr(parent), m_start(start), m_main(main), m_end(end)
96−{
97−}
98−
99−InfographicColorThemePrivate::~InfographicColorThemePrivate()
100−{
101−}
102−
103−InfographicColorTheme::InfographicColorTheme(QObject *parent) :
104− QObject(parent), d_ptr(new InfographicColorThemePrivate(this))
105−{
106−}
107−
108−InfographicColorTheme::InfographicColorTheme(QColor &first, QColor &main,
109− QColor &end, QObject *parent) :
110− QObject(parent), d_ptr(
111− new InfographicColorThemePrivate(first, main, end, this))
112−{
113−
114−}
115−
116−InfographicColorTheme & InfographicColorTheme::operator=(
117− const InfographicColorTheme & other)
118−{
119− if (d_ptr->m_start != other.d_ptr->m_start)
120− {
121− d_ptr->m_start = other.d_ptr->m_start;
122− startChanged(d_ptr->m_start);
123− }
124− if (d_ptr->m_main != other.d_ptr->m_main)
125− {
126− d_ptr->m_main = other.d_ptr->m_main;
127− mainChanged(d_ptr->m_main);
128− }
129−
130− if (d_ptr->m_end != other.d_ptr->m_end)
131− {
132− d_ptr->m_end = other.d_ptr->m_end;
133− endChanged(d_ptr->m_end);
134− }
135−
136− return *this;
137−}
138−
139−InfographicColorTheme::~InfographicColorTheme()
140−{
141− delete d_ptr;
142−}
143−
144−QColor InfographicColorTheme::start() const
145−{
146− return d_ptr->m_start;
147−}
148−
149−QColor InfographicColorTheme::main() const
150−{
151− return d_ptr->m_main;
152−}
153−
154−QColor InfographicColorTheme::end() const
155−{
156− return d_ptr->m_end;
157−}
158−
159−InfographicDataPrivate::InfographicDataPrivate(InfographicData *parent) :
160− q_ptr(parent), m_firstColor(this), m_secondColor(this)
161−{
162− m_length = calculateLength();
163−}
164−
165−InfographicDataPrivate::InfographicDataPrivate(const QString &label,
166− const InfographicColorTheme &firstColor, const QVariantList &firstMonth,
167− const InfographicColorTheme &secondColor,
168− const QVariantList &secondMonth, InfographicData *parent) :
169− q_ptr(parent), m_label(label), m_firstColor(this), m_firstMonth(
170− firstMonth), m_secondColor(this), m_secondMonth(secondMonth)
171−{
172− m_length = calculateLength();
173− m_firstColor = firstColor;
174− m_secondColor = secondColor;
175−}
176−
177−InfographicDataPrivate::~InfographicDataPrivate()
178−{
179−}
180−
181−int InfographicDataPrivate::calculateLength()
182−{
183− int day(m_firstMonth.size());
184− auto it = m_firstMonth.end(), end = m_firstMonth.begin();
185− while (it != end)
186− {
187− --it;
188− --day;
189− if (!it->isNull())
190− {
191− return day;
192− }
193− }
194−
195− return -1;
196−}
197−
198−InfographicData::InfographicData(QObject *parent) :
199− QObject(parent), d_ptr(new InfographicDataPrivate(this))
200−{
201−}
202−
203−InfographicData::InfographicData(const QString &label,
204− const InfographicColorTheme &firstColor, const QVariantList &firstMonth,
205− const InfographicColorTheme &secondColor,
206− const QVariantList &secondMonth, QObject* parent) :
207− QObject(parent), d_ptr(
208− new InfographicDataPrivate(label, firstColor, firstMonth,
209− secondColor, secondMonth, this))
210−{
211−}
212−
213−InfographicData::~InfographicData()
214−{
215− delete d_ptr;
216−}
217−
218−const QString & InfographicData::label() const
219−{
220− return d_ptr->m_label;
221−}
222−
223−const InfographicColorTheme & InfographicData::firstColor() const
224−{
225− return d_ptr->m_firstColor;
226−}
227−
228−const QVariantList & InfographicData::firstMonth() const
229−{
230− return d_ptr->m_firstMonth;
231−}
232−
233−const InfographicColorTheme & InfographicData::secondColor() const
234−{
235− return d_ptr->m_secondColor;
236−}
237−
238−const QVariantList & InfographicData::secondMonth() const
239−{
240− return d_ptr->m_secondMonth;
241−}
242−
243−int InfographicData::length() const
244−{
245− return d_ptr->m_length;
246−}
247−
248−InfographicModelPrivate::InfographicModelPrivate(InfographicModel *parent) :
249− q_ptr(parent), m_currentDay(0)
250−{
251− m_fakeData.insert("", InfographicDataPtr(new InfographicData(this)));
252−}
253−
254−InfographicModelPrivate::~InfographicModelPrivate()
255−{
256−}
257−
258−void InfographicModelPrivate::setUsername(const QString &username)
259−{
260− if(m_username == username) {
261− return;
262− }
263−
264− m_username = username;
265−
266− m_dataIndex = m_fakeData.constFind(m_username);
267− if (m_dataIndex == m_fakeData.end())
268− {
269− m_dataIndex = m_fakeData.constFind("");
270− }
271−
272− loadFakeData();
273−
274− q_ptr->usernameChanged(m_username);
275−}
276−
277−void InfographicModelPrivate::loadFakeData()
278−{
279− m_newData = *m_dataIndex;
280−
281− bool oldLabelEmpty = m_label.isEmpty();
282− bool newLabelEmpty = m_newData->label().isEmpty();
283−
284− if (oldLabelEmpty && !newLabelEmpty)
285− {
286− q_ptr->dataAboutToAppear();
287− finishSetFakeData();
288− } else if (!oldLabelEmpty && newLabelEmpty)
289− {
290− q_ptr->dataAboutToDisappear();
291− } else if (!oldLabelEmpty && !newLabelEmpty)
292− {
293− q_ptr->dataAboutToChange();
294− }
295− // we emit no signal if the data has stayed empty
296−}
297−
298−void InfographicModelPrivate::finishSetFakeData()
299−{
300− bool oldLabelEmpty = m_label.isEmpty();
301− bool newLabelEmpty = m_newData->label().isEmpty();
302−
303− m_label = m_newData->label();
304− m_firstColor = m_newData->firstColor();
305− m_firstMonth.setVariantList(m_newData->firstMonth());
306− m_secondColor = m_newData->secondColor();
307− m_secondMonth.setVariantList(m_newData->secondMonth());
308−
309− bool currentDayChanged = m_currentDay != m_newData->length();
310− m_currentDay = m_newData->length();
311−
312− q_ptr->labelChanged(m_label);
313− if (currentDayChanged)
314− {
315− q_ptr->currentDayChanged(m_currentDay);
316− }
317−
318− if (oldLabelEmpty && !newLabelEmpty)
319− {
320− q_ptr->dataAppeared();
321− } else if (!oldLabelEmpty && newLabelEmpty)
322− {
323− q_ptr->dataDisappeared();
324− } else if (!oldLabelEmpty && !newLabelEmpty)
325− {
326− q_ptr->dataChanged();
327− }
328− // we emit no signal if the data has stayed empty
329−}
330−
331−void InfographicModelPrivate::nextFakeData()
332−{
333− ++m_dataIndex;
334− if (m_dataIndex == m_fakeData.end() || m_dataIndex.key() != m_username)
335− {
336− m_dataIndex = m_fakeData.constFind(m_username);
337− }
338−
339− loadFakeData();
340−}
341−
342−InfographicModel::InfographicModel(QObject *parent) :
343− QObject(parent), d_ptr(new InfographicModelPrivate(this))
344−{
345− d_ptr->generateFakeData();
346− setUsername("");
347−
348− connect(this, SIGNAL(nextDataSource()), this, SLOT(nextDataSourceSlot()),
349− Qt::QueuedConnection);
350− connect(this, SIGNAL(readyForDataChange()), this,
351− SLOT(readyForDataChangeSlot()), Qt::QueuedConnection);
352−}
353−
354−InfographicModel::~InfographicModel()
355−{
356− delete d_ptr;
357−}
358−
359−QString InfographicModel::label() const
360−{
361− return d_ptr->m_label;
362−}
363−
364−QString InfographicModel::username() const
365−{
366− return d_ptr->m_username;
367−}
368−
369−void InfographicModel::setUsername(const QString &username)
370−{
371− d_ptr->setUsername(username);
372−}
373−
374−InfographicColorTheme * InfographicModel::firstColor() const
375−{
376− return &d_ptr->m_firstColor;
377−}
378−
379−InfographicColorTheme * InfographicModel::secondColor() const
380−{
381− return &d_ptr->m_secondColor;
382−}
383−
384−QAbstractItemModel * InfographicModel::firstMonth() const
385−{
386− return &d_ptr->m_firstMonth;
387−}
388−
389−QAbstractItemModel * InfographicModel::secondMonth() const
390−{
391− return &d_ptr->m_secondMonth;
392−}
393−
394−int InfographicModel::currentDay() const
395−{
396− return d_ptr->m_currentDay;
397−}
398−
399−void InfographicModel::nextDataSourceSlot()
400−{
401− d_ptr->nextFakeData();
402−}
403−
404−void InfographicModel::readyForDataChangeSlot()
405−{
406− d_ptr->finishSetFakeData();
407−}
408−
409−/**
410− * Factory methods
411− */
412−
413−InfographicModel * InfographicModel::getInstance()
414−{
415− return new InfographicModel();
416−}
tests/mocks/LightDM/InfographicModelPrivate.hdeleted−99
@@ -1,99 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Author: Pete Woods <pete.woods@canonical.com>
17− */
18−
19−#ifndef INFOGRAPHICMODEL_PRIVATE_H
20−#define INFOGRAPHICMODEL_PRIVATE_H
21−
22−#include <QtCore/QSharedPointer>
23−
24−#include "InfographicModel.h"
25−#include "plugins/Utils/qvariantlistmodel.h"
26−
27−namespace QLightDM
28−{
29−class InfographicDataPrivate;
30−
31−class Q_DECL_EXPORT InfographicData: public QObject
32−{
33−public:
34− explicit InfographicData(QObject *parent);
35−
36− InfographicData(const QString &label,
37− const InfographicColorTheme &firstColor,
38− const QVariantList &firstMonth,
39− const InfographicColorTheme &secondColor,
40− const QVariantList &secondMonth, QObject* parent);
41−
42− ~InfographicData();
43−
44−protected:
45− InfographicDataPrivate * const d_ptr;
46−
47−public:
48− const QString & label() const;
49− const InfographicColorTheme & firstColor() const;
50− const QVariantList & firstMonth() const;
51− const InfographicColorTheme & secondColor() const;
52− const QVariantList & secondMonth() const;
53− int length() const;
54−
55−private:
56− Q_DECLARE_PRIVATE(InfographicData)
57−};
58−
59−class InfographicModelPrivate: QObject
60−{
61−
62−public:
63− explicit InfographicModelPrivate(InfographicModel *parent);
64−
65− ~InfographicModelPrivate();
66−
67−public:
68− typedef QSharedPointer<InfographicData> InfographicDataPtr;
69− typedef QMultiMap<QString, InfographicDataPtr> FakeDataMap;
70−
71− InfographicModel * const q_ptr;
72− QString m_label;
73− InfographicColorTheme m_firstColor;
74− QVariantListModel m_firstMonth;
75− InfographicColorTheme m_secondColor;
76− QVariantListModel m_secondMonth;
77− int m_currentDay;
78− QString m_username;
79− FakeDataMap::const_iterator m_dataIndex;
80− InfographicDataPtr m_newData;
81− FakeDataMap m_fakeData;
82−
83− void setUsername(const QString &username);
84−
85−protected:
86− void nextFakeData();
87−
88− void generateFakeData();
89−
90− void loadFakeData();
91−
92− void finishSetFakeData();
93−
94−private:
95− Q_DECLARE_PUBLIC(InfographicModel)
96−};
97−}
98−
99−#endif // INFOGRAPHICMODEL_PRIVATE_H
tests/mocks/LightDM/demo/CMakeLists.txt+11−2
@@ -1,13 +1,22 @@
1+include(FindPkgConfig)
2+pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
3+
14set(LibLightDM_SOURCES
25 ../Greeter.cpp
36 ../UsersModel.cpp
4− ../InfographicModel.cpp
57 GreeterPrivate.cpp
68 UsersModelPrivate.cpp
7− InfographicModelPrivate.cpp
89 ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
910 )
1011
1112add_library(MockLightDM-demo STATIC ${LibLightDM_SOURCES})
1213
14+include_directories(
15+ ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
16+)
17+
18+target_link_libraries(MockLightDM-demo
19+ ${LIBUSERMETRICSOUTPUT_LDFLAGS}
20+ )
21+
1322qt5_use_modules(MockLightDM-demo Gui)
tests/mocks/LightDM/demo/UsersModelPrivate.cpp+1−1
@@ -26,7 +26,7 @@ UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
2626{
2727 entries =
2828 {
29− { "guest", "Guest", 0, 0, false, false, 0, 0 },
29+ { "single", "Guest", 0, 0, false, false, 0, 0 },
3030 };
3131}
3232
tests/mocks/LightDM/full/CMakeLists.txt−2
@@ -1,10 +1,8 @@
11set(LibLightDM_SOURCES
22 ../Greeter.cpp
33 ../UsersModel.cpp
4− ../InfographicModel.cpp
54 GreeterPrivate.cpp
65 UsersModelPrivate.cpp
7− InfographicModelPrivate.cpp
86 ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
97 )
108
tests/mocks/LightDM/single-passphrase/CMakeLists.txt−2
@@ -1,10 +1,8 @@
11set(LibLightDM_SOURCES
22 ../Greeter.cpp
33 ../UsersModel.cpp
4− ../InfographicModel.cpp
54 GreeterPrivate.cpp
65 UsersModelPrivate.cpp
7− InfographicModelPrivate.cpp
86 ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
97 )
108
tests/mocks/LightDM/single-passphrase/UsersModelPrivate.cpp+1−1
@@ -26,7 +26,7 @@ UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
2626{
2727 entries =
2828 {
29− { "has-pin", "Has PIN", 0, 0, false, false, 0, 0 },
29+ { "single", "Has Passphrase", 0, 0, false, false, 0, 0 },
3030 };
3131}
3232
tests/mocks/LightDM/single-pin/CMakeLists.txt−2
@@ -1,10 +1,8 @@
11set(LibLightDM_SOURCES
22 ../Greeter.cpp
33 ../UsersModel.cpp
4− ../InfographicModel.cpp
54 GreeterPrivate.cpp
65 UsersModelPrivate.cpp
7− InfographicModelPrivate.cpp
86 ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
97 )
108
tests/mocks/LightDM/single-pin/UsersModelPrivate.cpp+1−1
@@ -26,7 +26,7 @@ UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
2626{
2727 entries =
2828 {
29− { "has-pin", "Has PIN", 0, 0, false, false, 0, 0 },
29+ { "single", "Has PIN", 0, 0, false, false, 0, 0 },
3030 };
3131}
3232
tests/mocks/LightDM/single/CMakeLists.txt−2
@@ -1,9 +1,7 @@
11set(LibLightDM_SOURCES
22 ../Greeter.cpp
3− ../InfographicModel.cpp
43 ../UsersModel.cpp
54 GreeterPrivate.cpp
6− InfographicModelPrivate.cpp
75 UsersModelPrivate.cpp
86 ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
97 )
tests/mocks/LightDM/single/UsersModelPrivate.cpp+1−1
@@ -26,7 +26,7 @@ UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
2626{
2727 entries =
2828 {
29− { "one", "Only User", 0, 0, false, false, 0, 0 },
29+ { "single", "Single User", 0, 0, false, false, 0, 0 },
3030 };
3131}
3232
tests/mocks/libusermetrics/CMakeLists.txtnew file+17
@@ -0,0 +1,17 @@
1+set(mock_SOURCES
2+ ColorTheme.cpp
3+ UserMetrics.cpp
4+ ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
5+ )
6+
7+add_library(MockUserMetrics SHARED ${mock_SOURCES})
8+
9+qt5_use_modules(MockUserMetrics Gui)
10+
11+set_target_properties(MockUserMetrics PROPERTIES
12+ OUTPUT_NAME usermetricsoutput
13+ VERSION 1)
14+
15+install(TARGETS MockUserMetrics
16+ DESTINATION ${SHELL_APP_DIR}/plugins/mocks/libusermetrics
17+ )
tests/mocks/libusermetrics/ColorTheme.cppnew file+128
@@ -0,0 +1,128 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Author: Pete Woods <pete.woods@canonical.com>
17+ */
18+
19+#include "ColorTheme.h"
20+
21+#include <QtCore/QDir>
22+#include <QtCore/QString>
23+#include <QtGui/QIcon>
24+#include <QMultiMap>
25+
26+using namespace UserMetricsOutput;
27+
28+namespace UserMetricsOutput
29+{
30+
31+class ColorThemePrivate: QObject
32+{
33+public:
34+ explicit ColorThemePrivate(ColorTheme *parent = 0);
35+
36+ ColorThemePrivate(const QColor &start, const QColor &main,
37+ const QColor &end, ColorTheme *parent = 0);
38+
39+ ~ColorThemePrivate();
40+
41+ ColorTheme * const q_ptr;
42+
43+ QColor m_start;
44+
45+ QColor m_main;
46+
47+ QColor m_end;
48+
49+protected:
50+ int calculateLength();
51+
52+private:
53+ Q_DECLARE_PUBLIC(ColorTheme)
54+};
55+
56+}
57+
58+ColorThemePrivate::ColorThemePrivate(
59+ ColorTheme *parent) :
60+ q_ptr(parent)
61+{
62+}
63+
64+ColorThemePrivate::ColorThemePrivate(const QColor &start,
65+ const QColor &main, const QColor &end, ColorTheme *parent) :
66+ q_ptr(parent), m_start(start), m_main(main), m_end(end)
67+{
68+}
69+
70+ColorThemePrivate::~ColorThemePrivate()
71+{
72+}
73+
74+ColorTheme::ColorTheme(QObject *parent) :
75+ QObject(parent), d_ptr(new ColorThemePrivate(this))
76+{
77+}
78+
79+ColorTheme::ColorTheme(QColor &first, QColor &main,
80+ QColor &end, QObject *parent) :
81+ QObject(parent), d_ptr(
82+ new ColorThemePrivate(first, main, end, this))
83+{
84+
85+}
86+
87+ColorTheme & ColorTheme::operator=(
88+ const ColorTheme & other)
89+{
90+ if (d_ptr->m_start != other.d_ptr->m_start)
91+ {
92+ d_ptr->m_start = other.d_ptr->m_start;
93+ startChanged(d_ptr->m_start);
94+ }
95+ if (d_ptr->m_main != other.d_ptr->m_main)
96+ {
97+ d_ptr->m_main = other.d_ptr->m_main;
98+ mainChanged(d_ptr->m_main);
99+ }
100+
101+ if (d_ptr->m_end != other.d_ptr->m_end)
102+ {
103+ d_ptr->m_end = other.d_ptr->m_end;
104+ endChanged(d_ptr->m_end);
105+ }
106+
107+ return *this;
108+}
109+
110+ColorTheme::~ColorTheme()
111+{
112+ delete d_ptr;
113+}
114+
115+QColor ColorTheme::start() const
116+{
117+ return d_ptr->m_start;
118+}
119+
120+QColor ColorTheme::main() const
121+{
122+ return d_ptr->m_main;
123+}
124+
125+QColor ColorTheme::end() const
126+{
127+ return d_ptr->m_end;
128+}
tests/mocks/libusermetrics/ColorTheme.hnew file+68
@@ -0,0 +1,68 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Author: Pete Woods <pete.woods@canonical.com>
17+ */
18+
19+#ifndef UNITY_MOCK_COLORTHEME_H
20+#define UNITY_MOCK_COLORTHEME_H
21+
22+#include <QtGui/QColor>
23+
24+namespace UserMetricsOutput
25+{
26+class ColorThemePrivate;
27+
28+class Q_DECL_EXPORT ColorTheme: public QObject
29+{
30+Q_OBJECT
31+
32+Q_PROPERTY(QColor start READ start NOTIFY startChanged FINAL)
33+Q_PROPERTY(QColor main READ main NOTIFY mainChanged FINAL)
34+Q_PROPERTY(QColor end READ end NOTIFY endChanged FINAL)
35+
36+public:
37+ explicit ColorTheme(QObject *parent = 0);
38+
39+ explicit ColorTheme(QColor &first, QColor &main, QColor &end,
40+ QObject *parent = 0);
41+
42+ ColorTheme & operator=(const ColorTheme & other);
43+
44+ ~ColorTheme();
45+
46+ QColor start() const;
47+
48+ QColor main() const;
49+
50+ QColor end() const;
51+
52+Q_SIGNALS:
53+ void startChanged(const QColor &color);
54+
55+ void mainChanged(const QColor &color);
56+
57+ void endChanged(const QColor &color);
58+
59+protected:
60+ ColorThemePrivate * const d_ptr;
61+
62+ Q_DECLARE_PRIVATE(ColorTheme)
63+
64+};
65+
66+}
67+
68+#endif // UNITY_MOCK_COLORTHEME_H
tests/mocks/libusermetrics/UserMetrics.cppnew file+465
@@ -0,0 +1,465 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Author: Pete Woods <pete.woods@canonical.com>
17+ */
18+
19+#include "UserMetrics.h"
20+#include "plugins/Utils/qvariantlistmodel.h"
21+
22+#include <QtCore/QDir>
23+#include <QtCore/QString>
24+#include <QtGui/QIcon>
25+#include <QMultiMap>
26+
27+using namespace UserMetricsOutput;
28+
29+namespace UserMetricsOutput
30+{
31+class UserMetricsDataPrivate;
32+class UserMetricsPrivate;
33+
34+class Q_DECL_EXPORT UserMetricsData: public QObject
35+{
36+public:
37+ explicit UserMetricsData(QObject *parent);
38+
39+ UserMetricsData(const QString &label,
40+ const ColorTheme &firstColor,
41+ const QVariantList &firstMonth,
42+ const ColorTheme &secondColor,
43+ const QVariantList &secondMonth, QObject* parent);
44+
45+ ~UserMetricsData();
46+
47+protected:
48+ UserMetricsDataPrivate * const d_ptr;
49+
50+public:
51+ const QString & label() const;
52+ const ColorTheme & firstColor() const;
53+ const QVariantList & firstMonth() const;
54+ const ColorTheme & secondColor() const;
55+ const QVariantList & secondMonth() const;
56+ int length() const;
57+
58+private:
59+ Q_DECLARE_PRIVATE(UserMetricsData)
60+};
61+
62+class UserMetricsPrivate: QObject
63+{
64+public:
65+ explicit UserMetricsPrivate(UserMetrics *parent);
66+
67+ ~UserMetricsPrivate();
68+
69+public:
70+ typedef QSharedPointer<UserMetricsData> UserMetricsDataPtr;
71+ typedef QMultiMap<QString, UserMetricsDataPtr> FakeDataMap;
72+
73+ UserMetrics * const q_ptr;
74+ QString m_label;
75+ ColorTheme m_firstColor;
76+ QVariantListModel m_firstMonth;
77+ ColorTheme m_secondColor;
78+ QVariantListModel m_secondMonth;
79+ int m_currentDay;
80+ QString m_username;
81+ FakeDataMap::const_iterator m_dataIndex;
82+ UserMetricsDataPtr m_newData;
83+ FakeDataMap m_fakeData;
84+
85+ void setUsername(const QString &username);
86+
87+protected:
88+ void nextFakeData();
89+
90+ void generateFakeData();
91+
92+ void loadFakeData();
93+
94+ void finishSetFakeData();
95+
96+private:
97+ Q_DECLARE_PUBLIC(UserMetrics)
98+};
99+
100+class UserMetricsDataPrivate: QObject
101+{
102+public:
103+ explicit UserMetricsDataPrivate(UserMetricsData *parent);
104+
105+ UserMetricsDataPrivate(const QString &label,
106+ const ColorTheme &firstColor,
107+ const QVariantList &firstMonth,
108+ const ColorTheme &secondColor,
109+ const QVariantList &secondMonth, UserMetricsData *parent);
110+
111+ ~UserMetricsDataPrivate();
112+
113+ UserMetricsData * const q_ptr;
114+ QString m_label;
115+ ColorTheme m_firstColor;
116+ QVariantList m_firstMonth;
117+ ColorTheme m_secondColor;
118+ QVariantList m_secondMonth;
119+ int m_length;
120+
121+protected:
122+ int calculateLength();
123+
124+private:
125+ Q_DECLARE_PUBLIC(UserMetricsData)
126+};
127+
128+}
129+
130+UserMetricsDataPrivate::UserMetricsDataPrivate(UserMetricsData *parent) :
131+ q_ptr(parent), m_firstColor(this), m_secondColor(this)
132+{
133+ m_length = calculateLength();
134+}
135+
136+UserMetricsDataPrivate::UserMetricsDataPrivate(const QString &label,
137+ const ColorTheme &firstColor, const QVariantList &firstMonth,
138+ const ColorTheme &secondColor,
139+ const QVariantList &secondMonth, UserMetricsData *parent) :
140+ q_ptr(parent), m_label(label), m_firstColor(this), m_firstMonth(
141+ firstMonth), m_secondColor(this), m_secondMonth(secondMonth)
142+{
143+ m_length = calculateLength();
144+ m_firstColor = firstColor;
145+ m_secondColor = secondColor;
146+}
147+
148+UserMetricsDataPrivate::~UserMetricsDataPrivate()
149+{
150+}
151+
152+int UserMetricsDataPrivate::calculateLength()
153+{
154+ int day(m_firstMonth.size());
155+ auto it = m_firstMonth.end(), end = m_firstMonth.begin();
156+ while (it != end)
157+ {
158+ --it;
159+ --day;
160+ if (!it->isNull())
161+ {
162+ return day;
163+ }
164+ }
165+
166+ return -1;
167+}
168+
169+UserMetricsData::UserMetricsData(QObject *parent) :
170+ QObject(parent), d_ptr(new UserMetricsDataPrivate(this))
171+{
172+}
173+
174+UserMetricsData::UserMetricsData(const QString &label,
175+ const ColorTheme &firstColor, const QVariantList &firstMonth,
176+ const ColorTheme &secondColor,
177+ const QVariantList &secondMonth, QObject* parent) :
178+ QObject(parent), d_ptr(
179+ new UserMetricsDataPrivate(label, firstColor, firstMonth,
180+ secondColor, secondMonth, this))
181+{
182+}
183+
184+UserMetricsData::~UserMetricsData()
185+{
186+ delete d_ptr;
187+}
188+
189+const QString & UserMetricsData::label() const
190+{
191+ return d_ptr->m_label;
192+}
193+
194+const ColorTheme & UserMetricsData::firstColor() const
195+{
196+ return d_ptr->m_firstColor;
197+}
198+
199+const QVariantList & UserMetricsData::firstMonth() const
200+{
201+ return d_ptr->m_firstMonth;
202+}
203+
204+const ColorTheme & UserMetricsData::secondColor() const
205+{
206+ return d_ptr->m_secondColor;
207+}
208+
209+const QVariantList & UserMetricsData::secondMonth() const
210+{
211+ return d_ptr->m_secondMonth;
212+}
213+
214+int UserMetricsData::length() const
215+{
216+ return d_ptr->m_length;
217+}
218+
219+UserMetricsPrivate::UserMetricsPrivate(UserMetrics *parent) :
220+ q_ptr(parent), m_firstColor(this), m_secondColor(this)
221+{
222+ m_fakeData.insert("", UserMetricsDataPtr(new UserMetricsData(this)));
223+}
224+
225+UserMetricsPrivate::~UserMetricsPrivate()
226+{
227+}
228+
229+void UserMetricsPrivate::setUsername(const QString &username)
230+{
231+ if (m_username == username) {
232+ return;
233+ }
234+
235+ m_username = username;
236+
237+ m_dataIndex = m_fakeData.constFind(m_username);
238+ if (m_dataIndex == m_fakeData.end())
239+ {
240+ m_dataIndex = m_fakeData.constFind("");
241+ }
242+
243+ loadFakeData();
244+
245+ q_ptr->usernameChanged(m_username);
246+}
247+
248+void UserMetricsPrivate::generateFakeData()
249+{
250+ std::default_random_engine generator;
251+ std::normal_distribution<qreal> distribution(0.5, 0.2);
252+ auto rand = std::bind(distribution, generator);
253+
254+ QVector<QColor> colours;
255+ colours.push_back(QColor::fromRgbF(0.3, 0.27, 0.32));
256+ colours.push_back(QColor::fromRgbF(0.83, 0.49, 0.58));
257+ colours.push_back(QColor::fromRgbF(0.63, 0.51, 0.59));
258+
259+ colours.push_back(QColor::fromRgbF(0.28, 0.26, 0.4));
260+ colours.push_back(QColor::fromRgbF(0.47, 0.38, 0.56));
261+ colours.push_back(QColor::fromRgbF(0.69, 0.65, 0.78));
262+
263+ colours.push_back(QColor::fromRgbF(0.32, 0.21, 0.16));
264+ colours.push_back(QColor::fromRgbF(0.55, 0.45, 0.32));
265+ colours.push_back(QColor::fromRgbF(0.85, 0.74, 0.53));
266+
267+ colours.push_back(QColor::fromRgbF(0.25, 0.31, 0.19));
268+ colours.push_back(QColor::fromRgbF(0.63, 0.53, 0.3));
269+ colours.push_back(QColor::fromRgbF(0.89, 0.56, 0.31));
270+
271+ ColorTheme first(colours[0], colours[1], colours[2]);
272+ ColorTheme second(colours[3], colours[4], colours[5]);
273+ ColorTheme eighth(colours[6], colours[7], colours[8]);
274+ ColorTheme ninth(colours[9], colours[10], colours[11]);
275+
276+ {
277+ QVariantList firstMonth;
278+ while (firstMonth.size() < 17)
279+ firstMonth.push_back(QVariant(rand()));
280+ while (firstMonth.size() < 31)
281+ firstMonth.push_back(QVariant());
282+ QVariantList secondMonth;
283+ while (secondMonth.size() < 31)
284+ secondMonth.push_back(QVariant(rand()));
285+ QSharedPointer<UserMetricsData> data(
286+ new UserMetricsData("<b>52km</b> travelled", first, firstMonth,
287+ ninth, secondMonth, this));
288+ m_fakeData.insert("single", data);
289+ }
290+
291+ {
292+ QVariantList firstMonth;
293+ while (firstMonth.size() < 17)
294+ firstMonth.push_back(QVariant(rand()));
295+ while (firstMonth.size() < 31)
296+ firstMonth.push_back(QVariant());
297+ QVariantList secondMonth;
298+ while (secondMonth.size() < 31)
299+ secondMonth.push_back(QVariant(rand()));
300+ QSharedPointer<UserMetricsData> data(
301+ new UserMetricsData("<b>33</b> messages today", second,
302+ firstMonth, eighth, secondMonth, this));
303+ m_fakeData.insert("single", data);
304+ }
305+
306+ {
307+ QVariantList firstMonth;
308+ while (firstMonth.size() < 17)
309+ firstMonth.push_back(QVariant(rand()));
310+ while (firstMonth.size() < 31)
311+ firstMonth.push_back(QVariant());
312+ QVariantList secondMonth;
313+ while (secondMonth.size() < 31)
314+ secondMonth.push_back(QVariant(rand()));
315+ QSharedPointer<UserMetricsData> data(
316+ new UserMetricsData("<b>19</b> minutes talk time", eighth,
317+ firstMonth, second, secondMonth, this));
318+ m_fakeData.insert("single", data);
319+ // Also use same data for some tablet users
320+ m_fakeData.insert("has-password", data);
321+ m_fakeData.insert("no-password", data);
322+ m_fakeData.insert("empty-name", data);
323+ }
324+}
325+
326+void UserMetricsPrivate::loadFakeData()
327+{
328+ m_newData = *m_dataIndex;
329+
330+ bool oldLabelEmpty = m_label.isEmpty();
331+ bool newLabelEmpty = m_newData->label().isEmpty();
332+
333+ if (oldLabelEmpty && !newLabelEmpty)
334+ {
335+ q_ptr->dataAboutToAppear();
336+ finishSetFakeData();
337+ } else if (!oldLabelEmpty && newLabelEmpty)
338+ {
339+ q_ptr->dataAboutToDisappear();
340+ } else if (!oldLabelEmpty && !newLabelEmpty)
341+ {
342+ q_ptr->dataAboutToChange();
343+ }
344+ // we emit no signal if the data has stayed empty
345+}
346+
347+void UserMetricsPrivate::finishSetFakeData()
348+{
349+ bool oldLabelEmpty = m_label.isEmpty();
350+ bool newLabelEmpty = m_newData->label().isEmpty();
351+
352+ m_label = m_newData->label();
353+ m_firstColor = m_newData->firstColor();
354+ m_firstMonth.setVariantList(m_newData->firstMonth());
355+ m_secondColor = m_newData->secondColor();
356+ m_secondMonth.setVariantList(m_newData->secondMonth());
357+
358+ bool currentDayChanged = m_currentDay != m_newData->length();
359+ m_currentDay = m_newData->length();
360+
361+ q_ptr->labelChanged(m_label);
362+ if (currentDayChanged)
363+ {
364+ q_ptr->currentDayChanged(m_currentDay);
365+ }
366+
367+ if (oldLabelEmpty && !newLabelEmpty)
368+ {
369+ q_ptr->dataAppeared();
370+ } else if (!oldLabelEmpty && newLabelEmpty)
371+ {
372+ q_ptr->dataDisappeared();
373+ } else if (!oldLabelEmpty && !newLabelEmpty)
374+ {
375+ q_ptr->dataChanged();
376+ }
377+ // we emit no signal if the data has stayed empty
378+}
379+
380+void UserMetricsPrivate::nextFakeData()
381+{
382+ ++m_dataIndex;
383+ if (m_dataIndex == m_fakeData.end() || m_dataIndex.key() != m_username)
384+ {
385+ m_dataIndex = m_fakeData.constFind(m_username);
386+ }
387+
388+ loadFakeData();
389+}
390+
391+UserMetrics::UserMetrics(QObject *parent) :
392+ QObject(parent), d_ptr(new UserMetricsPrivate(this))
393+{
394+ d_ptr->generateFakeData();
395+ setUsername("");
396+
397+ connect(this, SIGNAL(nextDataSource()), this, SLOT(nextDataSourceSlot()),
398+ Qt::QueuedConnection);
399+ connect(this, SIGNAL(readyForDataChange()), this,
400+ SLOT(readyForDataChangeSlot()), Qt::QueuedConnection);
401+}
402+
403+UserMetrics::~UserMetrics()
404+{
405+ delete d_ptr;
406+}
407+
408+QString UserMetrics::label() const
409+{
410+ return d_ptr->m_label;
411+}
412+
413+QString UserMetrics::username() const
414+{
415+ return d_ptr->m_username;
416+}
417+
418+void UserMetrics::setUsername(const QString &username)
419+{
420+ d_ptr->setUsername(username);
421+}
422+
423+ColorTheme *UserMetrics::firstColor() const
424+{
425+ return &d_ptr->m_firstColor;
426+}
427+
428+ColorTheme *UserMetrics::secondColor() const
429+{
430+ return &d_ptr->m_secondColor;
431+}
432+
433+QAbstractItemModel *UserMetrics::firstMonth() const
434+{
435+ return &d_ptr->m_firstMonth;
436+}
437+
438+QAbstractItemModel *UserMetrics::secondMonth() const
439+{
440+ return &d_ptr->m_secondMonth;
441+}
442+
443+int UserMetrics::currentDay() const
444+{
445+ return d_ptr->m_currentDay;
446+}
447+
448+void UserMetrics::nextDataSourceSlot()
449+{
450+ d_ptr->nextFakeData();
451+}
452+
453+void UserMetrics::readyForDataChangeSlot()
454+{
455+ d_ptr->finishSetFakeData();
456+}
457+
458+/**
459+ * Factory methods
460+ */
461+
462+UserMetrics * UserMetrics::getInstance()
463+{
464+ return new UserMetrics();
465+}
tests/mocks/LightDM/InfographicModel.h → tests/mocks/libusermetrics/UserMetrics.hrenamed+22−60
@@ -16,74 +16,34 @@
1616 * Author: Pete Woods <pete.woods@canonical.com>
1717 */
1818
19−#ifndef LIGHTDM_INFOGRAPHICMODEL_H
20−#define LIGHTDM_INFOGRAPHICMODEL_H
19+#ifndef UNITY_MOCK_USERMETRICS_H
20+#define UNITY_MOCK_USERMETRICS_H
2121
22+#include "ColorTheme.h"
23+#include <QtCore/QAbstractListModel>
2224#include <QtCore/QString>
23−#include <QtGui/qcolor.h>
24−#include <QAbstractListModel>
25+#include <QtGui/QColor>
2526
26−namespace QLightDM
27+namespace UserMetricsOutput
2728{
28−class InfographicColorThemePrivate;
29+class UserMetricsPrivate;
2930
30−class Q_DECL_EXPORT InfographicColorTheme: public QObject
31−{
32−Q_OBJECT
33−
34−Q_PROPERTY(QColor start READ start NOTIFY startChanged FINAL)
35−Q_PROPERTY(QColor main READ main NOTIFY mainChanged FINAL)
36−Q_PROPERTY(QColor end READ end NOTIFY endChanged FINAL)
37−
38−public:
39− explicit InfographicColorTheme(QObject *parent = 0);
40−
41− explicit InfographicColorTheme(QColor &first, QColor &main, QColor &end,
42− QObject *parent = 0);
43−
44− InfographicColorTheme & operator=(const InfographicColorTheme & other);
45−
46− ~InfographicColorTheme();
47−
48− QColor start() const;
49−
50− QColor main() const;
51−
52− QColor end() const;
53−
54−Q_SIGNALS:
55− void startChanged(const QColor &color);
56−
57− void mainChanged(const QColor &color);
58−
59− void endChanged(const QColor &color);
60−
61−protected:
62− InfographicColorThemePrivate * const d_ptr;
63−
64− Q_DECLARE_PRIVATE(InfographicColorTheme)
65−
66−};
67−
68−class InfographicModelPrivate;
69−
70−class Q_DECL_EXPORT InfographicModel: public QObject
31+class Q_DECL_EXPORT UserMetrics: public QObject
7132{
7233Q_OBJECT
7334
7435Q_PROPERTY(QString label READ label NOTIFY labelChanged FINAL)
7536Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY usernameChanged FINAL)
76−Q_PROPERTY(QLightDM::InfographicColorTheme* firstColor READ firstColor NOTIFY firstColorChanged FINAL)
77−Q_PROPERTY(QLightDM::InfographicColorTheme* secondColor READ secondColor NOTIFY secondColorChanged FINAL)
37+Q_PROPERTY(UserMetricsOutput::ColorTheme* firstColor READ firstColor NOTIFY firstColorChanged FINAL)
38+Q_PROPERTY(UserMetricsOutput::ColorTheme* secondColor READ secondColor NOTIFY secondColorChanged FINAL)
7839Q_PROPERTY(QAbstractItemModel *firstMonth READ firstMonth NOTIFY firstMonthChanged FINAL)
7940Q_PROPERTY(QAbstractItemModel *secondMonth READ secondMonth NOTIFY secondMonthChanged FINAL)
8041Q_PROPERTY(int currentDay READ currentDay NOTIFY currentDayChanged FINAL)
8142
8243public:
83− static InfographicModel *getInstance();
44+ static UserMetrics *getInstance();
8445
85− explicit InfographicModel(QObject *parent = 0);
86− ~InfographicModel();
46+ ~UserMetrics();
8747
8848 QString label() const;
8949
@@ -91,13 +51,13 @@ public:
9151
9252 void setUsername(const QString &username);
9353
94− InfographicColorTheme * firstColor() const;
54+ ColorTheme * firstColor() const;
9555
9656 QAbstractItemModel *firstMonth() const;
9757
9858 int currentDay() const;
9959
100− InfographicColorTheme * secondColor() const;
60+ ColorTheme * secondColor() const;
10161
10262 QAbstractItemModel *secondMonth() const;
10363
@@ -106,13 +66,13 @@ Q_SIGNALS:
10666
10767 void usernameChanged(const QString &username);
10868
109− void firstColorChanged(InfographicColorTheme *color);
69+ void firstColorChanged(ColorTheme *color);
11070
11171 void firstMonthChanged(QAbstractItemModel *firstMonth);
11272
11373 void currentDayChanged(int length);
11474
115− void secondColorChanged(InfographicColorTheme *color);
75+ void secondColorChanged(ColorTheme *color);
11676
11777 void secondMonthChanged(QAbstractItemModel *secondMonth);
11878
@@ -138,13 +98,15 @@ protected Q_SLOTS:
13898 void readyForDataChangeSlot();
13999
140100protected:
141− InfographicModelPrivate * const d_ptr;
101+ UserMetricsPrivate * const d_ptr;
102+
103+ explicit UserMetrics(QObject *parent = 0);
142104
143− Q_DISABLE_COPY(InfographicModel)
144− Q_DECLARE_PRIVATE(InfographicModel)
105+ Q_DISABLE_COPY(UserMetrics)
106+ Q_DECLARE_PRIVATE(UserMetrics)
145107
146108};
147109
148110}
149111
150−#endif // LIGHTDM_INFOGRAPHICMODEL_H
112+#endif // UNITY_MOCK_USERMETRICS_H
tests/mocks/libusermetrics/libusermetricsoutput/ColorTheme.hnew file+1
@@ -0,0 +1 @@
1+../ColorTheme.h
tests/mocks/libusermetrics/libusermetricsoutput/UserMetrics.hnew file+1
@@ -0,0 +1 @@
1+../UserMetrics.h
tests/qmltests/CMakeLists.txt+4−4
@@ -49,13 +49,13 @@ add_qml_test(Dash FilterGrids IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMA
4949add_qml_test(Dash/Apps RunningApplicationsGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
5050add_qml_test(Dash/People PeopleFilterGrid IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_SOURCE_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
5151add_qml_test(Greeter Lockscreen IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins ${CMAKE_BINARY_DIR}/tests/mocks
52− PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
52+ ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
5353add_qml_test(Greeter Tablet IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins ${CMAKE_BINARY_DIR}/tests/mocks
54− ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
54+ ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
5555add_qml_test(Greeter Phone IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins ${CMAKE_BINARY_DIR}/tests/mocks
56− ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
56+ ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
5757add_qml_test(Greeter Infographics IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins ${CMAKE_BINARY_DIR}/tests/mocks
58− ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
58+ ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full")
5959add_qml_test(Hud Hud)
6060add_qml_test(Hud Result)
6161add_qml_test(Launcher Launcher IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})