⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hutils.tpl

📁 在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
💻 TPL
📖 第 1 页 / 共 2 页
字号:
ENDP

PROC hMenu%:
	hSendKey&:(KKeyMenu32&)
ENDP

PROC hEnter%:
	hSendKey&:(KKeyEnter%)
ENDP

PROC hDown%:
	hSendKey&:(KKeyDownArrow32&)
ENDP

PROC hUp%:
	hSendKey&:(KKeyUpArrow32&)
ENDP

PROC hRight%:
	hSendKey&:(KKeyRightArrow32&)
ENDP

PROC hLeft%:
	hSendKey&:(KKeyLeftArrow32&)
ENDP


PROC hPageDown%:
	hSendKey&:(KKeyPageDown32&)
ENDP

PROC hPageUp%:
	hSendKey&:(KKeyPageUp32&)
ENDP

PROC hPageRight%:
	hSendKey&:(KKeyPageRight32&)
ENDP

PROC hPageLeft%:
	hSendKey&:(KKeyPageLeft32&)
ENDP



PROC hHarnessSetForeground:
	SySetForeground:
ENDP

PROC hHarnessSetBackground:
	SySetBackground:
ENDP

CONST K2GrayBlackMode%=-1

PROC hPeekLine&:(ax%,ay%,aLength%)
	LOCAL d%(999)
	LOCAL total&, mask&, elem&
	LOCAL word%, oddbits%, flash%
	
	gPEEKLINE gIDENTITY,ax%,ay%,d%(),aLength%,K2GrayBlackMode%
	word%=aLength%/16
	REM Check the flash bits at the end...
	oddbits%=alength%-(word%*16)
	IF oddbits%
		flash%=d%(word%+1)
		mask&=&2**oddbits%-1
		flash%=flash% AND mask&
		total&=flash%
	ENDIF

	REM And the main body...
	WHILE word%
		elem&=d%(word%)
		if elem&<0
			elem&=elem&+65536
		endif
		total&=total&+elem&
		word%=word%-1
	ENDWH
	RETURN total&
ENDP

REM Formatting...
PROC hBIN$:(aValue&)
	REM Like HEX$ but different.
	LOCAL binary$(32),add$(1),value&,test&,append%
	append%=KFalse%
	value&=avalue&
	IF value& AND &80000000
		binary$="1" :append%=KTrue%
	ENDIF
	test&=&40000000
	DO
		IF value& AND test&
			add$="1" :append%=KTrue%
		ELSE
			add$="0"
		ENDIF
		IF append%
			binary$=binary$+add$
		ENDIF
		test&=test&/2
	UNTIL test&=0
	IF NOT append%
		binary$="0"
	ENDIF
	RETURN binary$
ENDP


REM Private functions


PROC _hPreModuleCheck%:
	REM Can't think of any just yet...
ENDP


PROC _hPostModuleCheck%:
	_hCheckDrawables%:
	_hCheckScreen%:
ENDP


PROC _hPreTestCheck%:
ENDP


PROC _hPostTestCheck%:
ENDP


PROC _hCheckDrawables%:
	EXTERNAL _hgWidth%,_hgHeight%
	LOCAL i%,err%
	i%=64
	DO
		TRAP gUSE i%
		IF ERR
			err%=err%+1
		ELSE
			IF i%=1 REM default window.
				IF gWIDTH<>_hgWidth% OR gHEIGHT<>_hgHeight%
					hLog%:(KhLogAlways%, "Bad size default window. Width="+GEN$(gwidth,4)+",height="+GEN$(gheight,4))
					gSETWIN 0,0,_hgWidth%,_hgHeight%
				ENDIF
			ELSE
				rem get info
				hLog%:(KhLogAlways%, "Stale window. Id%="+GEN$(i%,2)+",gwidth="+GEN$(gwidth,4)+",gheight="+GEN$(gheight,4))
				gCLOSE i%
			ENDIF
		ENDIF
		i%=i%-1
	UNTIL i%=0
	REM Should be 63 errors, as all but one of the 64 drawables are closed.
	IF err%<>63
		RAISE 10000
	ENDIF
