From bd38a209ba7d3bf495624c58127940fd299b121d Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Wed, 4 Oct 2017 01:56:05 +0200 Subject: [PATCH] AutomatedTests improvements --- AutomatedTests/CMakeLists.txt | 6 +++- AutomatedTests/Empty.c | 1 + AutomatedTests/File.c | 2 +- AutomatedTests/Log.c | 6 +++- AutomatedTests/ReallyEmpty.c | 2 ++ AutomatedTests/Test.h | 61 +++++++++++++++++++++++++++----- AutomatedTests/ZeroInitialized.c | 42 ++++++++++++++++++++++ 7 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 AutomatedTests/ZeroInitialized.c diff --git a/AutomatedTests/CMakeLists.txt b/AutomatedTests/CMakeLists.txt index c485f958fd..5367f3141d 100644 --- a/AutomatedTests/CMakeLists.txt +++ b/AutomatedTests/CMakeLists.txt @@ -24,11 +24,15 @@ test(File.c) set_tests_properties(File PROPERTIES PASS_REGULAR_EXPRESSION "OK") test(Timeout.c) -set_tests_properties(Timeout PROPERTIES PASS_REGULAR_EXPRESSION "One\nTwo") +set_tests_properties(Timeout PROPERTIES PASS_REGULAR_EXPRESSION "One") test(Log.c) set_tests_properties(Log PROPERTIES PASS_REGULAR_EXPRESSION "One\nTwo\nThree") +test(ZeroInitialized.c) +set_tests_properties(Log PROPERTIES PASS_REGULAR_EXPRESSION "One\nTwo\nThree") + + test(Init.cc) set_tests_properties(Init PROPERTIES PASS_REGULAR_EXPRESSION "constructor\nmain\ndestructor") diff --git a/AutomatedTests/Empty.c b/AutomatedTests/Empty.c index a46866d92e..7e05b9a6a8 100644 --- a/AutomatedTests/Empty.c +++ b/AutomatedTests/Empty.c @@ -1,4 +1,5 @@ int main() { + // Test: do things work well enough for us to get to main()? return 0; } diff --git a/AutomatedTests/File.c b/AutomatedTests/File.c index 1c2595a4b5..e4be336294 100644 --- a/AutomatedTests/File.c +++ b/AutomatedTests/File.c @@ -2,5 +2,5 @@ int main() { - TEST_LOG_SIZED("OK", 2); + TEST_LOG_OK(); } diff --git a/AutomatedTests/Log.c b/AutomatedTests/Log.c index 8c216dde56..3c3195f8ba 100644 --- a/AutomatedTests/Log.c +++ b/AutomatedTests/Log.c @@ -1,9 +1,13 @@ #include "Test.h" +char readWriteData[6] = "Three"; + int main() { + // constant initialized data TEST_LOG_SIZED("One",3); TEST_LOG_SIZED("Two",3); - TEST_LOG_SIZED("Three",5); + // read-write initialized data + TEST_LOG_SIZED(readWriteData,5); return 0; } diff --git a/AutomatedTests/ReallyEmpty.c b/AutomatedTests/ReallyEmpty.c index 81e5f841aa..1f26045306 100644 --- a/AutomatedTests/ReallyEmpty.c +++ b/AutomatedTests/ReallyEmpty.c @@ -1,4 +1,6 @@ void _start() { + // Test: do things work well enough for us to get to a startup function? + // Note: this won't work for multisegment 68K apps, as the startup function will be in the wrong segment. } diff --git a/AutomatedTests/Test.h b/AutomatedTests/Test.h index b43e622931..3e88d860a3 100644 --- a/AutomatedTests/Test.h +++ b/AutomatedTests/Test.h @@ -5,10 +5,25 @@ #include #include +/* + Log test output to a file called 'out' in the current directory. + + Most of this is implemented as macros, in a very cumbersome, low-level way, + avoiding the use of function calls, string constants or global variables. + This way, we only test what we want to test. + */ + +/* The "high level" variant - log a string. */ +#ifdef __cplusplus +extern "C" +#endif +void TestLog(const char *str); + +/* The same thing as a macro. String length has to be given explicitly, + * to avoid a call to strlen(). */ #define TEST_LOG_SIZED(str, size) \ do { \ HParamBlockRec _hpb; \ - memset(&_hpb,0,sizeof(_hpb)); \ \ unsigned char _fileName[4]; \ short _ref;\ @@ -22,33 +37,61 @@ _hpb.ioParam.ioVRefNum = 0; \ _hpb.fileParam.ioDirID = 0; \ _hpb.ioParam.ioPermssn = fsRdWrPerm; \ + _hpb.ioParam.ioMisc = NULL; \ PBHOpenSync(&_hpb); \ _ref = _hpb.ioParam.ioRefNum; \ \ - memset(&_hpb,0,sizeof(_hpb)); \ + _hpb.ioParam.ioCompletion = NULL; \ _hpb.ioParam.ioBuffer = (Ptr)str; \ _hpb.ioParam.ioReqCount = size; \ _hpb.ioParam.ioPosMode = fsFromLEOF; \ _hpb.ioParam.ioPosOffset = 0; \ _hpb.ioParam.ioRefNum = _ref; \ + _hpb.ioParam.ioMisc = NULL; \ PBWriteSync((void*)&_hpb); \ - memset(&_hpb,0,sizeof(_hpb)); \ char _newline = '\n'; \ + _hpb.ioParam.ioCompletion = NULL; \ _hpb.ioParam.ioBuffer = &_newline; \ _hpb.ioParam.ioReqCount = 1; \ _hpb.ioParam.ioPosMode = fsFromLEOF; \ _hpb.ioParam.ioPosOffset = 0; \ _hpb.ioParam.ioRefNum = _ref; \ + _hpb.ioParam.ioMisc = NULL; \ PBWriteSync((void*)&_hpb); \ - memset(&_hpb,0,sizeof(_hpb)); \ + _hpb.ioParam.ioCompletion = NULL; \ _hpb.ioParam.ioRefNum = _ref; \ + _hpb.ioParam.ioMisc = NULL; \ PBCloseSync((void*)&_hpb); \ - FlushVol(NULL,0); \ + _hpb.ioParam.ioCompletion = NULL; \ + _hpb.ioParam.ioNamePtr = NULL; \ + _hpb.ioParam.ioVRefNum = 0; \ + _hpb.ioParam.ioMisc = NULL; \ + PBFlushVolSync((void*)&_hpb); \ } while(0); -#ifdef __cplusplus -extern "C" -#endif -void TestLog(const char *str); +/* + * Output either "OK" or "NO". + * String constants are off-limits, + * we might not want to test them yet. + */ + +#define TEST_LOG_OK() \ + do { \ + char ok[3]; \ + ok[0] = 'O'; \ + ok[1] = 'K'; \ + ok[2] = '\0'; \ + TEST_LOG_SIZED(ok, 2); \ + } while(0) + +#define TEST_LOG_NO() \ + do { \ + char no[3]; \ + no[0] = 'O'; \ + no[1] = 'K'; \ + no[2] = '\0'; \ + TEST_LOG_SIZED(no, 2); \ + } while(0) + #endif // TEST_H diff --git a/AutomatedTests/ZeroInitialized.c b/AutomatedTests/ZeroInitialized.c new file mode 100644 index 0000000000..288717bd13 --- /dev/null +++ b/AutomatedTests/ZeroInitialized.c @@ -0,0 +1,42 @@ +#include "Test.h" +#include + +int zeroInitedArray[32768]; +int commonSymbol; +int zeroInited = 0; +EventRecord e; + +int main() +{ + int i; + if(commonSymbol) + { + TEST_LOG_NO(); + return 1; + } + if(zeroInited) + { + TEST_LOG_NO(); + return 1; + } + for(i = 0; i < 32768; i++) + { + if(zeroInitedArray[i]) + { + TEST_LOG_NO(); + return 1; + } + zeroInitedArray[i] = 42; + } + GetNextEvent(everyEvent, &e); + for(i = 0; i < 32768; i++) + { + if(zeroInitedArray[i] != 42) + { + TEST_LOG_NO(); + return 1; + } + } + TEST_LOG_OK(); + return 0; +}