Index: Diablo/1.0/install_test.ahk =================================================================== --- Diablo/1.0/install_test.ahk (revision 0) +++ Diablo/1.0/install_test.ahk (working copy) @@ -0,0 +1,151 @@ +/* + * Designed for Diablo 1.0 + * Copyright (C) 2014 Radek Liska + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +ModuleExe = %A_WorkingDir%\Apps\diablodemo.exe +TestName = 1.install +MainAppFile = diablo_s.exe ; Mostly this is going to be process we need to look for + +; Test if Setup file exists, if so, delete installed files, and run Setup +TestsTotal++ +IfNotExist, %ModuleExe% + TestsFailed("'" ModuleExe "' not found.") +else +{ + Process, Close, %MainAppFile% ; Teminate process + Process, WaitClose, %MainAppFile%, 4 + if ErrorLevel ; The PID still exists. + TestsFailed("Unable to terminate '" MainAppFile "' process.") ; So, process still exists + else + { + RegRead, InstalledDir, HKEY_LOCAL_MACHINE, SOFTWARE\Blizzard Entertainment\Archives, DiabloSpawn + if ErrorLevel + { + ; There was a problem (such as a nonexistent key or value). + ; That probably means we have not installed this app before. + ; Check in default directory to be extra sure + bHardcoded := true ; To know if we got path from registry or not + IfNotExist, C:\Diablo\Spawn + bContinue := true ; No previous versions detected in hardcoded path + else + { + FileRemoveDir, C:\Diablo, 1 + if ErrorLevel + TestsFailed("Unable to delete hardcoded path C:\Diablo' ('" MainAppFile "' process is reported as terminated).'") + else + bContinue := true + } + } + else + { + IfNotExist, %InstalledDir% + bContinue := true + else + { + FileRemoveDir, %InstalledDir%, 1 ; Delete just in case + if ErrorLevel + TestsFailed("Unable to delete existing '" InstalledDir "' ('" MainAppFile "' process is reported as terminated).") + else + bContinue := true + } + } + } + + if bContinue + { + RegDelete, HKEY_LOCAL_MACHINE, SOFTWARE\Blizzard Entertainment + + if bContinue + { + if bHardcoded + TestsOK("Either there were no previous versions or we succeeded removing it using hardcoded path.") + else + TestsOK("Either there were no previous versions or we succeeded removing it using data from registry.") + Run %ModuleExe% + } + } +} + + +; Test if 'Diablo - choose install directory' window appeared +TestsTotal++ +if bContinue +{ + WinWaitActive, Diablo - choose install directory,, 10 + if ErrorLevel + TestsFailed("'Diablo - choose install directory' window failed to appear.") + else + { + ControlClick, OK, Diablo - choose install directory ; Confirm the path and start installation + ;SendInput, {ENTER} ; Confirm the path and start installation + TestsOK("'Diablo - choose install directory' appeared and 'OK' button was clicked.") + } +} + + +; Test if 'Diablo' messagebox with 'Diablo shareware installation complete!' message appeared +TestsTotal++ +if bContinue +{ + WinWaitActive, Diablo, Diablo shareware installation complete, 15 + if ErrorLevel + TestsFailed("'Diablo' messagebox with 'Diablo shareware installation complete!' message failed to appear.") + else + { + ControlClick, OK, Diablo, Diablo shareware installation complete ; Close the messagebox + ;SendInput, {ENTER} ; Close the messagebox + TestsOK("'Diablo' messagebox with 'Diablo shareware installation complete!' message appeared and 'OK' button was clicked.") + } +} + + +; Diablo opens explorer window with its Start menu folder, close it +TestsTotal++ +if bContinue +{ + SetTitleMatchMode, 2 ; A window's title can contain WinTitle anywhere inside it to be a match. + WinWait, Diablo ahk_class CabinetWClass,, 5 + if ErrorLevel + TestsFailed("Explorer window 'Diablo' (SetTitleMatchMode=" A_TitleMatchMode ") failed to appear.") + else + { + WinClose, Diablo ahk_class CabinetWClass + WinWaitClose, Diablo ahk_class CabinetWClass,, 5 + if ErrorLevel + TestsFailed("Unable to close explorer window 'Diablo' (SetTitleMatchMode=" A_TitleMatchMode ").") + else + TestsOK("'Diablo' window appeared, window closed.") + } +} + + +; Check if program exists +TestsTotal++ +if bContinue +{ + RegRead, InstalledDir, HKEY_LOCAL_MACHINE, SOFTWARE\Blizzard Entertainment\Archives, DiabloSpawn + if ErrorLevel + TestsFailed("Either we can't read from registry or data doesn't exist.") + else + { + IfNotExist, %InstalledDir%\%MainAppFile% + TestsFailed("Something went wrong, can't find '" InstalledDir "\" MainAppFile "'.") + else + TestsOK("The application has been installed, because '" InstalledDir "\" MainAppFile "' was found.") + } +} Index: Diablo/1.0/player_walk.ahk =================================================================== --- Diablo/1.0/player_walk.ahk (revision 0) +++ Diablo/1.0/player_walk.ahk (working copy) @@ -0,0 +1,159 @@ +/* + * Designed for Diablo 1.0 + * Copyright (C) 2014 Radek Liska + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +TestName = 2.player_walk + +; Test if can load game and walk player on the map +TestsTotal++ +RunApplication() +if bContinue +{ + Sleep, 1500 + IfWinNotActive, DIABLO + TestsFailed("'DIABLO' is NOT active window.") + else + { + szApp = %A_WorkingDir%\Apps\Cap.exe ; Screenshot capture utility by Mysoft (Grégori Macário Harbs) + IfNotExist, %szApp% + TestsInfo("Can NOT find '" szApp "'.") + ; switch szSuffix in following tests to pcx if SendInput is used instead of Cap.exe + ;SendInput, {PRINTSCREEN} ; Screenshot standing at starting position + RunWait, %szApp% /full /png /silent %InstalledDir%\screen00.png,, Hide|UseErrorLevel + if ErrorLevel + TestsFailed("Unable to run Cap.exe, got error level '" ErrorLevel "'.") + else + { + Sleep, 1000 + MouseMove, 145, 270 + Sleep, 100 + MouseClick, LEFT, 145, 270 + Sleep, 3000 + ; switch szSuffix in following tests to pcx if SendInput is used instead of Cap.exe + ;SendInput, {PRINTSCREEN} ; Screenshot standing at the path beginning + RunWait, %szApp% /full /png /silent %InstalledDir%\screen01.png,, Hide|UseErrorLevel + if ErrorLevel + TestsFailed("Unable to run Cap.exe, got error level '" ErrorLevel "'.") + else + { + Sleep, 1000 + SendInput, {ESC} ; Bring up the menu + Sleep, 500 + SendInput, {UP}{ENTER} ; Select 'Quit Diablo' + Sleep, 500 + Process, WaitClose, %ProcessExe%, 4 + if ErrorLevel + TestsFailed("Unable to exit the game, because '" ProcessExe "' process still exists.") + else + TestsOK("Game works, closed game using its menu.") + } + } + } +} + + +; Test if player really walked by comparing screenshots +TestsTotal++ +if bContinue +{ + InstalledDir := ProcessPath + szSuffix = png + TestsInfo("Comparing screenshots to see if a specific screen region moved as expected, but still looks the same.") + ; Check screenshots existence + if !(FileExist(InstalledDir . "\screen00." . szSuffix) && FileExist(InstalledDir . "\screen01." . szSuffix)) + TestsFailed("Screenshots do not exist.") + else + { + szConvert = %A_WorkingDir%\Media\convert.exe ; ImageMagick's convert.exe + IfNotExist, %szConvert% + TestsFailed("Cannot find '" szConvert "'.") + else { + ; Check files contents - convert and crop the PNG/PCX into BMP, they should show the exactly same pixels + ; NOTE: PNG could not be used for output, because some metadata differs even between identical pictures + RunWait, %szConvert% %InstalledDir%\screen00.%szSuffix% -crop 130x130+158+96 %InstalledDir%\crop00.bmp,, Hide|UseErrorLevel + if ErrorLevel != 0 + TestsFailed("Converting 1st image failed.") + else + { + RunWait, %szConvert% %InstalledDir%\screen01.%szSuffix% -crop 130x130+350+0 %InstalledDir%\crop01.bmp,, Hide|UseErrorLevel + if ErrorLevel != 0 + TestsFailed("Converting 2nd image failed.") + else + { + ; Check crops existence + if !(FileExist(InstalledDir . "\crop00.bmp") && FileExist(InstalledDir . "\crop01.bmp")) + TestsFailed("Cropped images do not exist.") + else + { + RunWait, fc /b %InstalledDir%\crop00.bmp %InstalledDir%\crop01.bmp, %InstalledDir%, Hide|UseErrorLevel + if ErrorLevel != 0 + TestsFailed("The images differ.") + else + TestsOK("The images are the same.") + } + } + } + } + } +} + + +; Test if the screen contents changed at all by comparing screenshots (will detect black rectangle errors) +TestsTotal++ +if bContinue +{ + InstalledDir := ProcessPath + szSuffix = png + TestsInfo("Comparing screenshots to see if a specific screen region around player changed a little.") + ; Check screenshots existence + if !(FileExist(InstalledDir . "\screen00." . szSuffix) && FileExist(InstalledDir . "\screen01." . szSuffix)) + TestsFailed("Screenshots do not exist.") + else + { + szConvert = %A_WorkingDir%\Media\convert.exe ; ImageMagick's convert.exe + IfNotExist, %szConvert% + TestsFailed("Can NOT find '" szConvert "'.") + else { + ; Check files contents - convert and crop the PNG/PCX into BMP, they should differ + ; NOTE: PNG could not be used for output, because some metadata differs even between identical pictures + RunWait, %szConvert% %InstalledDir%\screen00.%szSuffix% -crop 130x130+255+80 %InstalledDir%\crop02.bmp,, Hide|UseErrorLevel + if ErrorLevel != 0 + TestsFailed("Converting 1st image failed.") + else + { + RunWait, %szConvert% %InstalledDir%\screen01.%szSuffix% -crop 130x130+255+80 %InstalledDir%\crop03.bmp,, Hide|UseErrorLevel + if ErrorLevel != 0 + TestsFailed("Converting 2nd image failed.") + else + { + ; Check crops existence + if !(FileExist(InstalledDir . "\crop02.bmp") && FileExist(InstalledDir . "\crop03.bmp")) + TestsFailed("Cropped images do not exist.") + else + { + RunWait, fc /b %InstalledDir%\crop02.bmp %InstalledDir%\crop03.bmp, %InstalledDir%, Hide|UseErrorLevel + if ErrorLevel = 1 + TestsOK("The images differ.") + else + TestsFailed("The images are the same, fc does not exist or some other error occured, errorlevel is " ErrorLevel ".") + } + } + } + } + } +} Index: Diablo/1.0/prepare.ahk =================================================================== --- Diablo/1.0/prepare.ahk (revision 0) +++ Diablo/1.0/prepare.ahk (working copy) @@ -0,0 +1,182 @@ +/* + * Designed for Diablo 1.0 + * Copyright (C) 2014 Edijs Kolesnikovics, Radek Liska + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +TestName = prepare + +; Test if the app is installed +TestsTotal++ +RegRead, InstalledDir, HKEY_LOCAL_MACHINE, SOFTWARE\Blizzard Entertainment\Archives, DiabloSpawn +if ErrorLevel + TestsFailed("Either registry key does not exist or we failed to read it.") +else +{ + if (InstalledDir = "") + TestsFailed("Either registry contains empty string or we failed to read it.") + else + { + ModuleExe = %InstalledDir%\diablo_s.exe + TestsOK("") + } +} + + +; Terminate application +if bContinue +{ + SplitPath, ModuleExe, ProcessExe, ProcessPath + bTerminateProcess(ProcessExe) +} + + +; Delete settings separately from RunApplication() in case we want to write our own settings +TestsTotal++ +if bContinue +{ + IfExist, %InstalledDir%\spawn_0.sv + { + FileDelete, %InstalledDir%\spawn_*.sv + if ErrorLevel + TestsFailed("Unable to delete '" InstalledDir "\spawn_*.sv'.") + else + TestsOK("") + } + else + TestsOK("") +} + + +; delete all the PCX/PNG screenshots and converted images +TestsTotal++ +if bContinue +{ + if bContinue + { + IfExist, %InstalledDir%\screen*.* + { + FileDelete, %InstalledDir%\screen*.* + if ErrorLevel + TestsFailed("Unable to delete '" InstalledDir "\screen_*.*'.") + } + } + + if bContinue + { + IfExist, %InstalledDir%\crop*.bmp + { + FileDelete, %InstalledDir%\crop*.bmp + if ErrorLevel + TestsFailed("Unable to delete '" InstalledDir "\crop*.bmp'.") + } + } + + if bContinue + { + TestsOK("") + } +} + + +; Test if can start application +RunApplication() +{ + global ModuleExe + global TestName + global TestsTotal + global bContinue + global ProcessExe + global ProcessPath + + TestsTotal++ + if bContinue + { + IfNotExist, %ModuleExe% + TestsFailed("RunApplication(): Can NOT find '" ModuleExe "'.") + else + { + Run, %ModuleExe%, %ProcessPath% + WinWaitActive, DIABLO,, 3 + if ErrorLevel + { + Process, Exist, %ProcessExe% + NewPID = %ErrorLevel% ; Save the value immediately since ErrorLevel is often changed. + if NewPID = 0 + TestsFailed("RunApplication(): Window 'DIABLO' failed to appear. No '" ProcessExe "' process detected.") + else + TestsFailed("RunApplication(): Window 'DIABLO' failed to appear. '" ProcessExe "' process detected.") + } + else + { + WinGetPos, X, Y, Width, Height, DIABLO + iTimeOut := 60 + while (iTimeOut > 0) + { + WinGetPos, X, Y, Width, Height, DIABLO + if (Width != A_ScreenWidth) OR (Height != A_ScreenHeight) + { + Sleep, 100 + iTimeOut-- + } + else + break + } + + if (Width != A_ScreenWidth) OR (Height != A_ScreenHeight) + TestsFailed("RunApplication(): Window size is not equal to screen size. Is '" Width "x" Height "', should be '" A_ScreenWidth "x" A_ScreenHeight "'. iTimeOut=" iTimeOut ".") + else + { + ; FIXME + Sleep, 2500 + Click, 330, 215 ; Close splash + ;SendInput, {ESC} + Sleep, 2500 + Click, 330, 215 ; Close splash + ;SendInput, {ESC} + Sleep, 2500 + Click, 330, 215 ; Single player + ;SendInput, {ENTER} + Sleep, 2500 + Click, 350, 445 ; Click OK to select Warrior (only available character in demo) + ;SendInput, {ENTER} + Sleep, 2500 + PlayerName = DiabloPlayer + SendInput, %PlayerName% ; Fill 'Character Name' field + TestsInfo("RunApplication(): Entered player name. Sending ENTER to start the actual game.") + SendInput, {ENTER} + iTimeOut := 15 + while (iTimeOut > 0) + { + WinGetPos, X, Y, Width, Height, DIABLO + if ((Width = 640) AND (Height = 480)) + break + else + { + Sleep, 1000 + iTimeOut-- + } + } + + if not ((Width = 640) AND (Height = 480)) + TestsFailed("RunApplication(): unexpected 'DIABLO' window size. Is '" Width "x" Height "', should be '640x480' (iTimeOut=" iTimeOut ").") + else + TestsOK("RunApplication(): Game is up and running (iTimeOut=" iTimeOut ").") + } + } + } + } +} Index: Diablo/1.0/zz_diablo_1.0_test.ahk =================================================================== --- Diablo/1.0/zz_diablo_1.0_test.ahk (revision 0) +++ Diablo/1.0/zz_diablo_1.0_test.ahk (working copy) @@ -0,0 +1,52 @@ +/* + * Designed for Diablo 1.0 + * Copyright (C) 2014 Radek Liska + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#Include ..\..\helper_functions.ahk +InitalizeCounters() + +params = +( + + 1.install + 2.player_walk + +) + +if CheckParam() +{ + ; Those brackets are required! + if 1 = 1.install + { + #include install_test.ahk + } + else + { + if 1 != --list + { + #include prepare.ahk + + if 1 = 2.player_walk + { + #include player_walk.ahk + } + } + } +} + +ShowTestResults()