on xenial help sign in
Add tests
commit9e3d77f1149702de88d200f2bfcf75ca3de270a3 authorMichal Hruby <michal.mhr@gmail.com> dateThu 5 Sep 2013, 12:48 (13 years ago) parent621f7db
4 files changed+138−1
plugins/Unity/categoryresults.h+1−1 tests/plugins/Unity/CMakeLists.txt+4 tests/plugins/Unity/resultstest.cpp+101 tests/plugins/Unity/resultstest.h+32
plugins/Unity/categoryresults.h+1−1
@@ -24,7 +24,7 @@
2424// dee-qt
2525#include "deelistmodel.h"
2626
27−class CategoryResults : public DeeListModel
27+class Q_DECL_EXPORT CategoryResults : public DeeListModel
2828{
2929 Q_OBJECT
3030
tests/plugins/Unity/CMakeLists.txt+4
@@ -5,6 +5,7 @@ pkg_check_modules(UNITYCORE REQUIRED unity-core-6.0)
55pkg_check_modules(LIBUNITYPROTO REQUIRED unity-protocol-private)
66pkg_check_modules(LIBUNITY REQUIRED unity)
77pkg_check_modules(LIBSIGCPP REQUIRED sigc++-2.0)
8+pkg_check_modules(QTDEE REQUIRED libdee-qt5>=3.2)
89
910include_directories(
1011 ${Unity-qml_SOURCE_DIR}
@@ -14,6 +15,7 @@ include_directories(
1415 ${LIBUNITY_INCLUDE_DIRS}
1516 ${LIBSIGCPP_INCLUDE_DIRS}
1617 ${UNITYCORE_INCLUDE_DIRS}
18+ ${QTDEE_INCLUDE_DIRS}
1719 )
1820
1921macro(run_tests)
@@ -36,6 +38,7 @@ macro(run_tests)
3638 ${LIBUNITY_LDFLAGS}
3739 ${LIBUNITYPROTO_LDFLAGS}
3840 ${LIBSIGCPP_LDFLAGS}
41+ ${QTDEE_LDFLAGS}
3942 )
4043
4144 set(_test_list "${_test_list};${_test}")
@@ -46,4 +49,5 @@ run_tests(
4649 signalslisttest
4750 previewbindingstest
4851 filtersbindingstest
52+ resultstest
4953 )
tests/plugins/Unity/resultstest.cppnew file+101
@@ -0,0 +1,101 @@
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+
17+#include <QTest>
18+#include <dee.h>
19+
20+#include "resultstest.h"
21+#include "categoryresults.h"
22+
23+static DeeModel* createBackendModel()
24+{
25+ auto model = dee_sequence_model_new();
26+ dee_model_set_schema(model, "s", "s", "u", "u", "s", "s", "s", "s", "a{sv}", NULL);
27+
28+ return model;
29+}
30+
31+void ResultsTest::testAllColumns()
32+{
33+ auto deeModel = createBackendModel();
34+ GVariantBuilder builder;
35+ g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
36+ g_variant_builder_add(&builder, "{sv}", "metadata-field", g_variant_new_string("foo"));
37+ dee_model_append (deeModel,
38+ "test:uri",
39+ "themed-icon",
40+ 4,
41+ 0,
42+ "application/octet-stream",
43+ "Test",
44+ "Comment",
45+ "test:dnd-uri",
46+ g_variant_builder_end(&builder));
47+
48+ CategoryResults* results = new CategoryResults(this);
49+ results->setModel(deeModel);
50+
51+ auto index = results->index(0, 0); // there's just one result
52+ QCOMPARE(index.data(CategoryResults::Roles::RoleUri).toString(), QString("test:uri"));
53+ QCOMPARE(index.data(CategoryResults::Roles::RoleIconHint).toString(), QString("image://theme/themed-icon"));
54+ QCOMPARE(index.data(CategoryResults::Roles::RoleCategory).toInt(), 4);
55+ QCOMPARE(index.data(CategoryResults::Roles::RoleMimetype).toString(), QString("application/octet-stream"));
56+ QCOMPARE(index.data(CategoryResults::Roles::RoleTitle).toString(), QString("Test"));
57+ QCOMPARE(index.data(CategoryResults::Roles::RoleComment).toString(), QString("Comment"));
58+ QCOMPARE(index.data(CategoryResults::Roles::RoleDndUri).toString(), QString("test:dnd-uri"));
59+ auto metadata = index.data(CategoryResults::Roles::RoleMetadata).toHash();
60+ QCOMPARE(metadata["metadata-field"].toString(), QString("foo"));
61+}
62+
63+void ResultsTest::testIconColumn_data()
64+{
65+ QTest::addColumn<QString>("giconString");
66+ QTest::addColumn<QString>("result");
67+
68+ QTest::newRow("absolute path") << "/usr/share/icons/example.png" << "/usr/share/icons/example.png";
69+ QTest::newRow("file uri") << "file:///usr/share/icons/example.png" << "file:///usr/share/icons/example.png";
70+ QTest::newRow("http uri") << "http://images.ubuntu.com/example.jpg" << "http://images.ubuntu.com/example.jpg";
71+ QTest::newRow("themed icon") << "accessories-other" << "image://theme/accessories-other";
72+ QTest::newRow("fileicon") << ". GFileIcon http://example.org/resource.gif" << "http://example.org/resource.gif";
73+ QTest::newRow("themedicon") << ". GThemedIcon accessories-other accessories generic" << "image://theme/accessories-other,accessories,generic";
74+ QTest::newRow("annotatedicon") << ". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'.%20GThemedIcon%20accessories-other%20accessories%20generic'%3E%7D" << "image://theme/accessories-other,accessories,generic";
75+}
76+
77+void ResultsTest::testIconColumn()
78+{
79+ QFETCH(QString, giconString);
80+ QFETCH(QString, result);
81+ auto deeModel = createBackendModel();
82+ dee_model_append (deeModel,
83+ "test:uri",
84+ giconString.toLocal8Bit().constData(),
85+ 0,
86+ 0,
87+ "application/octet-stream",
88+ "Test",
89+ "",
90+ "test:dnd-uri",
91+ g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0));
92+
93+ CategoryResults* results = new CategoryResults(this);
94+ results->setModel(deeModel);
95+
96+ auto index = results->index(0, 0); // there's just one result
97+ auto transformedIcon = index.data(CategoryResults::Roles::RoleIconHint).toString();
98+ QCOMPARE(transformedIcon, result);
99+}
100+
101+QTEST_MAIN(ResultsTest)
tests/plugins/Unity/resultstest.hnew file+32
@@ -0,0 +1,32 @@
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+
17+#ifndef RESULTSTEST_H
18+#define RESULTSTEST_H
19+
20+#include <QObject>
21+
22+class ResultsTest : public QObject
23+{
24+ Q_OBJECT
25+
26+ private Q_SLOTS:
27+ void testAllColumns();
28+ void testIconColumn_data();
29+ void testIconColumn();
30+};
31+
32+#endif