/*
* Copyright (C) 2013 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors:
* Michal Hruby
*/
#include
#include
#include "resultstest.h"
#include "categoryresults.h"
static DeeModel* createBackendModel()
{
auto model = dee_sequence_model_new();
dee_model_set_schema(model, "s", "s", "u", "u", "s", "s", "s", "s", "a{sv}", NULL);
return model;
}
void ResultsTest::testAllColumns()
{
auto deeModel = createBackendModel();
GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add(&builder, "{sv}", "metadata-field", g_variant_new_string("foo"));
dee_model_append (deeModel,
"test:uri",
"themed-icon",
4,
0,
"application/octet-stream",
"Test",
"Comment",
"test:dnd-uri",
g_variant_builder_end(&builder));
CategoryResults* results = new CategoryResults(this);
results->setModel(deeModel);
auto index = results->index(0, 0); // there's just one result
QCOMPARE(index.data(CategoryResults::Roles::RoleUri).toString(), QString("test:uri"));
QCOMPARE(index.data(CategoryResults::Roles::RoleIconHint).toString(), QString("image://theme/themed-icon"));
QCOMPARE(index.data(CategoryResults::Roles::RoleCategory).toInt(), 4);
QCOMPARE(index.data(CategoryResults::Roles::RoleMimetype).toString(), QString("application/octet-stream"));
QCOMPARE(index.data(CategoryResults::Roles::RoleTitle).toString(), QString("Test"));
QCOMPARE(index.data(CategoryResults::Roles::RoleComment).toString(), QString("Comment"));
QCOMPARE(index.data(CategoryResults::Roles::RoleDndUri).toString(), QString("test:dnd-uri"));
auto metadata = index.data(CategoryResults::Roles::RoleMetadata).toHash();
QCOMPARE(metadata["metadata-field"].toString(), QString("foo"));
}
void ResultsTest::testIconColumn_data()
{
QTest::addColumn("giconString");
QTest::addColumn("result");
QTest::newRow("absolute path") << "/usr/share/icons/example.png" << "/usr/share/icons/example.png";
QTest::newRow("file uri") << "file:///usr/share/icons/example.png" << "file:///usr/share/icons/example.png";
QTest::newRow("http uri") << "http://images.ubuntu.com/example.jpg" << "http://images.ubuntu.com/example.jpg";
QTest::newRow("themed icon") << "accessories-other" << "image://theme/accessories-other";
QTest::newRow("fileicon") << ". GFileIcon http://example.org/resource.gif" << "http://example.org/resource.gif";
QTest::newRow("themedicon") << ". GThemedIcon accessories-other accessories generic" << "image://theme/accessories-other,accessories,generic";
QTest::newRow("annotatedicon") << ". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'.%20GThemedIcon%20accessories-other%20accessories%20generic'%3E%7D" << "image://theme/accessories-other,accessories,generic";
}
void ResultsTest::testIconColumn()
{
QFETCH(QString, giconString);
QFETCH(QString, result);
auto deeModel = createBackendModel();
dee_model_append (deeModel,
"test:uri",
giconString.toLocal8Bit().constData(),
0,
0,
"application/octet-stream",
"Test",
"",
"test:dnd-uri",
g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0));
CategoryResults* results = new CategoryResults(this);
results->setModel(deeModel);
auto index = results->index(0, 0); // there's just one result
auto transformedIcon = index.data(CategoryResults::Roles::RoleIconHint).toString();
QCOMPARE(transformedIcon, result);
}
QTEST_MAIN(ResultsTest)