+ fix: restore accidentally removed test environment

This commit is contained in:
Rainer Kottenhoff 2019-07-15 13:33:19 +02:00
parent 2a063d33fe
commit 2f9b63f70e
4 changed files with 314 additions and 0 deletions

142
test/TestAhkNotepad3.ahk Normal file
View File

@ -0,0 +1,142 @@
; =============================================================================
; Regression Tests Notepad3 Gui
; Needs files in a Test Directory:
; Notepad3.exe and Notepad3.ini (from distrib)
; Execute: AutoHotkeyU32.exe "TestAhkNotepad3.ahk"
; =============================================================================
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines, -1
StringCaseSense, Off
CoordMode, Pixel, Screen
; =============================================================================
v_NP3Name = Notepad3
v_NP3TestDir = %A_WorkingDir%\_TESTDIR
v_NP3IniFile = %v_NP3Name%.ini
stdout := FileOpen("*", "w")
v_ExitCode := 0
; =============================================================================
Run, %v_NP3TestDir%/%v_NP3Name%.exe %v_NP3TestDir%/%v_NP3IniFile%, , UseErrorLevel, v_Notepad3_PID
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
stdout.WriteLine("*** ERROR: " . v_NP3Name . "could not be launched.")
v_ExitCode := 1
Goto LABEL_END
}
; -----------------------------------------------------------------------------
GoSub CHECK_NP3_STARTS
Sleep, 500
GoSub CHECK_WIN_TITLE
Sleep, 500
GoSub CHECK_ABOUT_BOX
Goto LABEL_END
; =============================================================================
; =============================================================================
CHECK_NP3_STARTS:
; check that NP3 starts up
WinWait ahk_pid %v_Notepad3_PID%, , 10
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
stdout.WriteLine("*** ERROR: " . v_NP3Name . "'s seems not to start in time ???")
v_ExitCode := 2
Goto LABEL_END
}
Return
; =============================================================================
; =============================================================================
CHECK_WIN_TITLE:
; check Main Window Title
WinGetTitle, v_NP3Title, ahk_pid %v_Notepad3_PID%
IfNotInString, v_NP3Title, %v_NP3Name%
{
v_ExitCode := 3
stdout.WriteLine("*** ERROR: " . v_NP3Name . " missing in Title: " . v_NP3Title)
}
IfNotInString, v_NP3Title, %v_NP3IniFile%
{
v_ExitCode := 3
stdout.WriteLine("*** ERROR: " . v_NP3IniFile . " missing in Title: " . v_NP3Title)
}
IfNotInString, v_NP3Title, %v_NP3TestDir%
{
v_ExitCode := 3
stdout.WriteLine("*** ERROR: " . v_NP3TestDir . " missing in Title: " . v_NP3Title)
}
If (v_ExitCode != 0)
{
Goto LABEL_END
}
Return
; =============================================================================
; =============================================================================
CHECK_ABOUT_BOX:
; check About DlgBox
WinActivate, ahk_pid %v_Notepad3_PID%
; This will select File->Open in Notepad:
WinMenuSelectItem, ahk_pid %v_Notepad3_PID%, , Help, About...
WinWait, About %v_NP3Name%, , 3
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
v_ExitCode := 4
stdout.WriteLine("*** ERROR: " . v_NP3Name . "'s About Box is not displayed!")
Goto LABEL_END
}
WinActivate ; About Box
;ControlFocus, OK, About %v_NP3Name%
ControlClick, OK, About %v_NP3Name%
;Send {Enter}
WinWaitClose, About %v_NP3Name%, , 2
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
v_ExitCode := 5
stdout.WriteLine("*** ERROR: " . v_NP3Name . "'s About Box can not be closed!")
Goto LABEL_END
}
Return
; =============================================================================
; =============================================================================
LABEL_END:
WinClose ahk_pid %v_Notepad3_PID%, , 2
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
v_ExitCode := 99
stdout.WriteLine("*** ERROR: " . v_NP3Name . "can not be closed!")
}
; -------------------------------------
WinWaitClose ahk_pid %v_Notepad3_PID%
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
v_ExitCode := 111
; FORCED Kill / HANGUP
}
; -------------------------------------
if (v_ExitCode != 0)
{
stdout.WriteLine("*** ERROR: Testing " . v_NP3Name . " exit with: " . v_ExitCode)
ExitApp, %v_ExitCode%
}
stdout.WriteLine("Testing " . v_NP3Name . ": All tests PASSED.")
ExitApp, 0
; =============================================================================

