[AHK_SumatraPDF_2.1.1]

Add a test to check if can open PDF document, find text in it and close app.
The test works fine in clean snapshot of win2k3 sp2.

svn path=/trunk/ahk_tests/; revision=1891
This commit is contained in:
Edijs Kolesnikovičs 2012-11-14 13:58:38 +00:00
parent 48b60012ff
commit a736db54d4
3 changed files with 245 additions and 0 deletions

View File

@ -0,0 +1,112 @@
/*
* Designed for SumatraPDF 2.1.1
* Copyright (C) 2012 Edijs Kolesnikovics
*
* 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.find_text
szDocument = %A_WorkingDir%\Media\Book.pdf ; Case sensitive!
; Test if can open PDF file and find some text in it
TestsTotal++
RunApplication(szDocument)
if not bContinue
TestsFailed("We failed somwehere in 'prepare.ahk'.")
else
{
SplitPath, szDocument, NameExt
IfWinNotActive, %NameExt%
TestsFailed("'" NameExt "' is not an active window.")
else
{
szSearchFor = divorced
ControlSetText, Edit2, %szSearchFor% ; Set 'Find' field text
if ErrorLevel
TestsFailed("Unable to enter '" szSearchFor "' in 'Find' field.")
else
{
ControlFocus, Edit2 ; Focus 'Find' field
if ErrorLevel
TestsFailed("Unable to focus 'Find' field.")
else
{
SendInput, {ENTER} ; Start the search
; Wait until small window in top left corner appears
iTimeOut := 3
while iTimeOut > 0
{
IfWinActive, %NameExt%
{
ControlGet, bVisible, Visible,, SUMATRA_PDF_NOTIFICATION_WINDOW1 ;
if bVisible = 1
break ; Control appeared, break the loop
else
{
Sleep, 1000
iTimeOut--
}
}
else
break ; exit the loop if something poped-up
}
if bVisible <> 1
TestsFailed("Small window in top left corner failed to appear. (iTimeOut=" iTimeOut ")")
else
{
; Wait until text in that small window is the same as expected
iTimeOut := 3
szResultHard = Found text at page 56 ; This is what we are hoping to find
while iTimeOut > 0
{
IfWinActive, %NameExt%
{
ControlGetText, szResult, SUMATRA_PDF_NOTIFICATION_WINDOW1 ;
if (szResult = szResultHard)
break ; Match found
else
{
Sleep, 1000
iTimeOut--
}
}
else
break ; exit the loop if something poped-up
}
if (szResult != szResultHard)
TestsFailed("Unable to find a match? Is '" szResult "', should be '" szResultHard "'. (iTimeOut=" iTimeOut ")")
else
{
WinClose, %NameExt%
WinWaitClose,,,3
if ErrorLevel
TestsFailed("Unable to close '" NameExt "' window. (SetTitleMatchMode=" A_TitleMatchMode ")")
else
{
Process, WaitClose, %ProcessExe%, 4
if ErrorLevel
TestsFailed("'" ProcessExe "' process failed to close despite '" NameExt "' window reported being closed. (SetTitleMatchMode=" A_TitleMatchMode ").")
else
TestsOK("Found a match, so, searching text using 'Find' field works. '" ProcessExe "' process closed after closing app window.")
}
}
}
}
}
}
}

View File

@ -0,0 +1,123 @@
/*
* Designed for SumatraPDF 2.1.1
* Copyright (C) 2012 Edijs Kolesnikovics
*
* 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, UninstallerPath, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SumatraPDF, UninstallString
if ErrorLevel
TestsFailed("Either registry key does not exist or we failed to read it.")
else
{
SplitPath, UninstallerPath,, InstalledDir
ModuleExe = %InstalledDir%\SumatraPDF.exe
TestsOK("")
}
; Terminate application
TestsTotal++
if bContinue
{
SplitPath, ModuleExe, ProcessExe
Process, Close, %ProcessExe%
Process, WaitClose, %ProcessExe%, 4
if ErrorLevel
TestsFailed("Unable to terminate '" ProcessExe "' process.")
else
TestsOK("")
}
; Delete settings separately from RunApplication() in case we want to write our own settings
TestsTotal++
if bContinue
{
IfExist, %A_AppData%\SumatraPDF
{
FileRemoveDir, %A_AppData%\SumatraPDF, 1
if ErrorLevel
TestsFailed("Unable to delete '" A_AppData "\SumatraPDF'.")
else
TestsOK("")
}
else
TestsOK("")
}
; Test if can start application
RunApplication(PathToFile)
{
global ModuleExe
global TestName
global TestsTotal
global bContinue
global ProcessExe
TestsTotal++
if bContinue
{
IfNotExist, %ModuleExe%
TestsFailed("Can NOT find '" ModuleExe "'.")
else
{
if PathToFile =
{
Run, %ModuleExe%,, Max ; Start maximized
WinWaitActive, SumatraPDF,,5
if ErrorLevel
{
Process, Exist, %ProcessExe%
NewPID = %ErrorLevel% ; Save the value immediately since ErrorLevel is often changed.
if NewPID = 0
TestsFailed("Window 'SumatraPDF' failed to appear. No '" ProcessExe "' process detected.")
else
TestsFailed("Window 'SumatraPDF' failed to appear. '" ProcessExe "' process detected.")
}
else
TestsOK("")
}
else
{
IfNotExist, %PathToFile%
TestsFailed("Can NOT find '" PathToFile "'.")
else
{
Run, %ModuleExe% "%PathToFile%",, Max
SetTitleMatchMode, 1 ; A window's title must start with the specified WinTitle to be a match.
SplitPath, PathToFile, NameExt
WinWaitActive, %NameExt%,,5
if ErrorLevel
{
Process, Exist, %ProcessExe%
NewPID = %ErrorLevel% ; Save the value immediately since ErrorLevel is often changed.
if NewPID = 0
TestsFailed("Window '" NameExt "' failed to appear (SetTitleMatchMode=" A_TitleMatchMode "). No '" ProcessExe "' process detected.")
else
TestsFailed("Window '" NameExt "' failed to appear (SetTitleMatchMode=" A_TitleMatchMode "). '" ProcessExe "' process detected.")
}
else
TestsOK("")
}
}
}
}
}

View File

@ -24,6 +24,7 @@ params =
(
1.install
2.find_text
)
@ -34,6 +35,15 @@ if CheckParam()
{
#include install_test.ahk
}
else
{
#include prepare.ahk
if 1 = 2.find_text
{
#include find_text.ahk
}
}
}
ShowTestResults()