#!/bin/sh

#The key is the test binary name, and the value is the list of arguments to
#use with the given binary. Each argument is a testcase to execute.

#These test cases were determined by running the actual test binary
#which lists all available test cases. Couldn't find a way to just simply
#run all. Also, BusyBox seems to have no associative array support, so
#plain variables are used with eval.

TestAsn="TestAsn1Module TestAsn1Encoder TestAsn1Decoder TestAsn1Encode TestAsn1Decode TestAsn1String \
    TestAsn1Integer TestAsn1Compare TestAsn1BerEnc TestAsn1BerDec TestAsn1DerEnc TestAsn1DerDec"
TestClient="TestClientRdpFile TestClientChannels TestClientCmdLine"
TestClipboard="TestClipboardFormats"
TestCommon="TestCommonAssistance"
TestCore="TestVersion TestSettings"
TestCredUI="TestCredUIParseUserName TestCredUIConfirmCredentials TestCredUIPromptForCredentials TestCredUICmdLinePromptForCredentials"
TestCrt="TestTypes TestFormatSpecifiers TestAlignment TestString TestUnicodeConversion"
TestCrypto="TestCryptoHash TestCryptoRand TestCryptoCipher TestCryptoProtectData TestCryptoProtectMemory TestCryptoCertEnumCertificatesInStore"
TestDsParse="TestDsMakeSpn TestDsCrackNames"
TestEnvironment="TestEnvironmentGetEnvironmentStrings TestEnvironmentSetEnvironmentVariable TestEnvironmentMergeEnvironmentStrings TestEnvironmentGetSetEB"
TestError="TestErrorSetLastError"
TestFile="TestFileCreateFile TestFileDeleteFile TestFileReadFile TestSetFileAttributes TestFileWriteFile \
    TestFilePatternMatch TestFileFindFirstFile TestFileFindFirstFileEx TestFileFindNextFile TestFileGetStdHandle"
TestFreeRDPCodec="TestFreeRDPRegion TestFreeRDPCodecMppc TestFreeRDPCodecNCrush TestFreeRDPCodecXCrush \
    TestFreeRDPCodecZGfx TestFreeRDPCodecPlanar TestFreeRDPCodecClear TestFreeRDPCodecInterleaved \
    TestFreeRDPCodecProgressive TestFreeRDPCodecRemoteFX"
TestFreeRDPCrypto="TestKnownHosts TestBase64 Test_x509_cert_info"
TestFreeRDPUtils="TestRingBuffer"
TestGdi="TestGdiRop3 TestGdiLine TestGdiRegion TestGdiRect TestGdiBitBlt TestGdiCreate TestGdiEllipse TestGdiClip"
TestInterlocked="TestInterlockedAccess TestInterlockedSList TestInterlockedDList"
TestIo="TestIoDevice TestIoGetOverlappedResult"
TestLibrary="TestLibraryLoadLibrary TestLibraryGetProcAddress TestLibraryGetModuleFileName"
TestLocale="TestLocaleFormatMessage"
TestMemory="TestMemoryCreateFileMapping"
TestNt="TestNtCreateFile TestNtCurrentTeb"
TestPath="TestPathCchAddBackslash TestPathCchRemoveBackslash TestPathCchAddBackslashEx TestPathCchRemoveBackslashEx \
    TestPathCchAddExtension TestPathCchAppend TestPathCchAppendEx TestPathCchCanonicalize TestPathCchCanonicalizeEx \
    TestPathAllocCanonicalize TestPathCchCombine TestPathCchCombineEx TestPathAllocCombine TestPathCchFindExtension \
    TestPathCchRenameExtension TestPathCchRemoveExtension TestPathCchIsRoot TestPathIsUNCEx TestPathCchSkipRoot \
    TestPathCchStripToRoot TestPathCchStripPrefix TestPathCchRemoveFileSpec TestPathShell TestPathMakePath"
TestPipe="TestPipeCreatePipe TestPipeCreateNamedPipe TestPipeCreateNamedPipeOverlapped"
TestPool="TestPoolIO TestPoolSynch TestPoolThread TestPoolTimer TestPoolWork"
TestPrimitives="TestPrimitivesAdd TestPrimitivesAlphaComp TestPrimitivesAndOr TestPrimitivesColors TestPrimitivesCopy \
    TestPrimitivesSet TestPrimitivesShift TestPrimitivesSign TestPrimitivesYUV TestPrimitivesYCbCr TestPrimitivesYCoCg"
TestRdTk="TestRdTkNinePatch"
TestSecurity="TestSecurityToken"
TestSmartCard="TestSmartCardListReaders"
TestSspi="TestQuerySecurityPackageInfo TestEnumerateSecurityPackages TestInitializeSecurityContext TestAcquireCredentialsHandle TestCredSSP TestNTLM"
TestSynch="TestSynchInit TestSynchEvent TestSynchMutex TestSynchBarrier TestSynchCritical TestSynchSemaphore \
    TestSynchThread TestSynchMultipleThreads TestSynchTimerQueue TestSynchWaitableTimer TestSynchWaitableTimerAPC TestSynchAPC"
TestSysInfo="TestGetNativeSystemInfo TestCPUFeatures TestGetComputerName TestSystemTime TestLocalTime"
TestThread="TestThreadCommandLineToArgv TestThreadCreateProcess TestThreadExitThread"
TestWinPR="TestIntrinsics TestTypes"
TestWinPRUtils="TestIni TestVersion TestImage TestBipBuffer TestBacktrace TestQueue TestPrint TestPubSub TestStream \
    TestBitStream TestArrayList TestLinkedList TestListDictionary TestCmdLine TestWLog TestWLogCallback TestHashTable \
    TestBufferPool TestStreamPool TestMessageQueue TestMessagePipe"
TestWnd="TestWndCreateWindowEx TestWndWmCopyData"
TestWtsApi="TestWtsApiEnumerateProcesses TestWtsApiEnumerateSessions TestWtsApiQuerySessionInformation \
    TestWtsApiSessionNotification TestWtsApiShutdownSystem TestWtsApiWaitSystemEvent"

run_test(){
  binary=$1
  tcs=$(eval "echo \$${binary}")
  if [ -z "$tcs" -o "$tcs" = ".so" ]; then
     return
  fi
  
  EXTRA_ARG=""
  if [ "$binary" = "TestFile" ]; then
    # This testcase needs an extra argument. TestFileArea is a folder
    # where some test files are used by this test.
    EXTRA_ARG="TestFileArea"
  fi
  
  for tc in $tcs; do
    ./$binary $tc $EXTRA_ARG > ../${binary}_${tc}.out 2>&1 && echo PASS: $binary $tc || echo FAIL: $binary $tc
  done
}

cd Testing

for testbin in *; do
  run_test $testbin
done