ENDP


PROC _hCheckScreen%:
	REM Check screen details:
	REM  mode etc.
	LOCAL c&(8)
	gUSE 1
	gCOLORINFO c&()
	hLog%:(KhLogAlways%,"Checking windows.")
	IF c&(1)<>KDisplayModeColor4K%
		hLog%:(KhLogAlways%,"Bad color depth.")
		RAISE 5000
	ENDIF
ENDP


PROC _hDoLog%:(aData$)
	REM Private fn to perform the log. Returns error value.
	GLOBAL _HLogHandle%
	LOCAL data$(KMaxStringLen%)
	LOCAL ret%

	ret%=_hOpenLog%:
	IF ret%<KErrNone%
		_hException:("Error: Unable to open file log.","Log open error='"+ERR$(ret%)+"'", "Test harness will now stop.")
		STOP
	ENDIF

	data$=aData$
	ret%=IOWRITE(_hLogHandle%,ADDR(data$)+1+KOplAlignment%,LEN(data$))
	REM report any error.
	IF ret%<KErrNone%
		_hException:("Error: Unable to write to file log.","Log write error='"+ERR$(ret%)+"'", "Test harness will now stop.")
		STOP
	ENDIF

	ret%=IOCLOSE(_HLogHandle%)
	IF ret%<KErrNone%
		REM RAISE ret%
		_hException:("Error: Unable to close file log.","Log close error='"+ERR$(ret%)+"'", "Test harness will now stop.")
		STOP
	ENDIF
	RETURN ret%
ENDP

PROC _hException:(a1$,a2$,a3$)
	REM !!TODO Use a dialog for this for now...
	dINIT "OPL TEST HARNESS EXCEPTION"
	dTEXT "",a1$
	dTEXT "",a2$
	dTEXT "",a3$
	DIALOG
ENDP

CONST KhMaxFailCount%=9 REM Attempts at opening file.

PROC _hOpenLog%:
	EXTERNAL _hLogHandle%
	LOCAL mode%,ret%
	LOCAL failCount%

	IF EXIST(KhLogName$)
		REM Append to any existing log.
		mode%=KIoOpenModeAppend% OR KIoOpenFormatText% OR KIoOpenAccessUpdate%
	ELSE
		mode%=KIoOpenModeCreate% OR KIoOpenFormatText% OR KIoOpenAccessUpdate%
	ENDIF

	DO
		ret%=IOOPEN(_hLogHandle%,KhLogName$,mode%)
		IF ret%>=KErrNone%
			BREAK REM Complete.
		ENDIF
		REM May have a 'KErrInUse%' error.
		failCount%=failCount%+1
		REM BEEP 1,100
		IF failCount%>KhMaxFailCount%
			_hLogHandle%=0
			BREAK REM Let the _hDoLog%: handle the error.
		ENDIF
		PAUSE 1+RND*7 REM Back off a little.
	UNTIL 0
	RETURN ret%
ENDP


PROC _hLogPrepareToUse%:(aUserFlag%)
	REM Prepares the log file. Returns error value.
	LOCAL ret%
	
	REM If logging only, keep the log as empty as possible.
	IF (aUserFlag% AND KhUserLogHeaders%)=0
		RETURN ret%
	ENDIF

	ret%=hLog%:(KhLogAlways%,"Logging start at "+DATIM$)
	IF ret%<KErrNone%
		dINIT "Unable to use log file"
		dTEXT "","Press any key"
		DIALOG
	ENDIF
	RETURN ret%
ENDP


