INTRODUCTION
I base this article around the need to pass command line parameters to a running program. Please note this does not seem to work with Windows yet (working in Linux and OSX not tested).
DISCUSSION
The idea is to use a set of command line parameters to execute a set of built in software tests between two or more instances of a given software and then automatically generate unit test reports. The whole thing can be automated via the sequencing of various tests in a bash script or batch file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
//============================================================================ // Name : Command Line Arguments // Author : Divide To Infinity // Version : V1.0 // Copyleft : Divide To Infinity 2015 - GNU GPL v2 // Description : JUCE Command Line Arguments Demo C++11, Ansi-style //============================================================================ #include "../JuceLibraryCode/JuceHeader.h" class CommandLineArguments : public JUCEApplication { public: CommandLineArguments(){} ~CommandLineArguments(){} void initialise(const String& commandLine) override { Logger * log = Logger::getCurrentLogger(); log->writeToLog(getApplicationName()); // Now list the command line arguments log->writeToLog("See the entered command line parameters below: "); log->writeToLog(JUCEApplicationBase::getCommandLineParameters()); } void shutdown() override {} const String getApplicationName() override { return "CommandLineArguments"; } const String getApplicationVersion() override { return "1.0"; } private: }; START_JUCE_APPLICATION(CommandLineArguments); |
FINDINGS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
//============================================================================ // Name : CommandLineArguments // Author : Divide To Infinity // Version : V1.0 // Copyleft : Divide To Infinity 2015 - GNU GPL v2 // Description : JUCE Command Line Arguments Demo C++11, Ansi-style //============================================================================ #include "../JuceLibraryCode/JuceHeader.h" using namespace std; class CommandLineArguments : public JUCEApplication { public: CommandLineArguments(){} ~CommandLineArguments(){} void initialise(const String& commandLine) override { Logger * log = Logger::getCurrentLogger(); log->writeToLog(getApplicationName()); // To get the parameters as an array, you can call JUCEApplication::getCommandLineParameters() // Now list the command line arguments log->writeToLog("See the entered command line parameters below: "); log->writeToLog(JUCEApplicationBase::getCommandLineParameters()); cout << endl; // Empty line : 0 // Now lets try and do something with the arguments // First use the getCommandLineParameterArray which returns a tokenised array // of Command Line args separated by whitespace StringArray argTokens = StringArray(JUCEApplicationBase::getCommandLineParameterArray()); for(int i = 0; i < argTokens.size(); ++i) { // Print out each arg line by line log->writeToLog(argTokens[i]); // We can use these args to call methods if (argTokens[i] == "-i") { cmdTest(); } // Then use args with parameters and error messages } } void cmdTest() { cout << "cmdTest called" << endl; } void shutdown() override {} const String getApplicationName() override { return "CommandLineArguments"; } const String getApplicationVersion() override { return "1.0"; } void unhandledException(const std::exception *, const String &sourceFilename, int lineNumber) override { // Here we can use this method to catch exceptions and generate reports } private: }; START_JUCE_APPLICATION(CommandLineArguments); |
LINKS
Command Line Arguments discussion on the JUCE forum
JUCEApplicationBase Class docs