[AHK_LibreOffice_3.6.2]

Add prepare and 2.writer_replace;
2.writer_replace: Test if can open text document with LibreOffice Writer, replace some text and save changes;
Test succeeds in clean snapshot of win2k3 ee sp1.

svn path=/trunk/ahk_tests/; revision=1916
This commit is contained in:
Edijs Kolesnikovičs 2012-12-02 14:33:56 +00:00
parent 03b2f5926a
commit 8a9d388e3b
3 changed files with 337 additions and 0 deletions

View File

@ -0,0 +1,92 @@
/*
* Designed for LibreOffice 3.6.2
* 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, InstalledDir, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1E85458A-9B00-443F-A187-2E06DBB15E43}, InstallLocation
if ErrorLevel
TestsFailed("Either registry key does not exist or we failed to read it.")
else
{
ModuleExe = %InstalledDir%program\soffice.exe
TestsOK("")
}
; Terminate application
if bContinue
{
SplitPath, ModuleExe, ProcessExe,,, Process_no_ext
bTerminateProcess(ProcessExe)
ProcessBin = %Process_no_ext%.bin
bTerminateProcess(ProcessBin)
}
; Delete settings separately from RunApplication() in case we want to write our own settings
TestsTotal++
if bContinue
{
IfExist, %A_AppData%\LibreOffice
{
FileRemoveDir, %A_AppData%\LibreOffice, 1
if ErrorLevel
TestsFailed("Unable to delete '" A_AppData "\LibreOffice'.")
else
TestsOK("")
}
else
TestsOK("")
}
; Test if can start application
RunApplication()
{
global ModuleExe
global TestName
global TestsTotal
global bContinue
global ProcessExe
TestsTotal++
if bContinue
{
IfNotExist, %ModuleExe%
TestsFailed("Can NOT find '" ModuleExe "'.")
else
{
Run, %ModuleExe%,, Max ; Start maximized
WinWaitActive, LibreOffice,,15 ; Takes a bit to load
if ErrorLevel
{
Process, Exist, %ProcessExe%
NewPID = %ErrorLevel% ; Save the value immediately since ErrorLevel is often changed.
if NewPID = 0
TestsFailed("Window 'LibreOffice' failed to appear. No '" ProcessExe "' process detected.")
else
TestsFailed("Window 'LibreOffice' failed to appear. '" ProcessExe "' process detected.")
}
else
TestsOK("")
}
}
}

View File

@ -0,0 +1,235 @@
/*
* Designed for LibreOffice 3.6.2
* 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.writer_replace
szDocument = C:\LibreOffice_Writer_test.txt
szSearchFor = Earl
szReplaceWith = Edijs
szText = Hello. My name is
; Test if can open document with LibreOffice Writer, replace some text and save changes
TestsTotal++
if bContinue
{
IfExist, %szDocument%
{
FileDelete, %szDocument%
if ErrorLevel
TestsFailed("Unable to delete existing '" szDocument "'.")
}
if bContinue
{
FileAppend, %szText% %szSearchFor%, %szDocument%
if ErrorLevel
TestsFailed("Unable to create '" szDocument "'.")
else
{
RunApplication()
if bContinue
{
IfWinNotActive, LibreOffice
TestsFailed("'LibreOffice' window is not active.")
else
{
SendInput, !fo ; Alt+F, O aka File->Open. 'WinMenuSelectItem, LibreOffice,, File, Open' fails on 2k3
WinWaitActive, Open, File &name, 3
if ErrorLevel
TestsFailed("'Open (File name)' window failed to appear.")
else
{
ControlSetText, Edit1, %szDocument%, Open, File &name
if ErrorLevel
TestsFailed("Unable to enter '" szDocument "' to 'File name' field in 'Open (File name)' window.")
else
{
ControlClick, Button2 ; Hit 'Open' button
if ErrorLevel
TestsFailed("Unable to hit 'Open' button in 'Open (File name)' window")
else
{
WinWaitClose, Open, File &name, 3
if ErrorLevel
{
TestsFailed("'Open (File name)' window failed to close.")
WinClose, Open, File &name
}
else
TestsOK("Hit File->Open, entered '" szDocument "' in 'File name' field in 'Open (File name)' window.")
}
}
}
}
}
}
}
}
TestsTotal++
if bContinue
{
SplitPath, szDocument, szFileName
WinWaitActive, %szFileName% - LibreOffice Writer,,5 ; Window caption/title is only thing we can use
if ErrorLevel
TestsFailed("'" szFileName " - LibreOffice Writer' window failed to appear.")
else
{
SendInput, ^h ; Ctrl+H aka Edit->Find & Replace. WinMenuSelectItem doesn't work here
WinWaitActive, Find & Replace,,3 ; Window caption/title is only thing we can use
if ErrorLevel
TestsFailed("'Find & Replace' window failed to appear. Ctrl+H fails?")
else
{
; Sleep, 5500 ; Let it to load
SendInput, !s ; Al+S to focus 'Search for' field in 'Find & Replace' window
SendInput, %szSearchFor%
clipboard = ; Empty the clipboard
SendInput, ^a ; Ctrl+A to select all
SendInput, ^c ; Ctrl+C to copy
ClipWait, 3
if ErrorLevel
TestsFailed("The attempt to copy text onto the clipboard failed.")
else
{
if (szSearchFor != clipboard)
TestsFailed("Unexpected clipboard text (is '" clipboard "', expected '" szSearchFor "').")
else
{
SendInput, !p ; Alt+P aka focus 'Replace with' field in 'Find & Replace' window
SendInput, %szReplaceWith% ; Put text
SendInput, !l ; Alt+L aka hit 'Replace All' button in 'Find & Replace' window
WinWaitActive, LibreOffice 3.6,,3 ; Thats all we can have to pass
if ErrorLevel
TestsFailed("'LibreOffice 3.6' window failed to appear.")
else
{
WinClose, LibreOffice 3.6
WinWaitClose,,,3
if ErrorLevel
TestsFailed("Unable to close 'LibreOffice 3.6' window.")
else
{
WinWaitActive, Find & Replace,,3
if ErrorLevel
TestsFailed("Closed 'LibreOffice 3.6' window, but 'Find & Replace' window was not activated.")
else
{
WinClose, Find & Replace
WinWaitClose,,,3
if ErrorLevel
TestsFailed("'Unable to close 'Find & Replace' window.")
else
TestsOK("Replaced '" szSearchFor "' with '" szReplaceWith "'.")
}
}
}
}
}
}
}
}
TestsTotal++
if bContinue
{
WinWaitActive, %szFileName% - LibreOffice Writer,,5
if ErrorLevel
TestsFailed("'" szFileName " - LibreOffice Writer' window was not activated.")
else
{
clipboard = ; Empty the clipboard
SendInput, ^a ; Ctrl+A to select all
SendInput, ^c ; Ctrl+C to copy
ClipWait, 3
if ErrorLevel
TestsFailed("The attempt to copy text from '" szFileName " - LibreOffice Writer' window onto the clipboard failed.")
else
{
szResult = %szText% %szReplaceWith%
if (clipboard != szResult)
TestsFailed("Text does NOT match (is '" clipboard "', expected '" szResult "').")
else
{
WinClose, %szFileName% - LibreOffice Writer
WinWaitActive, LibreOffice 3.6,,3 ; 'Do you want to save your changes?'
if ErrorLevel
TestsFailed("'LibreOffice 3.6' (save confirm) window failed to appear.")
else
{
SendInput, !s ; Alt+S aka hit 'Save' button
WinWaitClose, LibreOffice 3.6,,3
if ErrorLevel
TestsFailed("'LibreOffice 3.6' (save confirm) window failed to close despite Alt+S was sent.")
else
{
WinWaitActive, Confirm File Format,,3
if ErrorLevel
TestsFailed("'Confirm File Format' window failed to appear.")
else
{
SendInput, !u ; Alt+U aka hit 'Use Text Format' button
WinWaitClose, Confirm File Format,,3
if ErrorLevel
TestsFailed("'Confirm File Format' window failed to close despite Alt+U was sent.")
else
{
WinWaitClose, %szFileName% - LibreOffice Writer,,3
if ErrorLevel
TestsFailed("'" szFileName " - LibreOffice Writer' window failed to close.")
else
{
Process, WaitClose, %ProcessExe%, 5
if ErrorLevel ; The PID still exists
TestsFailed("'" ProcessExe "' process failed to close despite '" szFileName " - LibreOffice Writer' window being closed.")
else
{
Process, WaitClose, %ProcessBin%, 5
if ErrorLevel ; The PID still exists
TestsFailed("'" ProcessBin "' process failed to close despite '" szFileName " - LibreOffice Writer' window being closed.")
else
TestsOK("Replaced, saved, closed '" szFileName " - LibreOffice Writer' window, '" ProcessExe "' and '" ProcessBin "' closed on their own.")
}
}
}
}
}
}
}
}
}
}
TestsTotal++
if bContinue
{
FileReadLine, szSavedText, %szDocument%, 1 ; Read line 1 from saved document
if ErrorLevel <> 0
TestsFailed("Unable to read line 1 from '" szDocument "'.")
else
{
if (szResult != szSavedText)
TestsFailed("Got unexpected file content (is '" szSavedText "', should be '" szResult "').")
else
TestsOK("Read text document, content is correct.")
}
}

View File

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