PROC _hLogPrepareToStop:(aUserFlag%)
	LOCAL ret%,total%
	IF (aUserFlag% AND KhUserLogHeaders%)=0
		RETURN
	ENDIF
	hLog%:(KhLogAlways%,"Logging stop at "+DATIM$)
	total%=hTestNumber%:
	REM Log might be closed from non-test app.
	IF total%
		hLog%:(KhLogAlways%,GEN$(total%,5)+" tests run, "+GEN$(_hErrorCount%:,5)+" errors.")
	ENDIF
	hLog%:(KhLogAlways%,"---")
ENDP



PROC _hTestPath$:(aPath$)
	EXTERNAL _hTestRoot$
	LOCAL off%(6),p$(255)
	p$=PARSE$(aPath$,"",off%())
	p$=MID$(p$,off%(KParseAOffPath%),off%(KParseAOffFilename%)-off%(KParseAOffPath%))
	p$=RIGHT$(p$,LEN(p$)-LEN(_hTestRoot$)+2)
	RETURN p$
ENDP


PROC _hSetTestProcDesc%:(aName$)
	EXTERNAL _hTestProcDesc$
	_hTestProcDesc$=aName$
ENDP


PROC _hDescendTree%:(aPath$)
	EXTERNAL _hErrorCount%
	LOCAL prev$(255)
	LOCAL branch$(255)
	
	LOCAL dummyc%,curdep%

	prev$=aPath$+"\"
	ONERR ErrorHandlerDescend::
	branch$=Dir$(prev$)
rem	ONERR OFF

	rem probably a subdirectory name!
rem	_hPush%:
rem	hSetTestDesc%:(_hDirname$:(branch$))
	
	curdep%=0
	WHILE branch$<>""
		ONERR EHContinue::
		_hDescendTree%:(branch$)
		GOTO Skippy::
		
EHContinue::
		ONERR OFF
		rem PRINT "DEBUG: error in descendTree looper."
		
Skippy::
		REM Do peers, by restoring dir state.
		DIR$(prev$)
		dummyc%=0
		WHILE dummyc%<curdep%
			DIR$("")
			dummyc%=dummyc%+1
		ENDWH
		curdep%=curdep%+1
		branch$=DIR$("")
	ENDWH
rem	_hPop%:
	RETURN

ErrorHandlerDescend::
	ONERR OFF
	IF ERR<>KErrDir%
		hLog%:(KhLogAlways%, _hLogErrorFormat$:(ERR,ERRX$))
		_hErrorCount%=_hErrorCount%+1
		rem RAISE ERR
		RETURN
	ENDIF
	IF _hFileIsOpo%:(aPath$)
		_hFileLaunch%:(aPath$)
	ENDIF
ENDP


PROC _hFileIsOpo%:(aPath$)
	LOCAL extn$(4)
	IF LEN(aPath$)<5
		RETURN KFalse%
	ENDIF
	IF LOWER$(RIGHT$(aPath$,4))=".opo"
		RETURN KTrue%
	ENDIF
	RETURN KFalse%
ENDP



PROC _hFileLaunch%:(aOpofilename$)
	EXTERNAL _hErrorCount%
	EXTERNAL _hDebugMode%
	LOCAL procname$(KMaxStringLen%)
	procname$=_hFilename$:(aOpofilename$)
	LOADM aOpofilename$
	hLog%:(KhLogLow%,"Launching "+aOpofilename$+" using "+procname$+_KhLogProcSep$)

	REM Keep the test details.
	_hSetTestFileDesc%:(_hTestPath$:(aOpoFilename$)+procname$)
	_hSetTestProcDesc%:(procname$+_KhLogProcSep$)
	ONERR ERLaunch::

	IF _hDebugMode%
		_hPreModuleCheck%:
	ENDIF
	@(procname$):
	IF _hDebugMode%
		_hPostModuleCheck%:
	ENDIF

	GOTO Skippy::
ERLaunch::
	ONERR OFF
	hLog%:(KhLogAlways%, "!!! ERROR: test "+GEN$(hTestNumber%:,6)+" '"+hTestDesc$:+"'")
	hLog%:(KhLogAlways%, _hLogErrorFormat$:(ERR,ERRX$))
	_hErrorCount%=_hErrorCount%+1
