aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/examples/tst_examples.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/examples/tst_examples.cpp')
-rw-r--r--tests/auto/examples/tst_examples.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/tests/auto/examples/tst_examples.cpp b/tests/auto/examples/tst_examples.cpp
index 5a18f1e449..884ce92c32 100644
--- a/tests/auto/examples/tst_examples.cpp
+++ b/tests/auto/examples/tst_examples.cpp
@@ -88,6 +88,7 @@ void tst_Examples::parsing_data()
QTest::addColumn<QString>("videoLength");
QTest::addColumn<QStringList>("platforms");
QTest::addColumn<MetaData>("metaData");
+ QTest::addColumn<QStringList>("categories");
QTest::addRow("example")
<< QByteArray(R"raw(
@@ -102,6 +103,8 @@ void tst_Examples::parsing_data()
<fileToOpen mainFile="true">widgets/widgets/analogclock/analogclock.cpp</fileToOpen>
<meta>
<entry name="category">Graphics</entry>
+ <entry name="category">Graphics</entry>
+ <entry name="category">Foobar</entry>
<entry name="tags">widgets</entry>
</meta>
</example>
@@ -120,13 +123,29 @@ void tst_Examples::parsing_data()
"manifest/widgets/widgets/analogclock/analogclock.cpp")}
<< FilePath::fromUserInput("manifest/widgets/widgets/analogclock/analogclock.cpp")
<< FilePaths() << Example << true << false << false << ""
- << "" << QStringList() << MetaData({{"category", {"Graphics"}}, {"tags", {"widgets"}}});
+ << "" << QStringList()
+ << MetaData({{"category", {"Graphics", "Graphics", "Foobar"}}, {"tags", {"widgets"}}})
+ << QStringList{"Foobar", "Graphics"};
+
+ QTest::addRow("no category, highlighted")
+ << QByteArray(R"raw(
+ <examples>
+ <example name="No Category, highlighted"
+ isHighlighted="true">
+ </example>
+ </examples>
+ )raw") << /*isExamples=*/true
+ << "No Category, highlighted" << QString() << QString() << QStringList()
+ << FilePath("manifest") << QString() << FilePaths() << FilePath() << FilePaths() << Example
+ << /*hasSourceCode=*/false << false << /*isHighlighted=*/true << ""
+ << "" << QStringList() << MetaData() << QStringList{"Featured"};
}
void tst_Examples::parsing()
{
QFETCH(QByteArray, data);
QFETCH(bool, isExamples);
+ QFETCH(QStringList, categories);
const ExampleItem expected = fetchItem();
const expected_str<QList<ExampleItem *>> result
= parseExamples(data,
@@ -154,7 +173,17 @@ void tst_Examples::parsing()
QCOMPARE(item.videoLength, expected.videoLength);
QCOMPARE(item.platforms, expected.platforms);
QCOMPARE(item.metaData, expected.metaData);
- qDeleteAll(*result);
+
+ const QList<std::pair<QString, QList<ExampleItem *>>> resultCategories = getCategories(*result,
+ true);
+ QCOMPARE(resultCategories.size(), categories.size());
+ for (int i = 0; i < resultCategories.size(); ++i) {
+ QCOMPARE(resultCategories.at(i).first, categories.at(i));
+ QCOMPARE(resultCategories.at(i).second.size(), 1);
+ }
+
+ for (const auto &category : resultCategories)
+ qDeleteAll(category.second);
}
QTEST_APPLESS_MAIN(tst_Examples)