From 2477d3ae97a6fffea1569dc3a1ccbdaa98731f4f Mon Sep 17 00:00:00 2001 From: Miguel Costa Date: Mon, 29 Apr 2019 17:06:09 +0200 Subject: Load auto-test macros from file Macros can now be loaded directly from a QFile, including the possibility to use macros stored as resources in the test application. Change-Id: Ife59b32ff5b018a9a5557a88bc0d6269e7d79f25 Reviewed-by: Oliver Wolff --- src/qtvstest/MacroClient.h | 29 +++++++++++++ src/tests/CoreFeatures/CoreFeatures.vcxproj | 19 ++++++++ .../CoreFeatures/CoreFeatures.vcxproj.filters | 19 ++++++++ src/tests/CoreFeatures/Macros.qrc | 8 ++++ src/tests/CoreFeatures/main.cpp | 30 +++++++------ src/tests/macros/Test_CreateGuiApp.csmacro | 50 ++++++++++++++++++++++ src/tests/macros/Test_DebugGuiApp.csmacro | 42 ++++++++++++++++++ src/tests/macros/Test_QtVsToolsLoaded.csmacro | 36 ++++++++++++++++ src/tests/macros/Test_RebuildSolution.csmacro | 41 ++++++++++++++++++ 9 files changed, 261 insertions(+), 13 deletions(-) create mode 100644 src/tests/CoreFeatures/Macros.qrc create mode 100644 src/tests/macros/Test_CreateGuiApp.csmacro create mode 100644 src/tests/macros/Test_DebugGuiApp.csmacro create mode 100644 src/tests/macros/Test_QtVsToolsLoaded.csmacro create mode 100644 src/tests/macros/Test_RebuildSolution.csmacro diff --git a/src/qtvstest/MacroClient.h b/src/qtvstest/MacroClient.h index f8f6589b..d13db926 100644 --- a/src/qtvstest/MacroClient.h +++ b/src/qtvstest/MacroClient.h @@ -29,7 +29,10 @@ #ifndef MACROCLIENT_H #define MACROCLIENT_H +#include +#include #include + #include #include #include @@ -158,6 +161,32 @@ public: return QString::fromUtf8(data); } + QString runMacro(QFile ¯oFile) + { + return loadAndRunMacro(macroFile); + } + + QString loadMacro(QFile ¯oFile, QString macroName) + { + if (macroName.isNull() || macroName.isEmpty()) + return QStringLiteral(MACRO_ERROR_MSG("Invalid macro name")); + return loadAndRunMacro(macroFile, QString("//#macro %1").arg(macroName)); + } + + QString loadAndRunMacro(QFile ¯oFile, QString macroHeader = QString()) + { + if (!macroFile.open(QIODevice::ReadOnly | QIODevice::Text)) + return QStringLiteral(MACRO_ERROR_MSG("Macro load failed")); + QString macroCode = QString::fromUtf8(macroFile.readAll()); + macroFile.close(); + if (macroCode.isEmpty()) + return QStringLiteral(MACRO_ERROR_MSG("Macro load failed")); + if (!macroHeader.isNull()) + return runMacro(macroHeader + "\r\n" + macroCode); + else + return runMacro(macroCode); + } + }; // class MacroClient #endif // MACROCLIENT_H diff --git a/src/tests/CoreFeatures/CoreFeatures.vcxproj b/src/tests/CoreFeatures/CoreFeatures.vcxproj index 58c9070a..46a04c85 100644 --- a/src/tests/CoreFeatures/CoreFeatures.vcxproj +++ b/src/tests/CoreFeatures/CoreFeatures.vcxproj @@ -72,6 +72,10 @@ UNICODE;_UNICODE;WIN32;WIN64;QT_CORE_LIB;QT_TESTLIB_LIB;QT_NETWORK_LIB;%(PreprocessorDefinitions) $(SolutionDir)qtvstest;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtTest;$(QTDIR)\include\QtNetwork;%(AdditionalIncludeDirectories) + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + @@ -93,6 +97,10 @@ UNICODE;_UNICODE;WIN32;WIN64;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_TESTLIB_LIB;QT_NETWORK_LIB;%(PreprocessorDefinitions) $(SolutionDir)qtvstest;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtTest;$(QTDIR)\include\QtNetwork;%(AdditionalIncludeDirectories) + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + @@ -109,6 +117,17 @@ + + + Designer + + + + + + + + diff --git a/src/tests/CoreFeatures/CoreFeatures.vcxproj.filters b/src/tests/CoreFeatures/CoreFeatures.vcxproj.filters index a6c302c5..33852180 100644 --- a/src/tests/CoreFeatures/CoreFeatures.vcxproj.filters +++ b/src/tests/CoreFeatures/CoreFeatures.vcxproj.filters @@ -35,4 +35,23 @@ Header Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + + + Resource Files + + \ No newline at end of file diff --git a/src/tests/CoreFeatures/Macros.qrc b/src/tests/CoreFeatures/Macros.qrc new file mode 100644 index 00000000..2d460769 --- /dev/null +++ b/src/tests/CoreFeatures/Macros.qrc @@ -0,0 +1,8 @@ + + + ../macros/Test_QtVsToolsLoaded.csmacro + ../macros/Test_CreateGuiApp.csmacro + ../macros/Test_RebuildSolution.csmacro + ../macros/Test_DebugGuiApp.csmacro + + diff --git a/src/tests/CoreFeatures/main.cpp b/src/tests/CoreFeatures/main.cpp index ab553fa6..2cbbe626 100644 --- a/src/tests/CoreFeatures/main.cpp +++ b/src/tests/CoreFeatures/main.cpp @@ -30,8 +30,6 @@ #include -#define BR "\r\n" - class TestCoreFeatures : public QObject { Q_OBJECT @@ -42,17 +40,23 @@ private: private slots: void initTestCase() { - // * Ensure Qt VS Tools extension is loaded - // * Wait for Qt VS Tools to finish initialization - QString Result = client.runMacro(QStringLiteral( - "//# wait 15000 Assembly QtVsTools => GetAssembly(\"QtVsTools\")" BR - "var VsixType = QtVsTools.GetType(\"QtVsTools.Vsix\");" BR - "var VsixInstance = VsixType.GetProperty(\"Instance\"," - "BindingFlags.Public | BindingFlags.Static);" BR - "//# wait 15000 object Vsix => VsixInstance.GetValue(null)" BR - "Result = \"(ok)\";" BR - )); - QCOMPARE(Result, QStringLiteral("(ok)")); + MACRO_ASSERT_OK(client.runMacro(QFile(":/QtVsToolsLoaded"))); + } + + void guiAppCreateRebuildDebug() + { + client.runMacro("//# wait 5000 => !Dte.Solution.IsOpen"); + MACRO_ASSERT_OK(client.runMacro(QFile(":/CreateGuiApp"))); + MACRO_ASSERT_OK(client.runMacro(QFile(":/RebuildSolution"))); + MACRO_ASSERT_OK(client.runMacro(QFile(":/DebugGuiApp"))); + client.runMacro( + "Dte.Solution.Close(false);" "\r\n" + "//# wait 15000 => !Dte.Solution.IsOpen" "\r\n"); + } + + void cleanupTestCase() + { + client.runMacro("//#quit"); } }; diff --git a/src/tests/macros/Test_CreateGuiApp.csmacro b/src/tests/macros/Test_CreateGuiApp.csmacro new file mode 100644 index 00000000..1de72afc --- /dev/null +++ b/src/tests/macros/Test_CreateGuiApp.csmacro @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt VS Tools. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +//# using System.IO +//# using System.Threading.Tasks +var solutionName = "QtVsTest"; +var projectName = "MyGuiApp"; +var tempDir = Environment.GetEnvironmentVariable("TEMP"); +var solutionFileName = solutionName + ".sln"; +var solutionDir = Path.Combine(tempDir, solutionName); +var projectDir = Path.Combine(solutionDir, projectName); +if (Directory.Exists(solutionDir)) + Directory.Delete(solutionDir, recursive: true); +Directory.CreateDirectory(projectDir); +var solution = Dte.Solution as Solution2; +solution.Create(tempDir, solutionName); +solution.SaveAs(Path.Combine(solutionDir, solutionFileName)); +var templateGuiApp = solution.GetProjectTemplate("Qt GUI Application", "VC"); +var taskAddProj = Task.Run(() => solution.AddFromTemplate(templateGuiApp, projectDir, "MyGuiApp")); +//# ui context VS => "Qt GUI Application Wizard" +//# ui pattern Invoke => "Next >" +//# ui pattern Invoke => "Next >" +//# ui pattern Invoke => "Finish" +if (!taskAddProj.Wait(15000)) + throw new Exception("Timeout: Solution2.AddFromTemplate"); +Result = "(ok)"; diff --git a/src/tests/macros/Test_DebugGuiApp.csmacro b/src/tests/macros/Test_DebugGuiApp.csmacro new file mode 100644 index 00000000..8369758a --- /dev/null +++ b/src/tests/macros/Test_DebugGuiApp.csmacro @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt VS Tools. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//# using "Process = System.Diagnostics.Process" + +var solution = Dte.Solution as Solution2; +var solutionBuild = solution.SolutionBuild as SolutionBuild2; +var project = solution.Projects.Cast().First(); + +solutionBuild.Debug(); +//# wait 15000 => Dte.Debugger.CurrentMode == dbgDebugMode.dbgRunMode +//# wait 15000 IntPtr hWnd => Process.GetProcesses().Where(p => p.ProcessName.Equals(project.Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().MainWindowHandle +//# ui context HWND => hWnd +//# ui pattern Window mainWindow +mainWindow.Close(); +//# wait 15000 => Dte.Debugger.CurrentMode == dbgDebugMode.dbgDesignMode +Result = "(ok)"; diff --git a/src/tests/macros/Test_QtVsToolsLoaded.csmacro b/src/tests/macros/Test_QtVsToolsLoaded.csmacro new file mode 100644 index 00000000..83998ec1 --- /dev/null +++ b/src/tests/macros/Test_QtVsToolsLoaded.csmacro @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt VS Tools. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +/* + * - Ensure Qt VS Tools extension is loaded + * - Wait for Qt VS Tools to finish initialization + */ +//# wait 15000 Assembly QtVsTools => GetAssembly("QtVsTools") +var VsixType = QtVsTools.GetType("QtVsTools.Vsix"); +var VsixInstance = VsixType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static); +//# wait 15000 => VsixInstance.GetValue(null) +Result = "(ok)"; diff --git a/src/tests/macros/Test_RebuildSolution.csmacro b/src/tests/macros/Test_RebuildSolution.csmacro new file mode 100644 index 00000000..3234816d --- /dev/null +++ b/src/tests/macros/Test_RebuildSolution.csmacro @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt VS Tools. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//# using System.Threading.Tasks + +var solution = Dte.Solution as Solution2; +var solutionBuild = solution.SolutionBuild as SolutionBuild2; + +var taskRebuild = Task.Run(() => +{ + solutionBuild.Clean(WaitForCleanToFinish: true); + solutionBuild.Build(WaitForBuildToFinish: true); +}); + +bool buildOk = (taskRebuild.Wait(15000) && solutionBuild.LastBuildInfo == 0); +Result = buildOk ? "(ok)" : "(error)\r\nBuild failed."; -- cgit v1.2.3