From 0a9fa88e443f4b7ef76d98b39575a1b3c212eda5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 4 Oct 2012 17:24:31 +0200 Subject: [PATCH] Fix handling of nested @if in custom widget preprocessor. Task-number: QTCREATORBUG-7945 Change-Id: I5773a2c8da60d304a740f03a7b7ccf47b5fda72f Reviewed-by: Christian A. Reiter Reviewed-by: Eike Ziller --- .../customwizard/customwizardpreprocessor.cpp | 72 ++++++++++++++++++- src/plugins/projectexplorer/projectexplorer.h | 3 + 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.cpp b/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.cpp index a84fe06eb92..23ffafcda23 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.cpp @@ -28,6 +28,10 @@ ****************************************************************************/ #include "customwizardpreprocessor.h" +#ifdef WITH_TESTS +# include "projectexplorer.h" +# include +#endif #include @@ -192,7 +196,7 @@ bool PreprocessContext::process(const QString &in, QString *out, QString *errorM switch (preprocessorLine(lines.at(l), &expression)) { case IfSection: // '@If': Push new section - if (top.parentEnabled) { + if (top.condition) { if (!evaluateBooleanJavaScriptExpression(m_scriptEngine, expression, &expressionValue, errorMessage)) { *errorMessage = QString::fromLatin1("Error in @if at %1: %2"). arg(l + 1).arg(*errorMessage); @@ -282,4 +286,70 @@ bool customWizardPreprocess(const QString &in, QString *out, QString *errorMessa } } // namespace Internal + +#ifdef WITH_TESTS // Run qtcreator -test ProjectExplorer + +void ProjectExplorerPlugin::testCustomWizardPreprocessor_data() +{ + QTest::addColumn("input"); + QTest::addColumn("expectedOutput"); + QTest::addColumn("expectedSuccess"); + QTest::addColumn("expectedErrorMessage"); + QTest::newRow("if") + << QString::fromLatin1("@if 1\nline 1\n@elsif 0\nline 2\n@else\nline 3\n@endif\n") + << QString::fromLatin1("line 1") + << true << QString(); + QTest::newRow("elsif") + << QString::fromLatin1("@if 0\nline 1\n@elsif 1\nline 2\n@else\nline 3\n@endif\n") + << QString::fromLatin1("line 2") + << true << QString(); + QTest::newRow("else") + << QString::fromLatin1("@if 0\nline 1\n@elsif 0\nline 2\n@else\nline 3\n@endif\n") + << QString::fromLatin1("line 3") + << true << QString(); + QTest::newRow("nested-if") + << QString::fromLatin1("@if 1\n" + " @if 1\nline 1\n@elsif 0\nline 2\n@else\nline 3\n@endif\n" + "@else\n" + " @if 1\nline 4\n@elsif 0\nline 5\n@else\nline 6\n@endif\n" + "@endif\n") + << QString::fromLatin1("line 1") + << true << QString(); + QTest::newRow("nested-else") + << QString::fromLatin1("@if 0\n" + " @if 1\nline 1\n@elsif 0\nline 2\n@else\nline 3\n@endif\n" + "@else\n" + " @if 1\nline 4\n@elsif 0\nline 5\n@else\nline 6\n@endif\n" + "@endif\n") + << QString::fromLatin1("line 4") + << true << QString(); + QTest::newRow("twice-nested-if") + << QString::fromLatin1("@if 0\n" + " @if 1\n" + " @if 1\nline 1\n@else\nline 2\n@endif\n" + " @endif\n" + "@else\n" + " @if 1\n" + " @if 1\nline 3\n@else\nline 4\n@endif\n" + " @endif\n" + "@endif\n") + << QString::fromLatin1("line 3") + << true << QString(); +} + +void ProjectExplorerPlugin::testCustomWizardPreprocessor() +{ + QFETCH(QString, input); + QFETCH(QString, expectedOutput); + QFETCH(bool, expectedSuccess); + QFETCH(QString, expectedErrorMessage); + + QString errorMessage; + QString output; + const bool success = Internal::customWizardPreprocess(input, &output, &errorMessage); + QCOMPARE(success, expectedSuccess); + QCOMPARE(output.trimmed(), expectedOutput.trimmed()); + QCOMPARE(errorMessage, expectedErrorMessage); +} +#endif // WITH_TESTS } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index b7b9b4d43a6..03e46fb9b2d 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -262,6 +262,9 @@ private slots: void testFlavorForOs(); void testDeviceManager(); + + void testCustomWizardPreprocessor_data(); + void testCustomWizardPreprocessor(); #endif private: