From 3207211fa2729a92c38259bf0ec6ad92a5223fa6 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Mon, 26 Jan 2015 09:01:29 +0200
Subject: [PATCH 2/2] Add support for running the regression tests with
 MSBuild.

Use buildall -RegressionTests option to run them after building the driver.

(Not all tests pass currently on Windows, but at least you can run them
easily now)
---
 winbuild/BuildAll.ps1            |  21 ++++++-
 winbuild/regressiontests.vcxproj | 126 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 winbuild/regressiontests.vcxproj

diff --git a/winbuild/BuildAll.ps1 b/winbuild/BuildAll.ps1
index b6493c5..c96a8b6 100755
--- a/winbuild/BuildAll.ps1
+++ b/winbuild/BuildAll.ps1
@@ -15,6 +15,8 @@
     available.
 .PARAMETER AlongWithInstallers
     Specify when you'd like build installers after building drivers.
+.PARAMETER RegressionTests
+    Specify when you'd like run regression tests after building drivers.
 .PARAMETER Toolset
     MSBuild PlatformToolset is determined automatically unless this
     option is specified. Currently "v100", "Windows7.1SDK", "v110",
@@ -63,7 +65,8 @@ Param(
 [ValidateSet("Debug", "Release")]
 [String]$Configuration="Release",
 [string]$BuildConfigPath,
-[switch]$AlongWithInstallers
+[switch]$AlongWithInstallers,
+[switch]$RegressionTests
 )
 
 function buildPlatform($platinfo, $Platform)
@@ -118,6 +121,12 @@ function buildPlatform($platinfo, $Platform)
 	invoke-expression -Command "& `"${msbuildexe}`" ./platformbuild.vcxproj /tv:$MSToolsVersion /p:Platform=$Platform``;Configuration=$Configuration``;PlatformToolset=${Toolset} /t:$target /p:VisualStudioVersion=${VisualStudioVersion} /p:DRIVERVERSION=$DRIVERVERSION ${MACROS}"
 }
 
+function runRegressionTests($platinfo, $Platform, $DriverPath)
+{
+	invoke-expression -Command "& `"${msbuildexe}`" ./regressiontests.vcxproj /tv:$MSToolsVersion /p:Platform=$Platform``;Configuration=Debug``;PlatformToolset=${Toolset} /t:CreateTestDSN /t:RunRegressionTests /p:DriverPath=${DriverPath} /p:VisualStudioVersion=${VisualStudioVersion} ${MACROS}"
+}
+
+
 $scriptPath = (Split-Path $MyInvocation.MyCommand.Path)
 $configInfo = & "$scriptPath\configuration.ps1" "$BuildConfigPath"
 $DRIVERVERSION=$configInfo.Configuration.version
@@ -263,6 +272,11 @@ try {
 		if ($LastExitCode -ne 0) {
 			$recordResult = $false
 		}
+
+		if ($RegressionTests) {
+				runRegressionTests $configInfo.Configuration.x86 "Win32" Resolve-path("..\x86_ANSI_$Configuration")
+				runRegressionTests $configInfo.Configuration.x86 "Win32" Resolve-path("..\x86_Unicode_$Configuration")
+		}
 	}
 #
 #	build 64bit dlls
@@ -272,6 +286,11 @@ try {
 		if ($LastExitCode -ne 0) {
 			$recordResult = $false
 		}
+
+		if ($RegressionTests) {
+			runRegressionTests $configInfo.Configuration.x64 "x64" (Resolve-path "..\x64_ANSI_$Configuration")
+			runRegressionTests $configInfo.Configuration.x64 "x64" (Resolve-path "..\x64_Unicode_$Configuration")
+		}
 	}
 #
 #	Write the result to configuration xml
