version: "{build}"

image: Visual Studio 2015

configuration:
  - Release
  - Debug

clone_depth: 100

environment:
  MYSQL_PATH: C:\Program Files\MySql\MySQL Server 5.7
  POSTGRESQL_PATH: C:\Program Files\PostgreSQL\9.5
  PGUSER: postgres
  PGPASSWORD: Password12!
  matrix:
    - GENERATOR: "Visual Studio 14 2015"
      TARGET: v90
    - GENERATOR: "Visual Studio 14 2015"
      TARGET: v140_xp
    - GENERATOR: "Visual Studio 14 2015 Win64"
      TARGET: v140
matrix:
  exclude:
    - configuration: Debug
      GENERATOR: "Visual Studio 14 2015"
      TARGET: v90
    - configuration: Debug
      GENERATOR: "Visual Studio 14 2015"
      TARGET: v140_xp

clone_folder: c:\projects\gammu

install:
  - ps: if (($env:CONFIGURATION) -eq "Debug" ) { .\admin\install_opencppcoverage.ps1 }
  - appveyor DownloadFile https://download.microsoft.com/download/f/2/6/f263ac46-1fe9-4ae9-8fd3-21102100ebf5/msxsl.exe

before_build:
  - cmd: >-
         "%MYSQL_PATH%\\bin\\mysql.exe" "--password=Password12!" "--user=root" "-e" "create database smsd;"
  - cmd: >-
         "%POSTGRESQL_PATH%\\bin\\createdb.exe" smsd
  - cmd: >-
         cmake -G "%GENERATOR%" -DCMAKE_INSTALL_PREFIX=%P% -T "%TARGET%"
         -DODBC_TESTING=OFF "-DODBC_DSN=mysql:Driver={MySQL ODBC 5.3 Unicode Driver}:host=localhost;dbname=smsd" 
         -DMYSQL_TESTING=ON -DMYSQL_USER=root "-DMYSQL_PASSWORD=Password12!"
         -DPSQL_TESTING=ON -DPSQL_USER=postgres "-DPSQL_PASSWORD=Password12!" 
         -DMEMORYCHECK_COMMAND="c:/projects/gammu/contrib/coveragehelper/Debug/coveragehelper.exe" -DMEMORYCHECK_COMMAND_OPTIONS="--separator" -DMEMORYCHECK_TYPE=Valgrind
         -DPOSTGRES_FOUND=OFF -DMYSQL_FOUND=OFF

build:
  project: ALL_BUILD.vcxproj
  parallel: true
  verbosity: minimal

after_build:
  - cmake --build .  --config %CONFIGURATION% --target package -- /verbosity:minimal

test_script:
  - "SET PATH=%MYSQL_PATH%\\bin;%POSTGRESQL_PATH%\\bin;c:\\projects\\gammu;%PATH%"
  - ps: >-
        $failure = 0;
        try 
        {
            if (($env:CONFIGURATION) -eq "Release" ) {
                $mode = "ExperimentalTest";
            } else {
                $mode = "ExperimentalMemCheck";
            }
            ctest --output-on-failure --no-compress-output --dashboard $mode --build-config ($env:CONFIGURATION);
            $failure = $lastExitCode;
        }
        catch 
        {
            $failure = 1;
        }
        finally
        {
            # Copy test results to fixed name
            Copy-Item Testing\$(Get-Content Testing\TAG -TotalCount 1)\*.xml test.xml;
            # XLST CTest XML into Junit XML
            msxsl test.xml admin/ctest-to-junit.xsl -o junit.xml;
            # Upload results to AppVeyor
            $wc = New-Object 'System.Net.WebClient';
            $wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\junit.xml));
        }
        if ($failure -ne 0) {
            # Propagate error code from testsuite
            exit $failure;
        }

after_test:
  - bash admin/codecov.sh

services:
  - mysql
  - postgresql

artifacts:
  - path: Gammu-*-Windows.exe
    name: Gammu Installer
  - path: CMakeFiles/CMakeOutput.log
    name: CMake log
  - path: CMakeFiles/CMakeError.log
    name: CMake errors
  - path: CMakeCache.txt
    name: CMake cache
  - path: test.xml
    name: Test results
  - path: junit.xml
    name: Transformed test results
