Snippets
Created by
SeanB
last modified
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | External_Function WinAPI_GetCurrentProcessId "GetCurrentProcessId" Kernel32.Dll Returns Integer
External_Function WinAPI_EnumProcessModules "EnumProcessModules" Psapi.Dll Handle hProcess Address lphModule Integer cb Pointer lpcbNeeded Returns Integer
External_Function WinAPI_CloseHandle "CloseHandle" Kernel32.Dll Handle hObject Returns Integer
External_Function WinAPI_OpenProcess "OpenProcess" Kernel32.Dll DWord dwDesiredAccess Boolean bInheritHandle DWord dwProcessId Returns Handle
Define PROCESS_TERMINATE for |CI$0001
Define PROCESS_CREATE_THREAD for |CI$0002
Define PROCESS_SET_SESSIONID for |CI$0004
Define PROCESS_VM_OPERATION for |CI$0008
Define PROCESS_VM_READ for |CI$0010
Define PROCESS_VM_WRITE for |CI$0020
Define PROCESS_DUP_HANDLE for |CI$0040
Define PROCESS_CREATE_PROCESS for |CI$0080
Define PROCESS_SET_QUOTA for |CI$0100
Define PROCESS_SET_INFORMATION for |CI$0200
Define PROCESS_QUERY_INFORMATION for |CI$0400
Define PROCESS_ALL_ACCESS for (STANDARD_RIGHTS_REQUIRED ior SYNCHRONIZE ior |CI$FFFF)
External_Function FindWindowEx "FindWindowExA" user32.dll ;
Handle hWndParent ;
Handle hWndChildAfter ;
Pointer lpszClass ;
Pointer lpszWindow ;
Returns Handle
Function HandleFor Global String sSearch Returns Handle
Handle hwnd
String sData
Integer iVoid
Move (lowercase(sSearch)) to sSearch
Move (FindWindowEx(0, 0, "", "")) to hwnd
While (hwnd)
ZeroString 100 to sData
Move (GetWindowText(hwnd,(AddressOf(sData)),100)) to ivoid
Move (Lowercase(Trim(cString(sData)))) to sData
If (pos(sSearch,sData)) Begin
Function_Return hWnd
End
Move (FindWindowEx(0, hWnd, "", "")) to hwnd
Loop
Function_Return 0
End_Function
Global_Variable Integer ghlogfile
Object oSimpleLog is a cObject
Property String psPrivate.LogName
Property Boolean pisShow True
Property Boolean pisColored True
Property String psError "/e[0;31m"
Property String psMessage "/e[1;33m"
Property String psWarning "/e[0;35m"
Property String psOK "/e[0;32m"
Property String psWhite "/e[1;37m"
Property String psBlue "/e[1;34m"
Procedure Set logfile String sName
String sFolder
Get psHome of (phoWorkspace(oApplication)) to sFolder
If ((Right(sFolder,1))<>"\") Append sFolder "\"
Append sFolder sName
Set psPrivate.LogName to sFolder
End_Procedure
Function logfile Returns String
Function_Return ( psPrivate.LogName (Self))
End_Function
Procedure BaseLog String sColor String sText
Integer iCH
DateTime dtNow
Move (CurrentDateTime()) to dtNow
Move ("["+(String(dtNow)) +"] "+ sText) to sText
If ((pisColored(Self)) and (sColor<>"")) Move (sColor+sText+(psWhite(Self))) to sText
Move (Replaces("/e",sText,Character(27))) to sText
Get Seq_New_Channel to iCH
Append_Output channel iCH (logfile(Self))
Writeln channel iCH sText
Close_Output channel iCH
Send Seq_Release_Channel iCH
End_Procedure
Procedure log String sText
Send BaseLog "" sText
End_Procedure
Procedure log_error String sText
Send BaseLog (psError(Self)) sText
End_Procedure
Procedure log_ok String sText
Send BaseLog (psOK(Self)) sText
End_Procedure
Procedure log_note String sText
Send BaseLog (psBlue(Self)) sText
End_Procedure
Procedure log_yellow String stext
Send BaseLog (psMessage(Self)) sText
End_Procedure
Move (Self) to ghlogfile
End_Object
Global_Variable Integer ghTest
Object oTailTest is a cObject
Move (Self) to ghTest
Property Integer piErrorCount
Procedure DisplayError String sMessage
Set piErrorCount to ( (piErrorCount (Self))+1)
Send log_error to ghlogfile sMessage
End_Procedure
Procedure DisplayOK String sMessage
Send log_OK to ghlogfile sMessage
End_Procedure
Procedure DisplayMessage String sMessage
Send log_yellow to ghlogfile sMessage
End_Procedure
Procedure StartTesting
Set piErrorCount to 0
End_Procedure
Procedure doAssertEqual String sTest String sValue String sMessage
Move (Trim(sTest)) to sTest
Move (Trim(sMessage)) to sMessage
If (sTest<>sValue) Send DisplayError (SFormat("FAIL: "+sMessage,sTest,sValue))
If (sTest=sValue) Send DisplayOK (SFormat(sMessage,sTest,sValue))
End_Procedure
Procedure doAssertContains String sTest String sValue String sMessage
Integer iPos
String sCRLF
String sReport
Move ((Character(13))+(character(10))) to sCRLF
Move (Replaces(sCRLF,sValue," ")) to sValue
Move (Lowercase(sTest)) to sTest
Move (Lowercase(sValue)) to sValue
If ((Length(sValue))>30) Begin
Move (Pos(sTest,sValue)) to iPos
Move (iPos-10) to iPos
If (iPos<1) Move 1 to iPos
Move (Mid(sValue,30,iPos)) to sreport
If (iPos>1) Move ( "..."+sReport) to sReport
If ((iPos+30) < (Length(sValue)) ) Move (sReport+"...") to sReport
End
Else Begin
Move sValue to sReport
End
If (Pos(sTest,sValue)) Send DisplayOK (SFormat(sMessage,sTest,sReport))
Else Send DisplayError (SFormat("FAIL: "+sMessage,sTest,sReport))
End_Procedure
Procedure doAssertNotContains String sTest String sValue String sMessage
Integer iPos
String sCRLF
String sReport
Move ((Character(13))+(character(10))) to sCRLF
Move (Replaces(sCRLF,sValue," ")) to sValue
Move (Lowercase(sTest)) to sTest
Move (Lowercase(sValue)) to sValue
If ((Length(sValue))>30) Begin
Move (Pos(sTest,sValue)) to iPos
Move (iPos-10) to iPos
If (iPos<1) Move 1 to iPos
Move (Mid(sValue,30,iPos)) to sreport
If (iPos>1) Move ( "..."+sReport) to sReport
If ((iPos+30) < (Length(sValue)) ) Move (sReport+"...") to sReport
End
Else Begin
Move sValue to sReport
End
If (Pos(sTest,sValue)) Send DisplayError (SFormat("FAIL: "+sMessage,sTest,sReport))
Else Send DisplayOK (SFormat(sMessage,sTest,sReport))
End_Procedure
Procedure doAssertNotEqual String sTest String sValue String sMessage
Move (Trim(sTest)) to sTest
Move (Trim(sValue)) to sTest
Move (Trim(sMessage)) to sMessage
If (sTest=sValue) Send DisplayError (SFormat("NE-FAIL: "+sMessage,trim(sTest),trim(sValue)))
If (sTest<>sValue) Send DisplayOK (SFormat(sMessage,trim(sTest),trim(sValue)))
End_Procedure
Procedure DisplayLogFile
String sLogFile
String sProgName
String sRunProg
String sProgramPath
Get psHome of (phoWorkspace(ghoApplication)) to sProgramPath
If ((Right(sProgramPath,1))<>"\") Append sProgramPath "\"
Move (GetApplicationName(ghoApplication)) to sProgName
Move (sProgName+".log") to sLogFile
Set logfile of ghLogFile to sLogFile
Send log_note to ghLogFile sLogFile
Send log_note to ghLogFile "----------------------------"
If ((HandleFor("tail.exe"))=0) Begin
Move ("tail.exe "+'"'+(logfile(ghLogfile))+'"'+" -f") to sRunProg
Runprogram Background (sRunProg)
End
End_Procedure
Send DisplayLogFile
End_Object
Procedure AssertEqual Global String sTest String sValue String sMessage
Send doAssertEqual to ghTest sTest sValue sMessage
End_Procedure
Procedure AssertTrue Global String sValue String sMessage
Send doAssertEqual to ghTest sValue (True) sMessage
End_Procedure
Procedure AssertFalse Global String sValue String sMessage
Send doAssertEqual to ghTest sValue (False) sMessage
End_Procedure
Procedure AssertContains Global String sTest String sValue String sMessage
Send doAssertContains to ghTest sTest sValue sMessage
End_Procedure
Procedure AssertNotContains Global String sTest String sValue String sMessage
Send doAssertNotContains to ghTest sTest sValue sMessage
End_Procedure
Procedure AssertNotEqual Global String sTest String sValue String sMessage
Send doAssertNotEqual to ghTest sTest sValue sMessage
End_Procedure
Procedure TestMessage Global String sMessage
Send DisplayMessage to ghTest sMessage
End_Procedure
Procedure LogErrorMessage Global String sMessage String s1 String s2 String s3 String s4 String s5
String sParam
Integer iArg
For iArg from 2 to Num_Arguments
MoveStr iArg& to sParam
Move (Replaces("%"+String(iArg-1),sMessage,sParam)) to sMessage
Loop
Send log_error to ghLogFile sMessage
End_Procedure
Procedure OKMessage Global String sMessage String s1 String s2 String s3 String s4 String s5 String s6 string s7 String s8
String sParam
Integer iArg
For iArg from 2 to Num_Arguments
MoveStr iArg& to sParam
Move (Replaces("%"+String(iArg-1),sMessage,sParam)) to sMessage
Loop
Send log_ok to ghLogFile sMessage
End_Procedure
Procedure NoteMessage Global String sMessage
Send log_note to ghLogFile sMessage
End_Procedure
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.