@@ -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)