on xenial help sign in
files i forgot
commit48203419797d61c98cd330ac6eef50e7ebe48d45 authorAlbert Astals <albert.astals@canonical.com> dateWed 12 Feb 2014, 10:47 (13 years ago) parent09ed561
2 files changed+193
tests/mocks/Unity/fake_resultsmodel.cpp+113 tests/mocks/Unity/fake_resultsmodel.h+80
tests/mocks/Unity/fake_resultsmodel.cppnew file+113
@@ -0,0 +1,113 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Michal Hruby <michal.hruby@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+// self
21+#include "fake_resultsmodel.h"
22+
23+ResultsModel::ResultsModel(int result_count, int categoryId, QObject* parent)
24+ : QAbstractListModel(parent)
25+ , m_result_count(result_count)
26+ , m_categoryId(categoryId)
27+{
28+ m_roles[ResultsModel::RoleUri] = "uri";
29+ m_roles[ResultsModel::RoleCategoryId] = "categoryId";
30+ m_roles[ResultsModel::RoleDndUri] = "dndUri";
31+ m_roles[ResultsModel::RoleResult] = "result";
32+ m_roles[ResultsModel::RoleTitle] = "title";
33+ m_roles[ResultsModel::RoleArt] = "art";
34+ m_roles[ResultsModel::RoleSubtitle] = "subtitle";
35+ m_roles[ResultsModel::RoleMascot] = "mascot";
36+ m_roles[ResultsModel::RoleEmblem] = "emblem";
37+ m_roles[ResultsModel::RoleOldPrice] = "oldPrice";
38+ m_roles[ResultsModel::RolePrice] = "price";
39+ m_roles[ResultsModel::RoleAltPrice] = "altPrice";
40+ m_roles[ResultsModel::RoleRating] = "rating";
41+ m_roles[ResultsModel::RoleAltRating] = "altRating";
42+ m_roles[ResultsModel::RoleSummary] = "summary";
43+}
44+
45+QString ResultsModel::categoryId() const
46+{
47+ return QString::number(m_categoryId);
48+}
49+
50+void ResultsModel::setCategoryId(QString const& id)
51+{
52+ qFatal("Calling un-implemented ResultsModel::setCategoryId");
53+}
54+
55+QHash<int, QByteArray>
56+ResultsModel::roleNames() const
57+{
58+ return m_roles;
59+}
60+
61+int ResultsModel::rowCount(const QModelIndex& parent) const
62+{
63+ Q_UNUSED(parent);
64+
65+ return m_result_count;
66+}
67+
68+int ResultsModel::count() const
69+{
70+ return rowCount();
71+}
72+
73+QVariant ResultsModel::get(int row) const
74+{
75+ if (row >= m_result_count || row < 0) return QVariantMap();
76+
77+ QVariantMap result;
78+ QModelIndex modelIndex(index(row));
79+ QHashIterator<int, QByteArray> it(roleNames());
80+ while (it.hasNext()) {
81+ it.next();
82+ QVariant val(data(modelIndex, it.key()));
83+ if (val.isNull()) continue;
84+ result[it.value()] = val;
85+ }
86+
87+ return result;
88+}
89+
90+QVariant
91+ResultsModel::data(const QModelIndex& index, int role) const
92+{
93+ // TODO
94+ switch (role) {
95+ case RoleUri:
96+ case RoleCategoryId:
97+ case RoleDndUri:
98+ case RoleResult:
99+ case RoleTitle:
100+ case RoleArt:
101+ case RoleSubtitle:
102+ case RoleMascot:
103+ case RoleEmblem:
104+ case RoleOldPrice:
105+ case RolePrice:
106+ case RoleAltPrice:
107+ case RoleRating:
108+ case RoleAltRating:
109+ case RoleSummary:
110+ default:
111+ return QVariant();
112+ }
113+}
tests/mocks/Unity/fake_resultsmodel.hnew file+80
@@ -0,0 +1,80 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Michal Hruby <michal.hruby@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+
21+#ifndef FAKE_RESULTS_MODEL_H
22+#define FAKE_RESULTS_MODEL_H
23+
24+#include <QAbstractListModel>
25+
26+class ResultsModel : public QAbstractListModel
27+{
28+ Q_OBJECT
29+
30+ Q_ENUMS(Roles)
31+
32+ Q_PROPERTY(QString categoryId READ categoryId WRITE setCategoryId NOTIFY categoryIdChanged)
33+ Q_PROPERTY(int count READ count NOTIFY countChanged)
34+
35+public:
36+ explicit ResultsModel(int result_count, int categoryId, QObject* parent = 0);
37+
38+ enum Roles {
39+ RoleUri,
40+ RoleCategoryId,
41+ RoleDndUri,
42+ RoleResult,
43+ // card components
44+ RoleTitle,
45+ RoleArt,
46+ RoleSubtitle,
47+ RoleMascot,
48+ RoleEmblem,
49+ RoleOldPrice,
50+ RolePrice,
51+ RoleAltPrice,
52+ RoleRating,
53+ RoleAltRating,
54+ RoleSummary
55+ };
56+
57+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
58+ QHash<int, QByteArray> roleNames() const override;
59+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
60+
61+ Q_INVOKABLE QVariant get(int row) const;
62+
63+ /* getters */
64+ QString categoryId() const;
65+ int count() const;
66+
67+ /* setters */
68+ void setCategoryId(QString const& id);
69+
70+Q_SIGNALS:
71+ void categoryIdChanged();
72+ void countChanged();
73+
74+private:
75+ QHash<int, QByteArray> m_roles;
76+ int m_result_count;
77+ int m_categoryId;
78+};
79+
80+#endif // FAKE_RESULTS_MODEL_H