54
test/TestAhkNotepad3.cmd Normal file
View File

@ -0,0 +1,54 @@
@echo off
setlocal enableextensions
set SCRIPTDRV=%~d0
set SCRIPTDIR=%~dp0
set CWD=%CD%
set TEST_DIR=%SCRIPTDIR%_TESTDIR\
set TEST_LOG=test.log
set NP3_CONFIG_DIR=%SCRIPT_DIR%config\
set NP3_WIN32_DIR=%SCRIPT_DIR%..\Bin\Release_x86_v141\
set NP3_X64_DIR=%SCRIPT_DIR%..\Bin\Release_x64_v141\
set AHK_EXE=%ProgramW6432%/AutoHotkey/AutoHotkeyU32.exe
set AHK_EXE32=%ProgramFiles(x86)%/AutoHotkey/AutoHotkeyU32.exe
set AHK_EXE64=%ProgramFiles%/AutoHotkey/AutoHotkeyU32.exe
if not exist "%AHK_EXE%" set AHK_EXE=%AHK_EXE32%
if not exist "%AHK_EXE%" set AHK_EXE=%AHK_EXE64%
:: --------------------------------------------------------------------------------------------------------------------
:: prepare tests
if not exist "%TEST_DIR%" mkdir "%TEST_DIR%"
if not exist "%TEST_DIR%Favorites\" mkdir "%TEST_DIR%Favorites\"
copy "%NP3_CONFIG_DIR%Notepad3_distrib.ini" "%TEST_DIR%Notepad3.ini" /Y /V
if exist "%NP3_WIN32_DIR%Notepad3.exe" copy /B "%NP3_WIN32_DIR%Notepad3.exe" /B "%TEST_DIR%Notepad3.exe" /Y /V
if exist "%NP3_X64_DIR%Notepad3.exe" copy /B "%NP3_X64_DIR%Notepad3.exe" /B "%TEST_DIR%Notepad3.exe" /Y /V
::Loop over all ahk files in tests directory
echo. > "%TEST_LOG%"
set EXITCODE=0
::for /r %%i in (*.ahk) do (
for %%i in (*.ahk) do (
echo - Run Testsuite %%~nxi
echo +++ Run Testsuite %%~nxi +++ >> "%TEST_LOG%"
start "testing" /B /Wait "%AHK_EXE%" /ErrorStdOut "%%~nxi" >> "%TEST_LOG%" 2>&1
if errorlevel 1 (
set EXITCODE=1
echo *** Testsuite %%~nxi failed! ***
echo *** ERROR: Testsuite %%~nxi failed! *** >> "%TEST_LOG%"
) else (
echo +++ Testsuite %%~nxi succeeded. +++ >> "%TEST_LOG%"
)
echo. >> "%TEST_LOG%"
)
:: --------------------------------------------------------------------------------------------------------------------
:END
type "%TEST_LOG%"
:: - make EXITCODE survive 'endlocal'
endlocal & set EXITCODE=%EXITCODE%
::echo.EXITCODE=%EXITCODE%
::pause
if [%EXITCODE%] NEQ [0] exit /B %EXITCODE%
:: ====================================================================================================================

118
test/TestFileVersion.cmd Normal file
View File

@ -0,0 +1,118 @@
@echo off
setlocal enableextensions
set SCRIPT_DIR=%~dp0
set NP3_WIN32_DIR=%SCRIPT_DIR%..\Bin\Release_x86_v141\
set NP3_X64_DIR=%SCRIPT_DIR%..\Bin\Release_x64_v141\
set NP3_BUILD_VER=%SCRIPT_DIR%..\Versions\build.txt
:: --------------------------------------------------------------------------------------------------------------------
set YY=00
set MM=00
set DD=00
call :GETDATE
set "LZ=%MM:~0,1%"
if [%LZ%]==[0] set "MM=%MM:~1,1%"
set BUILD=0
call :GETBUILD "%~1"
set VERSHOULD=5.%YY%.%MM%%DD%.%BUILD%
:: --------------------------------------------------------------------------------------------------------------------
set TEST_RESULT=failure
set FILEVER=
set FILEVER32=
if exist "%NP3_WIN32_DIR%Notepad3.exe" call :GETFILEVER "%NP3_WIN32_DIR%Notepad3.exe"
if defined FILEVER set FILEVER32=%FILEVER%
set FILEVER=
set FILEVER64=
if exist "%NP3_X64_DIR%Notepad3.exe" call :GETFILEVER "%NP3_X64_DIR%Notepad3.exe"
if defined FILEVER set FILEVER64=%FILEVER%
if defined FILEVER32 set TEST_RESULT=success
if defined FILEVER64 set TEST_RESULT=success
call :COMPAREVER "%VERSHOULD%" "%FILEVER32%" "%FILEVER64%"
:: ====================================================================================================================
goto :END
:: --------------------------------------------------------------------------------------------------------------------
:COMPAREVER
if ["%~2"] NEQ [""] (
if ["%~1"] NEQ ["%~2"] (
echo ERROR: Expected version "%~1", found version "%~2" in 32-bit exe
set TEST_RESULT=failure
)
)
if ["%~3"] NEQ [""] (
if ["%~1"] NEQ ["%~3"] (
echo ERROR: Expected version "%~1", found version "%~3" in 64-bit exe
set TEST_RESULT=failure
)
)
goto:EOF
:: --------------------------------------------------------------------------------------------------------------------
:GETDATE
for /f "tokens=2 delims==" %%a in ('
wmic OS Get localdatetime /value
') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
::set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
::set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
::echo src: "%dt%"
::echo datestamp: "%datestamp%"
::echo timestamp: "%timestamp%"
::echo fullstamp: "%fullstamp%"
goto:EOF
:: --------------------------------------------------------------------------------------------------------------------
:GETFILEVER
set "file=%~1"
if not defined file goto:EOF
if not exist "%file%" goto:EOF
set "FILEVER="
for /F "tokens=2 delims==" %%a in ('
wmic datafile where name^="%file:\=\\%" Get Version /value
') do set "FILEVER=%%a"
::echo %file% = %FILEVER%
goto:EOF
:: --------------------------------------------------------------------------------------------------------------------
:GETBUILD
set argbuild=%~1
if defined argbuild (
set BUILD=%argbuild%
goto:EOF
)
::set /p nxbuild=<"%NP3_BUILD_VER%"
::set /a BUILD=%nxbuild% - 1
set /p BUILD=<"%NP3_BUILD_VER%"
goto:EOF
:: --------------------------------------------------------------------------------------------------------------------
:: ====================================================================================================================
:END
echo Expected Version = %VERSHOULD%
if ["%FILEVER32%"] NEQ [""] (
echo 32-bit exe Version = %FILEVER32%
) else (
echo No 32-bit exe Version found
)
if ["%FILEVER64%"] NEQ [""] (
echo 64-bit exe Version = %FILEVER64%
) else (
echo No 64-bit exe Version found
)
echo Version Test Result: %TEST_RESULT%
:: - make TEST_RESULT survive 'endlocal'
endlocal & set TEST_RESULT=%TEST_RESULT%
::pause
if [%TEST_RESULT%] NEQ [success] exit /B 1
:: ====================================================================================================================

Binary file not shown.