static void Main(string[] args) { string functionName = null; uint port = 0; int numFailed = 0; // Initialize log file logFile = new System.IO.StreamWriter(GetWorkingDirectory() + "log.txt"); logFile.WriteLine("QXDM Automation Test Log"); // Parse arguments waitForInputToExit = true; switch (args.Length) { case 0: ExitWithFail("Tried to run with improper syntax. Syntax is: QXDMAutomation <functionname> {port #} {nowait}", ExitCode.AUTOMATION_SETUP_ERROR); break; case 1: functionName = args[0]; break; // 2nd argument is ambiguous (port or "nowait"?) so check by type case 2: functionName = args[0]; uint tempPort = 0; if (uint.TryParse(args[1], out tempPort)) { port = tempPort; } else if (args[1] == waitForInput_arg) { waitForInputToExit = false; } break; default: functionName = args[0]; uint.TryParse(args[1], out port); if (args[2] == waitForInput_arg) { waitForInputToExit = false; } break; } if (InitializeTestFunctions() == false) { ExitWithFail("Could not initialize test functions.", ExitCode.AUTOMATION_SETUP_ERROR); } QXDMAutoApplication qxdmApplication = null; try { qxdmApplication = (QXDMAutoApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("QXDM.QXDMAutoApplication"); } catch (COMException e) { if (e.HResult == -2147221021) // Running object not found { qxdmApplication = new QXDMAutoApplication(); // Attempt to start it } if (qxdmApplication == null) { ExitWithFail("Error Starting QXDM", ExitCode.AUTOMATION_SETUP_ERROR); } } if (qxdmApplication != null) { Console.WriteLine("Interface Version: {0}", qxdmApplication.Get_Automation_Version()); AutomationWindow automationWindow = qxdmApplication.GetAutomationWindow(); automationWindow.SetVisible(true); Console.WriteLine("QXDM Version: {0}", automationWindow.GetQXDMVersion()); QXDMAutomation.TestCase testCase = null; if (functionName.ToLower() == runall) // Running all test cases { TestFunctionsIterator iterator = gTestFunctions.GetEnumerator(); while (iterator.MoveNext() == true) { CurrTestFunction current = iterator.Current; string testName = current.Key; testCase = current.Value; // If no port is defined, only run test cases that do not require a COM port if (port != 0 || testCase._requiresComPort == false) { if (RunTestCase(testCase, testName, automationWindow, port) == false) { numFailed++; } } } } else if (gTestFunctions.TryGetValue(functionName.ToLower(), out testCase)) // Run a single test case { if (RunTestCase(testCase, functionName, automationWindow, port) == false) { numFailed++; } } else { LogEverywhere("Function " + functionName + " not found."); // Could not find test case numFailed++; } automationWindow.Quit(); // Exit with an error if any test cases failed. if (numFailed > 1) { ExitWithFail("Two or more test cases failed.", ExitCode.MULT_TESTCASES_FAILED); } else if (numFailed == 1) { ExitWithFail("A test case failed.", ExitCode.TESTCASE_FAILED); } LogEverywhere("\n. . .\n[SUCCESS] All test cases passed"); if (waitForInputToExit) { Console.Write("\n\nPress enter to exit."); Console.Read(); } } logFile.Close(); }