diff --git a/winbuild/regressiontests.vcxproj b/winbuild/regressiontests.vcxproj
new file mode 100644
index 0000000..b8dad8c
--- /dev/null
+++ b/winbuild/regressiontests.vcxproj
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="RunRegressionTests" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+    <PropertyGroup>
+	<srcPath>..\</srcPath>
+    </PropertyGroup>
+
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{79F872B5-9FAF-43DF-B441-9C860EAE52CF}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>psqlodbc</RootNamespace>
+    <ProjectName>regressiontests</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Platform)'=='Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v120_xp</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Platform)'=='x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v120_xp</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Platform)'=='Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Platform)'=='x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <!--			-->
+  <PropertyGroup Condition="'$(Platform)'=='Win32'">
+    <TARGET_CPU>x86</TARGET_CPU>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Platform)'!='Win32'">
+    <TARGET_CPU>x64</TARGET_CPU>
+  </PropertyGroup>
+
+  <PropertyGroup>
+    <IntDir>$(srcPath)$(TARGET_CPU)_Tests\</IntDir>
+    <OutDir>$(srcPath)$(TARGET_CPU)_Tests\</OutDir>
+  </PropertyGroup>
+
+  <Import Project="psqlodbc.Cpp.props" />
+
+  <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;$(ADD_DEFINES);WIN_MULTITHREAD_SUPPORT;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Platform)'=='x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;$(ADD_DEFINES);DYNAMIC_LOAD;WIN_MULTITHREAD_SUPPORT;WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+  </ItemDefinitionGroup>
+
+  <ItemGroup>
+    <RegressionSources Include="$(srcPath)\test\src\*-test.c" />
+  </ItemGroup>
+  
+  <ItemGroup>
+    <ClInclude Include="$(srcPath)\test\src\common.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="$(srcPath)\test\src\common.c" />
+    <ClCompile Include="$(srcPath)\test\runsuite.c" />
+    <ClCompile Include="$(srcPath)\test\reset-db.c" />
+    <ClCompile Include="@(RegressionSources)" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+  <Target Name="Info">
+    <Message Text="VCInstallDir=$(VCInstallDir) VSInstallDir=$(VSInstallDir) ExecutablePath=$(ExecutablePath)" />
+  </Target>
+
+  <!-- Note: We don't run on the built-in Link step, because that would link
+       all the regression tests into one .exe. We want each of them to become
+       a separate .exe.
+  -->
+
+  <Target Name="BuildRegressionTests" DependsOnTargets="LinkRegressionTests">
+  </Target>
+  <Target Name="LinkRegressionTests" DependsOnTargets="ClCompile">
+    <!-- Link regression test binaries -->
+    <Link Sources="$(Outdir)%(RegressionSources.Filename).obj;$(Outdir)common.obj"
+	  AdditionalDependencies="odbc32.lib"
+	  OutputFile="$(Outdir)%(RegressionSources.Filename).exe"
+	  />
+
+    <!-- Link the test harness -->
+    <Link Sources="$(Outdir)runsuite.obj" OutputFile="$(Outdir)runsuite.exe"/>
+    <Link Sources="$(Outdir)reset-db.obj"
+	  AdditionalDependencies="odbc32.lib"
+	  OutputFile="$(Outdir)reset-db.exe"/>
+  </Target>
+
+  <!-- Run the regression tests -->
+  <Target Name="RunRegressionTests" DependsOnTargets="BuildRegressionTests">
+    <Delete Files="$(srcPath)\test\regression.diffs" />
+    <Delete Files="$(srcPath)\test\results\*" />
+    <Exec WorkingDirectory="$(srcPath)\test" Command="$(Outdir)reset-db.exe &lt; sampletables.sql" />
+    <Exec WorkingDirectory="$(srcPath)\test"
+	  Command="$(Outdir)runsuite.exe @(RegressionSources->'$(Outdir)%(Filename).exe', ' ')" />
+  </Target>
+
+  <Target Name="CreateTestDSN">
+    <Exec Command='reg add HKCU\Software\ODBC\ODBC.INI\psqlodbc_test_dsn /f' />
+    <Exec Command='reg add HKCU\Software\ODBC\ODBC.INI\psqlodbc_test_dsn /v Description /t REG_SZ /d "psqlodbc regression test DSN" /f' />
+    <Exec Command='reg add HKCU\Software\ODBC\ODBC.INI\psqlodbc_test_dsn /v Database /t REG_SZ /d contrib_regression /f' />
+    <Exec Command='reg add HKCU\Software\ODBC\ODBC.INI\psqlodbc_test_dsn /v Driver /t REG_SZ /d "$(DriverPath)" /f' />
+  </Target>
+</Project>
-- 
2.1.4