Skippy::
	UNLOADM aOpofilename$
ENDP


PROC _hDirName$:(afile$)
	REM Just the folder name of the file, no other path details.
	LOCAL off%(6), p$(255), rel$(255)
	LOCAL len%,i%
	p$=PARSE$(afile$,rel$,off%())
	p$=MID$(p$,off%(KParseAOffPath%),off%(KParseAOffFilename%)-off%(KParseAOffPath%))
	len%=LEN(p$)
	REM Minimum name is "\a\"
	IF len%<3 :RETURN p$ :ENDIF
	
	REM Now start at last char, not the trailing slash.
	i%=len%-1
	DO
		IF MID$(p$,i%,1)="\"
			RETURN MID$(p$,i%+1,len%-i%)
		ENDIF
		i%=i%-1
	UNTIL i%=0
	REM Give up here.
	RETURN p$
ENDP


PROC _hFilename$:(afile$)
	REM Return filename without extension.
	LOCAL off%(6), p$(255)
	p$=PARSE$(afile$,"",off%())
	RETURN MID$(p$,off%(KParseAOffFilename%),off%(KParseAOffExt%)-off%(KParseAOffFilename%))
ENDP


PROC _hFilenameExt$:(aFile$)
	REM Returns filename with extension.
	LOCAL o%(6)
	PARSE$(aFile$,"",o%())
	RETURN MID$(aFile$, o%(KParseAOffFilename%), o%(KParseAOffFilename%)-o%(KParseAOffPath%)+1)
ENDP


PROC _hBase$:(aFile$)
	REM Returns full pathname of folder.
	LOCAL o%(6)
	PARSE$(aFile$,"",o%())
	RETURN MID$(aFile$, 1, o%(KParseAOffFilename%)-1)
ENDP


PROC _hSetTestFileDesc%:(aPath$)
	EXTERNAL _hTestFileDesc$
	_hTestFileDesc$=aPath$
ENDP


PROC _hErrorCount%:
	EXTERNAL _hErrorCount%
	RETURN _hErrorCount%
ENDP


PROC _hInit:
	REM Initialise the harness utils.
	EXTERNAL hLogThreshold%
	EXTERNAL hCallVerbose%,_hDryRunOnly%
	REM Verbose controls the level at which calls are logged.
	REM Currently, all test calls are logged; this is the same as
	REM the RTest class in C++.
	hLogThreshold%=KhLogAlways%
	hCallVerbose%=KhLogAlways%
	_hDryRunOnly%=KFalse%
ENDP


PROC _hLogErrorFormat$:(aErr%,aErr$)
	LOCAL formattedErr$(KMaxStringLen%)
	IF aErr%=KErrNoProc%
		formattedErr$=_hlogErrorProcname$:(aErr$)
	ELSE
		formattedErr$=aErr$
	ENDIF
	RETURN "Error: "+ERR$(aErr%)+" ("+formattedErr$+")"
ENDP


PROC _hLogErrorProcname$:(aErr$)
	LOCAL len%,i%
	IF LOC(aErr$,",")=0
		REM No comma here (unusual!) so give up.
		RETURN aErr$
	ENDIF

	REM Start from end and scan backwards for last comma
	len%=LEN(aErr$)
	i%=len%
	
	WHILE i%>0
		IF MID$(aErr$,i%,1)=","
			RETURN MID$(aErr$,i%+1,len%-i%+1)
		ENDIF
		i%=i%-1
	ENDWH
	rem never get here.
	RETURN aErr$
ENDP


PROC _hLogLevelText$:(aLevel%)
	IF aLevel%=KhLogLow% :RETURN "Low"
	ELSEIF aLevel%=KhLogMedium% :RETURN "Medium"
	ELSEIF aLevel%=KhLogHigh% :RETURN "High"
	ELSE RETURN "Always"
	ENDIF
ENDP


REM End of hUtils.tpl

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -