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/>.
17 * Michal Hruby <michal.hruby@canonical.com>
23#include "resultstest.h"
24#include "categoryresults.h"
26static DeeModel* createBackendModel()
28 auto model = dee_sequence_model_new();
29 dee_model_set_schema(model, "s", "s", "u", "u", "s", "s", "s", "s", "a{sv}", NULL);
34void ResultsTest::testAllColumns()
36 auto deeModel = createBackendModel();
37 GVariantBuilder builder;
38 g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
39 g_variant_builder_add(&builder, "{sv}", "metadata-field", g_variant_new_string("foo"));
40 dee_model_append (deeModel,
45 "application/octet-stream",
49 g_variant_builder_end(&builder));
51 CategoryResults* results = new CategoryResults(this);
52 results->setModel(deeModel);
54 auto index = results->index(0, 0); // there's just one result
55 QCOMPARE(index.data(CategoryResults::Roles::RoleUri).toString(), QString("test:uri"));
56 QCOMPARE(index.data(CategoryResults::Roles::RoleIconHint).toString(), QString("image://theme/themed-icon"));
57 QCOMPARE(index.data(CategoryResults::Roles::RoleCategory).toInt(), 4);
58 QCOMPARE(index.data(CategoryResults::Roles::RoleMimetype).toString(), QString("application/octet-stream"));
59 QCOMPARE(index.data(CategoryResults::Roles::RoleTitle).toString(), QString("Test"));
60 QCOMPARE(index.data(CategoryResults::Roles::RoleComment).toString(), QString("Comment"));
61 QCOMPARE(index.data(CategoryResults::Roles::RoleDndUri).toString(), QString("test:dnd-uri"));
62 auto metadata = index.data(CategoryResults::Roles::RoleMetadata).toHash();
63 QCOMPARE(metadata["metadata-field"].toString(), QString("foo"));
66void ResultsTest::testIconColumn_data()
68 QTest::addColumn<QString>("giconString");
69 QTest::addColumn<QString>("result");
71 QTest::newRow("absolute path") << "/usr/share/icons/example.png" << "/usr/share/icons/example.png";
72 QTest::newRow("file uri") << "file:///usr/share/icons/example.png" << "file:///usr/share/icons/example.png";
73 QTest::newRow("http uri") << "http://images.ubuntu.com/example.jpg" << "http://images.ubuntu.com/example.jpg";
74 QTest::newRow("themed icon") << "accessories-other" << "image://theme/accessories-other";
75 QTest::newRow("fileicon") << ". GFileIcon http://example.org/resource.gif" << "http://example.org/resource.gif";
76 QTest::newRow("themedicon") << ". GThemedIcon accessories-other accessories generic" << "image://theme/accessories-other,accessories,generic";
77 QTest::newRow("annotatedicon") << ". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'.%20GThemedIcon%20accessories-other%20accessories%20generic'%3E%7D" << "image://theme/accessories-other,accessories,generic";
80void ResultsTest::testIconColumn()
82 QFETCH(QString, giconString);
83 QFETCH(QString, result);
84 auto deeModel = createBackendModel();
85 dee_model_append (deeModel,
87 giconString.toLocal8Bit().constData(),
90 "application/octet-stream",
94 g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0));
96 CategoryResults* results = new CategoryResults(this);
97 results->setModel(deeModel);
99 auto index = results->index(0, 0); // there's just one result
100 auto transformedIcon = index.data(CategoryResults::Roles::RoleIconHint).toString();
101 QCOMPARE(transformedIcon, result);
104QTEST_MAIN(ResultsTest)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list