From 2f9b63f70edc296fe603f033bac954b06e2c3655 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 15 Jul 2019 13:33:19 +0200 Subject: [PATCH] + fix: restore accidentally removed test environment --- test/TestAhkNotepad3.ahk | 142 +++++++++++++++++++++++++++++++ test/TestAhkNotepad3.cmd | 54 ++++++++++++ test/TestFileVersion.cmd | 118 +++++++++++++++++++++++++ test/config/Notepad3_distrib.ini | Bin 0 -> 1258 bytes 4 files changed, 314 insertions(+) create mode 100644 test/TestAhkNotepad3.ahk create mode 100644 test/TestAhkNotepad3.cmd create mode 100644 test/TestFileVersion.cmd create mode 100644 test/config/Notepad3_distrib.ini diff --git a/test/TestAhkNotepad3.ahk b/test/TestAhkNotepad3.ahk new file mode 100644 index 000000000..715d3b540 --- /dev/null +++ b/test/TestAhkNotepad3.ahk @@ -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 +; ============================================================================= diff --git a/test/TestAhkNotepad3.cmd b/test/TestAhkNotepad3.cmd new file mode 100644 index 000000000..c9eb1ec18 --- /dev/null +++ b/test/TestAhkNotepad3.cmd @@ -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% +:: ==================================================================================================================== diff --git a/test/TestFileVersion.cmd b/test/TestFileVersion.cmd new file mode 100644 index 000000000..fec7d8189 --- /dev/null +++ b/test/TestFileVersion.cmd @@ -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 +:: ==================================================================================================================== diff --git a/test/config/Notepad3_distrib.ini b/test/config/Notepad3_distrib.ini new file mode 100644 index 0000000000000000000000000000000000000000..1f621e1bac78912dc84f0f82f2666958202a2eb7 GIT binary patch literal 1258 zcmZvcTW`}q5QWb(692(3JhsK=(ts49LWxv~pi-ygA?3l1O&Z}QAqj~5dElE_uVYeV zZM>N|d*;k#{pa^YAGOq0l~yWL>Y2Xiu^wrn9NU&>u7zgWH1^CjTB`jOrp|H?Bo&hn|?93XO1|G@mbFAU?v2MVcg0B6> zm5s39661`Od(IZ$Vm|Ho$FP+iyRYYNA98N3Z~EYQ&Ujm0x@sSK40G?g`sy|Oho~WZ zB|I@7^IIRzQ1?z3JO%2mH6o*4tI}%qtJUxxC8g`JKJ7DE!c~*4DSxXUWGy725jo5?NsI*VP}k4%a{5tZT+c72uO=%yHuxM z--q*-H4}G<`bu9}Yu}aRU6ApNj0%1$@5z+CO;4PaKKq4^s9f&+c~c+5#7VmVv7si$ zW>XM*kTY`?Y&Bh2@mzzl=&@HdT{#DRcysLD?9YZ%xpp3-ViJbBf@>dTil%dx1|obdx;Hs#D;&QX6Eff5^x(Idjo+Goz4kAt gx2{A?j{cqNjjW-<85Jq1qs>S`U21T9Y`hJB0hFl8%>V!Z literal 0 HcmV?d00001