@@ -0,0 +1,101 @@
2+ * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
20+#include "resultstest.h"
21+#include "categoryresults.h"
23+static DeeModel* createBackendModel()
25+ auto model = dee_sequence_model_new();
26+ dee_model_set_schema(model, "s", "s", "u", "u", "s", "s", "s", "s", "a{sv}", NULL);
31+void ResultsTest::testAllColumns()
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,
42+ "application/octet-stream",
46+ g_variant_builder_end(&builder));
48+ CategoryResults* results = new CategoryResults(this);
49+ results->setModel(deeModel);
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"));
63+void ResultsTest::testIconColumn_data()
65+ QTest::addColumn<QString>("giconString");
66+ QTest::addColumn<QString>("result");
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";
77+void ResultsTest::testIconColumn()
79+ QFETCH(QString, giconString);
80+ QFETCH(QString, result);
81+ auto deeModel = createBackendModel();
82+ dee_model_append (deeModel,
84+ giconString.toLocal8Bit().constData(),
87+ "application/octet-stream",
91+ g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0));
93+ CategoryResults* results = new CategoryResults(this);
94+ results->setModel(deeModel);
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);
101+QTEST_MAIN(ResultsTest)