module test_exceptionHandler
easifemBase
easifemClasses
implicit none
contains
subroutine test0
TYPE( exceptionHandler_ ) :: obj
CALL obj%setQuietMode(.TRUE.)
CALL obj%setLogFileUnit(23)
OPEN(UNIT=obj%getLogFileUnit(),FILE='Exception.log', &
ACCESS='SEQUENTIAL',FORM='FORMATTED')
CALL obj%setLogActive(.TRUE.)
CALL display(obj%isLogActive(), "isLogActive=")
CALL obj%raiseInformation('Test information')
CALL obj%raiseWarning('Test warning')
CALL obj%raiseDebug('Test debug')
CALL obj%raiseError('Test error')
end
subroutine test1
WRITE(*,*) 'TESTING PARAMETERS'
WRITE(*,*) ' Passed: EXCEPTION_OK = ',EXCEPTION_OK
WRITE(*,*) ' Passed: EXCEPTION_INFORMATION = ',EXCEPTION_INFORMATION
WRITE(*,*) ' Passed: EXCEPTION_WARNING = ',EXCEPTION_WARNING
WRITE(*,*) ' Passed: EXCEPTION_DEBUG = ',EXCEPTION_DEBUG
WRITE(*,*) ' Passed: EXCEPTION_ERROR = ',EXCEPTION_ERROR
WRITE(*,*) ' Passed: EXCEPTION_FATAL_ERROR = ',EXCEPTION_FATAL_ERROR
WRITE(*,*) ' Passed: EXCEPTION_SIZE = ',EXCEPTION_SIZE
WRITE(*,*) ' Passed: EXCEPTION_MAX_MESG_LENGTH = ', EXCEPTION_MAX_MESG_LENGTH
end
subroutine test2
type( exceptionHandler_ ) :: obj
CALL Display( obj%isQuietMode(),'%isQuietMode() = ' )
CALL Display( obj%isQuietMode(EXCEPTION_INFORMATION),'%isQuietMode(INFO)=')
CALL Display( obj%isQuietMode(EXCEPTION_WARNING),'%isQuietMode(WARNING)=')
CALL Display( obj%isQuietMode(EXCEPTION_DEBUG),'%isQuietMode(DEBUG)=')
CALL Display( obj%isQuietMode(EXCEPTION_ERROR),'%isQuietMode(ERROR)=')
CALL Display( obj%isQuietMode(EXCEPTION_FATAL_ERROR),'%isQuietMode(FATAL_ERROR)=')
CALL Display( obj%isQuietMode(EXCEPTION_OK),'%isQuietMode(OK) =')
CALL Display(obj%isStopOnError(),'%isStopOnError =')
CALL Display(ALL(obj%getCounterAll() == 0),'getCounterAll() =')
CALL Display(obj%getCounter(EXCEPTION_INFORMATION) == 0,'INFO =')
CALL Display(obj%getCounter(EXCEPTION_WARNING) == 0,'WARN =')
CALL Display(obj%getCounter(EXCEPTION_DEBUG) == 0,'DEBUG =')
CALL Display(obj%getCounter(EXCEPTION_ERROR) == 0,'ERROR =')
CALL Display(obj%getCounter(EXCEPTION_FATAL_ERROR) == 0,'FATAL_ERROR =')
CALL Display(obj%getCounter(EXCEPTION_OK) == -1,'OK =')
CALL Display(obj%getLastMessage() == '','%getLastMessage() = ' )
CALL Display(obj%getLogFileUnit() == 666,'%getLogFileUnit = ')
CALL Display(.NOT.obj%isLogActive(),'%isLogActive = ')
CALL obj%setQuietMode(.TRUE.)
CALL Display(obj%isQuietMode(),'%setQuietMode(T)=')
CALL Display(obj%isQuietMode(EXCEPTION_INFORMATION),'%setQuietMode(T) INFO =')
CALL Display(obj%isQuietMode(EXCEPTION_WARNING),'%setQuietMode(T) WARN=')
CALL Display(obj%isQuietMode(EXCEPTION_DEBUG),'%setQuietMode(T) DEBUG=')
CALL Display(obj%isQuietMode(EXCEPTION_ERROR),'%setQuietMode(T) ERROR=')
CALL Display(.NOT.obj%isQuietMode(EXCEPTION_FATAL_ERROR),'%setQuietMode(T) FATAL=')
CALL obj%setQuietMode(.FALSE.)
CALL Display(.NOT.obj%isQuietMode(),'%setQuietMode(F)=')
CALL Display(.NOT.obj%isQuietMode(EXCEPTION_INFORMATION),'%setQuietMode(F) INFO =')
CALL Display(.NOT.obj%isQuietMode(EXCEPTION_WARNING),'%setQuietMode(F) WARNING =')
CALL Display(.NOT.obj%isQuietMode(EXCEPTION_DEBUG),'%setQuietMode(F) DEBUG=')
CALL Display(.NOT.obj%isQuietMode(EXCEPTION_ERROR),'%setQuietMode(F) ERROR=')
CALL Display(.NOT.obj%isQuietMode(EXCEPTION_FATAL_ERROR),'%setQuietMode(F) FATAL=')
CALL obj%setQuietMode(EXCEPTION_INFORMATION,.TRUE.)
CALL Display(.NOT.obj%isQuietMode(),'%setQuietMode(INFO,T)=')
CALL Display(obj%isQuietMode(EXCEPTION_INFORMATION),'%setQuietMode(INFO,T) INFO=')
CALL obj%setQuietMode(EXCEPTION_WARNING,.TRUE.)
CALL Display(.NOT.obj%isQuietMode(),'%setQuietMode(WARN,T)=')
CALL Display(obj%isQuietMode(EXCEPTION_WARNING),'%setQuietMode(WARN,T) WARN=')
CALL obj%setQuietMode(EXCEPTION_DEBUG,.FALSE.)
CALL Display(.NOT.obj%isQuietMode(),'%setQuietMode(DEBUG,F)=')
CALL Display(.NOT.obj%isQuietMode(EXCEPTION_DEBUG),'%setQuietMode(DEBUG,F) DEBUG=')
CALL obj%setQuietMode(EXCEPTION_ERROR,.TRUE.)
CALL Display(.NOT.obj%isQuietMode(),'%setQuietMode(ERROR,T)=')
CALL Display(obj%isQuietMode(EXCEPTION_ERROR),'%setQuietMode(ERROR,T) ERROR=')
CALL obj%setQuietMode(EXCEPTION_FATAL_ERROR,.TRUE.)
CALL Display(.NOT.obj%isQuietMode(),'%setQuietMode(FATAL,T)=')
CALL Display(.NOT.obj%isQuietMode(EXCEPTION_FATAL_ERROR),'%setQuietMode(FATAL,T) FATAL=')
CALL obj%setQuietMode(EXCEPTION_OK,.FALSE.)
CALL Display(.NOT.obj%isQuietMode(),'%setQuietMode(OK,T)=')
CALL Display(.NOT.obj%isQuietMode(EXCEPTION_OK),'%setQuietMode(OK,T) OK=')
CALL obj%setQuietMode((/.FALSE.,.FALSE.,.FALSE.,.FALSE./))
CALL obj%setVerboseMode(.TRUE.)
CALL Display(obj%isVerboseMode(),'%setVerboseMode(T)=')
CALL Display(obj%isVerboseMode(EXCEPTION_INFORMATION),'%setVerboseMode(T) INFO=')
CALL Display(obj%isVerboseMode(EXCEPTION_WARNING),'%setVerboseMode(T) WARN=')
CALL Display(obj%isVerboseMode(EXCEPTION_DEBUG),'%setVerboseMode(T) DEBUG=')
CALL Display(obj%isVerboseMode(EXCEPTION_ERROR),'%setVerboseMode(T) ERROR=')
CALL Display(.NOT.obj%isVerboseMode(EXCEPTION_FATAL_ERROR),'%setVerboseMode(T) FATAL=')
CALL obj%setVerboseMode(.FALSE.)
CALL Display(.NOT.obj%isVerboseMode(),'%setVerboseMode(F)=')
CALL Display(.NOT.obj%isVerboseMode(EXCEPTION_INFORMATION),'%setVerboseMode(F) INFO=')
CALL Display(.NOT.obj%isVerboseMode(EXCEPTION_WARNING),'%setVerboseMode(F) WARNING=')
CALL Display(.NOT.obj%isVerboseMode(EXCEPTION_DEBUG),'%setVerboseMode(F) DEBUG=')
CALL Display(.NOT.obj%isVerboseMode(EXCEPTION_ERROR),'%setVerboseMode(F) ERROR=')
CALL Display(.NOT.obj%isVerboseMode(EXCEPTION_FATAL_ERROR),'%setVerboseMode(F) FATAL=')
CALL obj%setVerboseMode(EXCEPTION_INFORMATION,.TRUE.)
CALL Display(.NOT.obj%isVerboseMode(),'%setVerboseMode(INFO,T)=')
CALL Display(obj%isVerboseMode(EXCEPTION_INFORMATION),'%setVerboseMode(INFO,T) INFO=')
CALL obj%setVerboseMode(EXCEPTION_WARNING,.TRUE.)
CALL Display(.NOT.obj%isVerboseMode(),'%setVerboseMode(WARN,T)=')
CALL Display(obj%isVerboseMode(EXCEPTION_WARNING),'%setVerboseMode(WARN,T) WARN=')
CALL obj%setVerboseMode(EXCEPTION_DEBUG,.FALSE.)
CALL Display(.NOT.obj%isVerboseMode(),'%setVerboseMode(DEBUG,F)=')
CALL Display(.NOT.obj%isVerboseMode(EXCEPTION_DEBUG),'%setVerboseMode(DEBUG,F) DEBUG=')
CALL obj%setVerboseMode(EXCEPTION_ERROR,.TRUE.)
CALL Display(.NOT.obj%isVerboseMode(),'%setVerboseMode(ERROR,T)=')
CALL Display(obj%isVerboseMode(EXCEPTION_ERROR),'%setVerboseMode(ERROR,T) ERROR=')
CALL obj%setVerboseMode(EXCEPTION_FATAL_ERROR,.TRUE.)
CALL Display(.NOT.obj%isVerboseMode(),'%setVerboseMode(FATAL,T)=')
CALL Display(.NOT.obj%isVerboseMode(EXCEPTION_FATAL_ERROR),'%setVerboseMode(FATAL,T) FATAL=')
CALL obj%setVerboseMode(EXCEPTION_OK,.FALSE.)
CALL Display(.NOT.obj%isVerboseMode(),'%setVerboseMode(OK,T)=')
CALL Display(.NOT.obj%isVerboseMode(EXCEPTION_OK),'%setVerboseMode(OK,T) OK=')
CALL obj%setVerboseMode((/.TRUE.,.TRUE.,.TRUE.,.TRUE./))
end
subroutine test3
type( exceptionHandler_ ) :: obj
CHARACTER( LEN = EXCEPTION_MAX_MESG_LENGTH ) :: mesg
CALL obj%raiseInformation('Test information')
CALL Display(ALL(obj%getCounterAll() == (/1,0,0,0,0/)),'%counterall=')
CALL Display(obj%getCounter(EXCEPTION_INFORMATION) == 1,'%counter(INFO)=')
mesg=' - EXCEPTION_INFORMATION: Test information'
CALL Display( obj%getLastMessage(), "last mesg=")
CALL Display(obj%getLastMessage() == TRIM(mesg),'mesg=')
CALL obj%raiseWarning('Test warning')
CALL Display(ALL(obj%getCounterAll() == (/1,1,0,0,0/)),'%counterall=')
CALL Display(obj%getCounter(EXCEPTION_WARNING) == 1,'%counter(WARN)=')
mesg='#### EXCEPTION_WARNING #### - Test warning'
CALL Display( obj%getLastMessage(), "last mesg=")
CALL Display(obj%getLastMessage() == TRIM(mesg),'mesg=')
CALL obj%raiseDebug('Test debug')
CALL Display(ALL(obj%getCounterAll() == (/1,1,1,0,0/)),'%raiseDebug=')
CALL Display(obj%getCounter(EXCEPTION_DEBUG) == 1,'%counter(DEBUG)=')
mesg='#### EXCEPTION_DEBUG_MESG #### - Test debug'
CALL Display(obj%getLastMessage() == TRIM(mesg),'mesg=')
CALL obj%setStopOnError(.FALSE.)
CALL Display(.NOT.obj%isStopOnError(),'setStopOnError(F)=')
CALL obj%setStopOnError(.TRUE.)
CALL Display(obj%isStopOnError(),'setStopOnError(T)=')
CALL obj%setStopOnError(.FALSE.)
CALL Display(.NOT.obj%isStopOnError(),'setStopOnError(F)=')
CALL obj%raiseError('Test error')
CALL Display(ALL(obj%getCounterAll() == (/1,1,1,1,0/)),'%raiseError=')
CALL Display(obj%getCounter(EXCEPTION_ERROR) == 1,'%counter(ERROR)=')
mesg='#### EXCEPTION_ERROR #### - Test error'
CALL Display(obj%getLastMessage() == TRIM(mesg),'mesg=')
CALL obj%initCounter()
CALL Display(ALL(obj%getCounterAll() == 0),'counterAll=')
CALL Display(obj%getCounter(EXCEPTION_INFORMATION) == 0,'%counter(INFO)=')
CALL Display(obj%getCounter(EXCEPTION_WARNING) == 0,'%counter(WARN)=')
CALL Display(obj%getCounter(EXCEPTION_DEBUG) == 0,'%counter(DEBUG)=')
CALL Display(obj%getCounter(EXCEPTION_ERROR) == 0,'%counter(ERROR)=')
CALL Display(obj%getCounter(EXCEPTION_FATAL_ERROR) == 0,'%counter(FATAL)=')
CALL Display(obj%getLastMessage() == '','mesg=')
CALL obj%raiseWarning('Very '//&
'long '//&
'message '//&
'exceeding '//&
'size '//&
'of '//&
'character '//&
'length '//&
'limit '//&
'of '//&
'512.....The remainder of this message will be truncated')
end
subroutine test4
type( exceptionHandler_ ) :: obj
CALL Display( "test04")
CALL EqualLine()
CALL obj%setQuietMode(.TRUE.)
CALL obj%setLogFileUnit(stdout)
CALL obj%setLogFileUnit(stderr)
CALL obj%setLogFileUnit(-1)
CALL Display(obj%getCounter(EXCEPTION_WARNING),'%counter(WARN)=')
CALL Display(TRIM(obj%getLastMessage()),'%getLastMessage=')
CALL obj%setLogFileUnit(23)
CALL Display(obj%getLogFileUnit() == 23,'setLogFileUnit(23)=')
CALL obj%setQuietMode(.FALSE.)
CALL Display(.NOT.obj%isLogActive(),'%isLogActive=')
CALL obj%setLogActive(.TRUE.)
CALL Display(.NOT.obj%isLogActive(),'%setLogActive=')
CALL obj%setLogActive(.FALSE.)
CALL Display(.NOT.obj%isLogActive(),'%setLogActive=')
OPEN(UNIT=obj%getLogFileUnit(),FILE='Exception.log', &
ACCESS='SEQUENTIAL', FORM='FORMATTED')
CALL obj%setLogActive(.TRUE.)
CALL Display(obj%isLogActive(),'%setLogActive ')
CALL obj%setLogActive(.FALSE.)
CALL Display(.NOT.obj%isLogActive(),'%setLogActive ')
CALL obj%setLogActive(.TRUE.)
CALL obj%setQuietMode(.TRUE.)
CALL obj%setStopOnError(.FALSE.)
CALL obj%raiseInformation('Test information')
CALL obj%raiseWarning('Test warning')
CALL obj%raiseDebug('Test debug')
CALL obj%raiseError('Test error')
CLOSE(obj%getLogFileUnit())
end
end module
program main
test_exceptionHandler
implicit none
call test0
end program main