From 15fbb1931d9d801ac473421d04a60952e3e2f538 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 20 Jun 2012 15:07:32 +0200 Subject: [PATCH] Remove old cruft. It is not referenced anywhere, and the last meaningful commit dates from 2006. --- win32_test_app/include/TBuffer.h | 60 -- win32_test_app/include/TDefs.h | 47 - win32_test_app/include/TErrno.h | 119 --- win32_test_app/include/TStream.h | 190 ---- win32_test_app/include/TTestCaseContext.h | 144 --- win32_test_app/include/TTestRunner.h | 49 - win32_test_app/include/TTestSuite.h | 160 --- win32_test_app/include/TThreadDynarray.h | 221 ----- win32_test_app/include/TTime.h | 12 - win32_test_app/prj/Test.bpf | 4 - win32_test_app/prj/Test.bpr | 179 ---- win32_test_app/prj/Test.res | Bin 876 -> 0 bytes win32_test_app/src/TBuffer.c | 117 --- win32_test_app/src/TErrno.c | 46 - win32_test_app/src/TStream.c | 631 ------------ win32_test_app/src/TTestCaseContext.c | 299 ------ win32_test_app/src/TTestRunner.c | 68 -- win32_test_app/src/TTestSuite.c | 1080 --------------------- win32_test_app/src/TThreadDynarray.c | 489 ---------- win32_test_app/src/TTime.c | 13 - win32_test_app/src/Test.c | 51 - 21 files changed, 3979 deletions(-) delete mode 100644 win32_test_app/include/TBuffer.h delete mode 100644 win32_test_app/include/TDefs.h delete mode 100644 win32_test_app/include/TErrno.h delete mode 100644 win32_test_app/include/TStream.h delete mode 100644 win32_test_app/include/TTestCaseContext.h delete mode 100644 win32_test_app/include/TTestRunner.h delete mode 100644 win32_test_app/include/TTestSuite.h delete mode 100644 win32_test_app/include/TThreadDynarray.h delete mode 100644 win32_test_app/include/TTime.h delete mode 100644 win32_test_app/prj/Test.bpf delete mode 100644 win32_test_app/prj/Test.bpr delete mode 100644 win32_test_app/prj/Test.res delete mode 100644 win32_test_app/src/TBuffer.c delete mode 100644 win32_test_app/src/TErrno.c delete mode 100644 win32_test_app/src/TStream.c delete mode 100644 win32_test_app/src/TTestCaseContext.c delete mode 100644 win32_test_app/src/TTestRunner.c delete mode 100644 win32_test_app/src/TTestSuite.c delete mode 100644 win32_test_app/src/TThreadDynarray.c delete mode 100644 win32_test_app/src/TTime.c delete mode 100644 win32_test_app/src/Test.c diff --git a/win32_test_app/include/TBuffer.h b/win32_test_app/include/TBuffer.h deleted file mode 100644 index 85f681d768..0000000000 --- a/win32_test_app/include/TBuffer.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __BUFFER_H__ -#define __BUFFER_H__ - -#include -#include -#include - -/* struct s_Buffer declaration. */ -typedef struct s_Buffer { - char *data; /* the buffer data. */ - size_t size; /* the buffer size (in bytes). */ - size_t capacity; /* the buffer capacity (in bytes). */ -} s_Buffer_t, *Buffer_t; - -/* Asserts that a s_Buffer is valid. */ -#define ASSERT_VALID_Buffer(p) ( ASSERT_NOT_NULL(p) /*&& ASSERT_NOT_NULL((p)->data)*/ ) - -/* The default buffer capacity (512 bytes). */ -#define DEFAULT_Buffer_CAPACITY ((size_t)512) - -/* struct s_buffet connected functions. */ - -/* Constructs an new buffer. - * If successful, the function returns a pointer to - * the new buffer. Otherwise, the function returns - * NULL. - */ -Buffer_t Buffer_new(void); - -/* Clears the buffer (this function don't destroy it, - * see Buffer_free function). - */ -void Buffer_clear(Buffer_t buffer); - -/* Appends a string in the buffer. If successful, - * the function returns true. Otherwise the function - * returns false. - */ -bool Buffer_append(Buffer_t buffer, char *str); - -/* - * Removes all the linefeed from the buffer. - */ -void Buffer_chomp(Buffer_t buffer); - -/* - * Destroy the buffer. - */ -void Buffer_free(Buffer_t buffer); - -/* - * This function returns true is the buffer is empty. - * Otherwrise the function returns false. - */ -bool Buffer_empty(Buffer_t buffer); - - - - -#endif /* #ifndef __BUFFER_H__ */ diff --git a/win32_test_app/include/TDefs.h b/win32_test_app/include/TDefs.h deleted file mode 100644 index 4b00aaa8d6..0000000000 --- a/win32_test_app/include/TDefs.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef __DEFS_H__ -#define __DEFS_H__ - -#include - -/* NULL definition*/ -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif /* #ifndef NULL */ - -#if !defined(__cplusplus) && !defined(__BOOL_TYPE_DEFINED) -typedef int bool; -#define __BOOL_TYPE_DEFINED -#endif /* #ifndef __cplusplus */ - -#ifndef __SSIZE_TYPE_DEFINED -typedef int ssize_t; -#define __SSIZE_TYPE_DEFINED -#endif /* #ifndef __SSIZE_TYPE_DEFINED */ - -#ifndef true -#define true 1 -#endif /* #ifndef true */ - -#ifndef false -#define false 0 -#endif /* #ifndef false */ - -/* Asserts that a condition is true.*/ -#define ASSERT(c) assert(c) -/* Asserts that a pointer is not NULL.*/ -#define ASSERT_NOT_NULL(p) assert(NULL != (p)) - -/* Error number type (int) */ -#ifndef __ERRNO_TYPE_DEFINED -typedef int errno_t; -#define __ERRNO_TYPE_DEFINED -#endif /* #ifndef __ERRNO_TYPE_DEFINED */ - -/* comment this line if you don't want activate the verbose mode. */ -#define __VERBOSE - -#endif /* #ifndef __DEFS_H__ */ diff --git a/win32_test_app/include/TErrno.h b/win32_test_app/include/TErrno.h deleted file mode 100644 index 8713366041..0000000000 --- a/win32_test_app/include/TErrno.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef __ERRNO_H__ -#define __ERRNO_H__ - -#include -#include -#include - -#define E_SUCCESS ((errno_t)0) /* Success */ -#define E_TEST_RUNNER_ALLOCATION_FAILED ((errno_t)1) /* Test runner allocation failed */ -#define E_TEST_CASE_CONTEXT_ALLOCATION_FAILED ((errno_t)2) /* Test case context allocation failed */ -#define E_BUFFER_ALLOCATION_FAILED ((errno_t)3) /* Buffer allocation failed */ -#define E_BUFFER_DATA_ALLOCATION_FAILED ((errno_t)4) /* Buffer data allocation failed */ -#define E_TEST_SUITE_ALLOCATION_FAILED ((errno_t)5) /* Test suite allocation failed */ -#define E_FILE_NOT_FOUND ((errno_t)6) /* Ffile not found */ -#define E_BAD_USAGE ((errno_t)7) /* Bad usage */ -#define E_INVALID_FILE_Stream ((errno_t)8) /* Invalid file stream */ -#define E_STREAM_ALLOCATION_FAILED ((errno_t)9) /* Stream allocation failed */ -#define E_Buffer_DATA_REALLOCATION_FAILED ((errno_t)10) /* Buffer data reallocation failed */ -#define E_STREAM_LINE_ALLOCATION_FAILED ((errno_t)11) /* Stream line allocation failed */ -#define E_STREAM_LINE_REALLOCATION_FAILED ((errno_t)12) /* Stream line reallocation failed */ -#define E_STREAM_EMPTY ((errno_t)13) /* File empty */ -#define E_STREAM_ERROR ((errno_t)14) /* File error */ -#define E_UNKWN_META_COMMAND ((errno_t)15) /* Unknown meta command detected */ -#define E_INVALID_TIMEOUT_VALUE ((errno_t)16) /* Invalid timeout value */ -#define E_INVALID_EXIT_CODE_VALUE ((errno_t)17) /* Invalid exit code */ -#define E_INVALID_EXPORT ((errno_t)18) /* Invalid export meta command */ -#define E_INVALID_UNSET ((errno_t)19) /* Invalid unset meta command */ -#define E_EXPORT_FAILED ((errno_t)20) /* Export failed */ -#define E_UNSET_FAILED ((errno_t)21) /* Unset failed */ -#define E_SYNC_TEST_CASE_ALLOCATION_FAILED ((errno_t)22) /* Synchrone test case allocation failed */ -#define E_CANNOT_CREATE_CHILD_STDOUT_READ_HANDLE ((errno_t)23) /* Can't create the child std output read handle */ -#define E_CANNOT_CREATE_CHILD_STDERR_READ_HANDLE ((errno_t)24) /* Can't create the child std error read handle */ -#define E_CANNOT_CREATE_CHILD_STDIN_WRITE_HANDLE ((errno_t)25) /* Can't create the child std input write handle */ -#define E_CANNOT_CREATE_STDOUT_READ_HANDLE ((errno_t)26) /* Can't create the std output handle */ -#define E_CANNOT_CREATE_STDIN_WRITE_HANDLE ((errno_t)27) /* Can't create the std input handle */ -#define E_CANNOT_CLOSE_CHILD_STDIN_TEMPORY_HANDLE ((errno_t)28) /* Can't close the tempory child std input handle */ -#define E_CANNOT_CLOSE_CHILD_STDOUT_TEMPORY_HANDLE ((errno_t)29) /* Can't close the tempory child std output handle */ -#define E_CANNOT_CREATE_CHILD_PROCESS ((errno_t)30) /* Can't create the child process */ -#define E_CANNOT_CLOSE_PROCESS_THREAD_HANDLE ((errno_t)31) /* Can't close the child process handle */ -#define E_CANNOT_CLOSE_CHILD_STDOUT_HANDLE ((errno_t)32) /* Can't close the child std output handle */ -#define E_CANNOT_CLOSE_CHILD_STDIN_HANDLE ((errno_t)33) /* Can't close the child std input handle */ -#define E_CANNOT_CLOSE_CHILD_STDERR_HANDLE ((errno_t)34) /* Can't close the child std error handle */ -#define E_CANNOT_WRITE_ON_CHILD_STDIN ((errno_t)35) /* Can't write on child std output */ -#define E_CANNOT_CREATE_READ_CHILD_OUTPUT_THREAD ((errno_t)36) /* Can't create the read child output thread */ -#define E_WAIT_THREAD_FAILED ((errno_t)37) /* Wait thread failed */ -#define E_CANNOT_CLOSE_THREAD_HANDLE ((errno_t)38) /* Can't close thread handle */ -#define E_CANNOT_CLOSE_READ_HANDLE ((errno_t)39) /* Can't close the read handle */ -#define E_CANNOT_CLOSE_WRITE_HANDLE ((errno_t)40) /* Can't close the write handle */ -#define E_WAIT_FAILURE ((errno_t)41) /* Wait failure */ -#define E_CANNOT_CLOSE_PROCESS_HANDLE ((errno_t)42) /* Can't close the process handle */ -#define E_OUTPUT_DONT_MATCH ((errno_t)43) /* Output don't match */ -#define E_OPEN_FILE_FAILED ((errno_t)44) /* Open file failed */ -#define E_INVALID_TOKEN ((errno_t)45) /* Invalid token */ -#define E_WAIT_TIMEOUT ((errno_t)46) /* Wait timeout detected */ -#define E_EXIT_CODE_DONT_MATCH ((errno_t)47) /* Exit code don't match */ -#define E_CHANGE_DIRECTORY_FAILED ((errno_t)48) /* Change directory failed */ - -/* error message list */ -static const char *__errlist[] = { - "Success", - "Test runner allocation failed", - "Test case context allocation failed", - "Buffer allocation failed", - "Buffer data allocation failed", - "Test suite allocation failed", - "File not found", - "Bad usage", - "Invalid file stream", - "Stream allocation failed", - "Buffer data reallocation failed", - "Stream line allocation failed", - "Stream line reallocation failed", - "File empty", - "File error", - "Unknown meta command detected", - "Invalid timeout value", - "Invalid exit code", - "Invalid export meta command", - "Invalid unset meta command", - "Export failed", - "Unset failed", - "Synchrone test case allocation failed", - "Can't create the child std output read handle", - "Can't create the child std error read handle", - "Can't create the child std input write handle", - "Can't create the std output handle", - "Can't create the std input handle", - "Can't close the tempory child std input handle", - "Can't close the tempory child std output handle", - "Can't create the child process", - "Can't close the child process handle", - "Can't close the child std output handle", - "Can't close the child std input handle", - "Can't close the child std error handle", - "Can't write on child std output", - "Can't create the read child output thread", - "Wait thread failed", - "Can't close thread handle", - "Can't close the read handle", - "Can't close the write handle", - "Wait failure", - "Can't close the process handle", - "Output don't match", - "Open file failed", - "Invalid token", - "Wait timeout detected", - "Exit code don't match", - "Change directory failed" -}; - -extern void initializeErrno(void); - -extern void terminateErrno(void); - -extern void setErrno(errno_t e); - -extern errno_t getErrno(void); - -#endif /* #ifndef __ERRNO_H__ */ diff --git a/win32_test_app/include/TStream.h b/win32_test_app/include/TStream.h deleted file mode 100644 index 2d09f9dd16..0000000000 --- a/win32_test_app/include/TStream.h +++ /dev/null @@ -1,190 +0,0 @@ -#ifndef __Stream_H__ -#define __STREAM_H__ - -#include -#include -#include -#include - - -/* - * Declaration of the s_Stream structure, - * which represents a file stream. - */ - -typedef struct s_Stream { - FILE *file; /* the file stream. */ - char *line; /* the current text line */ - size_t line_number; /* line number in the testsuite file */ - CRITICAL_SECTION cs; /* std output managment */ -} s_Stream_t, *Stream_t; - -/* Line type. */ -typedef enum { - comment_line_type, /* the text line is a comment */ - invalid_token_line_type, /* the text line contains a invalid token */ - unknwn_meta_command_line_type, /* the text line contains a unknown macro command */ - invalid_timeout_value_line_type, /* the text line contains a invalid timeout value */ - timeout_value_line_type, /* the text line contains a valid timeout value */ - invalid_exit_code_line_type, /* the text line contains a invalid exit code value */ - exit_code_line_type, /* the text line contains a valid exit code value */ - invalid_export_line_type, /* the text line contains a invalid export meta command */ - export_line_type, /* the text line contains a valid export meta command */ - invalid_unset_line_type, /* the text line contains a invalid unset meta command */ - unset_line_type, /* the text line contains a valid unset meta command */ - enable_output_checking_line_type, /* the text line contains a enable output checking meta command */ - disable_output_checking_line_type, /* the text line contains a disable output checking meta command */ - enable_post_output_checking_line_type, /* the text line contains a enable post output checking meta command */ - disable_post_output_checking_line_type, /* the text line contains a disable post output checking meta command */ - export_failed_line_type, /* the text line contains a export meta command which failed */ - unset_failed_line_type, /* the text line contains a unset meta command which failed */ - create_console_line_type, /* the text line contains a create console meta command */ - create_no_console_line_type, /* the text line contains a create no console meta command */ - enable_exit_code_checking_line_type, /* the text line contains a enable exit code checking */ - disable_exit_code_checking_line_type, /* the text line contains a disable exit code checking */ - change_directory_line_type, /* the text line contains a change directory command */ - command_line_line_type /* the text line contains a command line */ -} line_type_t; - -/* - * Buffer size used in the getline function. - */ -#define DEFAULT_ALLOC_SIZE ((size_t)64) - -/* - * s_Stream struct connected functions. - */ - -/* - * Create a new s_Stream struct and return - * a pointer to self - */ - -Stream_t Stream_new(void); - -/* - * Returns true if the current text line is blank. - */ -bool Stream_lineIsBlank(Stream_t stream); - -/* - * Return true if the caracter is space or tab. - */ -bool Stream_isBlankChar(char ch); - - -/* - * Return E_SUCCESS if the file is valid. - * Otherwise the fuction returns E_INVALID_FILE. - */ -errno_t Stream_isValidFile(const char *file_name); - - -/* - * Return E_SUCCESS is the open file operation succeeded. - * Otherwise the functions returns E_OPEN_FILE_FAILED. - */ -errno_t Stream_openFile(Stream_t ptr, const char *file_name); - -/* - * This function reads an entire line, storing - * the address of the buffer containing the text into - * *dest. - */ -ssize_t Stream_getLine(Stream_t ptr); - -/* - * Return true if the current line is a comment. - * Otherwise the functions returns false. - */ -bool Stream_lineIsComment(Stream_t stream); - -/* Return true if the current line contains a invalide token. - * Otherwise, the function returns false. - */ -bool Stream_lineContainsInvalidToken(Stream_t stream); - -/* - * Return true if the text line is a meta command. - * Otherwise, the functions returns false. - */ -bool Stream_lineIsMetaCommand(Stream_t stream); - -/* Retun true if the text line contains a unknown meta command. - * Otherwise the function returns false. - */ -bool Stream_lineIsUnknwnMetaCommand(Stream_t stream); - -/* - * Returns true if the timeout value is invalid. - * Otherwise the function returns false. - */ -bool Stream_isInvalidTimeout(Stream_t stream); - -/* - * Returns true if the expected code value is invalid. - * Otherwise the function returns false. - */ -bool Stream_isInvalidExpectedCode(Stream_t stream); - -/* - * Returns true if the export is invalid. - * Otherwise the function returns false. - */ -bool Stream_isInvalidExport(Stream_t stream); - -/* - * Returns true if the unset is invalid. - * Otherwise the function returns false. - */ -bool Stream_isInvalidUnset(Stream_t stream); - -/* - * Return true if the stream line contains a - * expected child output. Otherwhise the function - * returns false. - */ -bool Stream_lineIsExpectedChildOutput(Stream_t stream); - -/* - * Return true if the stream line contains a - * child input. Otherwhise the function - * returns false. - */ -bool Stream_lineIsChildInput(Stream_t stream); - -/* - * Return true, if the stream line containts a - * synchrone test case. otherwise the function - * returns false. - */ -bool Stream_lineIsSyncTestCase(Stream_t stream); - -bool Stream_lineIsAsyncTestCase(Stream_t stream); - -/* - * Return true if the text line contains a invalid - * meta command. Otherwise the function returns false. - */ -bool Stream_lineIsInvalidMetaCommand(Stream_t stream); - -/* - * Print the file line. - */ -void Stream_printLine(Stream_t stream, line_type_t line_type); - -void Stream_lock(Stream_t ptr); -void Stream_unlock(Stream_t ptr); - -bool Stream_lineIsChangeDir(Stream_t stream); - -extern CRITICAL_SECTION cs; - -/* - * Free a s_Stream. - */ - -void Stream_free(Stream_t ptr); - - -#endif /* #ifndef __STREAM_H__ */ diff --git a/win32_test_app/include/TTestCaseContext.h b/win32_test_app/include/TTestCaseContext.h deleted file mode 100644 index 25002c39b8..0000000000 --- a/win32_test_app/include/TTestCaseContext.h +++ /dev/null @@ -1,144 +0,0 @@ -#ifndef __TestCaseContext_H__ -#define __TestCaseContext_H__ - -#include -#include - -/* - * Declaration a the s_TestCaseContext structure - * which represents the context of a test case during his - * execution. - */ -typedef struct s_TestCaseContext { - char *name; /* the test case name */ - int timeoutValue; /* the timeout value */ - bool isOutputCheckingEnabled; /* if true, output checking is enable */ - bool isPostOutputCheckingEnabled; /* if true, the post output checking mode is enable */ - Buffer_t inputBuffer; /* buffer that contains child input */ - Buffer_t outputBuffer; /* the child output buffer */ - Buffer_t expectedOutputBuffer; /* buffer that contains child expected output */ - int expectedExitCode; /* the child expected exit code */ - int threadExitCode; /* the thread exit code */ - int exitCode; /* the child process exit code */ - bool runThread; /* false if the thread of the test case must terminate */ - HANDLE hThread; /* the handle of the thread */ - HANDLE hOutputRead; /* handle to the read pipe */ - HANDLE hInputWrite; /* handle to the write pipe */ - HANDLE hChildStdInRead; /* handle to the pipe used to read the child std input */ - HANDLE hChildStdOutWrite; /* handle to the pipe used to write to the chil std output */ - HANDLE hChildStderr; /* handle to the pipe used to read the child std error */ - PROCESS_INFORMATION pi; /* this structure contains child process informations */ - HANDLE hChildStdoutReadTmp; /* tempory handle */ - HANDLE hChildStdinWriteTmp; /* tempory handle */ - bool createConsole; /* true if we can create a console for the child process */ - bool exitCodeCheckingEnabled; /* true if we want to check the child exit code */ - HANDLE hConsole; /* handle to the console */ - bool started; /* true if the child process started */ - Buffer_t commandLineBuffer; /* command line buffer */ - -} s_TestCaseContext_t, *TestCaseContext_t; - -/* Output checking is disabled by default*/ -#define DEFAULT_OUTPUT_CHECKING_MODE false - -/* Post output checking mode is disabled by default*/ -#define DEFAULT_POST_OUTPUT_CHECKING_MODE false - -/* The default timeout value is 5 seconds*/ -#define DEFAULT_TIMEOUT_VALUE ((int)120000) - -/* Invalid exit code value (default value)*/ -#define INVALID_EXIT_CODE ((int)0xFFFFFF) - -/* - * s_TestCaseContext struct connected functions. - */ - -/* - * Create a new s_TestCaseContext and returns a pointer to self. - */ -TestCaseContext_t TestCaseContext_new(void); - -/* - * Destroy the s_TestCaseContext referenced by context. - */ -void TestCaseContext_free(TestCaseContext_t context); - -/* - * Clear the s_TestCaseContext referenced by context. - */ -void TestCaseContext_clear(TestCaseContext_t context); - -/* - * Set the timeout of the test case context. - */ -void TestCaseContext_setTimeout(TestCaseContext_t context, int timeout); - -/* - * Enable the output checking of the test case context. - */ -void TestCaseContext_enableOutputChecking(TestCaseContext_t context); - -/* - * Disable the output checking of the test case context. - */ -void TestCaseContext_disableOutputChecking(TestCaseContext_t context); - -/* - * Enable the post output checking of the test case context. - */ -void TestCaseContext_enable_post_output_checking(TestCaseContext_t - context); - -/* - * Disable the post output checking of the test case context. - */ -void TestCaseContext_disablePostOutputChecking(TestCaseContext_t context); - -/* - * Set the expected exit code of the test case context. - */ -void TestCaseContext_setExpectedExitCode(TestCaseContext_t context, - int expected_code); - -/* - * Return true if the output checking mode is enabled for this - * test case context. Otherwise the functions returns false. - */ -bool TestCaseContext_isOutputCheckingEnabled(TestCaseContext_t context); - -/* - * Append a child output to check in the - * test case context. - */ -void TestCaseContext_appendExpectedOutput(TestCaseContext_t context, - char *expected_output); - -/* - * Append a child output to check in the - * test case context. - */ -void TestCaseContext_appendChildInput(TestCaseContext_t context, - char *input); - -/* - * Set the name of the test case name. - */ -void TestCaseContext_setName(TestCaseContext_t context, char *name); - -void TestCaseContext_createConsole(TestCaseContext_t context); - -void TestCaseContext_createNoConsole(TestCaseContext_t context); - -void TestCaseContext_enableExitCodeChecking(TestCaseContext_t context); - -void TestCaseContext_disableExitCodeChecking(TestCaseContext_t context); - - -void TestCaseContext_setCommandLine(TestCaseContext_t context, - char *cmdLine); - - - - -#endif /* #ifndef __TestCaseContext_H__ */ diff --git a/win32_test_app/include/TTestRunner.h b/win32_test_app/include/TTestRunner.h deleted file mode 100644 index ee61b015ee..0000000000 --- a/win32_test_app/include/TTestRunner.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __TEST_RUNNER_H__ -#define __TEST_RUNNER_H__ - -#include - - -/* - * Declaration of the s_TestRunner structure, which represents - * a test runner used to run suites of tests. - */ -typedef struct s_TestRunner { - Buffer_t buffer; /* a single buffer */ - TestSuite_t testSuite; /* the test suite to run */ - -} s_TestRunner_t, *TestRunner_t; - - -/* - * s_TestRunner structure connected functions. - */ - -/* - * Create an new s_TestRunner struct and - * returns a pointer to self. - */ -TestRunner_t TestRunner_new(void); - -/* - * Initialize the s_TestRunner struct. - */ -errno_t TestRunner_initialize(TestRunner_t runner, int argc, char *argv[]); - -/* - * Launch the test runner. - */ -void TestRunner_run(TestRunner_t runner); - -/* - * Free the s_TestRunner. - */ -void TestRunner_free(TestRunner_t runner); - - - - - - - -#endif /* #ifndef __TestRunner_H__ */ diff --git a/win32_test_app/include/TTestSuite.h b/win32_test_app/include/TTestSuite.h deleted file mode 100644 index 25a7d8ed14..0000000000 --- a/win32_test_app/include/TTestSuite.h +++ /dev/null @@ -1,160 +0,0 @@ -#ifndef __TestSuite_H__ -#define __TestSuite_H__ - -#include -#include - -/* - * Declaration of the s_TestSuite, which represents - * a suite of tests. - */ -typedef struct s_TestSuite { - TestCaseContext_t test_case_context; /* the context of the current test case */ - Stream_t stream; /* stdin or file stream */ - size_t testCaseCount; /* test case count */ - size_t successCount; /* test case success count */ - size_t failureCount; /* test case failure count */ -#ifdef __VERBOSE - char currentTime[30]; /* the current time */ -#endif /* #ifdef __VERBOSE */ - ThreadDynarray_t threads; -} s_TestSuite_t, *TestSuite_t; - -/* - * s_TestSuite connected functions. - */ - -/* - * Create a new s_TestSuite an returns a pointer to self. - */ -TestSuite_t TestSuite_new(void); - -/* - * Free the s_TestSuite pointed to by ptr. - */ -void TestSuite_free(TestSuite_t ptr); - - /* - * Initialize the s_TestSuite structure. - */ -errno_t TestSuite_initialize(TestSuite_t ptr, int argc, char *argv[]); - - -/* - * This function reads an entire line, storing - * the address of the buffer containing the text into - * s_TestSuite.current_line. - */ -ssize_t TestSuite_getline(TestSuite_t ptr, size_t * len); - -/* - * Launch the test suite. - */ -void TestSuite_run(TestSuite_t ptr); - -/* - * Meta command processing. - */ -errno_t TestSuite_processMetaCommand(TestSuite_t testSuite); - -/* - * Set the timeout of the test case context of the - * test suite. - */ -void TestSuite_setTimeout(TestSuite_t testSuite); - -/* - * Enable output checking for the current test case context. - */ -void TestSuite_enableOutputChecking(TestSuite_t testSuite); - -/* - * Disable output checking for the current test case context. - */ -void TestSuite_disableOutputChecking(TestSuite_t testSuite); - -/* - * Enable post output checking for the current test case context. - */ -void TestSuite_enablePostOutputChecking(TestSuite_t testSuite); - -/* - * Disable post output checking for the current test case context. - */ -void TestSuite_disablePostOutputChecking(TestSuite_t testSuite); - -/* - * Set the expected exit code of the current test case context of the test suite. - */ -void TestSuite_setExpectedExitCode(TestSuite_t testSuite); - -/* - * Export a variable in the environment of the current test_runner.exe process. - */ -errno_t TestSuite_export(TestSuite_t testSuite); - -/* - * Expected child output processing. - */ -errno_t TestSuite_processExpectedChildOutput(TestSuite_t testSuite); - -/* - * Child input processing. - */ -errno_t TestSuite_processChildInput(TestSuite_t testSuite); - -/* - * Check the child output. - */ -errno_t TestSuite_checkChildOutput(TestCaseContext_t context); - -/* - * Print message - */ -void TestSuite_print(const char *str); - -/* - * Check the child process exit code. - */ -errno_t TestSuite_checkChildExitCode(TestCaseContext_t context); - -errno_t TestSuite_unset(TestSuite_t testSuite); - -void TestSuite_createConsole(TestSuite_t testSuite); - -void TestSuite_createNoConsole(TestSuite_t testSuite); - -void TestSuite_enableExitCodeChecking(TestSuite_t testSuite); - -void TestSuite_disableExitCodeChecking(TestSuite_t testSuite); - -unsigned long WINAPI TestSuite_runSyncTestCase(void *param); - -errno_t TestSuite_runAsyncTestCase(TestSuite_t testSuite); - -/* - * Terminate the test suite. - */ -void TestSuite_terminate(TestSuite_t testSuite); - -unsigned long WINAPI TestSuite_asyncReadChildOutput(void *param); - -bool TestSuite_iSPostOutputCheckingEnabled(TestCaseContext_t context); - -bool TestSuite_iSExitCodeCheckingEnabled(TestCaseContext_t context); - -errno_t TestSuite_changeDir(TestSuite_t testSuite); - -void TestSuite_setCommandLine(TestSuite_t testSuite); - - -#ifdef __VERBOSE -/* - * Update the current time. - */ -void TestSuite_update_current_time(TestSuite_t ptr); -#endif /* #ifdef __VERBOSE */ - - - -#endif /* #ifndef __TestSuite_H__ */ diff --git a/win32_test_app/include/TThreadDynarray.h b/win32_test_app/include/TThreadDynarray.h deleted file mode 100644 index e7bb219c20..0000000000 --- a/win32_test_app/include/TThreadDynarray.h +++ /dev/null @@ -1,221 +0,0 @@ -#ifndef __THREAD_DYNARRAY_H__ -#define __THREAD_DYNARRAY_H__ - -#include -#include -#include -#include -#include - - -typedef struct s_ThreadEntry { - HANDLE hThread; - DWORD threadId; - TestCaseContext_t context; -} s_ThreadEntry_t, *ThreadEntry_t; -/* - * s_ThreadDynarray struct declaration. - */ - -typedef struct s_ThreadDynarray { - /* threads */ - ThreadEntry_t threads; - /* thread count */ - unsigned long count; - /* Storage capacity */ - unsigned long capacity; - CRITICAL_SECTION cs; - bool is_locked; - -} s_ThreadDynarray_t, *ThreadDynarray_t; - -/* - * Constructs a ThreadDynarray with the specified capacity. - */ -ThreadDynarray_t ThreadDynarray_new(unsigned long capacity); - -/* - * Destroy the ThreadDynarray - */ -void ThreadDynarray_destroy(ThreadDynarray_t ptr); - -/* - * Returns an const pointer THREAD_entry pointed to by index. - */ -ThreadEntry_t const ThreadDynarray_at(ThreadDynarray_t ptr, - unsigned long index); - -/* - * Fill the content of the entry addressed by the __entry with the content - * of the entry pointed to by index. - */ -void ThreadDynarray_get(ThreadDynarray_t ptr, unsigned long index, - ThreadEntry_t const __entry); - -/* - * Fill the content of the entry pointed to by index with the content of - * the entry addressed by __entry. - */ -void ThreadDynarray_set(ThreadDynarray_t ptr, unsigned long index, - ThreadEntry_t const __entry); - -/* - * Returns a const pointer to the first entry. - */ -ThreadEntry_t const ThreadDynarray_getFront(ThreadDynarray_t ptr); - -/* - * Returns a const pointer to the last entry. - */ -ThreadEntry_t const ThreadDynarray_getBack(ThreadDynarray_t ptr); - -/* - * Inserts a copy of __entry at the front - */ -void ThreadDynarray_pushFront(ThreadDynarray_t ptr, - ThreadEntry_t const __entry); - -/* - * Appends a copy of __entry to the end. - */ -void ThreadDynarray_pushBack(ThreadDynarray_t ptr, - ThreadEntry_t const __entry); - -/* - * Inserts __entry at the position pointed to by index. - */ -void ThreadDynarray_insert(ThreadDynarray_t ptr, unsigned long index, - ThreadEntry_t const __entry); - -/* - * Deletes the entry pointed to by index. If __entry is not NULL the - * fuction saves the entry threads at this address before. - */ -void ThreadDynarray_erase(ThreadDynarray_t ptr, unsigned long index, - ThreadEntry_t const __entry); - -/* - * Find the first entry with the same content of the entry addressed by - * __entry.The function returns the index of the founded entry, -1 if - * no entry is founded. - */ -long ThreadDynarray_getIndex(ThreadDynarray_t ptr, - ThreadEntry_t const __entry); - -/* - * Returns true if the entry exist. - */ -bool ThreadDynarray_exist(ThreadDynarray_t ptr, - ThreadEntry_t const __entry); - -/* Deletes the first entry with the same content of the entry addressed - * by __entry.The function returns true if the entry is deleted, false - * if no entry is founded. - */ -bool ThreadDynarray_remove(ThreadDynarray_t ptr, - ThreadEntry_t const __entry); - -/* - * Erase all elements of the self. - */ -void ThreadDynarray_clear(ThreadDynarray_t ptr); - -/* - * Resets entry count to zero. - */ -void ThreadDynarray_reset(ThreadDynarray_t ptr); - -/* - * Moves count elements from src index to dst index. - */ -void ThreadDynarray_move(ThreadDynarray_t ptr, const unsigned long dst, - const unsigned long src, unsigned long count); - -/* Compare the content of the entry pointed to by index with the content of - * the entry addressed by __entry. The function returns true if the contents - * are same. - */ -bool ThreadDynarray_compare(ThreadDynarray_t ptr, - const unsigned long index, - ThreadEntry_t const __entry); - -/* - * Returns a reference to a new ThreadDynarray new set is a clone of the self. - */ -ThreadDynarray_t ThreadDynarray_clone(ThreadDynarray_t ptr); - -/* - * Extends the capacity when the container is full. - */ -void ThreadDynarray_resize(ThreadDynarray_t ptr); - -/* - * Returns the number of elements. - */ -unsigned long ThreadDynarray_getCount(ThreadDynarray_t ptr); - -/* - * Returns the current storage capacity of the ThreadDynarray. This is guaranteed - * to be at least as large as count(). - */ -unsigned long ThreadDynarray_getCapacity(ThreadDynarray_t ptr); - -/* - * Returns upper bound of self (max index). - */ -unsigned long ThreadDynarray_getUpperBound(ThreadDynarray_t ptr); - -/* - * Returns lower bound of self (always zero). - */ -unsigned long ThreadDynarray_getLowerBound(ThreadDynarray_t ptr); - -/* - * Returns the size of the elements. - */ -unsigned long ThreadDynarray_getElementSize(ThreadDynarray_t ptr); - -/* - * Returns true if the size of self is zero. - */ -bool ThreadDynarray_isEmpty(ThreadDynarray_t ptr); - -/* - * Returns true if capacity available. - */ -bool ThreadDynarray(ThreadDynarray_t ptr); - -/* - * Returns true if the container is full. - */ -bool ThreadDynarray_is_full(ThreadDynarray_t ptr); - - /* - * Returns true if capacity available. - */ -bool ThreadDynarray_getCapacityAvailable(ThreadDynarray_t ptr); - -/* - * Assignement. - */ -ThreadDynarray_t ThreadDynarray_assign(ThreadDynarray_t src, - ThreadDynarray_t dst); - -/* - * Returns true if the dynamic arrays are equal. - */ -bool ThreadDynarray_areEquals(ThreadDynarray_t ptr1, - ThreadDynarray_t ptr2); - -/* - * Returns true if the dynamic arrays are not equal. - */ -bool ThreadDynarray_areNotEquals(ThreadDynarray_t ptr1, - ThreadDynarray_t ptr2); - -void ThreadDynarray_lock(ThreadDynarray_t ptr); - -void ThreadDynarray_unlock(ThreadDynarray_t ptr); - - -#endif /* #ifndef __THREAD_DYNARRAY_H__ */ diff --git a/win32_test_app/include/TTime.h b/win32_test_app/include/TTime.h deleted file mode 100644 index b82bcbdfcf..0000000000 --- a/win32_test_app/include/TTime.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __TIME_H__ -#define __TIME_H__ - -#include -#include -#include - - -void __time(char *t); - - -#endif /* #ifndef __TIME_H__ */ diff --git a/win32_test_app/prj/Test.bpf b/win32_test_app/prj/Test.bpf deleted file mode 100644 index 12ae5a47b7..0000000000 --- a/win32_test_app/prj/Test.bpf +++ /dev/null @@ -1,4 +0,0 @@ -Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet - - -main \ No newline at end of file diff --git a/win32_test_app/prj/Test.bpr b/win32_test_app/prj/Test.bpr deleted file mode 100644 index ad9095a4b6..0000000000 --- a/win32_test_app/prj/Test.bpr +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[Version Info] -IncludeVerInfo=0 -AutoIncBuild=0 -MajorVer=1 -MinorVer=0 -Release=0 -Build=0 -Debug=0 -PreRelease=0 -Special=0 -Private=0 -DLL=0 -Locale=1036 -CodePage=1252 - -[Version Info Keys] -CompanyName= -FileDescription= -FileVersion=1.0.0.0 -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename= -ProductName= -ProductVersion=1.0.0.0 -Comments= - -[Excluded Packages] -c:\program files\borland\cbuilder6\Bin\dclclxdb60.bpl=Composants BD CLX Borland -C:\Program Files\Borland\CBuilder6\Bin\dclclxstd60.bpl=Composants Standard CLX Borland - -[HistoryLists\hlIncludePath] -Count=10 -Item0=..\src;$(BCB)\include;$(BCB)\include\vcl;C:\dev\cvs\simgrid\win32_test_app\include -Item1=..\src;$(BCB)\include;$(BCB)\include\vcl;C:\com\inria\projects\simgrid\win32_test_app\include -Item2=$(BCB)\include; $(BCB)\include\vcl;C:\dev\cvs\simgrid\win32_test_app\include -Item3=C:\dev\cvs\simgrid\win32_test_app\src -Item4=..\..\..\src\xbt\collection;C:\Program Files\Borland\CBuilder5;$(BCB)\include;$(BCB)\include\vcl;..\..\..\include -Item5=C:\Program Files\Borland\CBuilder5;$(BCB)\include;$(BCB)\include\vcl;..\..\..\include -Item6=..\..\..\src\xbt\collection;C:\Program Files\Borland\CBuilder5\;$(BCB)\include;$(BCB)\include\vcl;..\..\..\include -Item7=C:\Program Files\Borland\CBuilder5\;$(BCB)\include;$(BCB)\include\vcl;C:\com\inria\projects\sg\include -Item8=..\..\..\src\xbt\collection;C:\Program Files\Borland\CBuilder5\;$(BCB)\include;$(BCB)\include\vcl -Item9=C:\Program Files\Borland\CBuilder5\;$(BCB)\include;$(BCB)\include\vcl - -[HistoryLists\hlLibraryPath] -Count=7 -Item0=..\src;$(BCB)\lib;$(BCB)\lib\obj -Item1=$(BCB)\lib;$(BCB)\lib\obj -Item2=C:\dev\cvs\simgrid\win32_test_app\src -Item3=..\..\..\src\xbt\collection;C:\Program Files\Borland\CBuilder5;$(BCB)\Projects\Lib;$(BCB)\lib\obj;$(BCB)\lib -Item4=C:\Program Files\Borland\CBuilder5;$(BCB)\Projects\Lib;$(BCB)\lib\obj;$(BCB)\lib -Item5=..\..\..\src\xbt\collection;C:\Program Files\Borland\CBuilder5\;$(BCB)\Projects\Lib;$(BCB)\lib\obj;$(BCB)\lib -Item6=C:\Program Files\Borland\CBuilder5\;$(BCB)\Projects\Lib;$(BCB)\lib\obj;$(BCB)\lib - -[HistoryLists\hlDebugSourcePath] -Count=1 -Item0=$(BCB)\source\vcl - -[HistoryLists\hlConditionals] -Count=1 -Item0=_DEBUG - -[HistoryLists\hlIntOutputDir] -Count=4 -Item0=C:\dev\cvs\simgrid\win32_test_app\obj -Item1=C:\com\inria\projects\simgrid\win32_test_app\obj -Item2=..\..\..\lib -Item3=C:\com\inria\projects\sg\lib - -[HistoryLists\hlFinalOutputDir] -Count=5 -Item0=C:\dev\cvs\simgrid\win32_test_app\bin\ -Item1=C:\com\inria\projects\simgrid\win32_test_app\bin\ -Item2=C:\dev\cvs\simgrid\win32_test_app\bin -Item3=..\..\..\bin\test\ -Item4=C:\com\inria\projects\sg\bin\test - -[Debugging] -DebugSourceDirs=$(BCB)\source\vcl - -[Parameters] -RunParams=C:\buildslave\projects\simgrid\test\test_all.tst -Launcher= -UseLauncher=0 -DebugCWD= -HostApplication= -RemoteHost= -RemotePath= -RemoteLauncher= -RemoteCWD= -RemoteDebug=0 - -[Compiler] -ShowInfoMsgs=0 -LinkDebugVcl=0 -LinkCGLIB=0 - -[CORBA] -AddServerUnit=1 -AddClientUnit=1 -PrecompiledHeaders=1 - -[Language] -ActiveLang= -ProjectLang= -RootDir= - - \ No newline at end of file diff --git a/win32_test_app/prj/Test.res b/win32_test_app/prj/Test.res deleted file mode 100644 index 53d1accc46d0945afe50cda57289ae401923c1fa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 876 zcmb_bu}Z{15S{3iB3E2*N=xBd!N>)Ih58qMf?H&Zl!3edxgt%9gEaFQ78Z-Yu)epO zy^BT=!AIWCyq$ToA!J2Fa?txoq+jrUmg?u|$wFZmnzf z51ktJx=uSS%K~fEMvay)h1R3yAZqNR*91Rx^m4D$%|7Za>hxEy(N7N>lb;@*pZwHQ zKXt3ER`%QZdOZJwc!Opy&O3;dL$wcI0J?@&GnlB`P-kn@NLUAY0bJBf1H$Yieu;ht zxx&A3q96w`CXqkuA9$O2neqlRRI9TftkD F$tNfOCK><$ diff --git a/win32_test_app/src/TBuffer.c b/win32_test_app/src/TBuffer.c deleted file mode 100644 index cd41e18622..0000000000 --- a/win32_test_app/src/TBuffer.c +++ /dev/null @@ -1,117 +0,0 @@ -#include - -/* struct s_Buffer connected functions. */ - -/* Constructs an new buffer. - * If successful, the function returns a pointer to - * the new buffer. Otherwise, the function returns - * NULL. - */ -Buffer_t Buffer_new(void) -{ - Buffer_t buffer = (Buffer_t) calloc(1, sizeof(s_Buffer_t)); - - if (NULL == buffer) { - setErrno(E_BUFFER_ALLOCATION_FAILED); - return NULL; - } - - buffer->data = (char *) calloc(1, DEFAULT_Buffer_CAPACITY); - - - if (NULL == buffer->data) { - Buffer_free(buffer); - setErrno(E_BUFFER_DATA_ALLOCATION_FAILED); - return NULL; - } - - buffer->capacity = DEFAULT_Buffer_CAPACITY; - Buffer_clear(buffer); - return buffer; -} - -/* Clears the buffer (this function don't destroy it, - * see Buffer_free function.). - */ -void Buffer_clear(Buffer_t buffer) -{ - /* must be a valid buffer. */ - ASSERT_VALID_Buffer(buffer); - - buffer->size = 0; - buffer->data[0] = '\n'; - buffer->data[1] = '\0'; -} - -/* Appends a string in the buffer. If successful, - * the function returns true. Otherwise the function - * returns false. - */ -bool Buffer_append(Buffer_t buffer, char *str) -{ - size_t len = strlen(str); - size_t capacity_needed = buffer->size + len + 1; - size_t capacity_available = buffer->capacity - buffer->size; - - /* must be a valid buffer. */ - ASSERT_VALID_Buffer(buffer); - /* must be a valid string. */ - ASSERT_NOT_NULL(str); - - if (capacity_available < capacity_needed) { - buffer->data = (char *) realloc(buffer->data, capacity_needed); - - if (NULL == buffer->data) { - setErrno(E_Buffer_DATA_REALLOCATION_FAILED); - return false; - } - - buffer->capacity = capacity_needed; - } - - strcpy(buffer->data + buffer->size, str); - buffer->size += len; /* + 1 */ ; - - return true; -} - -/* - * Removes all the linefeed from the buffer. - */ -void Buffer_chomp(Buffer_t buffer) -{ - /* must be a valid buffer. */ - ASSERT_VALID_Buffer(buffer); - - while ((buffer->data[buffer->size - 1] == '\n') - || (buffer->data[buffer->size - 1] == '\r')) { - buffer->data[buffer->size - 1] = '\0'; - - if (buffer->size) - (buffer->size)--; - } -} - -/* - * Destroy the buffer. - */ -void Buffer_free(Buffer_t buffer) -{ - if (NULL == buffer) - return; - - free(buffer->data); - - free(buffer); -} - -/* - * This function returns true is the buffer is empty. - * Otherwrise the function returns false. - */ -bool Buffer_empty(Buffer_t buffer) -{ - /* must be a valid buffer. */ - ASSERT_VALID_Buffer(buffer); - return (buffer->size) == 0; -} diff --git a/win32_test_app/src/TErrno.c b/win32_test_app/src/TErrno.c deleted file mode 100644 index 59b51fcba6..0000000000 --- a/win32_test_app/src/TErrno.c +++ /dev/null @@ -1,46 +0,0 @@ -#include - -/* Global variable */ -static errno_t __errno = E_SUCCESS; -static CRITICAL_SECTION errno_cs; -static bool errno_cs_initialized = false; -static is_last_errno = false; - -void initializeErrno(void) -{ - if (!errno_cs_initialized) { - memset(&errno_cs, 0, sizeof(CRITICAL_SECTION)); - InitializeCriticalSection(&errno_cs); - errno_cs_initialized = true; - } -} - -void terminateErrno(void) -{ - if (errno_cs_initialized) { - DeleteCriticalSection(&errno_cs); - } -} - - -void setErrno(errno_t e) -{ - EnterCriticalSection(&errno_cs); - - if ((E_SUCCESS != e) && !is_last_errno) { - __errno = e; - is_last_errno = true; - } - - LeaveCriticalSection(&errno_cs); -} - -errno_t getErrno(void) -{ - errno_t e; - EnterCriticalSection(&errno_cs); - e = __errno; - LeaveCriticalSection(&errno_cs); - - return e; -} diff --git a/win32_test_app/src/TStream.c b/win32_test_app/src/TStream.c deleted file mode 100644 index da18135d95..0000000000 --- a/win32_test_app/src/TStream.c +++ /dev/null @@ -1,631 +0,0 @@ -#include - -extern const char *TOKENS = "$<>#!p&"; - -CRITICAL_SECTION cs; - -const char *__metacommandlist[] = { - "set timeout ", - "enable output checking", - "disable output checking", - "enable post output checking", - "disable post output checking", - "expect exit code ", - "export ", - "unset ", - "create console", - "create no console", - "enable exit code checking", - "disable exit code checking", - "command line ", - NULL -}; - -/* - * Create a new s_Stream struct and return - * a pointer to self - */ - -Stream_t Stream_new(void) -{ - Stream_t ptr = (Stream_t) calloc(1, sizeof(s_Stream_t)); - - if (NULL == ptr) { - setErrno(E_STREAM_ALLOCATION_FAILED); - Stream_free(ptr); - } - - memset(&cs, 0, sizeof(CRITICAL_SECTION)); - InitializeCriticalSection(&cs); - - ptr->line = NULL; - ptr->line_number = 0; - - return ptr; -} - -/* - * Returns true if the current text line is blank. - */ -bool Stream_lineIsBlank(Stream_t stream) -{ - size_t i = 0; - char *p = (char *) stream->line; - - while (p[i] != '\n') { - if (!Stream_isBlankChar(p[i])) - return false; - i++; - - } - - return true; -} - -/* - * Return true if the caracter is space or tab. - */ -bool Stream_isBlankChar(char ch) -{ - return ((ch == ' ') || ch == ('\t')); -} - -/* - * Return E_SUCCESS if the file is valid. - * Otherwise the fuction returns E_INVALID_FILE. - */ -errno_t Stream_isValidFile(const char *file_name) -{ - WIN32_FIND_DATA wfd = { 0 }; - HANDLE hFile = FindFirstFile(file_name, &wfd); - - if (INVALID_HANDLE_VALUE == hFile) - return E_FILE_NOT_FOUND; - - FindClose(hFile); - return E_SUCCESS; -} - -/* - * Return E_SUCCESS is the open file operation succeeded. - * Otherwise the functions returns E_OPEN_FILE_FAILED. - */ -errno_t Stream_openFile(Stream_t ptr, const char *file_name) -{ - ptr->file = fopen(file_name, "r"); - - if (NULL == ptr->file) { - setErrno(E_OPEN_FILE_FAILED); - return getErrno(); - } - - return E_SUCCESS; -} - -/* - * This function reads an entire line, storing - * the address of the buffer containing the text into - * *dest. - */ -ssize_t Stream_getLine(Stream_t stream) -{ - size_t capacity_available; /* capacity available in the buffer */ - char *pos; /* read operation position */ - ssize_t size; /* the size of the text line (minus the 0 terminal */ - static size_t len = 0; - register int ch; /* the current character */ - FILE *file = stream->file; - - if (NULL == file) { - setErrno(E_INVALID_FILE_Stream); - return -1; - } - - if (NULL == stream->line) { - len = DEFAULT_ALLOC_SIZE; - stream->line = (char *) calloc(1, len); - - if (NULL == stream->line) { - setErrno(E_STREAM_LINE_ALLOCATION_FAILED); - return -1; - } - } else { - memset(stream->line, 0, len); - } - - capacity_available = len; - pos = stream->line; - - while (true) { - ch = getc(file); - - /* un byte for the next char and one byte for the zero terminal. */ - if (capacity_available < 2) { - if (len > DEFAULT_ALLOC_SIZE) - len = len << 1; - else - len += DEFAULT_ALLOC_SIZE; - - capacity_available = stream->line + len - pos; - stream->line = realloc(stream->line, len); - - if (NULL == stream->line) { - setErrno(E_STREAM_LINE_REALLOCATION_FAILED); - return -1; - } - - pos = stream->line + len - capacity_available; - } - - if (ferror(file)) { - /* file error exit on error */ - setErrno(E_STREAM_ERROR); - return -1; - } - - if ((EOF == ch)) { - /* Empty file */ - if (!strlen(stream->line) && !stream->line_number) { - setErrno(E_STREAM_EMPTY); - return -1; - } - /* end of file */ - else if (!strlen(stream->line) && stream->line_number) { - return -1; - } - - break; - } - - *pos++ = ch; - capacity_available--; - - /* we have a line, exit loop */ - if (ch == '\n') - break; - } - - /* append the zero terminal */ - - *pos = '\0'; - size = pos - stream->line; - - stream->line_number++; - - /* size of texte line without zero terminal */ - return size; -} - - -/* - * Free a s_Stream. - */ - -void Stream_free(Stream_t ptr) -{ - if (NULL == ptr) - return; - - if ((NULL != ptr->file) && (stdin != ptr->file)) - fclose(ptr->file); - - free(ptr->line); - - DeleteCriticalSection(&cs); - - free(ptr); -} - -/* - * Return true if the current line is a comment. - * Otherwise the functions returns false. - */ -bool Stream_lineIsComment(Stream_t stream) -{ - return stream->line[0] == '#'; -} - -/* Return true if the current line contains a invalide token. - * Otherwise, the function returns false. - */ -bool Stream_lineContainsInvalidToken(Stream_t stream) -{ - if (strchr(TOKENS, stream->line[0]) == NULL) { - Stream_printLine(stream, invalid_token_line_type); - setErrno(E_INVALID_TOKEN); - return true; - } - - return false; -} - -/* - * Return true if the text line is a meta command. - * Otherwise, the functions returns false. - */ -bool Stream_lineIsMetacommand(Stream_t stream) -{ - return stream->line[0] == '!'; -} - -/* Retun true if the text line contains a unknown meta command. - * Otherwise the function returns false. - */ -bool Stream_lineIsUnknwnMetaCommand(Stream_t stream) -{ - size_t i = 0; - while (__metacommandlist[i]) { - if (!strncmp - (__metacommandlist[i], stream->line + 2, - strlen(__metacommandlist[i]))) - return false; - i++; - } - - Stream_printLine(stream, unknwn_meta_command_line_type); - - setErrno(E_UNKWN_META_COMMAND); - return true; -} - -/* - * Return true if the text line contains a invalid - * meta command. Otherwise the function returns false. - */ -bool Stream_lineIsInvalidMetaCommand(Stream_t stream) -{ - if (!strncmp("set timeout ", stream->line + 2, strlen("set timeout "))) { - return Stream_isInvalidTimeout(stream); - } else - if (!strncmp - ("command line ", stream->line + 2, strlen("command line "))) { - Stream_printLine(stream, command_line_line_type); - } else - if (!strncmp - ("enable output checking", stream->line + 2, - strlen("enable output checking"))) { - Stream_printLine(stream, enable_output_checking_line_type); - } else - if (!strncmp - ("disable output checking", stream->line + 2, - strlen("disable output checking"))) { - Stream_printLine(stream, disable_output_checking_line_type); - } else - if (!strncmp - ("enable post output checking", stream->line + 2, - strlen("enable post output checking"))) { - Stream_printLine(stream, enable_post_output_checking_line_type); - } else - if (!strncmp - ("disable post output checking", stream->line + 2, - strlen("disable post output checking"))) { - Stream_printLine(stream, disable_post_output_checking_line_type); - } else - if (!strncmp - ("expect exit code ", stream->line + 2, - strlen("expect exit code "))) { - return Stream_isInvalidExpectedCode(stream); - } else if (!strncmp("export ", stream->line + 2, strlen("export "))) { - return Stream_isInvalidExport(stream); - } else if (!strncmp("unset ", stream->line + 2, strlen("unset "))) { - return Stream_isInvalidUnset(stream); - } else - if (!strncmp - ("create console", stream->line + 2, strlen("create console"))) { - Stream_printLine(stream, create_console_line_type); - } else - if (!strncmp - ("create no console", stream->line + 2, - strlen("create no console"))) { - Stream_printLine(stream, create_no_console_line_type); - } else - if (!strncmp - ("enable exit code checking", stream->line + 2, - strlen("enable exit code checking"))) { - Stream_printLine(stream, enable_exit_code_checking_line_type); - } else - if (!strncmp - ("disable exit code checking", stream->line + 2, - strlen("disaable exit code checking"))) { - Stream_printLine(stream, disable_exit_code_checking_line_type); - } else { - return true; - } - - return false; - -} - - - -/* - * Print the file line. - */ -void Stream_printLine(Stream_t stream, line_type_t line_type) -{ - char *__date = NULL; - __date = (char *) calloc(1, 30); - - __time(__date); - - - Stream_lock(stream); - - switch (line_type) { -#ifdef __VERBOSE - case comment_line_type: - - if (*(stream->line + 2) != '\0') - printf("%s %3d %s", __date, - stream->line_number, stream->line + 2); - else - /* empty comment */ - printf("%s %3d %s", __date, - stream->line_number, " \n"); - break; - - case timeout_value_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line + 2 + strlen("set timeout ")); - break; - - case exit_code_line_type: - printf("%s %3d %s", __date, - stream->line_number, - stream->line + 2 + strlen("expect exit code ")); - break; - - case export_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line + 2); - break; - - case unset_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line + 2); - break; - - case enable_output_checking_line_type: - printf("%s %3d\n", __date, - stream->line_number); - break; - - case disable_output_checking_line_type: - printf("%s %3d\n", __date, - stream->line_number); - break; - - case enable_post_output_checking_line_type: - printf("%s %3d\n", __date, - stream->line_number); - break; - - case disable_post_output_checking_line_type: - printf("%s %3d\n", __date, - stream->line_number); - break; - - case create_console_line_type: - printf("%s %3d\n", __date, - stream->line_number); - break; - - case create_no_console_line_type: - printf("%s %3d\n", __date, - stream->line_number); - break; - - case enable_exit_code_checking_line_type: - printf("%s %3d\n", __date, - stream->line_number); - break; - - case disable_exit_code_checking_line_type: - printf("%s %3d\n", __date, - stream->line_number); - break; - - case change_directory_line_type: - printf("%s %3d %s\n", __date, - stream->line_number, stream->line + 5); - break; - - case command_line_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line + 2); - break; - -#endif /* #ifdef __VERBOSE */ - - case invalid_token_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line); - break; - - case unknwn_meta_command_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line); - break; - - case invalid_timeout_value_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line); - break; - - case invalid_exit_code_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line); - break; - - case invalid_export_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line); - break; - - case invalid_unset_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line); - break; - - case export_failed_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line); - break; - - case unset_failed_line_type: - printf("%s %3d %s", __date, - stream->line_number, stream->line); - break; - - /* default: - ASSERT(false); - */ - } - - free(__date); - - Stream_unlock(stream); -} - - -/* - * Returns true if the timeout value is invalid. - * Otherwise the function returns false. - */ -bool Stream_isInvalidTimeout(Stream_t stream) -{ - size_t i = 0; - char *p = stream->line + 2 + strlen("set timeout "); - - while (p[i] != '\n') { - if (!isdigit(p[i])) { - setErrno(E_INVALID_TIMEOUT_VALUE); - Stream_printLine(stream, invalid_timeout_value_line_type); - return true; - } - - i++; - } - - Stream_printLine(stream, timeout_value_line_type); - return false; -} - - -/* - * Returns true if the expected code value is invalid. - * Otherwise the function returns false. - */ -bool Stream_isInvalidExpectedCode(Stream_t stream) -{ - size_t i = 0; - char *p = stream->line + 2 + strlen("expect exit code "); - - while (p[i] != '\n') { - if (!isdigit(p[i])) { - setErrno(E_INVALID_EXIT_CODE_VALUE); - Stream_printLine(stream, invalid_exit_code_line_type); - return true; - } - i++; - } - - Stream_printLine(stream, exit_code_line_type); - return false; -} - - -/* - * Returns true if the export is invalid. - * Otherwise the function returns false. - */ -bool Stream_isInvalidExport(Stream_t stream) -{ - /* todo trim */ - const char *ptr = strchr(stream->line, '='); - - if (ptr && (*(++ptr) != '\n')) { - Stream_printLine(stream, export_line_type); - return false; - } - - setErrno(E_INVALID_EXPORT); - Stream_printLine(stream, invalid_export_line_type); - return true; -} - -/* - * Returns true if the unset is invalid. - * Otherwise the function returns false. - */ -bool Stream_isInvalidUnset(Stream_t stream) -{ - /* todo trim */ - const char *ptr = strchr(stream->line, ' '); - - if ((*(++ptr) != '\n')) { - Stream_printLine(stream, unset_line_type); - return false; - } - - setErrno(E_INVALID_UNSET); - Stream_printLine(stream, invalid_unset_line_type); - - - return true; -} - - -/* - * Return true if the stream line contains a - * expected child output. Otherwhise the function - * returns false. - */ - -bool Stream_lineIsExpectedChildOutput(Stream_t stream) -{ - return stream->line[0] == '>'; -} - -/* - * Return true if the stream line contains a - * child input. Otherwhise the function - * returns false. - */ -bool Stream_lineIsChildInput(Stream_t stream) -{ - return stream->line[0] == '<'; -} - - - -/* - * Return true, if the stream line containts a - * synchrone test case. otherwise the function - * returns false. - */ -bool Stream_lineIsSyncTestCase(Stream_t stream) -{ - return stream->line[0] == '$'; -} - -bool Stream_lineIsAsyncTestCase(Stream_t stream) -{ - return stream->line[0] == '&'; -} - -bool Stream_lineIsChangeDir(Stream_t stream) -{ - return ((stream->line[0] == '$') - && (!strncmp(stream->line + 2, "cd ", strlen("cd ")))); -} - -void Stream_lock(Stream_t ptr) -{ - EnterCriticalSection(&cs); -} - -void Stream_unlock(Stream_t ptr) -{ - LeaveCriticalSection(&cs); -} diff --git a/win32_test_app/src/TTestCaseContext.c b/win32_test_app/src/TTestCaseContext.c deleted file mode 100644 index ed14c542c3..0000000000 --- a/win32_test_app/src/TTestCaseContext.c +++ /dev/null @@ -1,299 +0,0 @@ -#include - -/* - * Implementation of s_TestCaseContext connected functions. - */ - -/* - * Create a new s_TestCaseContext and returns a pointer to self. - */ -TestCaseContext_t TestCaseContext_new(void) -{ - TestCaseContext_t context = calloc(1, sizeof(s_TestCaseContext_t)); - - if (NULL == context) { - setErrno(E_TEST_CASE_CONTEXT_ALLOCATION_FAILED); - return NULL; - } - - context->inputBuffer = Buffer_new(); - - if (NULL == context->inputBuffer) { - TestCaseContext_free(context); - return NULL; - } - - context->outputBuffer = Buffer_new(); - - if (NULL == context->outputBuffer) { - TestCaseContext_free(context); - return NULL; - } - - context->expectedOutputBuffer = Buffer_new(); - - if (NULL == context->expectedOutputBuffer) { - TestCaseContext_free(context); - return NULL; - } - - context->commandLineBuffer = Buffer_new(); - - if (NULL == context->commandLineBuffer) { - TestCaseContext_free(context); - return NULL; - } - - - context->isOutputCheckingEnabled = DEFAULT_OUTPUT_CHECKING_MODE; - context->isPostOutputCheckingEnabled = DEFAULT_POST_OUTPUT_CHECKING_MODE; - context->timeoutValue = DEFAULT_TIMEOUT_VALUE; - context->expectedExitCode = INVALID_EXIT_CODE; - context->exitCode = INVALID_EXIT_CODE; - context->name = NULL; - - context->runThread = true; - context->hThread = NULL; - context->hOutputRead = NULL; - context->hInputWrite = NULL; - context->hChildStdInRead = NULL; - context->hChildStdOutWrite = NULL; - context->hChildStderr = NULL; - context->hChildStdoutReadTmp = NULL; - context->hChildStdinWriteTmp = NULL; - context->hConsole = NULL; - - context->createConsole = false; - context->exitCodeCheckingEnabled = false; - - context->started = false; - - memset(&(context->pi), 0, sizeof(PROCESS_INFORMATION)); - - return context; -} - -/* - * Destroy the s_TestCaseContext referenced by context. - */ -void TestCaseContext_free(TestCaseContext_t context) -{ - if (NULL == context) - return; - - if (NULL != context->inputBuffer) - Buffer_free(context->inputBuffer); - - if (NULL != context->outputBuffer) - Buffer_free(context->outputBuffer); - - if (NULL != context->expectedOutputBuffer) - Buffer_free(context->expectedOutputBuffer); - - if (NULL != context->commandLineBuffer) - Buffer_free(context->commandLineBuffer); - - if (NULL == context->name) - free(context->name); - - - /* Close all pipe handles. */ - if (context->hChildStdoutReadTmp) - CloseHandle(context->hChildStdoutReadTmp); - - if (context->hChildStdInRead) - CloseHandle(context->hChildStdInRead); - - if (context->hChildStdinWriteTmp) - CloseHandle(context->hChildStdinWriteTmp); - - if (context->hChildStdOutWrite) - CloseHandle(context->hChildStdOutWrite); - - if (context->hOutputRead) - CloseHandle(context->hOutputRead); - - if (context->pi.hThread) - CloseHandle(context->pi.hThread); - - /* Use some violence, no choice. */ - if (context->pi.hProcess) { - /* Kill the child process. */ - TerminateProcess(context->pi.hProcess, 0); - } - - if (context->hThread) { - /* Terminate the thread */ - TerminateThread(context->hThread, 0); - } - - if (context->hInputWrite) - CloseHandle(context->hInputWrite); - - if (context->hChildStderr) - CloseHandle(context->hChildStderr); - - free(context); - context = NULL; -} - -/* - * Set the timeout of the test case context. - */ -void TestCaseContext_setTimeout(TestCaseContext_t context, int timeout) -{ - context->timeoutValue = timeout; -} - -/* - * Enable the output checking of the test case context. - */ -void TestCaseContext_enableOutputChecking(TestCaseContext_t context) -{ - context->isOutputCheckingEnabled = true; -} - -/* - * Enable the output checking of the test case context. - */ -void TestCaseContext_disableOutputChecking(TestCaseContext_t context) -{ - /* If the post output checking mode is enable, disable it */ - context->isPostOutputCheckingEnabled = false; - context->isOutputCheckingEnabled = false; -} - -/* - * Enable the post output checking of the test case context. - */ -void TestCaseContext_enable_post_output_checking(TestCaseContext_t context) -{ - /* enable the post output checking mode if the output checking mode is enabled */ - if (context->isOutputCheckingEnabled) - context->isPostOutputCheckingEnabled = true; -} - -/* - * Disable the post output checking of the test case context. - */ -void TestCaseContext_disablePostOutputChecking(TestCaseContext_t context) -{ - context->isPostOutputCheckingEnabled = false; -} - -void TestCaseContext_createConsole(TestCaseContext_t context) -{ - context->createConsole = true; -} - -void TestCaseContext_createNoConsole(TestCaseContext_t context) -{ - context->createConsole = false; -} - -/* - * Set the expected exit code of the test case context. - */ -void TestCaseContext_setExpectedExitCode(TestCaseContext_t context, - int expected_code) -{ - context->expectedExitCode = expected_code; -} - -/* - * Return true if the output checking mode is enabled for this - * test case context. Otherwise the functions returns false. - */ -bool TestCaseContext_isOutputCheckingEnabled(TestCaseContext_t context) -{ - return context->isOutputCheckingEnabled; -} - -void TestCaseContext_enableExitCodeChecking(TestCaseContext_t context) -{ - context->exitCodeCheckingEnabled = true; -} - -void TestCaseContext_disableExitCodeChecking(TestCaseContext_t context) -{ - context->exitCodeCheckingEnabled = false; -} - -void TestCaseContext_setCommandLine(TestCaseContext_t context, - char *cmdLine) -{ - Buffer_append(context->commandLineBuffer, cmdLine); -} - - -/* - * Append a child output to check in the - * test case context. - */ -void TestCaseContext_appendExpectedOutput(TestCaseContext_t context, - char *expected_output) -{ - Buffer_append(context->expectedOutputBuffer, expected_output); -} - -/* - * Append a child output to check in the - * test case context. - */ -void TestCaseContext_appendChildInput(TestCaseContext_t context, - char *input) -{ - Buffer_append(context->inputBuffer, input); -} - -/* - * Set the name of the test case name. - */ -void TestCaseContext_setName(TestCaseContext_t context, char *name) -{ - size_t size; - - free(context->name); - - context->name = strdup(name); - size = strlen(name); - - while ((context->name[size - 1] == '\n') - || (context->name[size - 1] == '\r')) { - context->name[size - 1] = '\0'; - - if (size) - size--; - } - - /*context->name[strlen(context->name) - 1] ='\0'; */ -} - -/* - * Clear the s_TestCaseContext referenced by context. - */ -void TestCaseContext_clear(TestCaseContext_t context) -{ - if (!Buffer_empty(context->inputBuffer)) - Buffer_clear(context->inputBuffer); - - if (!Buffer_empty(context->outputBuffer)) - Buffer_clear(context->outputBuffer); - - if (!Buffer_empty(context->expectedOutputBuffer)) - Buffer_clear(context->expectedOutputBuffer); - - if (!Buffer_empty(context->commandLineBuffer)) - Buffer_clear(context->commandLineBuffer); - - if (NULL == context->name) { - free(context->name); - context->name = NULL; - } - - context->isOutputCheckingEnabled = DEFAULT_OUTPUT_CHECKING_MODE; - context->isPostOutputCheckingEnabled = DEFAULT_POST_OUTPUT_CHECKING_MODE; - context->timeoutValue = DEFAULT_TIMEOUT_VALUE; - context->expectedExitCode = INVALID_EXIT_CODE; - context->exitCode = INVALID_EXIT_CODE; -} diff --git a/win32_test_app/src/TTestRunner.c b/win32_test_app/src/TTestRunner.c deleted file mode 100644 index 3855f96430..0000000000 --- a/win32_test_app/src/TTestRunner.c +++ /dev/null @@ -1,68 +0,0 @@ -#include - - -/* - * Create an new s_TestRunner struct and - * returns a pointer to self. - */ -TestRunner_t TestRunner_new(void) -{ - TestRunner_t ptr = calloc(1, sizeof(s_TestRunner_t)); - - if (NULL == ptr) { - setErrno(E_TEST_RUNNER_ALLOCATION_FAILED); - return NULL; - } - - ptr->buffer = Buffer_new(); - - if (NULL == ptr->buffer) { - TestRunner_free(ptr); - return NULL; - } - - ptr->testSuite = TestSuite_new(); - - if (NULL == ptr->testSuite) { - TestRunner_free(ptr); - return NULL; - } - - setErrno(E_SUCCESS); - return ptr; -} - -/* - * Initialize the s_TestRunner struct - * by processing the command line. - */ -errno_t TestRunner_initialize(TestRunner_t runner, int argc, char *argv[]) -{ - if (E_SUCCESS != TestSuite_initialize(runner->testSuite, argc, argv)) - return getErrno(); - - return E_SUCCESS; -} - -/* - * Launch the test runner. - */ -void TestRunner_run(TestRunner_t runner) -{ - TestSuite_run(runner->testSuite); -} - -/* - * Free the s_TestRunner. - */ -void TestRunner_free(TestRunner_t runner) -{ - if (NULL == runner) - return; - - if (NULL != runner->buffer) - Buffer_free(runner->buffer); - - if (NULL != runner->testSuite) - TestSuite_free(runner->testSuite); -} diff --git a/win32_test_app/src/TTestSuite.c b/win32_test_app/src/TTestSuite.c deleted file mode 100644 index 30fc661900..0000000000 --- a/win32_test_app/src/TTestSuite.c +++ /dev/null @@ -1,1080 +0,0 @@ -#include - - -/* - * Create a new s_TestSuite an returns a pointer to self. - */ -TestSuite_t TestSuite_new(void) -{ - TestSuite_t testSuite = calloc(1, sizeof(s_TestSuite_t)); - - if (NULL == testSuite) { - setErrno(E_TEST_SUITE_ALLOCATION_FAILED); - TestSuite_free(testSuite); - return NULL; - } - - testSuite->stream = Stream_new(); - - if (NULL == testSuite->stream) { - TestSuite_free(testSuite); - return NULL; - } - - testSuite->test_case_context = TestCaseContext_new(); - - if (NULL == testSuite->test_case_context) { - TestSuite_free(testSuite); - return NULL; - } - - testSuite->test_case_context->hConsole = GetStdHandle(STD_OUTPUT_HANDLE); - - testSuite->threads = ThreadDynarray_new(15); - - if (NULL == testSuite->threads) { - TestSuite_free(testSuite); - return NULL; - } - - testSuite->successCount = 0; - testSuite->failureCount = 0; - - return testSuite; -} - -/* - * Initialize the s_TestSuite structure. - */ -errno_t TestSuite_initialize(TestSuite_t ptr, int argc, char *argv[]) -{ - switch (argc) { - case 1: - TestSuite_print("Run the test case from the console.\n"); - - ptr->stream->file = stdin; - return E_SUCCESS; - - case 2: - - if (E_SUCCESS != Stream_isValidFile(argv[1])) - return getErrno(); - - printf("\n\n Test runner : %s\n\n", argv[1]); - - if (E_SUCCESS != Stream_openFile(ptr->stream, argv[1])) - return getErrno(); - - return E_SUCCESS; - - default: - { - setErrno(E_BAD_USAGE); - return getErrno(); - } - } -} - -/* - * Launch the test suite. - */ -void TestSuite_run(TestSuite_t testSuite) -{ - Stream_t stream = testSuite->stream; - - /* Handle all lines in the testsuite file (or from stdin) */ - while ((Stream_getLine(stream) != -1) && (E_SUCCESS == getErrno())) { - /* Don't process blank lines. */ - if (Stream_lineIsBlank(stream)) - continue; - - /* Check if the current text line contains a invalid token. */ - if (Stream_lineContainsInvalidToken(stream)) - return; - - /* Check if the text line contains a meta command. */ - if (Stream_lineIsMetaCommand(stream)) { - /* Check if the current text line contains a unknown meta command. */ - if (Stream_lineIsUnknwnMetaCommand(stream)) - return; - - /* Check the meta command validity. */ - if (Stream_lineIsInvalidMetaCommand(stream)) - return; - - /* We have a valid meta command, process it */ - if (E_SUCCESS != TestSuite_processMetaCommand(testSuite)) - return; - - continue; - } - - /* Handle the comment. */ - if (Stream_lineIsComment(stream)) { - Stream_printLine(testSuite->stream, comment_line_type); - continue; - } - - /* Handle expected child output. */ - if (Stream_lineIsExpectedChildOutput(stream)) { - if (E_SUCCESS != TestSuite_processExpectedChildOutput(testSuite)) - return; - - continue; - } - - /* Handle expected child input. */ - if (Stream_lineIsChildInput(stream)) { - if (E_SUCCESS != TestSuite_processChildInput(testSuite)) - return; - - continue; - } - - if (Stream_lineIsChangeDir(stream)) { - if (E_SUCCESS != TestSuite_changeDir(testSuite)) - return; - - continue; - } - - /* Handle synchrone synchrone test case. */ - if (Stream_lineIsSyncTestCase(stream)) { - TestCaseContext_setName(testSuite->test_case_context, - stream->line + 2); - - TestSuite_runSyncTestCase(testSuite->test_case_context); - - - if (TestSuite_iSPostOutputCheckingEnabled - (testSuite->test_case_context)) { - TestSuite_checkChildOutput(testSuite->test_case_context); - } - - if (TestSuite_iSExitCodeCheckingEnabled - (testSuite->test_case_context)) { - if (E_SUCCESS != - TestSuite_checkChildExitCode(testSuite->test_case_context)) - return; - } - - - if (E_SUCCESS != getErrno()) - return; - } - /* Handle asynchrone synchrone test case. */ - else if (Stream_lineIsAsyncTestCase(stream)) { - TestCaseContext_setName(testSuite->test_case_context, - stream->line + 2); - - if (E_SUCCESS != TestSuite_runAsyncTestCase(testSuite)) - return; - } else { - ASSERT(false); - } - - /* Clear the child input stream. */ - Buffer_clear(testSuite->test_case_context->inputBuffer); - /* Clear the command line buffer. */ - Buffer_clear(testSuite->test_case_context->commandLineBuffer); - } -} - -/* - * Meta command processing. - */ -errno_t TestSuite_processMetaCommand(TestSuite_t testSuite) -{ - Stream_t stream = testSuite->stream; - - if (!strncmp("set timeout ", stream->line + 2, strlen("set timeout "))) { - TestSuite_setTimeout(testSuite); - } else - if (!strncmp - ("command line ", stream->line + 2, strlen("command line"))) { - TestSuite_setCommandLine(testSuite); - } else - if (!strncmp - ("enable output checking", stream->line + 2, - strlen("enable output checking"))) { - TestSuite_enableOutputChecking(testSuite); - } else - if (!strncmp - ("disable output checking", stream->line + 2, - strlen("disable output checking"))) { - TestSuite_disableOutputChecking(testSuite); - } else - if (!strncmp - ("enable post output checking", stream->line + 2, - strlen("enable post output checking"))) { - TestSuite_enablePostOutputChecking(testSuite); - } else - if (!strncmp - ("disable post output checking", stream->line + 2, - strlen("disable post output checking"))) { - TestSuite_disablePostOutputChecking(testSuite); - } else - if (!strncmp - ("expect exit code ", stream->line + 2, - strlen("expect exit code "))) { - TestSuite_setExpectedExitCode(testSuite); - } else if (!strncmp("export ", stream->line + 2, strlen("export "))) { - TestSuite_export(testSuite); - } else if (!strncmp("unset ", stream->line + 2, strlen("unset "))) { - TestSuite_unset(testSuite); - } else - if (!strncmp - ("create console", stream->line + 2, strlen("create console"))) { - TestSuite_createConsole(testSuite); - } else - if (!strncmp - ("create no console", stream->line + 2, - strlen("create no console"))) { - TestSuite_createNoConsole(testSuite); - } else - if (!strncmp - ("enable exit code checking", stream->line + 2, - strlen("enable exit code checking"))) { - TestSuite_enableExitCodeChecking(testSuite); - } else - if (!strncmp - ("disable exit code checking", stream->line + 2, - strlen("disable exit code checking"))) { - TestSuite_disableExitCodeChecking(testSuite); - } else { - /* TODO */ - ASSERT(false); - } - - return E_SUCCESS; - -} - -/* - * Set the timeout of the test case context of the - * test suite. - */ -void TestSuite_setTimeout(TestSuite_t testSuite) -{ - - int timeout = atoi(testSuite->stream->line + 2 + strlen("set timeout ")); - TestCaseContext_setTimeout(testSuite->test_case_context, timeout); -} - -/* - * Enable output checking for the current test case context. - */ -void TestSuite_enableOutputChecking(TestSuite_t testSuite) -{ - TestCaseContext_enableOutputChecking(testSuite->test_case_context); -} - -void TestSuite_setCommandLine(TestSuite_t testSuite) -{ - TestCaseContext_setCommandLine(testSuite->test_case_context, - testSuite->stream->line + 2 + - strlen("command line ")); -} - -/* - * Disable output checking for the current test case context. - */ -void TestSuite_disableOutputChecking(TestSuite_t testSuite) -{ - TestCaseContext_disableOutputChecking(testSuite->test_case_context); -} - -/* - * Enable post output checking for the current test case context. - */ -void TestSuite_enablePostOutputChecking(TestSuite_t testSuite) -{ - TestCaseContext_enable_post_output_checking(testSuite-> - test_case_context); -} - -void TestSuite_createConsole(TestSuite_t testSuite) -{ - TestCaseContext_createConsole(testSuite->test_case_context); -} - -void TestSuite_createNoConsole(TestSuite_t testSuite) -{ - TestCaseContext_createNoConsole(testSuite->test_case_context); -} - -/* - * Disable post output checking for the current test case context. - */ -void TestSuite_disablePostOutputChecking(TestSuite_t testSuite) -{ - TestCaseContext_disablePostOutputChecking(testSuite->test_case_context); -} - -/* - * Set the expected exit code of the current test case context of the test suite. - */ -void TestSuite_setExpectedExitCode(TestSuite_t testSuite) -{ - int expectedExitCode = - atoi(testSuite->stream->line + 2 + strlen("expect exit code ")); - TestCaseContext_setExpectedExitCode(testSuite->test_case_context, - expectedExitCode); -} - -void TestSuite_enableExitCodeChecking(TestSuite_t testSuite) -{ - TestCaseContext_enableExitCodeChecking(testSuite->test_case_context); -} - -void TestSuite_disableExitCodeChecking(TestSuite_t testSuite) -{ - TestCaseContext_disableExitCodeChecking(testSuite->test_case_context); -} - - -/* - * Export a variable in the environment of the current test_runner.exe process. - */ -errno_t TestSuite_export(TestSuite_t testSuite) -{ - /* TODO trim */ - const char *ptr; - const char *pos; - char __buffer[50] = { 0 }; - char *line = testSuite->stream->line + strlen("export "); - - line[strlen(line) - 1] = '\0'; - - ptr = strchr(line, ' '); - pos = ++ptr; - ptr = strchr(line, '='); - strncpy(__buffer, pos, ptr - pos); - if (!SetEnvironmentVariable(__buffer, ++ptr)) { - setErrno(E_EXPORT_FAILED); - Stream_printLine(testSuite->stream, export_failed_line_type); - return getErrno(); - - } - - return E_SUCCESS; -} - -errno_t TestSuite_unset(TestSuite_t testSuite) -{ - char line[128] = { 0 }; - const char *ptr; - strcpy(line, testSuite->stream->line + 2); - ptr = strchr(line, ' '); - line[strlen(line) - 1] = '\0'; - - if (!SetEnvironmentVariable(++ptr, NULL)) { - - setErrno(E_UNSET_FAILED); - Stream_printLine(testSuite->stream, unset_failed_line_type); - return getErrno(); - } - - return E_SUCCESS; -} - -/* - * Expected child output processing. - */ -errno_t TestSuite_processExpectedChildOutput(TestSuite_t testSuite) -{ - /* TODO : logic error */ - if (!TestCaseContext_isOutputCheckingEnabled - (testSuite->test_case_context)) - return E_SUCCESS; - - /* TODO : trim */ - TestCaseContext_appendExpectedOutput(testSuite->test_case_context, - testSuite->stream->line + 2); - - return E_SUCCESS; -} - -/* - * Child input processing. - */ -errno_t TestSuite_processChildInput(TestSuite_t testSuite) -{ - /* TODO : trim */ - TestCaseContext_appendChildInput(testSuite->test_case_context, - testSuite->stream->line + 2); - - return E_SUCCESS; -} - -/* - * Free the s_TestSuite pointed to by ptr. - */ -void TestSuite_free(TestSuite_t testSuite) -{ - ThreadEntry_t entry; - unsigned long count; - unsigned long i; - DWORD dwWaitResult; - bool steel_running; - bool last_async_process_error = false; - DWORD ExitCode = 0; - errno_t e = getErrno(); - - if (NULL == testSuite) - return; - - count = ThreadDynarray_getCount(testSuite->threads); - - /* Wait for all asynchrone process */ - if (NULL != testSuite->threads && count) { - while (true) { - steel_running = false; - - for (i = 0; i < count; i++) { - entry = ThreadDynarray_at(testSuite->threads, i); - - GetExitCodeThread(entry->hThread, &ExitCode); - - if (STILL_ACTIVE == ExitCode) { - Sleep(0); - steel_running = true; - } - } - - if (!steel_running) - break; - } - - for (i = 0; i < count; i++) { - entry = ThreadDynarray_at(testSuite->threads, i); - - if (entry->context->pi.hProcess) { - dwWaitResult = WaitForSingleObject(entry->hThread, INFINITE); - - if ((WAIT_FAILED == dwWaitResult)) - TerminateThread(entry->hThread, 0); - else - CloseHandle(entry->hThread); - } - - /*if(((E_SUCCESS == e) || (E_EXIT_CODE_DONT_MATCH == e) || (E_OUTPUT_DONT_MATCH == e)) && !last_async_process_error) - { */ - /* Child output and exit code checking */ - if (TestSuite_iSPostOutputCheckingEnabled(entry->context)) { - if (E_SUCCESS != TestSuite_checkChildOutput(entry->context)) - last_async_process_error = true; - } - - if (TestSuite_iSExitCodeCheckingEnabled(entry->context)) { - if (E_SUCCESS != TestSuite_checkChildExitCode(entry->context)) - last_async_process_error = true; - } - } - - TestCaseContext_free(entry->context); - /*} */ - - ThreadDynarray_destroy(testSuite->threads); - } - - if (NULL != testSuite->test_case_context) - TestCaseContext_free(testSuite->test_case_context); - - if (NULL != testSuite->stream) - Stream_free(testSuite->stream); - - free(testSuite); -} - -/* - * Check the child output. - */ -errno_t TestSuite_checkChildOutput(TestCaseContext_t context) -{ - bool are_equals = false; - char str[256] = { 0 }; - - - if (context->expectedOutputBuffer->size == 0 - && context->outputBuffer->size == 0) - return E_SUCCESS; - - Buffer_chomp(context->outputBuffer); - Buffer_chomp(context->expectedOutputBuffer); - - - if (context->outputBuffer->size != context->expectedOutputBuffer->size - || strcmp(context->outputBuffer->data, - context->expectedOutputBuffer->data)) { - strcpy(str, " \n"); - TestSuite_print(str); - - } else { - are_equals = true; - strcpy(str, " \n"); - TestSuite_print(str); - - - } - - memset(str, 0, 256); - - if (context->expectedOutputBuffer->size) { - sprintf(str, - " SIZE (%4d) DATA (%s)\n", - context->expectedOutputBuffer->size, - context->expectedOutputBuffer->data); - TestSuite_print(str); - } else { - scanf(str, - " SIZE (%4d) DATA (%s)\n", - context->expectedOutputBuffer->size, "empty"); - TestSuite_print(str); - } - - memset(str, 0, 256); - - if (context->outputBuffer->size) { - sprintf(str, - " SIZE (%4d) DATA (%s)\n", - context->outputBuffer->size, context->outputBuffer->data); - TestSuite_print(str); - } else { - sprintf(str, - " SIZE (%4d) DATA (%s)\n", - context->outputBuffer->size, "empty"); - TestSuite_print(str); - } - - Buffer_clear(context->expectedOutputBuffer); - Buffer_clear(context->outputBuffer); - - if (!are_equals) { - setErrno(E_OUTPUT_DONT_MATCH); - return getErrno(); - } - - return E_SUCCESS; -} - -/* - * Check the child process exit code. - */ -errno_t TestSuite_checkChildExitCode(TestCaseContext_t context) -{ - bool __success = false; - char str[256] = { 0 }; - - sprintf(str, " %s %3ld\n", - context->name, context->exitCode); - TestSuite_print(str); - - memset(str, 0, 256); - - /* if a expected exit code was signaled, compare it with the real. */ - if (context->expectedExitCode != INVALID_EXIT_CODE) { - if (context->expectedExitCode != context->exitCode) { - - TestSuite_print("\n"); - } else { - __success = true; - TestSuite_print("\n"); - } - sprintf(str, " (%3d)\n", - context->expectedExitCode); - TestSuite_print(str); - - memset(str, 0, 256); - - sprintf(str, " (%3d)\n", - context->exitCode); - TestSuite_print(str); - - context->expectedExitCode = INVALID_EXIT_CODE; - } - - if (!__success) { - setErrno(E_EXIT_CODE_DONT_MATCH); - return getErrno(); - } - - return E_SUCCESS; -} - -/* - * Terminate the test suite. - */ -void TestSuite_terminate(TestSuite_t testSuite) -{ - TestCaseContext_t context = testSuite->test_case_context; - - /* cleanup the child_input_stream/output buffers. */ - if (NULL != context->inputBuffer) - Buffer_free(context->inputBuffer); - - if (NULL != context->outputBuffer) - Buffer_free(context->outputBuffer); - - if (NULL != context->expectedOutputBuffer) - Buffer_free(context->expectedOutputBuffer); - - /* close the file stream. */ - if (NULL != testSuite->stream) - Stream_free(testSuite->stream); - - -} - - -/* - * Print message - */ -void TestSuite_print(const char *str) -{ - char *t = (char *) calloc(1, 20); - - __time(t); - - EnterCriticalSection(&cs); - printf("%s %s", t, str); - LeaveCriticalSection(&cs); - - free(t); - -} - -unsigned long WINAPI TestSuite_asyncReadChildOutput(void *param) -{ - char str[1024] = { 0 }; - char __buffer[1024] = { 0 }; - - DWORD nBytesRead; - DWORD nCharsWritten; - TestCaseContext_t context = (TestCaseContext_t) param; - HANDLE hPipeRead = context->hOutputRead; - - - while (context->runThread) { - if (!ReadFile(hPipeRead, str, sizeof(str), &nBytesRead, NULL) - || !nBytesRead) { - if (GetLastError() == ERROR_BROKEN_PIPE) { - break; - } else { - /* TODO */ - context->threadExitCode = 1; - exit(1); - } - } - - if (nBytesRead) { - if (context->isOutputCheckingEnabled) { - if (!Buffer_empty(context->outputBuffer)) - Buffer_clear(context->outputBuffer); - - TestSuite_print(str); - - - Buffer_append(context->outputBuffer, str); - } - - memset(str, 0, 1024); - memset(__buffer, 0, 1024); - } - - } - context->threadExitCode = 0; - return 0; -} - -errno_t TestSuite_runAsyncTestCase(TestSuite_t testSuite) -{ - DWORD ThreadId; - s_ThreadEntry_t entry; - /* = (ThreadEntry_t)calloc(1,sizeof(s_ThreadEntry_t)); */ - - TestCaseContext_t context = testSuite->test_case_context; - memset(&entry, 0, sizeof(s_ThreadEntry_t)); - entry.context = TestCaseContext_new(); - - Buffer_append(entry.context->inputBuffer, context->inputBuffer->data); - Buffer_append(entry.context->outputBuffer, context->outputBuffer->data); - Buffer_append(entry.context->expectedOutputBuffer, - context->expectedOutputBuffer->data); - Buffer_append(entry.context->commandLineBuffer, - context->commandLineBuffer->data); - entry.context->name = strdup(context->name); - entry.context->timeoutValue = context->timeoutValue; - entry.context->isOutputCheckingEnabled = - context->isOutputCheckingEnabled; - entry.context->isPostOutputCheckingEnabled = - context->isPostOutputCheckingEnabled; - entry.context->expectedExitCode = context->expectedExitCode; - entry.context->createConsole = context->createConsole; - entry.context->exitCodeCheckingEnabled = - context->exitCodeCheckingEnabled; - entry.context->hConsole = context->hConsole; - Buffer_clear(context->inputBuffer); - Buffer_clear(context->outputBuffer); - Buffer_clear(context->expectedOutputBuffer); - memset(&(entry.context->pi), 0, sizeof(PROCESS_INFORMATION)); - entry.context->runThread = true; - - entry.hThread = - CreateThread(NULL, 0, TestSuite_runSyncTestCase, - (LPVOID) entry.context, CREATE_SUSPENDED, &ThreadId); - entry.threadId = ThreadId; - ThreadDynarray_pushBack(testSuite->threads, &entry); - ResumeThread(entry.hThread); - Sleep(0); - setErrno(E_SUCCESS); - - return getErrno(); -} - -unsigned long WINAPI TestSuite_runSyncTestCase(void *param) -{ - STARTUPINFO si = { 0 }; - SECURITY_ATTRIBUTES sa = { 0 }; - DWORD dwWaitResult = 0; - DWORD dwExitCode = 0; - DWORD ThreadId; - DWORD nBytes = 0; - DWORD dwCreationMode = CREATE_NO_WINDOW; - char cmdLine[4098] = { 0 }; - - TestCaseContext_t context = (TestCaseContext_t) param; - context->started = true; - - - sa.nLength = sizeof(SECURITY_ATTRIBUTES); - sa.lpSecurityDescriptor = NULL; - /* The pipe handes can be inherited by the child. */ - sa.bInheritHandle = TRUE; - - /* Create a write pipe handle for the child std output */ - if (!CreatePipe - (&(context->hChildStdoutReadTmp), &(context->hChildStdOutWrite), &sa, - 0)) { - setErrno(E_CANNOT_CREATE_CHILD_STDOUT_READ_HANDLE); - return getErrno(); - } - - /* - * Create a duplicate of the output write handle for the std error - * write handle. This is necessary in case the child application closes - * one of its std output handles. - */ - if (!DuplicateHandle - (GetCurrentProcess(), (context->hChildStdOutWrite), - GetCurrentProcess(), &(context->hChildStderr), 0, TRUE, - DUPLICATE_SAME_ACCESS)) { - setErrno(E_CANNOT_CREATE_CHILD_STDERR_READ_HANDLE); - return getErrno(); - } - - /* Create a read pipe handle for the child std input */ - if (!CreatePipe - (&(context->hChildStdInRead), &(context->hChildStdinWriteTmp), &sa, - 0)) { - setErrno(E_CANNOT_CREATE_CHILD_STDIN_WRITE_HANDLE); - return getErrno(); - } - - - /* Create new output read handle and the input write handle use by - * the parent process to communicate with his child. Set the Properties - * to FALSE. Otherwise, the child inherits the properties and, as a - * result, non-closeable handles to the pipes are created. - */ - - /* Read handle for read operations on the child std output. */ - if (!DuplicateHandle - (GetCurrentProcess(), (context->hChildStdoutReadTmp), - GetCurrentProcess(), &(context->hOutputRead), 0, FALSE, - DUPLICATE_SAME_ACCESS)) { - setErrno(E_CANNOT_CREATE_STDOUT_READ_HANDLE); - return getErrno(); - } - - - /* Write handle for write operations on the child std input. */ - if (!DuplicateHandle - (GetCurrentProcess(), (context->hChildStdinWriteTmp), - GetCurrentProcess(), &(context->hInputWrite), 0, FALSE, - DUPLICATE_SAME_ACCESS)) { - setErrno(E_CANNOT_CREATE_STDIN_WRITE_HANDLE); - return getErrno(); - } - - - /* Close inheritable copies of the handles you do not want to be inherited. */ - if (!CloseHandle(context->hChildStdoutReadTmp)) { - setErrno(E_CANNOT_CLOSE_CHILD_STDIN_TEMPORY_HANDLE); - return getErrno(); - } - - context->hChildStdoutReadTmp = NULL; - - if (!CloseHandle(context->hChildStdinWriteTmp)) { - setErrno(E_CANNOT_CLOSE_CHILD_STDOUT_TEMPORY_HANDLE); - return getErrno(); - } - - - context->hChildStdinWriteTmp = NULL; - - si.cb = sizeof(STARTUPINFO); - /* Set the child std handles. */ - si.dwFlags = STARTF_USESTDHANDLES; - si.hStdOutput = context->hChildStdOutWrite; - si.hStdInput = context->hChildStdInRead; - si.hStdError = context->hChildStderr; - - if (context->createConsole) - dwCreationMode = CREATE_NEW_CONSOLE; - - if (!Buffer_empty(context->commandLineBuffer)) { - Buffer_chomp(context->commandLineBuffer); - sprintf(cmdLine, "%s %s", context->name, - context->commandLineBuffer->data); - } else - strcpy(cmdLine, context->name); - - - /* Create the child process. */ - if (!CreateProcess - (NULL, cmdLine, NULL, NULL, TRUE, dwCreationMode, NULL, NULL, &si, - &(context->pi))) { - setErrno(E_CANNOT_CREATE_CHILD_PROCESS); - return getErrno(); - } - - if (!CloseHandle(context->pi.hThread)) { - setErrno(E_CANNOT_CLOSE_PROCESS_THREAD_HANDLE); - return getErrno(); - } - - - context->pi.hThread = NULL; - - /* close unnessary pipe handles. */ - if (!CloseHandle(context->hChildStdOutWrite)) { - setErrno(E_CANNOT_CLOSE_CHILD_STDOUT_HANDLE); - return getErrno(); - } - - context->hChildStdOutWrite = NULL; - - if (!CloseHandle(context->hChildStdInRead)) { - setErrno(E_CANNOT_CLOSE_CHILD_STDIN_HANDLE); - return getErrno(); - } - - context->hChildStdInRead = NULL; - - if (!CloseHandle(context->hChildStderr)) { - setErrno(E_CANNOT_CLOSE_CHILD_STDERR_HANDLE); - return getErrno(); - } - - context->hChildStderr = NULL; - - if (!Buffer_empty(context->inputBuffer)) { - if (!WriteFile - (context->hInputWrite, context->inputBuffer->data, - context->inputBuffer->size, &nBytes, NULL)) { - setErrno(E_CANNOT_WRITE_ON_CHILD_STDIN); - return getErrno(); - } - } - - context->hThread = - CreateThread(&sa, 0, TestSuite_asyncReadChildOutput, - (LPVOID) context, 0, &ThreadId); - Sleep(0); - - if (NULL == context->hThread) { - setErrno(E_CANNOT_CREATE_READ_CHILD_OUTPUT_THREAD); - return getErrno(); - } - - - dwWaitResult = - WaitForSingleObject(context->pi.hProcess, context->timeoutValue); - - if (WAIT_FAILED == dwWaitResult) { - TerminateProcess(context->pi.hProcess, 0); - context->pi.hProcess = NULL; - context->runThread = false; - - if (WAIT_FAILED == WaitForSingleObject(context->hThread, INFINITE)) { - setErrno(E_WAIT_THREAD_FAILED); - return getErrno(); - } - - if (!CloseHandle(context->hThread)) { - setErrno(E_CANNOT_CLOSE_THREAD_HANDLE); - return getErrno(); - } - - context->hThread = NULL; - - if (!CloseHandle(context->hOutputRead)) { - setErrno(E_CANNOT_CLOSE_READ_HANDLE); - return getErrno(); - } - - context->hOutputRead = NULL; - - if (!CloseHandle(context->hInputWrite)) { - setErrno(E_CANNOT_CLOSE_WRITE_HANDLE); - return getErrno(); - } - - context->hInputWrite = NULL; - setErrno(E_WAIT_FAILURE); - return getErrno(); - } - - if (WAIT_TIMEOUT == dwWaitResult) { - TerminateProcess(context->pi.hProcess, 0); - context->pi.hProcess = NULL; - context->runThread = false; - - if (WAIT_FAILED == WaitForSingleObject(context->hThread, INFINITE)) { - setErrno(E_WAIT_THREAD_FAILED); - return getErrno(); - } - - if (!CloseHandle(context->hThread)) { - setErrno(E_CANNOT_CLOSE_THREAD_HANDLE); - return getErrno(); - } - - context->hThread = NULL; - - if (!CloseHandle(context->hOutputRead)) { - setErrno(E_CANNOT_CLOSE_READ_HANDLE); - return getErrno(); - } - - - context->hOutputRead = NULL; - - if (!CloseHandle(context->hInputWrite)) { - setErrno(E_CANNOT_CLOSE_WRITE_HANDLE); - return getErrno(); - } - - context->hInputWrite = NULL; - setErrno(E_WAIT_TIMEOUT); - return getErrno(); - } - - /* all is ok . */ - - context->runThread = false; - - if (WAIT_FAILED == WaitForSingleObject(context->hThread, INFINITE)) { - setErrno(E_WAIT_THREAD_FAILED); - return getErrno(); - } - - if (!CloseHandle(context->hThread)) { - setErrno(E_CANNOT_CLOSE_THREAD_HANDLE); - return getErrno(); - } - - context->hThread = NULL; - - if (!CloseHandle(context->hOutputRead)) { - setErrno(E_CANNOT_CLOSE_READ_HANDLE); - return getErrno(); - } - - context->hOutputRead = NULL; - - if (!CloseHandle(context->hInputWrite)) { - setErrno(E_CANNOT_CLOSE_WRITE_HANDLE); - return getErrno(); - } - - context->hInputWrite = NULL; - - - /* Get the child exit code before close it. */ - GetExitCodeProcess(context->pi.hProcess, &dwExitCode); - - context->exitCode = (int) dwExitCode; - - if (!CloseHandle(context->pi.hProcess)) { - setErrno(E_CANNOT_CLOSE_PROCESS_HANDLE); - return getErrno(); - } - - context->runThread = true; - - if (TestSuite_iSPostOutputCheckingEnabled(context)) { - if (context->expectedOutputBuffer->size != 0 - || context->outputBuffer->size != 0) { - Buffer_chomp(context->outputBuffer); - Buffer_chomp(context->expectedOutputBuffer); - - if (context->outputBuffer->size != - context->expectedOutputBuffer->size - || strcmp(context->outputBuffer->data, - context->expectedOutputBuffer->data)) { - setErrno(E_OUTPUT_DONT_MATCH); - } - } - } - - if (TestSuite_iSExitCodeCheckingEnabled(context)) { - if (context->expectedExitCode != INVALID_EXIT_CODE) { - if (context->expectedExitCode != context->exitCode) { - setErrno(E_EXIT_CODE_DONT_MATCH); - } - } - } - - context->pi.hProcess = NULL; - return getErrno(); -} - -bool TestSuite_iSPostOutputCheckingEnabled(TestCaseContext_t context) -{ - if (!context->isPostOutputCheckingEnabled - && context->isOutputCheckingEnabled) { - return true; - } - - return false; -} - -bool TestSuite_iSExitCodeCheckingEnabled(TestCaseContext_t context) -{ - return context->exitCodeCheckingEnabled; -} - -errno_t TestSuite_changeDir(TestSuite_t testSuite) -{ - char *line = testSuite->stream->line + 5; - size_t size = strlen(line); - - while ((line[size - 1] == '\n') || (line[size - 1] == '\r')) { - line[size - 1] = '\0'; - - if (size) - (size)--; - } - - if (!SetCurrentDirectory(line)) { - setErrno(E_CHANGE_DIRECTORY_FAILED); - return E_CHANGE_DIRECTORY_FAILED; - } - - Stream_printLine(testSuite->stream, change_directory_line_type); - - return E_SUCCESS; -} diff --git a/win32_test_app/src/TThreadDynarray.c b/win32_test_app/src/TThreadDynarray.c deleted file mode 100644 index 0691116091..0000000000 --- a/win32_test_app/src/TThreadDynarray.c +++ /dev/null @@ -1,489 +0,0 @@ - -#include - -/* - * Constructs a ThreadDynarray with the specified capacity. - */ -ThreadDynarray_t ThreadDynarray_new(unsigned long capacity) -{ - ThreadDynarray_t ptr = calloc(1, sizeof(s_ThreadDynarray_t)); - - ptr->count = 0; - ptr->capacity = capacity; - - memset(&(ptr->cs), 0, sizeof(CRITICAL_SECTION)); - InitializeCriticalSection(&(ptr->cs)); - ptr->is_locked = false; - - if (capacity) - ptr->threads = - (ThreadEntry_t) calloc(capacity, sizeof(s_ThreadEntry_t)); - else - ptr->threads = NULL; - - return ptr; -} - -/* - * Destroy the ThreadDynarray - */ -void ThreadDynarray_destroy(ThreadDynarray_t ptr) -{ - ThreadDynarray_clear(ptr); - DeleteCriticalSection(&(ptr->cs)); - free(ptr); - ptr = NULL; -} - -/* - * Returns an const pointer to entry pointed to by index. - */ -ThreadEntry_t const ThreadDynarray_at(ThreadDynarray_t ptr, - unsigned long index) -{ - ThreadEntry_t __entry; - ThreadDynarray_lock(ptr); - __entry = &(ptr->threads)[index]; - ThreadDynarray_unlock(ptr); - return __entry; -} - -/* - * Fill the content of the entry addressed by __entry with the content - * of the entry pointed to by index. - */ -void ThreadDynarray_get(ThreadDynarray_t ptr, unsigned long index, - ThreadEntry_t const __entry) -{ - ThreadDynarray_lock(ptr); - ::memcpy(__entry, ThreadDynarray_at(ptr, index), - sizeof(s_ThreadEntry_t)); - ThreadDynarray_unlock(ptr); -} - -/* - * Fill the content of the entry pointed to by index with the content of - * the entry addressed by __entry. - */ -void ThreadDynarray_set(ThreadDynarray_t ptr, unsigned long index, - ThreadEntry_t const __entry) -{ - - ThreadDynarray_lock(ptr); - memcpy(ThreadDynarray_at(ptr, index), __entry, sizeof(s_ThreadEntry_t)); - ThreadDynarray_unlock(ptr); -} - -/* - * Returns a const pointer to the first entry. - */ -ThreadEntry_t const ThreadDynarray_getFront(ThreadDynarray_t ptr) -{ - ThreadEntry_t __entry; - ThreadDynarray_lock(ptr); - __entry = ThreadDynarray_at(ptr, 0); - ThreadDynarray_unlock(ptr); - return __entry; -} - -/* - * Returns a const pointer to the last entry. - */ -ThreadEntry_t const ThreadDynarray_getBack(ThreadDynarray_t ptr) -{ - ThreadEntry_t __entry; - ThreadDynarray_lock(ptr); - __entry = ThreadDynarray_at(ptr, ptr->count - 1);; - ThreadDynarray_unlock(ptr); - return __entry; -} - -/* - * Inserts a copy of __entry at the front - */ -void ThreadDynarray_pushFront(ThreadDynarray_t ptr, - ThreadEntry_t const __entry) -{ - ThreadDynarray_lock(ptr); - - if (!ThreadDynarray_getCapacityAvailable(ptr)) - ThreadDynarray_resize(ptr); - - ptr->count++; - ThreadDynarray_move(ptr, 1, ThreadDynarray_getLowerBound(ptr), - ThreadDynarray_getUpperBound(ptr)); - ThreadDynarray_set(ptr, ThreadDynarray_getLowerBound(ptr), __entry); - - ThreadDynarray_unlock(ptr); -} - -/* - * Appends a copy of __entry to the end. - */ -void ThreadDynarray_pushBack(ThreadDynarray_t ptr, - ThreadEntry_t const __entry) -{ - ThreadDynarray_lock(ptr); - - if (!ThreadDynarray_getCapacityAvailable(ptr)) - ThreadDynarray_resize(ptr); - - ptr->count++; - ThreadDynarray_set(ptr, ThreadDynarray_getUpperBound(ptr), __entry); - - ThreadDynarray_unlock(ptr); -} - - -/* - * Inserts __entry at the position pointed to by index. - */ -void ThreadDynarray_insert(ThreadDynarray_t ptr, unsigned long index, - ThreadEntry_t const __entry) -{ - ThreadDynarray_lock(ptr); - - if (!ThreadDynarray_getCapacityAvailable(ptr)) - ThreadDynarray_resize(ptr); - - ThreadDynarray_move(ptr, index + 1, index, ptr->count - index); - ptr->count++; - ThreadDynarray_set(ptr, index, __entry); - - ThreadDynarray_unlock(ptr); -} - -/* - * Deletes the entry pointed to by index. If __entry is not NULL the - * fuction saves the entry threads at this address before. - */ -void ThreadDynarray_erase(ThreadDynarray_t ptr, unsigned long index, - ThreadEntry_t const __entry) -{ - - ThreadDynarray_lock(ptr); - - if (__entry) - ThreadDynarray_set(ptr, index, __entry); - - if (index != ThreadDynarray_getUpperBound(ptr)) - ThreadDynarray_move(ptr, index, index + 1, (ptr->count - (index + 1))); - - ptr->count--; - - ThreadDynarray_unlock(ptr); -} - -/* - * Find the first entry with the same content of the entry addressed by - * __entry.The function returns the index of the founded entry, -1 if - * no entry is founded. - */ -long ThreadDynarray_getIndex(ThreadDynarray_t ptr, - ThreadEntry_t const __entry) -{ - - unsigned long i; - ThreadDynarray_lock(ptr); - - for (i = 0; i < ptr->count; i++) { - if (ThreadDynarray_compare(ptr, i, __entry)) { - ThreadDynarray_unlock(ptr); - return i; - } - } - - ThreadDynarray_unlock(ptr); - return -1; -} - -/* - * Returns true if the entry exist. - */ -bool ThreadDynarray_exist(ThreadDynarray_t ptr, - ThreadEntry_t const __entry) -{ - bool exist; - - ThreadDynarray_lock(ptr); - exist = (-1 != ThreadDynarray_getIndex(ptr, __entry)); - ThreadDynarray_unlock(ptr); - return exist; -} - -/* Deletes the first entry with the same content of the entry addressed - * by __entry.The function returns true if the entry is deleted, false - * if no entry is founded. - */ -bool ThreadDynarray_remove(ThreadDynarray_t ptr, - ThreadEntry_t const __entry) -{ - /* assert(!empty(ptr)); */ - - long __index; - ThreadDynarray_lock(ptr); - __index = ThreadDynarray_getIndex(ptr, __entry); - - if (__index == -1) { - ThreadDynarray_unlock(ptr); - return false; - } - - ThreadDynarray_set(ptr, (unsigned long) __index, NULL); - ThreadDynarray_unlock(ptr); - return true; -} - -/* - * Erase all elements of the self. - */ -void ThreadDynarray_clear(ThreadDynarray_t ptr) -{ - ThreadDynarray_lock(ptr); - - free(ptr->threads); - ptr->threads = NULL; - - ptr->count = 0; - ptr->capacity = 0; - ThreadDynarray_unlock(ptr); -} - -/* - * Resets entry count to zero. - */ -void ThreadDynarray_reset(ThreadDynarray_t ptr) -{ - ThreadDynarray_lock(ptr); - ptr->count = 0; - ThreadDynarray_unlock(ptr); -} - -/* - * Moves count elements from src index to dst index. - */ -void ThreadDynarray_move(ThreadDynarray_t ptr, const unsigned long dst, - const unsigned long src, unsigned long count) -{ - ThreadDynarray_lock(ptr); - - if (ptr->count) - memmove(ThreadDynarray_at(ptr, dst), ThreadDynarray_at(ptr, src), - count * sizeof(s_ThreadEntry_t)); - - ThreadDynarray_unlock(ptr); -} - -/* Compare the content of the entry pointed to by index with the content of - * the entry addressed by __entry. The function returns true if the contents - * are same. - */ -bool ThreadDynarray_compare(ThreadDynarray_t ptr, - const unsigned long index, - ThreadEntry_t const __entry) -{ - bool are_equals; - ThreadDynarray_lock(ptr); - are_equals = - (!memcmp - (ThreadDynarray_at(ptr, index), __entry, sizeof(s_ThreadEntry_t))); - ThreadDynarray_unlock(ptr); - return are_equals; -} - -/* - * Returns a reference to a new ThreadDynarray new set is a clone of the self. - */ -ThreadDynarray_t ThreadDynarray_clone(ThreadDynarray_t ptr) -{ - ThreadDynarray_t new_ptr; - ThreadDynarray_lock(ptr); - ptr = ThreadDynarray_new(ptr->capacity); - - if (ptr->count) { - memcpy(new_ptr->threads, ptr->threads, - ptr->count * sizeof(s_ThreadEntry_t)); - new_ptr->count = ThreadDynarray_getCount(ptr); - } - ThreadDynarray_unlock(ptr); - return new_ptr; -} - -/* - * Extends the capacity when the container is full. - */ -void ThreadDynarray_resize(ThreadDynarray_t ptr) -{ - ThreadDynarray_lock(ptr); - - ptr->capacity = (!ptr->capacity) ? 1 : (ptr->count << 1); - ptr->threads = - (ThreadEntry_t) realloc(ptr->threads, - ptr->capacity * sizeof(s_ThreadEntry_t)); - - ThreadDynarray_unlock(ptr); -} - - -/* - * Returns the number of elements. - */ -unsigned long ThreadDynarray_getCount(ThreadDynarray_t ptr) -{ - unsigned count; - ThreadDynarray_lock(ptr); - count = ptr->count; - ThreadDynarray_unlock(ptr); - return count; -} - -/* - * Returns the current storage capacity of the ThreadDynarray. This is guaranteed - * to be at least as large as count(). - */ -unsigned long ThreadDynarray_getCapacity(ThreadDynarray_t ptr) -{ - unsigned capacity; - ThreadDynarray_lock(ptr); - capacity = ptr->capacity; - ThreadDynarray_unlock(ptr); - return capacity; -} - - -/* - * Returns upper bound of self (max index). - */ -unsigned long ThreadDynarray_getUpperBound(ThreadDynarray_t ptr) -{ - unsigned long upper_bound; - ThreadDynarray_lock(ptr); - upper_bound = (ptr->count - 1); - ThreadDynarray_unlock(ptr); - return upper_bound; -} - -/* - * Returns lower bound of self (always zero). - */ -unsigned long ThreadDynarray_getLowerBound(ThreadDynarray_t ptr) -{ - return 0; -} - -/* - * Returns the size of the elements. - */ -unsigned long ThreadDynarray_getElementSize(ThreadDynarray_t ptr) -{ - return sizeof(s_ThreadEntry_t); -} - -/* - * Returns true if the size of self is zero. - */ -bool ThreadDynarray_isEmpty(ThreadDynarray_t ptr) -{ - bool is_empty; - ThreadDynarray_lock(ptr); - is_empty = (ptr->count == 0); - ThreadDynarray_unlock(ptr); - return is_empty; -} - -/* - * Returns true if capacity available. - */ -bool ThreadDynarray_getCapacityAvailable(ThreadDynarray_t ptr) -{ - bool capacity_available; - ThreadDynarray_lock(ptr); - capacity_available = (ptr->capacity > ptr->count); - ThreadDynarray_unlock(ptr); - return capacity_available; -} - -/* - * Returns true if the container is full. - */ -bool ThreadDynarray_is_full(ThreadDynarray_t ptr) -{ - bool is_full; - ThreadDynarray_lock(ptr); - is_full = (!ThreadDynarray_isEmpty(ptr) - && !ThreadDynarray_getCapacityAvailable(ptr)); - ThreadDynarray_unlock(ptr); - return is_full; -} - -/* - * Assignement. - */ -ThreadDynarray_t ThreadDynarray_assign(ThreadDynarray_t src, - ThreadDynarray_t dst) -{ - ThreadDynarray_lock(src); - ThreadDynarray_lock(dst); - - if (src != dst) { - ThreadDynarray_clear(dst); - - if (src->count) { - dst->count = src->count; - dst->capacity = src->capacity; - dst->threads = - (ThreadEntry_t) malloc(src->capacity * sizeof(s_ThreadEntry_t)); - memcpy(dst->threads, src->threads, - src->count * sizeof(s_ThreadEntry_t)); - } - } - ThreadDynarray_unlock(src); - ThreadDynarray_unlock(dst); - - return dst; -} - -/* - * Returns true if the dynamic arrays are equal. - */ -bool ThreadDynarray_areEquals(ThreadDynarray_t ptr1, ThreadDynarray_t ptr2) -{ - bool are_equals; - - ThreadDynarray_lock(ptr1); - ThreadDynarray_lock(ptr2); - - are_equals = (ptr1->count == ptr2->count && - ptr1->capacity == ptr2->capacity && - !memcmp(ptr2->threads, ptr1->threads, ptr1->capacity) - ); - - ThreadDynarray_unlock(ptr1); - ThreadDynarray_unlock(ptr2); - - return are_equals; -} - -/* - * Returns true if the dynamic arrays are not equal. - */ -ThreadDynarray_areNotEquals(ThreadDynarray_t ptr1, ThreadDynarray_t ptr2) -{ - return !ThreadDynarray_areEquals(ptr1, ptr2); -} - -void ThreadDynarray_lock(ThreadDynarray_t ptr) -{ - if (!ptr->is_locked) { - EnterCriticalSection(&(ptr->cs)); - ptr->is_locked = true; - } -} - -void ThreadDynarray_unlock(ThreadDynarray_t ptr) -{ - if (ptr->is_locked) { - LeaveCriticalSection(&(ptr->cs)); - ptr->is_locked = false; - } -} diff --git a/win32_test_app/src/TTime.c b/win32_test_app/src/TTime.c deleted file mode 100644 index 1094d22d07..0000000000 --- a/win32_test_app/src/TTime.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -void __time(char *t) -{ - - time_t timer; - struct tm *tblock; - timer = time(NULL); - tblock = localtime(&timer); - - sprintf(t, "%02d/%02d/%d %02d:%02d", tblock->tm_mday, tblock->tm_mon, - tblock->tm_year + 1900, tblock->tm_hour, tblock->tm_min); -} diff --git a/win32_test_app/src/Test.c b/win32_test_app/src/Test.c deleted file mode 100644 index 590437bd89..0000000000 --- a/win32_test_app/src/Test.c +++ /dev/null @@ -1,51 +0,0 @@ - -#pragma hdrstop - -#include - -TestRunner_t test_runner = NULL; - -void terminate(void); - -#pragma argsused - -int main(int argc, char *argv[]) -{ - errno_t e; - initializeErrno(); - - /* Create a test runner. */ - test_runner = TestRunner_new(); - - if (NULL == test_runner) - terminate(); - - /* Initialize the test runner. */ - if (E_SUCCESS != TestRunner_initialize(test_runner, argc, argv)) - terminate(); - - /* Launch the test runner. */ - TestRunner_run(test_runner); - - e = getErrno(); - - terminate(); - - return e; -} - - -void terminate(void) -{ - errno_t e = getErrno(); - - if (NULL != test_runner) - TestRunner_free(test_runner); - - printf("\n Program terminated with the exit code : %3d (%s)\n", - getErrno(), __errlist[getErrno()]); - - terminateErrno(); - - exit(e); -} -- 2.20.1