on xenial help sign in
Add unit tests
commit0e92f125bb2b6732129821aa06a34ef2fa13440a authorMichal Hruby <michal.mhr@gmail.com> dateTue 15 Oct 2013, 15:06 (13 years ago) parent24e9e14
3 files changed+56−1
plugins/Unity/variantutils.h+2−1 tests/plugins/Unity/resultstest.cpp+52 tests/plugins/Unity/resultstest.h+2
plugins/Unity/variantutils.h+2−1
@@ -29,6 +29,7 @@
2929unity::glib::HintsMap convertToHintsMap(const QHash<QString, QVariant> &val);
3030unity::glib::HintsMap convertToHintsMap(const QVariant &var);
3131QVariantHash convertToQVariantHash(const unity::glib::HintsMap &var);
32−QVariantHash subscopeUriToMetadataHash(const QString &metadata_string);
32+/* used in tests, so we have to export it */
33+Q_DECL_EXPORT QVariantHash subscopeUriToMetadataHash(const QString &metadata_string);
3334
3435#endif
tests/plugins/Unity/resultstest.cpp+52
@@ -23,6 +23,7 @@
2323
2424#include "resultstest.h"
2525#include "categoryresults.h"
26+#include "variantutils.h"
2627
2728static DeeModel* createBackendModel()
2829{
@@ -193,4 +194,55 @@ void ResultsTest::testSpecialIcons()
193194 QCOMPARE(transformedIcon, result);
194195}
195196
197+void ResultsTest::testMetadataOverride_data()
198+{
199+ QTest::addColumn<QString>("uri");
200+ QTest::addColumn<QVariantHash>("result");
201+
202+ QVariantHash expected_result;
203+ QVariantHash inner_hash;
204+
205+ expected_result = QVariantHash();
206+ expected_result["scope-id"] = QVariant::fromValue(QString("applications.scope"));
207+ expected_result["content"] = QVariant::fromValue(QVariantHash());
208+
209+ QTest::newRow("single scope") << "subscope:applications.scope" << expected_result;
210+
211+ expected_result = QVariantHash();
212+ expected_result["scope-id"] = QVariant::fromValue(QString("applications.scope"));
213+ inner_hash = QVariantHash();
214+ inner_hash["foo"] = QVariant::fromValue(QString("bar"));
215+ inner_hash["qoo"] = QVariant::fromValue(QString("baz"));
216+ expected_result["content"] = QVariant::fromValue(inner_hash);
217+
218+ QTest::newRow("single scope with data") << "subscope:applications.scope?foo=bar&qoo=baz" << expected_result;
219+
220+ expected_result = QVariantHash();
221+ inner_hash = QVariantHash();
222+ inner_hash["scope-id"] = QVariant::fromValue(QString("applications-local.scope"));
223+ inner_hash["content"] = QVariant::fromValue(QVariantHash());
224+ expected_result["scope-id"] = QVariant::fromValue(QString("applications.scope"));
225+ expected_result["content"] = QVariant::fromValue(inner_hash);
226+ QTest::newRow("master scope") << "subscope:applications.scope/applications-local.scope" << expected_result;
227+
228+ expected_result = QVariantHash();
229+ expected_result["foo"] = QVariant::fromValue(QString("baz"));
230+ expected_result["qoo"] = QVariant::fromValue(QString("baz"));
231+ inner_hash = QVariantHash();
232+ inner_hash["scope-id"] = QVariant::fromValue(QString("applications-local.scope"));
233+ inner_hash["content"] = QVariant::fromValue(expected_result);
234+ expected_result = QVariantHash();
235+ expected_result["scope-id"] = QVariant::fromValue(QString("applications.scope"));
236+ expected_result["content"] = QVariant::fromValue(inner_hash);
237+ QTest::newRow("nested with data") << "subscope:applications.scope/applications-local.scope?foo=baz&qoo=baz" << expected_result;
238+}
239+
240+void ResultsTest::testMetadataOverride()
241+{
242+ QFETCH(QString, uri);
243+ QFETCH(QVariantHash, result);
244+
245+ QCOMPARE(subscopeUriToMetadataHash(uri), result);
246+}
247+
196248QTEST_MAIN(ResultsTest)
tests/plugins/Unity/resultstest.h+2
@@ -32,6 +32,8 @@ class ResultsTest : public QObject
3232 void testIconColumn();
3333 void testSpecialIcons_data();
3434 void testSpecialIcons();
35+ void testMetadataOverride_data();
36+ void testMetadataOverride();
3537};
3638
3739#endif