diff options
Diffstat (limited to 'tests')
10 files changed, 169 insertions, 9 deletions
diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index de51c866e1..1e87c76d2f 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -76,6 +76,8 @@ private slots: void testHelpOption(); void testQuoteEscaping(); void testUnknownOption(); + void testHelpAll_data(); + void testHelpAll(); }; static char *empty_argv[] = { 0 }; @@ -542,7 +544,8 @@ void tst_QCommandLineParser::testVersionOption() static const char expectedOptionsHelp[] = "Options:\n" - " -h, --help Displays this help.\n" + " -h, --help Displays help on commandline options.\n" + " --help-all Displays help including Qt specific options.\n" " -v, --version Displays version information.\n" " --load <url> Load file from URL.\n" " -o, --output <file> Set output file.\n" @@ -576,8 +579,8 @@ void tst_QCommandLineParser::testHelpOption_data() " parsingMode The parsing mode to test.\n" " command The command to execute.\n"); #ifdef Q_OS_WIN - expectedOutput.replace(" -h, --help Displays this help.\n", - " -?, -h, --help Displays this help.\n"); + expectedOutput.replace(" -h, --help Displays help on commandline options.\n", + " -?, -h, --help Displays help on commandline options.\n"); expectedOutput.replace("testhelper/", "testhelper\\"); #endif @@ -625,8 +628,8 @@ void tst_QCommandLineParser::testHelpOption() "Arguments:\n" " resize Resize the object to a new size.\n"; #ifdef Q_OS_WIN - expectedResizeHelp.replace(" -h, --help Displays this help.\n", - " -?, -h, --help Displays this help.\n"); + expectedResizeHelp.replace(" -h, --help Displays help on commandline options.\n", + " -?, -h, --help Displays help on commandline options.\n"); expectedResizeHelp.replace("testhelper/", "testhelper\\"); #endif QCOMPARE(output, QString(expectedResizeHelp)); @@ -680,6 +683,60 @@ void tst_QCommandLineParser::testUnknownOption() #endif // QT_CONFIG(process) } +void tst_QCommandLineParser::testHelpAll_data() +{ + QTest::addColumn<QCommandLineParser::SingleDashWordOptionMode>("parsingMode"); + QTest::addColumn<QString>("expectedHelpOutput"); + + QString expectedOutput = QString::fromLatin1( + "Usage: testhelper/qcommandlineparser_test_helper [options] parsingMode command\n" + "Test helper\n" + "\n") + + QString::fromLatin1(expectedOptionsHelp) + + QString::fromLatin1( + " --qmljsdebugger <value> Activates the QML/JS debugger with a specified\n" + " port. The value must be of format\n" + " port:1234[,block]. \"block\" makes the application\n" + " wait for a connection.\n" + "\n" + "Arguments:\n" + " parsingMode The parsing mode to test.\n" + " command The command to execute.\n"); +#ifdef Q_OS_WIN + expectedOutput.replace(" -h, --help Displays help on commandline options.\n", + " -?, -h, --help Displays help on commandline options.\n"); + expectedOutput.replace("testhelper/", "testhelper\\"); +#endif + + QTest::newRow("collapsed") << QCommandLineParser::ParseAsCompactedShortOptions << expectedOutput; + QTest::newRow("long") << QCommandLineParser::ParseAsLongOptions << expectedOutput; +} + +void tst_QCommandLineParser::testHelpAll() +{ +#if !QT_CONFIG(process) + QSKIP("This test requires QProcess support"); +#else +#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) + QSKIP("Deploying executable applications to file system on Android not supported."); +#endif + + QFETCH(QCommandLineParser::SingleDashWordOptionMode, parsingMode); + QFETCH(QString, expectedHelpOutput); + QCoreApplication app(empty_argc, empty_argv); + QProcess process; + process.start("testhelper/qcommandlineparser_test_helper", QStringList() << QString::number(parsingMode) << "--help-all"); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QString output = process.readAll(); +#ifdef Q_OS_WIN + output.replace(QStringLiteral("\r\n"), QStringLiteral("\n")); +#endif + QCOMPARE(output.split('\n'), expectedHelpOutput.split('\n')); // easier to debug than the next line, on failure + QCOMPARE(output, expectedHelpOutput); +#endif // QT_CONFIG(process) +} + QTEST_APPLESS_MAIN(tst_QCommandLineParser) #include "tst_qcommandlineparser.moc" diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 124e3cdf00..f76f3aa0c6 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -34,6 +34,8 @@ #include <sstream> #include <algorithm> +#include <unordered_set> + class tst_QHashFunctions : public QObject { Q_OBJECT @@ -59,6 +61,8 @@ private Q_SLOTS: void range(); void rangeCommutative(); + void stdHash(); + void setGlobalQHashSeed(); }; @@ -281,6 +285,38 @@ void tst_QHashFunctions::rangeCommutative() (void)qHashRangeCommutative(hashables, hashables + numHashables, seed); } +void tst_QHashFunctions::stdHash() +{ + { + std::unordered_set<QString> s = {QStringLiteral("Hello"), QStringLiteral("World")}; + QCOMPARE(s.size(), 2UL); + s.insert(QStringLiteral("Hello")); + QCOMPARE(s.size(), 2UL); + } + + { + std::unordered_set<QStringView> s = {QStringLiteral("Hello"), QStringLiteral("World")}; + QCOMPARE(s.size(), 2UL); + s.insert(QStringLiteral("Hello")); + QCOMPARE(s.size(), 2UL); + } + + { + std::unordered_set<QLatin1String> s = {QLatin1String("Hello"), QLatin1String("World")}; + QCOMPARE(s.size(), 2UL); + s.insert(QLatin1String("Hello")); + QCOMPARE(s.size(), 2UL); + } + + { + std::unordered_set<QByteArray> s = {QByteArrayLiteral("Hello"), QByteArrayLiteral("World")}; + QCOMPARE(s.size(), 2UL); + s.insert(QByteArray("Hello")); + QCOMPARE(s.size(), 2UL); + } + +} + void tst_QHashFunctions::setGlobalQHashSeed() { // Setter works as advertised diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md index f429fcc21b..44c198fdc5 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md @@ -13,7 +13,8 @@ MacFarlane writes: > > as readable as possible. The idea is that a Markdown-formatted document should > > be publishable as-is, as plain text, without looking like it's been marked up > > with tags or formatting instructions. ( -> > [http://daringfireball.net/projects/markdown/](http://daringfireball.net/projects/markdown/)) +> > [http://daringfireball.net/projects/markdown/](http://daringfireball.net/projects/markdown/) +> > ) > The point can be illustrated by comparing a sample of AsciiDoc with an > equivalent sample of Markdown. Here is a sample of AsciiDoc from the AsciiDoc diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/headingsAndLists.md b/tests/auto/gui/text/qtextmarkdownwriter/data/headingsAndLists.md new file mode 100644 index 0000000000..d5d14fb168 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/headingsAndLists.md @@ -0,0 +1,12 @@ +# heading 1 + +- list item 1 +- list item 2 + +## heading 2 + +1) list item 1 +2) list item 2 + +the end paragraph + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/wordWrap.md b/tests/auto/gui/text/qtextmarkdownwriter/data/wordWrap.md new file mode 100644 index 0000000000..dacb0acf77 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/wordWrap.md @@ -0,0 +1,13 @@ +[The CommonMark Specification](https://spec.commonmark.org/0.29/) is the +conservative formal specification of the Markdown format, while +[GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) +adds extra features such as task lists and tables. + +Qt owes thanks to the authors of the [MD4C parser](https://github.com/mity/md4c) +for making markdown import possible. The QTextMarkdownWriter class does not +have such dependencies, and also has not yet been tested as extensively, so we +do not yet guarantee that we are able to rewrite every Markdown document that +you are able to read and display with Text or QTextEdit. But you are free to +write [bugs](https://bugreports.qt.io) about any troublesome cases that you +encounter. + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp index 9998794762..acc74a9060 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp +++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp @@ -357,6 +357,8 @@ void tst_QTextMarkdownWriter::rewriteDocument_data() QTest::newRow("block quotes") << "blockquotes.md"; QTest::newRow("example") << "example.md"; + QTest::newRow("list items after headings") << "headingsAndLists.md"; + QTest::newRow("word wrap") << "wordWrap.md"; } void tst_QTextMarkdownWriter::rewriteDocument() diff --git a/tests/auto/widgets/widgets/qtextbrowser/CMakeLists.txt b/tests/auto/widgets/widgets/qtextbrowser/CMakeLists.txt index 15601c9855..17742cf036 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/CMakeLists.txt +++ b/tests/auto/widgets/widgets/qtextbrowser/CMakeLists.txt @@ -1,3 +1,24 @@ -add_qt_test("tst_qtextbrowser" RUN_SERIAL SOURCES tst_qtextbrowser.cpp LIBRARIES Qt::Widgets) +# Generated from qtextbrowser.pro. -extend_target("tst_qtextbrowser" CONDITION builtin_testdata DEFINES BUILTIN_TESTDATA) +##################################################################### +## tst_qtextbrowser Test: +##################################################################### + +add_qt_test(tst_qtextbrowser + SOURCES + tst_qtextbrowser.cpp + PUBLIC_LIBRARIES + Qt::Widgets +) + +#### Keys ignored in scope 1:.:.:qtextbrowser.pro:<TRUE>: +# CONFIG = "testcase" +# TESTDATA = "*.html" "*.md" "subdir/*" + +## Scopes: +##################################################################### + +extend_target(tst_qtextbrowser CONDITION builtin_testdata + DEFINES + BUILTIN_TESTDATA +) diff --git a/tests/auto/widgets/widgets/qtextbrowser/markdown.md b/tests/auto/widgets/widgets/qtextbrowser/markdown.md new file mode 100644 index 0000000000..be56aef234 --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/markdown.md @@ -0,0 +1,2 @@ +### this is a heading +this is a paragraph diff --git a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro index 9680ffd871..05c156bf59 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro +++ b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro @@ -4,6 +4,6 @@ SOURCES += tst_qtextbrowser.cpp QT += widgets testlib -TESTDATA += *.html subdir/* +TESTDATA += *.html *.md subdir/* builtin_testdata: DEFINES += BUILTIN_TESTDATA diff --git a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp index 1f95032165..22cd3b46c6 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp +++ b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp @@ -92,6 +92,7 @@ private slots: void focusIndicator(); void focusHistory(); void urlEncoding(); + void markdown(); private: TestBrowser *browser; @@ -678,5 +679,20 @@ void tst_QTextBrowser::urlEncoding() delete browser; } +void tst_QTextBrowser::markdown() +{ + browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA("markdown.md"))); + QTextFrame::iterator iterator = browser->document()->rootFrame()->begin(); + int maxHeadingLevel = -1; + while (!iterator.atEnd()) + maxHeadingLevel = qMax(iterator++.currentBlock().blockFormat().intProperty(QTextFormat::HeadingLevel), maxHeadingLevel); +#if QT_CONFIG(textmarkdownreader) + QCOMPARE(maxHeadingLevel, 3); +#else + // If Qt doesn't support markdown, this document will be misidentified as HTML, so it won't have any H3's. + QCOMPARE(maxHeadingLevel, 0); +#endif +} + QTEST_MAIN(tst_QTextBrowser) #include "tst_qtextbrowser.moc" |