forked from rizonesoft/Notepad3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestAhkNotepad3.ahk
146 lines (130 loc) · 4.44 KB
/
TestAhkNotepad3.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
; =============================================================================
; 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
; =============================================================================
stdout.WriteLine("Run " . v_NP3Name . ": " . v_NP3TestDir . "\" . v_NP3Name . ".exe '" . v_NP3TestDir . "\" . v_NP3IniFile . ".")
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, 1000
GoSub CHECK_WIN_TITLE
Sleep, 1000
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%
stdout.WriteLine(v_NP3Name . "'s Title is: " . v_NP3Title)
IfNotInString, v_NP3Title, %v_NP3Name%
{
v_ExitCode := 3
stdout.WriteLine("*** ERROR: " . v_NP3Name . " missing in Title: ")
}
IfNotInString, v_NP3Title, %v_NP3IniFile%
{
v_ExitCode := 3
stdout.WriteLine("*** ERROR: " . v_NP3IniFile . " missing in Title: ")
}
IfNotInString, v_NP3Title, %v_NP3TestDir%
{
v_ExitCode := 3
stdout.WriteLine("*** ERROR: " . v_NP3TestDir . " missing in Title: ")
}
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
; =============================================================================