#include "TestLib.h"
#ifdef _WIN32
#include <windows.h>
#else
#include <limits.h>
#include <spawn.h>
#include <sys/wait.h>
extern char **environ;
#endif
#define NUM_EXECUTABLES 33
static const char *dpiTestNames[NUM_EXECUTABLES] = {
"TestContext",
"TestNumbers",
"TestConn",
"TestConnProperties",
"TestPool",
"TestPoolProperties",
"TestQueries",
"TestTransactions",
"TestMiscCases",
"TestVariables",
"TestStatements",
"TestDataTypes",
"TestObjectTypes",
"TestObjects",
"TestEnqOptions",
"TestDeqOptions",
"TestMsgProps",
"TestAQ",
"TestLOBs",
"TestImplicitResults",
"TestRowIds",
"TestScrollCursors",
"TestSubscriptions",
"TestBatchErrors",
"TestDMLReturning",
"TestSodaDb",
"TestSodaColl",
"TestSodaCollCursor",
"TestSodaDoc",
"TestSodaDocCursor",
"TestSessTags",
"TestQueue",
"TestBinds"
};
int dpiTest_runExecutable(const char *runnerName, const char *name)
{
#ifdef _WIN32
PROCESS_INFORMATION processInfo;
STARTUPINFO startupInfo;
DWORD result;
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
ZeroMemory(&processInfo, sizeof(processInfo));
if (!CreateProcess(NULL, (char*) name, NULL, NULL, FALSE, 0, NULL, NULL,
&startupInfo, &processInfo)) {
fprintf(stderr, "Unable to create process\n");
return -1;
}
WaitForSingleObject(processInfo.hProcess, INFINITE);
GetExitCodeProcess(processInfo.hProcess, &result);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
if (result != 0)
return -1;
#else
char executableName[PATH_MAX + 1], *temp;
char * const argv[2] = { executableName, NULL };
int status;
pid_t pid;
strcpy(executableName, runnerName);
temp = strrchr(executableName, '/');
if (temp)
strcpy(temp + 1, name);
else strcpy(executableName, name);
status = posix_spawn(&pid, executableName, NULL, NULL, argv, environ);
if (status != 0) {
perror("Failed to spawn executable");
return -1;
}
if (waitpid(pid, &status, 0) < 0) {
perror("Failed to wait for child process");
return -1;
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
return -1;
#endif
return 0;
}
int main(int argc, char **argv)
{
int testResults[NUM_EXECUTABLES], i, someTestsFailed;
dpiTestSuite_initialize(0);
someTestsFailed = 0;
for (i = 0; i < NUM_EXECUTABLES; i++) {
fprintf(stderr, "Running cases in %s\n", dpiTestNames[i]);
fflush(stderr);
testResults[i] = dpiTest_runExecutable(argv[0], dpiTestNames[i]);
fprintf(stderr, "\n");
fflush(stderr);
if (testResults[i] < 0)
someTestsFailed = 1;
}
if (someTestsFailed) {
fprintf(stderr, "Cases in the following tests failed:\n");
for (i = 0; i < NUM_EXECUTABLES; i++) {
if (testResults[i] < 0)
fprintf(stderr, " %s\n", dpiTestNames[i]);
}
return 1;
}
fprintf(stderr, "All tests passed!\n");
fflush(stderr);
return 0;
}