From 44db1306788b18698b48b6f65c250130aa176a76 Mon Sep 17 00:00:00 2001 From: dkrutsko Date: Wed, 22 Feb 2017 23:51:05 -0500 Subject: [PATCH 1/4] Initial implementation --- Test/Clipboard.cc | 46 +++++++++++--- Test/Keyboard.cc | 107 +++++++++++++++++++++++++------- Test/Main.cc | 133 +++++++++++++++++----------------------- Test/Memory.cc | 153 ++++++++++++++++++++++++++++------------------ Test/Mouse.cc | 51 ++++++++++++---- Test/Process.cc | 58 +++++++++++++----- Test/Screen.cc | 54 ++++++++++++---- Test/Test.h | 8 +-- Test/Timer.cc | 28 ++++++--- Test/Types.cc | 65 +++++++++++++------- Test/Window.cc | 71 +++++++++++++-------- 11 files changed, 508 insertions(+), 266 deletions(-) diff --git a/Test/Clipboard.cc b/Test/Clipboard.cc index ccf99f4..9ff8e98 100644 --- a/Test/Clipboard.cc +++ b/Test/Clipboard.cc @@ -17,7 +17,7 @@ //----------------------------------------------------------------------------// -// Functions // +// Locals // //----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// @@ -365,7 +365,7 @@ static bool TestSpeed (void) } VERIFY (Clipboard::Clear()); - cout << endl; + cout << "\n\n"; #endif @@ -382,14 +382,40 @@ static bool TestSpeed (void) bool TestClipboard (void) { - cout << "BEGIN CLIPBOARD TESTING\n------------------------------\n"; + cout << "TEST CLIPBOARD\n" + << "------------------------------\n" + << " 0: All \n" + << " 1: Linux\n" + << " 2: Text \n" + << " 3: Image\n" + << " 4: Speed\n\n"; + + // Ask the user to make a selection + cout << "Enter component(s) to test: "; + string input; getline (cin, input); + + int selection; cout << endl; + // Tokenize the input value + stringstream stream (input); + while (stream >> selection) + { + // Test everything + if (selection == 0) + { + return TestLinux() + && TestText () + && TestImage() + && TestSpeed(); + } - cout << "Warning: Some set of tests cannot be automated\n" - << " Please execute the following commands\n\n"; + switch (selection) + { + case 1: if (!TestLinux()) return false; break; + case 2: if (!TestText ()) return false; break; + case 3: if (!TestImage()) return false; break; + case 4: if (!TestSpeed()) return false; break; + } + } - if (!TestLinux()) { cout << ">> Linux Failed\n\n"; return false; } - if (!TestText ()) { cout << ">> Text Failed \n\n"; return false; } - if (!TestImage()) { cout << ">> Image Failed\n\n"; return false; } - if (!TestSpeed()) { cout << ">> Speed Failed\n\n"; return false; } - cout << ">> Success\n\n"; return true; + return true; } diff --git a/Test/Keyboard.cc b/Test/Keyboard.cc index ccdc19a..2839a38 100644 --- a/Test/Keyboard.cc +++ b/Test/Keyboard.cc @@ -39,7 +39,7 @@ static Keyboard k; //----------------------------------------------------------------------------// -// Functions // +// Locals // //----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// @@ -502,9 +502,17 @@ static bool TestCompiler (void) //////////////////////////////////////////////////////////////////////////////// +// Whether to continue running the thread +static volatile bool resumeThread = false; + +//////////////////////////////////////////////////////////////////////////////// + static void LiveThread (void) { Timer::Sleep (500); + if (!resumeThread) + return; + k.Click (Key0); k.Click (Key1); k.Click (Key2); @@ -518,6 +526,9 @@ static void LiveThread (void) k.Click (KeyReturn); Timer::Sleep (500); + if (!resumeThread) + return; + k.Click (KeyA); k.Click (KeyB); k.Click (KeyC); @@ -547,6 +558,9 @@ static void LiveThread (void) k.Click (KeyReturn); Timer::Sleep (500); + if (!resumeThread) + return; + k.Press (KeyShift); k.Click (KeyA); k.Click (KeyB); @@ -578,6 +592,9 @@ static void LiveThread (void) k.Click (KeyReturn); Timer::Sleep (500); + if (!resumeThread) + return; + k.Click (KeyAdd); k.Click (KeySubtract); k.Click (KeyMultiply); @@ -596,6 +613,9 @@ static void LiveThread (void) k.Click (KeyEnter); Timer::Sleep (500); + if (!resumeThread) + return; + k.Click (KeyMinus); k.Click (KeyEqual); k.Click (KeyBackspace); @@ -615,6 +635,9 @@ static void LiveThread (void) k.Click (KeyReturn); Timer::Sleep (500); + if (!resumeThread) + return; + k.Press (KeyShift); k.Click (KeyGrave); k.Click (KeyMinus); @@ -632,9 +655,14 @@ static void LiveThread (void) k.Click (KeyReturn); Timer::Sleep (500); + if (!resumeThread) + return; + k.Click ("+Hello +Robo<<<+(obot)+1~"); } +//////////////////////////////////////////////////////////////////////////////// + static bool TestLive (void) { #if (_MSC_VER == 1600) @@ -645,45 +673,51 @@ static bool TestLive (void) getchar(); char input[32] = { 0 }; - // Create live testing thread - std::thread live (LiveThread); + resumeThread = true; + // Create testing thread + thread live (LiveThread); cout << "Numbers: "; cin.getline (input, 32); - VERIFY (strcmp (input, "0123456789") == 0); + if (strcmp (input, "0123456789")) + { resumeThread = false; live.join(); VERIFY (false); } cout << "Alphabet: "; cin.getline (input, 32); - VERIFY (strcmp (input, "abcdefghijklmnopqrstuvwxyz") == 0); + if (strcmp (input, "abcdefghijklmnopqrstuvwxyz")) + { resumeThread = false; live.join(); VERIFY (false); } cout << "Alphabet: "; cin.getline (input, 32); - VERIFY (strcmp (input, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == 0); + if (strcmp (input, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) + { resumeThread = false; live.join(); VERIFY (false); } cout << "Keypad: "; cin.getline (input, 32); - VERIFY (strcmp (input, "+-*/.0123456789") == 0); + if (strcmp (input, "+-*/.0123456789")) + { resumeThread = false; live.join(); VERIFY (false); } cout << "Punctuation: "; cin.getline (input, 32); - VERIFY (strcmp (input, "`-=[ ]\\;',./") == 0); + if (strcmp (input, "`-=[ ]\\;',./")) + { resumeThread = false; live.join(); VERIFY (false); } cout << "Punctuation: "; cin.getline (input, 32); - VERIFY (strcmp (input, "~_+{ }|:\"<>?") == 0); + if (strcmp (input, "~_+{ }|:\"<>?")) + { resumeThread = false; live.join(); VERIFY (false); } cout << "Hello Robot: "; cin.getline (input, 32); - VERIFY (strcmp (input, "Hello ROBOT!") == 0); + if (strcmp (input, "Hello ROBOT!")) + { resumeThread = false; live.join(); VERIFY (false); } // End thread live.join(); + cout << endl; #endif - cout << "\nWarning: The next set of tests cannot be automated\n" - << " Please review the following instructions!\n\n"; - cout << "- Live testing will be performed in sets\n" << "- Press enter to begin testing a new set\n" << "- After beginning, focus the testing app\n" @@ -764,9 +798,6 @@ static bool TestLive (void) static bool TestGetState (void) { - cout << "Warning: The next set of tests cannot be automated\n" - << " Please review the following instructions!\n\n"; - cout << "- Press keys and verify output\n" << "- Press enter to begin testing\n" << "- Press escape to stop testing\n"; @@ -916,13 +947,47 @@ static bool TestGetState (void) return true; } + + +//----------------------------------------------------------------------------// +// Functions // +//----------------------------------------------------------------------------// + //////////////////////////////////////////////////////////////////////////////// bool TestKeyboard (void) { - cout << "BEGIN KEYBOARD TESTING\n------------------------------\n"; - if (!TestCompiler()) { cout << ">> Compiler Failed \n\n"; return false; } - if (!TestLive ()) { cout << ">> Live Test Failed\n\n"; return false; } - if (!TestGetState()) { cout << ">> Get State Failed\n\n"; return false; } - cout << ">> Success\n\n"; return true; + cout << "TEST KEYBOARD\n" + << "------------------------------\n" + << " 0: All \n" + << " 1: Compiler \n" + << " 2: Live Test\n" + << " 3: GetState \n\n"; + + // Ask the user to make a selection + cout << "Enter component(s) to test: "; + string input; getline (cin, input); + + int selection; cout << endl; + // Tokenize the input value + stringstream stream (input); + while (stream >> selection) + { + // Test everything + if (selection == 0) + { + return TestCompiler() + && TestLive () + && TestGetState(); + } + + switch (selection) + { + case 1: if (!TestCompiler()) return false; break; + case 2: if (!TestLive ()) return false; break; + case 3: if (!TestGetState()) return false; break; + } + } + + return true; } diff --git a/Test/Main.cc b/Test/Main.cc index 28919cb..5c2967d 100644 --- a/Test/Main.cc +++ b/Test/Main.cc @@ -52,86 +52,65 @@ int main (int argc, const char* argv[]) #endif #endif - cout << (Process::IsSys64Bit() ? " 64\n" : " 32\n"); - - cout << "------------------------------\n" - << "(C) 2010-2017 Robot Developers\n\n"; - - // Check args - if (argc < 2) - { - cout << "This program is designed to test the Robot library for\n" - << "compliance and compatibility on the target platform. It\n" - << "does this by running a series of test cases on various\n" - << "components of the library; if an error is detected all\n" - << "subsequent tests are cancelled. In order to get started\n" - << "please select the tests you wish to run via the command\n" - << "line. Possible tests include: types, timer, keyboard,\n" - << "mouse, process, window, memory, screen and clipboard.\n" - << "Multiple tests can be run at the same time.\n\n"; - - // All the tests have concluded - cout << "Press enter to exit\n"; - getchar(); - return 1; - } - - bool types = false; - bool timer = false; - bool keyboard = false; - bool mouse = false; - bool process = false; - bool window = false; - bool memory = false; - bool screen = false; - bool clipboard = false; - - // Determine which tests to run - for (int i = 1; i < argc; ++i) + cout << (Process::IsSys64Bit() ? " 64\n" : " 32\n") + << "------------------------------\n" + << "(C) 2010-2017 Robot Developers\n\n" + + << "This program is designed to test the Robot library for\n" + << "compliance and compatibility on the target platform. It\n" + << "does this by running a series of test cases on various\n" + << "components of the library. To get started, please select\n" + << "the test cases you wish to run by using the menu below.\n" + << "Multiple tests can be run at the same time.\n\n"; + + while (true) { - // Check for a special all keyword - if (strcmp (argv[i], "all") == 0) + cout << "MAIN MENU\n" + << "------------------------------\n" + << " 1: Types \n" + << " 2: Timer \n" + << " 3: Keyboard \n" + << " 4: Mouse \n" + << " 5: Process \n" + << " 6: Window \n" + << " 7: Memory \n" + << " 8: Screen \n" + << " 9: Clipboard\n\n"; + + // Ask the user to make a selection + cout << "Enter component(s) to test: "; + string input; getline (cin, input); + + int selection; cout << endl; + // Tokenize the input value + stringstream stream (input); + while (stream >> selection) { - types = true; - timer = true; - keyboard = true; - mouse = true; - process = true; - window = true; - memory = true; - screen = true; - clipboard = true; - break; + bool result; + switch (selection) + { + case 1: result = TestTypes (); break; + case 2: result = TestTimer (); break; + case 3: result = TestKeyboard (); break; + case 4: result = TestMouse (); break; + case 5: result = TestProcess (); break; + case 6: result = TestWindow (); break; + case 8: result = TestScreen (); break; + case 9: result = TestClipboard(); break; + + case 7: + cout << uppercase; + result = TestMemory(); + cout << nouppercase; + break; + + default: continue; + } + + cout << (result ? ">> Success\n" : ">> Failure\n"); + cout << "Press enter to continue...\n"; getchar(); } - - if (strcmp (argv[i], "types" ) == 0) types = true; else - if (strcmp (argv[i], "timer" ) == 0) timer = true; else - if (strcmp (argv[i], "keyboard" ) == 0) keyboard = true; else - if (strcmp (argv[i], "mouse" ) == 0) mouse = true; else - if (strcmp (argv[i], "process" ) == 0) process = true; else - if (strcmp (argv[i], "window" ) == 0) window = true; else - if (strcmp (argv[i], "memory" ) == 0) memory = true; else - if (strcmp (argv[i], "screen" ) == 0) screen = true; else - if (strcmp (argv[i], "clipboard") == 0) clipboard = true; - } - - int res = 2; - while (res) - { - if (types && !TestTypes ()) break; - if (timer && !TestTimer ()) break; - if (keyboard && !TestKeyboard ()) break; - if (mouse && !TestMouse ()) break; - if (process && !TestProcess ()) break; - if (window && !TestWindow ()) break; - if (memory && !TestMemory ()) break; - if (screen && !TestScreen ()) break; - if (clipboard && !TestClipboard()) break; - res = 0; } - // All the tests have concluded - cout << "Press enter to exit\n"; - getchar(); - return res; + return 0; } diff --git a/Test/Memory.cc b/Test/Memory.cc index 06134b0..e0152b6 100644 --- a/Test/Memory.cc +++ b/Test/Memory.cc @@ -21,24 +21,22 @@ //////////////////////////////////////////////////////////////////////////////// -#define TEST_INVALID_RW( mem, address ) \ - { \ - VERIFY (mem. ReadData (address, nullptr, 0) == 0); \ - VERIFY (mem. ReadData (address, nullptr, 1) == 0); \ - VERIFY (mem. ReadData (address, &data, 0) == 0); \ - VERIFY (mem. ReadData (address, &data, 1) == 0); \ - \ - VERIFY (mem.WriteData (address, nullptr, 0) == 0); \ - VERIFY (mem.WriteData (address, nullptr, 1) == 0); \ - VERIFY (mem.WriteData (address, &data, 0) == 0); \ - VERIFY (mem.WriteData (address, &data, 1) == 0); \ - } - +#define ALL( cont ) cont.begin(), cont.end() +//////////////////////////////////////////////////////////////////////////////// -//----------------------------------------------------------------------------// -// Locals // -//----------------------------------------------------------------------------// +#define TEST_INVALID_RW( mem, address ) \ +{ \ + VERIFY (mem. ReadData (address, nullptr, 0) == 0); \ + VERIFY (mem. ReadData (address, nullptr, 1) == 0); \ + VERIFY (mem. ReadData (address, &data, 0) == 0); \ + VERIFY (mem. ReadData (address, &data, 1) == 0); \ + \ + VERIFY (mem.WriteData (address, nullptr, 0) == 0); \ + VERIFY (mem.WriteData (address, nullptr, 1) == 0); \ + VERIFY (mem.WriteData (address, &data, 0) == 0); \ + VERIFY (mem.WriteData (address, &data, 1) == 0); \ +} //////////////////////////////////////////////////////////////////////////////// @@ -124,7 +122,7 @@ //----------------------------------------------------------------------------// -// Functions // +// Locals // //----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// @@ -1653,63 +1651,100 @@ static bool TestFind (const Process& p) return true; } -//////////////////////////////////////////////////////////////////////////////// -// This section can be used to write miscellaneous tests on other applications. -static bool TestMisc (void) -{ - return true; -} + +//----------------------------------------------------------------------------// +// Functions // +//----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// bool TestMemory (void) { - cout << "BEGIN MEMORY TESTING\n------------------------------\n"; - - cout << "Warning: Some set of tests cannot be automated\n" - << " Please execute the following commands\n\n"; + char sPID[32]; Process p1 = Process::GetCurrent(), p2; + cout << uppercase << "Open a program and input PID: "; + cin.getline (sPID, 32); + auto pid = atoi (sPID); - cout << uppercase; - char input[32] = { 0 }; Process p1 = Process::GetCurrent(), p2; - cout << "Open a program and input PID: "; cin.getline (input, 32); - int32 pid = atoi (input); VERIFY (pid > 0); VERIFY (p2.Open (pid)); + VERIFY (pid > 0 ); VERIFY (p2.Open (pid) ); VERIFY (p1.IsValid()); VERIFY (!p1.HasExited()); - VERIFY (p2.IsValid()); VERIFY (!p2.HasExited()); cout << endl; + VERIFY (p2.IsValid()); VERIFY (!p2.HasExited()); #ifdef ROBOT_ARCH_32 + VERIFY (!p2.Is64Bit()); // We don't support 64-Bit targets through 32-Bit + #endif - if (!TestInvalid ( )) { cout << ">> Invalid Failed \n\n"; return false; } - if (!TestEquals ( )) { cout << ">> Equals Failed \n\n"; return false; } - if (!TestParams ( )) { cout << ">> Params Failed \n\n"; return false; } - if (!TestDebug (p1)) { cout << ">> Debug p1 Failed \n\n"; return false; } - if (!TestDebug (p2)) { cout << ">> Debug p2 Failed \n\n"; return false; } - if (!TestRegion (p1)) { cout << ">> Region p1 Failed \n\n"; return false; } - if (!TestRegion (p2)) { cout << ">> Region p2 Failed \n\n"; return false; } - if (!TestModules (p1)) { cout << ">> Modules p1 Failed\n\n"; return false; } - if (!TestModules (p2)) { cout << ">> Modules p2 Failed\n\n"; return false; } - if (!TestStress ( )) { cout << ">> Modules p2 Failed\n\n"; return false; } - - if (p2.GetName().substr (0, 4) != "Peon") + cout << "TEST MEMORY\n" + << "------------------------------\n" + << " 0: All \n" + << " 1: Invalid \n" + << " 2: Equals \n" + << " 3: Params \n" + << " 4: Debug \n" + << " 5: Region \n" + << " 6: Modules \n" + << " 7: Stress \n" + << " 8: RW (Peon)\n" + << " 9: Cache (Peon)\n" + << " 10: Flags (Peon)\n" + << " 11: Find (Peon)\n\n"; + + // Ask the user to make a selection + cout << "Enter component(s) to test: "; + string input; getline (cin, input); + + int selection; cout << endl; + // Tokenize the input value + stringstream stream (input); + while (stream >> selection) { - cout << "Open peon app and input PID: "; cin.getline (input, 32); - int32 pid = atoi (input); VERIFY (pid > 0); VERIFY (p2.Open (pid)); - VERIFY (p2.IsValid()); VERIFY (!p2.HasExited()); - VERIFY (p2.GetName().substr (0, 4) == "Peon"); cout << endl; - } + // Check for valid selection requirements + if ((selection == 0 || selection >= 9) && + p2.GetName().substr (0, 4) != "Peon") + { + cout << "These tests require selecting Peon!\n\n"; + if (selection == 0) return false; else continue; + } -#ifdef ROBOT_ARCH_32 - VERIFY (!p2.Is64Bit()); // We don't support 64-Bit targets through 32-Bit -#endif + // Test everything + if (selection == 0) + { + return TestInvalid ( ) + && TestEquals ( ) + && TestParams ( ) + && TestDebug (p1) + && TestDebug (p2) + && TestRegion (p1) + && TestRegion (p2) + && TestModules (p1) + && TestModules (p2) + && TestStress ( ) + && TestRW (p2) + && TestCache (p2) + && TestFlags (p2) + && TestFind (p2); + } - if (!TestRW (p2)) { cout << ">> RW Failed \n\n"; return false; } - if (!TestCache (p2)) { cout << ">> Cache Failed\n\n"; return false; } - if (!TestFlags (p2)) { cout << ">> Flags Failed\n\n"; return false; } - if (!TestFind (p2)) { cout << ">> Find Failed \n\n"; return false; } - if (!TestMisc ( )) { cout << ">> Misc Failed \n\n"; return false; } + switch (selection) + { + case 1: if (!TestInvalid ( )) return false; break; + case 2: if (!TestEquals ( )) return false; break; + case 3: if (!TestParams ( )) return false; break; + case 4: if (!TestDebug (p1) && + !TestDebug (p2)) return false; break; + case 5: if (!TestRegion (p1) && + !TestRegion (p2)) return false; break; + case 6: if (!TestModules (p1) && + !TestModules (p2)) return false; break; + case 7: if (!TestStress ( )) return false; break; + case 8: if (!TestRW (p2)) return false; break; + case 9: if (!TestCache (p2)) return false; break; + case 10: if (!TestFlags (p2)) return false; break; + case 11: if (!TestFind (p2)) return false; break; + } + } - cout << nouppercase; - cout << ">> Success\n\n"; return true; + return true; } diff --git a/Test/Mouse.cc b/Test/Mouse.cc index c6ca40d..c0528db 100644 --- a/Test/Mouse.cc +++ b/Test/Mouse.cc @@ -17,7 +17,7 @@ static Mouse m; //----------------------------------------------------------------------------// -// Functions // +// Locals // //----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// @@ -34,10 +34,7 @@ static bool TestLive (void) Mouse::SetPos ( 50, 200); Timer::Sleep (1000); p = Mouse::GetPos(); VERIFY (p.X == 50 && p.Y == 200); Mouse::SetPos (200, 50); Timer::Sleep (1000); p = Mouse::GetPos(); VERIFY (p.X == 200 && p.Y == 50); Mouse::SetPos ( 0, 0); Timer::Sleep (1000); p = Mouse::GetPos(); VERIFY (p.X == 0 && p.Y == 0); - Mouse::SetPos (old ); Timer::Sleep (1000); p = Mouse::GetPos(); VERIFY (p == old); - - cout << "\nWarning: The next set of tests cannot be automated\n" - << " Please review the following instructions!\n\n"; + Mouse::SetPos (old ); Timer::Sleep (1000); p = Mouse::GetPos(); VERIFY (p == old); cout << endl; cout << "- Live testing will be performed in sets\n" << "- Press enter to begin testing a new set\n" @@ -103,6 +100,7 @@ static bool TestLive (void) Mouse::SetPos (old); m.Release (ButtonRight); + cout << endl; return true; } @@ -110,9 +108,6 @@ static bool TestLive (void) static bool TestGetState (void) { - cout << "\nWarning: The next set of tests cannot be automated\n" - << " Please review the following instructions!\n\n"; - cout << "- Press buttons and verify output\n" << "- Press enter to begin testing\n" << "- Press escape to stop testing\n"; @@ -147,12 +142,44 @@ static bool TestGetState (void) return true; } + + +//----------------------------------------------------------------------------// +// Functions // +//----------------------------------------------------------------------------// + //////////////////////////////////////////////////////////////////////////////// bool TestMouse (void) { - cout << "BEGIN MOUSE TESTING\n------------------------------\n"; - if (!TestLive ()) { cout << ">> Live Test Failed\n\n"; return false; } - if (!TestGetState()) { cout << ">> Get State Failed\n\n"; return false; } - cout << ">> Success\n\n"; return true; + cout << "TEST MOUSE\n" + << "------------------------------\n" + << " 0: All \n" + << " 1: Live Test\n" + << " 2: GetState \n\n"; + + // Ask the user to make a selection + cout << "Enter component(s) to test: "; + string input; getline (cin, input); + + int selection; cout << endl; + // Tokenize the input value + stringstream stream (input); + while (stream >> selection) + { + // Test everything + if (selection == 0) + { + return TestLive () + && TestGetState(); + } + + switch (selection) + { + case 1: if (!TestLive ()) return false; break; + case 2: if (!TestGetState()) return false; break; + } + } + + return true; } diff --git a/Test/Process.cc b/Test/Process.cc index 16061d3..b993759 100644 --- a/Test/Process.cc +++ b/Test/Process.cc @@ -38,7 +38,7 @@ //----------------------------------------------------------------------------// -// Functions // +// Locals // //----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// @@ -85,8 +85,6 @@ static bool TestSelect (void) Process p1, p2; char input1[32] = { 0 }; char input2[32] = { 0 }; - cout << "Warning: The next set of tests cannot be automated\n" - << " Please execute the following instructions\n\n"; #ifdef ROBOT_OS_LINUX @@ -187,9 +185,6 @@ static bool TestSelect (void) static bool TestCurrent (void) { - cout << "Warning: The next set of tests cannot be automated\n" - << " Please execute the following instructions\n\n"; - cout << "Input this application's PID: "; char input[32] = { 0 }; cin.getline (input, 32); @@ -259,9 +254,6 @@ static bool TestCurrent (void) static bool TestGetList (void) { - cout << "Warning: The next set of tests cannot be automated\n" - << " Please verify the following process lists\n\n"; - #ifdef ROBOT_OS_LINUX cout << "Open a couple Leafpads & gedits and press enter\n"; @@ -343,14 +335,50 @@ static bool TestGetList (void) return true; } + + +//----------------------------------------------------------------------------// +// Functions // +//----------------------------------------------------------------------------// + //////////////////////////////////////////////////////////////////////////////// bool TestProcess (void) { - cout << "BEGIN PROCESS TESTING\n------------------------------\n"; - if (!TestInvalid()) { cout << ">> Invalid Failed\n\n"; return false; } - if (!TestSelect ()) { cout << ">> Select Failed \n\n"; return false; } - if (!TestCurrent()) { cout << ">> Current Failed\n\n"; return false; } - if (!TestGetList()) { cout << ">> GetList Failed\n\n"; return false; } - cout << ">> Success\n\n"; return true; + cout << "TEST PROCESS\n" + << "------------------------------\n" + << " 0: All \n" + << " 1: Invalid\n" + << " 2: Select \n" + << " 3: Current\n" + << " 4: GetList\n\n"; + + // Ask the user to make a selection + cout << "Enter component(s) to test: "; + string input; getline (cin, input); + + int selection; cout << endl; + // Tokenize the input value + stringstream stream (input); + while (stream >> selection) + { + // Test everything + if (selection == 0) + { + return TestInvalid() + && TestSelect () + && TestCurrent() + && TestGetList(); + } + + switch (selection) + { + case 1: if (!TestInvalid()) return false; break; + case 2: if (!TestSelect ()) return false; break; + case 3: if (!TestCurrent()) return false; break; + case 4: if (!TestGetList()) return false; break; + } + } + + return true; } diff --git a/Test/Screen.cc b/Test/Screen.cc index a9f3c35..42029fb 100644 --- a/Test/Screen.cc +++ b/Test/Screen.cc @@ -17,7 +17,7 @@ //----------------------------------------------------------------------------// -// Functions // +// Locals // //----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// @@ -333,7 +333,7 @@ static bool TestGrab (void) //////////////////////////////////////////////////////////////////////////////// -static bool TestSpeed (void) +static bool TestPerf (void) { Timer timer; Image image (1920, 1080); @@ -379,7 +379,7 @@ static bool TestSpeed (void) cout << timer() << " "; } - cout << endl; + cout << "\n\n"; return true; } @@ -393,15 +393,43 @@ static bool TestSpeed (void) bool TestScreen (void) { - cout << "BEGIN SCREEN TESTING\n------------------------------\n"; - - cout << "Warning: Some set of tests cannot be automated\n" - << " Please execute the following commands\n\n"; + cout << "TEST SCREEN\n" + << "------------------------------\n" + << " 0: All \n" + << " 1: Invalid\n" + << " 2: Aero \n" + << " 3: Sync \n" + << " 4: Grab \n" + << " 5: Perf \n\n"; + + // Ask the user to make a selection + cout << "Enter component(s) to test: "; + string input; getline (cin, input); + + int selection; cout << endl; + // Tokenize the input value + stringstream stream (input); + while (stream >> selection) + { + // Test everything + if (selection == 0) + { + return TestInvalid() + && TestAero () + && TestSync () + && TestGrab () + && TestPerf (); + } + + switch (selection) + { + case 1: if (!TestInvalid()) return false; break; + case 2: if (!TestAero ()) return false; break; + case 3: if (!TestSync ()) return false; break; + case 4: if (!TestGrab ()) return false; break; + case 5: if (!TestPerf ()) return false; break; + } + } - if (!TestInvalid()) { cout << ">> Invalid Failed\n\n"; return false; } - if (!TestAero ()) { cout << ">> Aero Failed \n\n"; return false; } - if (!TestSync ()) { cout << ">> Sync Failed \n\n"; return false; } - if (!TestGrab ()) { cout << ">> Grab Failed \n\n"; return false; } - if (!TestSpeed ()) { cout << ">> Speed Failed \n\n"; return false; } - cout << ">> Success\n\n"; return true; + return true; } diff --git a/Test/Test.h b/Test/Test.h index 574414e..169222b 100644 --- a/Test/Test.h +++ b/Test/Test.h @@ -22,7 +22,6 @@ using std::cout; using std::endl; using std::ostream; using std::istream; - using std:: uppercase; using std::nouppercase; @@ -49,6 +48,9 @@ using std::sort; using std::is_sorted; using std::unique; +#include +using std::stringstream; + #if (_MSC_VER != 1600) #include using std::thread; @@ -74,10 +76,6 @@ ROBOT_NS_USE_ALL; return false; \ } -//////////////////////////////////////////////////////////////////////////////// - -#define ALL( cont ) cont.begin(), cont.end() - //----------------------------------------------------------------------------// diff --git a/Test/Timer.cc b/Test/Timer.cc index 2eb7ac2..624da1d 100644 --- a/Test/Timer.cc +++ b/Test/Timer.cc @@ -16,15 +16,13 @@ //----------------------------------------------------------------------------// -// Functions // +// Locals // //----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// -bool TestTimer (void) +static bool TestGeneric (void) { - cout << "BEGIN TIMER TESTING\n------------------------------\n"; - Timer t1; VERIFY (!t1.HasStarted()); Timer t2; VERIFY (!t2.HasStarted()); t1.Reset(); VERIFY (!t1.HasStarted()); @@ -55,9 +53,6 @@ bool TestTimer (void) //----------------------------------------------------------------------------// - cout << "Warning: The next set of tests cannot be automated\n" - << " Please verify the following results below\n\n"; - t1.Start(); VERIFY ( t1.HasStarted()); VERIFY (!t2.HasStarted()); @@ -170,5 +165,22 @@ bool TestTimer (void) t1.Reset(); VERIFY (!t1.HasStarted()); t2.Reset(); VERIFY (!t2.HasStarted()); - cout << ">> Success\n\n"; return true; + + return true; +} + + + +//----------------------------------------------------------------------------// +// Functions // +//----------------------------------------------------------------------------// + +//////////////////////////////////////////////////////////////////////////////// + +bool TestTimer (void) +{ + cout << "TEST TIMER\n" + << "------------------------------\n"; + + return TestGeneric(); } diff --git a/Test/Types.cc b/Test/Types.cc index ec1427b..d7095fa 100644 --- a/Test/Types.cc +++ b/Test/Types.cc @@ -16,7 +16,7 @@ //----------------------------------------------------------------------------// -// Functions // +// Locals // //----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// @@ -66,18 +66,12 @@ enum TestEnum1 Enum1Value4, }; -enum TestEnum2 -{ - Enum2Value1, - Enum2Value2, -}; - -// CAUTION: Template specializations -// cannot be in different namespaces -// when compiling with GCC. - ROBOT_NS_BEGIN + // CAUTION: Template specializations + // cannot be in different namespaces + // when compiling with GCC. + ROBOT_ENUM (TestEnum1) { ROBOT_ENUM_MAP (Enum1Value1, "ENUM1Value1"); @@ -86,6 +80,22 @@ ROBOT_NS_BEGIN ROBOT_ENUM_MAP (Enum1Value4, "ENUM1Value4"); } +ROBOT_NS_END + +//////////////////////////////////////////////////////////////////////////////// + +enum TestEnum2 +{ + Enum2Value1, + Enum2Value2, +}; + +ROBOT_NS_BEGIN + + // CAUTION: Template specializations + // cannot be in different namespaces + // when compiling with GCC. + ROBOT_ENUM (TestEnum2) { ROBOT_ENUM_MAP (Enum2Value1); @@ -94,7 +104,9 @@ ROBOT_NS_BEGIN ROBOT_NS_END -bool TestEnum (void) +//////////////////////////////////////////////////////////////////////////////// + +static bool TestEnum (void) { VERIFY (Enum::Size() == 4); VERIFY (Enum::Size() == 2); @@ -300,6 +312,8 @@ static Image TestGetImage (void) return i; } +//////////////////////////////////////////////////////////////////////////////// + static bool TestImage1 (void) { Image i1; @@ -1286,18 +1300,25 @@ static bool TestBounds (void) return true; } + + +//----------------------------------------------------------------------------// +// Functions // +//----------------------------------------------------------------------------// + //////////////////////////////////////////////////////////////////////////////// bool TestTypes (void) { - cout << "BEGIN TYPES TESTING\n------------------------------\n"; - if (!TestGlobal()) { cout << ">> Global Failed\n\n"; return false; } - if (!TestEnum ()) { cout << ">> Enum Failed \n\n"; return false; } - if (!TestHash ()) { cout << ">> Hash Failed \n\n"; return false; } - if (!TestColor ()) { cout << ">> Color Failed \n\n"; return false; } - if (!TestImage1()) { cout << ">> Image1 Failed\n\n"; return false; } - if (!TestImage2()) { cout << ">> Image2 Failed\n\n"; return false; } - if (!TestRange ()) { cout << ">> Range Failed \n\n"; return false; } - if (!TestBounds()) { cout << ">> Bounds Failed\n\n"; return false; } - cout << ">> Success\n\n"; return true; + cout << "TEST TYPES\n" + << "------------------------------\n"; + + return TestGlobal() + && TestEnum () + && TestHash () + && TestColor () + && TestImage1() + && TestImage2() + && TestRange () + && TestBounds(); } diff --git a/Test/Window.cc b/Test/Window.cc index 3347632..d0f28ba 100644 --- a/Test/Window.cc +++ b/Test/Window.cc @@ -46,7 +46,7 @@ //----------------------------------------------------------------------------// -// Functions // +// Locals // //----------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////// @@ -120,11 +120,6 @@ static bool TestInvalid (void) static bool TestSelect1 (void) { - cout << "Warning: The next set of tests cannot be automated\n" - << " Please execute the following instructions\n\n"; - - //----------------------------------------------------------------------------// - #ifdef ROBOT_OS_LINUX cout << "Open Leafpad and gedit"; @@ -373,11 +368,6 @@ static bool TestSelect1 (void) static bool TestSelect2 (void) { - cout << "Warning: The next set of tests cannot be automated\n" - << " Please execute the following instructions\n\n"; - - //----------------------------------------------------------------------------// - #ifdef ROBOT_OS_LINUX cout << "Open Leafpad"; @@ -494,9 +484,6 @@ static bool TestSelect2 (void) static bool TestGetList1 (void) { - cout << "Warning: The next set of tests cannot be automated\n" - << " Please verify the following window lists\n\n"; - #ifdef ROBOT_OS_LINUX cout << "Open a couple Leafpads & gedits and press enter\n"; @@ -591,9 +578,6 @@ static bool TestGetList1 (void) static bool TestGetList2 (void) { - cout << "Warning: The next set of tests cannot be automated\n" - << " Please verify the following window lists\n\n"; - cout << "Open a multi-window testing application"; getchar(); Window w, wx = Window::GetActive(); @@ -619,16 +603,55 @@ static bool TestGetList2 (void) return true; } + + +//----------------------------------------------------------------------------// +// Functions // +//----------------------------------------------------------------------------// + //////////////////////////////////////////////////////////////////////////////// bool TestWindow (void) { - cout << "BEGIN WINDOW TESTING\n------------------------------\n"; VERIFY (Window::IsAxEnabled()); - if (!TestInvalid ()) { cout << ">> Invalid Failed \n\n"; return false; } - if (!TestSelect1 ()) { cout << ">> Select1 Failed \n\n"; return false; } - if (!TestSelect2 ()) { cout << ">> Select2 Failed \n\n"; return false; } - if (!TestGetList1()) { cout << ">> GetList1 Failed\n\n"; return false; } - if (!TestGetList2()) { cout << ">> GetList2 Failed\n\n"; return false; } - cout << ">> Success\n\n"; return true; + + cout << "TEST WINDOW\n" + << "------------------------------\n" + << " 0: All \n" + << " 1: Invalid \n" + << " 2: Select1 \n" + << " 3: Select2 \n" + << " 4: GetList1\n" + << " 5: GetList2\n\n"; + + // Ask the user to make a selection + cout << "Enter component(s) to test: "; + string input; getline (cin, input); + + int selection; cout << endl; + // Tokenize the input value + stringstream stream (input); + while (stream >> selection) + { + // Test everything + if (selection == 0) + { + return TestInvalid () + && TestSelect1 () + && TestSelect2 () + && TestGetList1() + && TestGetList2(); + } + + switch (selection) + { + case 1: if (!TestInvalid ()) return false; break; + case 2: if (!TestSelect1 ()) return false; break; + case 3: if (!TestSelect2 ()) return false; break; + case 4: if (!TestGetList1()) return false; break; + case 5: if (!TestGetList2()) return false; break; + } + } + + return true; } From 1ed686ea064932af9a97a1b06d408745851e4962 Mon Sep 17 00:00:00 2001 From: dkrutsko Date: Sat, 25 Feb 2017 00:36:15 -0500 Subject: [PATCH 2/4] Small formatting fixes --- Test/Process.cc | 26 +++++++++++++------------- Test/Window.cc | 34 +++++++++++++++++----------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Test/Process.cc b/Test/Process.cc index b993759..121e6a5 100644 --- a/Test/Process.cc +++ b/Test/Process.cc @@ -21,19 +21,19 @@ //////////////////////////////////////////////////////////////////////////////// -#define TEST_PROCESS \ - { \ - VERIFY ( list1[i].IsValid ()); \ - VERIFY ( list2[i].IsValid ()); \ - VERIFY (!list1[i].HasExited()); \ - \ - VERIFY ( (list1[i] == list2[i])); \ - VERIFY (!(list1[i] != list2[i])); \ - \ - cout << setw (6) << list1[i].GetPID() << " " \ - << (list1[i].Is64Bit() ? "x64 " : "x32 ") \ - << list1[i].GetName() << endl; \ - } +#define TEST_PROCESS \ +{ \ + VERIFY ( list1[i].IsValid ()); \ + VERIFY ( list2[i].IsValid ()); \ + VERIFY (!list1[i].HasExited()); \ + \ + VERIFY ( (list1[i] == list2[i])); \ + VERIFY (!(list1[i] != list2[i])); \ + \ + cout << setw (6) << list1[i].GetPID() << " " \ + << (list1[i].Is64Bit() ? "x64 " : "x32 ") \ + << list1[i].GetName() << endl; \ +} diff --git a/Test/Window.cc b/Test/Window.cc index d0f28ba..b536718 100644 --- a/Test/Window.cc +++ b/Test/Window.cc @@ -21,26 +21,26 @@ //////////////////////////////////////////////////////////////////////////////// -#define TEST_WINDOW \ - { \ - VERIFY (list1[i].IsValid()); \ - VERIFY (list2[i].IsValid()); \ - \ - VERIFY ( (list1[i] == list2[i])); \ - VERIFY (!(list1[i] != list2[i])); \ - \ - cout << setw (6) << list1[i].GetPID () \ - << ": " << list1[i].GetTitle() \ - << "\n"; \ - } +#define TEST_WINDOW \ +{ \ + VERIFY (list1[i].IsValid()); \ + VERIFY (list2[i].IsValid()); \ + \ + VERIFY ( (list1[i] == list2[i])); \ + VERIFY (!(list1[i] != list2[i])); \ + \ + cout << setw (6) << list1[i].GetPID () \ + << ": " << list1[i].GetTitle() \ + << "\n"; \ +} //////////////////////////////////////////////////////////////////////////////// -#define MINMAX_TEST( action ) \ - Timer::Sleep (500); \ - cout << " - " action " = " \ - << (w.IsMinimized() ? " Min " : "!Min ") \ - << (w.IsMaximized() ? " Max " : "!Max "); \ +#define MINMAX_TEST( action ) \ + Timer::Sleep (500); \ + cout << " - " action " = " \ + << (w.IsMinimized() ? " Min " : "!Min ") \ + << (w.IsMaximized() ? " Max " : "!Max "); \ getchar(); From 0200c5de1a714a0a523e518362e1b34a3a075107 Mon Sep 17 00:00:00 2001 From: dkrutsko Date: Sat, 25 Feb 2017 00:59:50 -0500 Subject: [PATCH 3/4] Fixed memory test case bug --- Test/Memory.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Test/Memory.cc b/Test/Memory.cc index e0152b6..8b1984d 100644 --- a/Test/Memory.cc +++ b/Test/Memory.cc @@ -1704,7 +1704,7 @@ bool TestMemory (void) if ((selection == 0 || selection >= 9) && p2.GetName().substr (0, 4) != "Peon") { - cout << "These tests require selecting Peon!\n\n"; + cout << "This test requires selecting Peon!\n\n"; if (selection == 0) return false; else continue; } @@ -1732,11 +1732,11 @@ bool TestMemory (void) case 1: if (!TestInvalid ( )) return false; break; case 2: if (!TestEquals ( )) return false; break; case 3: if (!TestParams ( )) return false; break; - case 4: if (!TestDebug (p1) && + case 4: if (!TestDebug (p1) || !TestDebug (p2)) return false; break; - case 5: if (!TestRegion (p1) && + case 5: if (!TestRegion (p1) || !TestRegion (p2)) return false; break; - case 6: if (!TestModules (p1) && + case 6: if (!TestModules (p1) || !TestModules (p2)) return false; break; case 7: if (!TestStress ( )) return false; break; case 8: if (!TestRW (p2)) return false; break; From 02002a78cdecb5eb95c97c9a2f20116eb17d3cea Mon Sep 17 00:00:00 2001 From: dkrutsko Date: Sat, 25 Feb 2017 01:28:10 -0500 Subject: [PATCH 4/4] Small formatting fixes --- Test/Memory.cc | 8 +++++--- Test/Window.cc | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Test/Memory.cc b/Test/Memory.cc index 8b1984d..9a52fd5 100644 --- a/Test/Memory.cc +++ b/Test/Memory.cc @@ -1661,10 +1661,14 @@ static bool TestFind (const Process& p) bool TestMemory (void) { + cout << "TEST MEMORY\n" + << "------------------------------\n"; + char sPID[32]; Process p1 = Process::GetCurrent(), p2; cout << uppercase << "Open a program and input PID: "; cin.getline (sPID, 32); auto pid = atoi (sPID); + cout << endl; VERIFY (pid > 0 ); VERIFY (p2.Open (pid) ); VERIFY (p1.IsValid()); VERIFY (!p1.HasExited()); @@ -1676,9 +1680,7 @@ bool TestMemory (void) #endif - cout << "TEST MEMORY\n" - << "------------------------------\n" - << " 0: All \n" + cout << " 0: All \n" << " 1: Invalid \n" << " 2: Equals \n" << " 3: Params \n" diff --git a/Test/Window.cc b/Test/Window.cc index b536718..22199c8 100644 --- a/Test/Window.cc +++ b/Test/Window.cc @@ -613,11 +613,12 @@ static bool TestGetList2 (void) bool TestWindow (void) { + cout << "TEST WINDOW\n" + << "------------------------------\n"; + VERIFY (Window::IsAxEnabled()); - cout << "TEST WINDOW\n" - << "------------------------------\n" - << " 0: All \n" + cout << " 0: All \n" << " 1: Invalid \n" << " 2: Select1 \n" << " 3: Select2 \n"