' SimpleTestCase.ab

#console

Dim hStdOut = _System_hConsoleOut

Function GetTempDirectory() As String
	Return System.IO.Path.GetDirectoryName( System.Windows.Forms.Application.ExecutablePath ) + "\temp\"
'	Return System.IO.Path.GetTempPath()
End Function

Sub Initialize()
	' 初期化関数

	' 一時ディレクトリを空にしておく
	Dim tempDir = GetTempDirectory()
	If System.IO.Directory.Exists( tempDir ) Then
		Try
			' 存在するときは一旦消す
			System.IO.Directory.Delete( tempDir, True )
		Catch e As System.IO.IOException
			OutputDebugString(e.ToString)
		End Try
	End If
	System.IO.Directory.CreateDirectory( tempDir )
End Sub

Initialize()

Dim csbi As CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo(hStdOut, csbi)

#include "SimpleTestCase.idx"

Dim failureCount = 0 As DWord

Sub UnitTest( msg As String, isSuccessful As Boolean )
	Dim resultStr = Nothing As String
	If isSuccessful Then
		resultStr = Ex"OK      "
	Else
		resultStr = Ex"FAILURE!"
		failureCount++
	End If

	If Not isSuccessful Then
		SetConsoleTextAttribute(hStdOut, BACKGROUND_RED Or BACKGROUND_GREEN Or BACKGROUND_INTENSITY)
	End If

	Print resultStr; msg

	If Not isSuccessful Then
		SetConsoleTextAttribute(hStdOut, csbi.wAttributes)
	End If
End Sub

Sub UnitTest( msg As String, test As String, expectation As String)
	If test = expectation Then
		Print Ex"OK      "; msg
	Else
		SetConsoleTextAttribute(hStdOut, BACKGROUND_RED Or BACKGROUND_GREEN Or BACKGROUND_INTENSITY)
		Print Ex"FAILURE!"; msg
		Print "  期待 = '" + expectation + "'" + " 結果 = '" + test + "'"
		SetConsoleTextAttribute(hStdOut, csbi.wAttributes)
		failureCount++
	End If
End Sub

Function GetExclusiveTempDirPath( testCaseName As String ) As String
	Dim tempDir = GetTempDirectory()
	Dim exclusiveTempDirPath = tempDir + testCaseName

	If Not System.IO.Directory.Exists( exclusiveTempDirPath ) Then
		' 無かったら作る
		System.IO.Directory.CreateDirectory( exclusiveTempDirPath )
	End If

	Return exclusiveTempDirPath
End Function

Print "失敗"; failureCount; "個"
Print "Please Enter key"
System.Console.ReadLine()
