aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Costa <miguel.costa@qt.io>2019-04-29 17:06:09 +0200
committerMiguel Costa <miguel.costa@qt.io>2019-05-08 10:58:54 +0000
commit2477d3ae97a6fffea1569dc3a1ccbdaa98731f4f (patch)
treeee37850e34b3b7a55d73cfaae0c235d2ca05d40d
parent6e58bea9883b5ff9c05fb07f807e9566e8911eda (diff)
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 <oliver.wolff@qt.io>
-rw-r--r--src/qtvstest/MacroClient.h29
-rw-r--r--src/tests/CoreFeatures/CoreFeatures.vcxproj19
-rw-r--r--src/tests/CoreFeatures/CoreFeatures.vcxproj.filters19
-rw-r--r--src/tests/CoreFeatures/Macros.qrc8
-rw-r--r--src/tests/CoreFeatures/main.cpp30
-rw-r--r--src/tests/macros/Test_CreateGuiApp.csmacro50
-rw-r--r--src/tests/macros/Test_DebugGuiApp.csmacro42
-rw-r--r--src/tests/macros/Test_QtVsToolsLoaded.csmacro36
-rw-r--r--src/tests/macros/Test_RebuildSolution.csmacro41
9 files changed, 261 insertions, 13 deletions
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 <QDir>
+#include <QFile>
#include <QString>
+
#include <QElapsedTimer>
#include <QtNetwork>
#include <QProcess>
@@ -158,6 +161,32 @@ public:
return QString::fromUtf8(data);
}
+ QString runMacro(QFile &macroFile)
+ {
+ return loadAndRunMacro(macroFile);
+ }
+
+ QString loadMacro(QFile &macroFile, 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 &macroFile, 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 @@
<Define>UNICODE;_UNICODE;WIN32;WIN64;QT_CORE_LIB;QT_TESTLIB_LIB;QT_NETWORK_LIB;%(PreprocessorDefinitions)</Define>
<IncludePath>$(SolutionDir)qtvstest;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtTest;$(QTDIR)\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
</QtMoc>
+ <QtRcc>
+ <ExecutionDescription>Rcc'ing %(Identity)...</ExecutionDescription>
+ <OutputFile>.\GeneratedFiles\qrc_%(Filename).cpp</OutputFile>
+ </QtRcc>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
@@ -93,6 +97,10 @@
<Define>UNICODE;_UNICODE;WIN32;WIN64;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_TESTLIB_LIB;QT_NETWORK_LIB;%(PreprocessorDefinitions)</Define>
<IncludePath>$(SolutionDir)qtvstest;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtTest;$(QTDIR)\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
</QtMoc>
+ <QtRcc>
+ <ExecutionDescription>Rcc'ing %(Identity)...</ExecutionDescription>
+ <OutputFile>.\GeneratedFiles\qrc_%(Filename).cpp</OutputFile>
+ </QtRcc>
</ItemDefinitionGroup>
<ItemGroup>
<QtMoc Include="main.cpp">
@@ -109,6 +117,17 @@
<ItemGroup>
<ClInclude Include="..\..\qtvstest\MacroClient.h" />
</ItemGroup>
+ <ItemGroup>
+ <QtRcc Include="Macros.qrc">
+ <SubType>Designer</SubType>
+ </QtRcc>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="..\macros\Test_CreateGuiApp.csmacro"/>
+ <None Include="..\macros\Test_DebugGuiApp.csmacro"/>
+ <None Include="..\macros\Test_QtVsToolsLoaded.csmacro"/>
+ <None Include="..\macros\Test_RebuildSolution.csmacro"/>
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" />
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 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
+ <ItemGroup>
+ <None Include="..\macros\Test_QtVsToolsLoaded.csmacro">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="..\macros\Test_CreateGuiApp.csmacro">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="..\macros\Test_RebuildSolution.csmacro">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="..\macros\Test_DebugGuiApp.csmacro">
+ <Filter>Resource Files</Filter>
+ </None>
+ </ItemGroup>
+ <ItemGroup>
+ <QtRcc Include="Macros.qrc">
+ <Filter>Resource Files</Filter>
+ </QtRcc>
+ </ItemGroup>
</Project> \ 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 @@
+<RCC>
+ <qresource prefix="/">
+ <file alias="QtVsToolsLoaded">../macros/Test_QtVsToolsLoaded.csmacro</file>
+ <file alias="CreateGuiApp" >../macros/Test_CreateGuiApp.csmacro</file>
+ <file alias="RebuildSolution">../macros/Test_RebuildSolution.csmacro</file>
+ <file alias="DebugGuiApp" >../macros/Test_DebugGuiApp.csmacro</file>
+ </qresource>
+</RCC>
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 <MacroClient.h>
-#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<Project>().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.";