Commit cd760991 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Modified UserInterface, its unit test, and added new files for the unit test....

Modified UserInterface, its unit test, and added new files for the unit test. Using -h on the command line displays help regardless of errors on the command line. Using -h=parameterName is no longer case sensitive. Fixes #552. Fixes #1735. Modified isismake.objs. Coco coverage tool now works for objects. Fixes #2119.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@5937 41f8697f-d340-4b68-9986-7bafba869bb8
parent df6fdab4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -317,7 +317,7 @@ unitTest: $(OBJS) unitTest.o
	    $(CP) $(ISISROOT)/lib/libisis$(ISISLIBVERSION).a.csmes                   \
	      libisis$(ISISLIBVERSION).a.csmes;                                      \
	  fi;                                                                        \
	  $(AR) $(ISISARFLAGS) -rs libisis$(ISISLIBVERSION).a $(OBJS);               \
	  $(AR) $(ISISARFLAGS) -crs libisis$(ISISLIBVERSION).a $(OBJS);               \
	  $(RANLIB) libisis$(ISISLIBVERSION).a;                                      \
	  $(LDSHARED) $(ISISSHAREDFLAGS) $(ISISSHAREDON)                             \
	      -o libisis$(ISISLIBVERSION).$(SHAREDLIBEXT) libisis$(ISISLIBVERSION).a \
+691 −567

File changed.

Preview size limit exceeded, changes collapsed.

+77 −49
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@
 *   http://www.usgs.gov/privacy.html.
 */

#include "IsisAml.h"
#include "PvlTokenizer.h"
#include "FileName.h"
#include "Gui.h"
#include "IsisAml.h"
#include "PvlTokenizer.h"

class Gui;

@@ -125,6 +125,26 @@ namespace Isis {
   *                           $base, $mro, etc. Now when -batchlist does not
   *                           understand a variable it preserves it in the
   *                           parameter list. Fixes #365.
   *   @history 2014-06-09 Ian Humphrey - Added PreProcess() and ResolveParameter()
   *                           functions to replace redundant code in LoadCommandLine().
   *                           These functions evaulate -HELP and -WEBHELP flags regardless
   *                           of errors on commandline. Fixes #552. 
   *   @history 2014-06-10 Ian Humphrey - Fixed issue causing parameter name values 
   *                           on the -HELP flag to only evaluate if uppercase. Fixes #1735.
   *                           Reorganized header and cpp layout. Renamed private member functions
   *                           to follow code convention. Began modifying unitTest.cpp.
   *   @history 2014-06-11 Ian Humphrey - Added throws to evaluateOption() so that if the parameter 
   *                           is -HELP or -WEBHELP unitTest.cpp can catch and continue running.
   *   @history 2014-06-12 Ian Humphrey - Modified logic in loadCommandLine() throw statements so
   *                           an exception is thrown when -BATCHLIST is used with -GUI, -SAVE,
   *                           -LAST, or -RESTORE options. Added bool usedDashRestore.
   *   @history 2014-06-17 Ian Humphrey - Added to unitTest.xml to test -HELP=value. Renamed 
   *                           application name from 'hist' to 'unitTest'. Modified logic of
   *                           resolveParameter() to give appropriate error message to user
   *                           when using an invalid reserved parameter (e.g. -x).
   *   @history 2014-06-18 Ian Humphrey - Finished developing unitTest.cpp and reorganized. 
   *                           Added lacking [at]throws documentation to UserInterface.cpp.                         
   *                           
   */

  class UserInterface : public IsisAml {
@@ -133,22 +153,15 @@ namespace Isis {
      ~UserInterface();

      /**
       * Indicates if the Isis Graphical User Interface is operating.
       * Returns true if the program should abort on error, and false if it
       * should continue
       *
       * @return bool
       */
      bool IsInteractive() {
        return p_gui != NULL;
      };

      /**
       * @return the Gui
       * @return bool True for abort, False for continue
       */
      Gui *TheGui() {
        return p_gui;
      bool AbortOnError() {
        return p_abortOnError;
      };    
      

      /**
       * Returns the size of the batchlist.  If there is no batchlist, it will
       * return 0
@@ -159,6 +172,15 @@ namespace Isis {
        return p_batchList.size();
      };
      
      /**
       * Indicates if the Isis Graphical User Interface is operating.
       *
       * @return bool
       */
      bool IsInteractive() {
        return p_gui != NULL;
      };

      /**
       * Returns the parent id
       *
@@ -169,51 +191,57 @@ namespace Isis {
      };  
      
      /**
       * Returns true if the program should abort on error, and false if it
       * should continue
       *
       * @return bool True for abort, False for continue
       * @return the Gui
       */
      bool AbortOnError() {
        return p_abortOnError;
      Gui *TheGui() {
        return p_gui;
      };

      void SaveHistory();
      QString GetInfoFileName();
      bool GetInfoFlag();
      
      void SetBatchList(int i);
      void SetErrorList(int i);
      
      bool GetInfoFlag();
      QString GetInfoFileName();
      void SaveHistory();

    private:
      std::vector<char *> p_cmdline; /**< This variable will contain argv.*/
      int p_parentId;               /**< This is a status to indicate if the GUI
                                        is running or not.*/

      void LoadCommandLine(int argc, char *argv[]);
      void LoadBatchList(const QString file);
      void LoadHistory(const QString file);
      void EvaluateOption(const QString name, const QString value);
      void GetNextParameter(unsigned int &curPos,
                            QString &name, std::vector<QString> &value);
      std::vector<QString> ReadArray(QString arrayString);

      //! Boolean value representing whether to abort or continue on error
      void loadBatchList(const QString file);
      void loadCommandLine(int argc, char *argv[]);
      void loadHistory(const QString file);
      
      void evaluateOption(const QString name, const QString value);
      void getNextParameter(unsigned int &curPos, 
                            QString &unresolvedParam, 
                            std::vector<QString> &value);
      void preProcess(QString fullReservedName, std::vector<QString> &reservedParams);
      std::vector<QString> readArray(QString arrayString);
      QString resolveParameter(QString &name, 
                               std::vector<QString> &reservedParams,
                               bool handleNoMatches = true);

      //! Boolean value representing whether to abort or continue on error.
      bool p_abortOnError;
      QString p_saveFile;        //!< FileName to save last history to
      QString p_progName;        //!< Name of program to run

      //!FileName to write batchlist line that caused error on
      QString p_errList;

      //!Vector of batchlist data
      //! Vector of batchlist data.
      std::vector<std::vector<QString> > p_batchList;

      bool p_interactive;  /**< Boolean value representing whether the
                                program is interactive or not.*/
      bool p_info;  //!< Boolean value representing if its in debug mode.
      QString p_infoFileName;  //!< FileName to save debugging info
      Gui *p_gui;                  //!< Pointer to the gui object
      //! This variable will contain argv.
      std::vector<char *> p_cmdline; 
      //! FileName to write batchlist line that caused error on.
      QString p_errList;
      //! Pointer to the gui object.
      Gui *p_gui;                  
      //! Boolean value representing if it's in debug mode.
      bool p_info;  
      //! FileName to save debugging info.
      QString p_infoFileName;  
      //! Boolean value representing whether the program is interactive or not.
      bool p_interactive;  
      //! This is a status to indicate if the GUI is running or not.                         
      int p_parentId;               
      //! Name of program to run.                                  
      QString p_progName;        
      //! FileName to save last history to.
      QString p_saveFile;          
  };
};

+232 −11
Original line number Diff line number Diff line
@@ -40,21 +40,68 @@ TO:

GUI:     0

Testing Escaped Array \(
FROM:    /ISISROOT/testData/base/isisTruth.cub
TO:      
 >> (escaped, argument)

Testing Escaped Array \\(
FROM:    /ISISROOT/testData/base/isisTruth.cub
TO:      
 >> \(escaped, argument)

Testing param = value Format
FROM:    dog
TO:      bread
GUI:     0

Testing Space in Argument Value
Testing Space in Parameter Value
FROM:    input file.cub
TO:      output.cub
GUI:     0

Testing =value
**USER ERROR** Unknown parameter [=input.cub].

Testing param =value
**USER ERROR** Unknown parameter [=bread].

Testing mismatched quotes for array-value
**USER ERROR** Invalid array format [("hello)].

Testing array-value ending in backslash
**USER ERROR** Invalid array format [(hello)\].

Testing Invalid Parameter
**USER ERROR** Invalid command line.
**USER ERROR** Unknown parameter [bogus].

Testing Invalid Reserved Parameter
**USER ERROR** Invalid Reserve Parameter Option [-LASTT]. Choices are  [-GUI,-NOGUI,-BATCHLIST,-LAST,-RESTORE,-WEBHELP,-HELP,-ERRLIST,-ONERROR,-SAVE,-INFO,-PREFERENCE,-LOG,-VERBOSE].

Testing Reserved Parameter=Invalid Value
**USER ERROR** Invalid value for reserve parameter [-VERBOSE].

Testing Unambiguous Reserved Parameter Resolution (-la)
FROM:    It
TO:      Worked
GUI:     0

Testing Ambiguous Reserved Parameter Resolution
**USER ERROR** Ambiguous Reserve Parameter [-L]. Please clarify.

Testing unitTest v. ./unitTest for GUI
GUI:     0

GUI:     0

Testing -PID and -GUI
**ERROR** -GUI and -PID are incompatible arguments.

Testing ParentId() and TheGui()
Testing -NOGUI
GUI:     0

Starting Batchlist Test
unitTest from=peaks.cub to=out1.txt 
FROM:    peaks.cub
@@ -88,23 +135,197 @@ GUI: 0

Finished Batchlist Test

Testing =value
**USER ERROR** Unknown parameter [=input.cub].
Testing -BATCHLIST with -GUI
**USER ERROR** -BATCHLIST cannot be used with -GUI, -SAVE, -RESTORE, or -LAST.

Testing param =value
**USER ERROR** Unknown parameter [=bread].
Testing -BATCHLIST with -SAVE
**USER ERROR** -BATCHLIST cannot be used with -GUI, -SAVE, -RESTORE, or -LAST.

Testing unterminated array-value quote
**USER ERROR** Invalid array format [("hello)].
Testing -BATCHLIST with -RESTORE
**USER ERROR** -BATCHLIST cannot be used with -GUI, -SAVE, -RESTORE, or -LAST.

Testing array-value ending in backslash
**USER ERROR** Invalid array format [(hello)\].
Testing -BATCHLIST with -LAST
**USER ERROR** -BATCHLIST cannot be used with -GUI, -SAVE, -RESTORE, or -LAST.

Testing -BATCHLIST with nonexistent .lis file
**USER ERROR** The batchlist file [doesntExist.lis] could not be opened.

Testing -BATCHLIST with empty .lis file
**USER ERROR** The list file [unitTestEmpty.lis] does not contain any data.

Testing -BATCHLIST with mismatched columns in .lis file
**USER ERROR** The number of columns must be constant in batchlist.

Testing -ONERROR=CONTINUE
AbortOnError() returns: 0

Testing -ONERROR=ABORT
AbortOnError() returns: 1

Testing -ONERROR=badValue
**USER ERROR** [badValue] is an invalid value for -ONERROR, options are ABORT or CONTINUE.

Testing -ONERROR=CONTINUE without -BATCHLIST
**USER ERROR** -ERRLIST and -ONERROR=continue cannot be used without  the -BATCHLIST option.

Testing -ERRLIST=value without -BATCHLIST
**USER ERROR** -ERRLIST and -ONERROR=continue cannot be used without  the -BATCHLIST option.

Testing -ERRLIST with no value
**USER ERROR** -ERRLIST expects a file name.

Testing -ERRLIST=value
./unitTest 
./unitTest 
./unitTest 
./unitTest 
./unitTest 
./unitTest 

Testing -HELP Priority (invalid parameters present)
FROM         = /ISISROOT/testData/base/isisTruth.cub
TO           = $temporary/junk.dat
TESTONE      = 0
TESTTWO      = 1
TESTTHREE    = 1
LISTTEST     = (*INCLUDEOPT, EXCLUDEOPT)
EXCLUDEDTEST = 10
**PROGRAMMER ERROR** Evaluating -HELP should only throw this exception during a unitTest.

Testing -HELP=value ...

Testing pixelType
ParameterName = TO
Brief         = "Test cube"
Type          = filename
PixelType     = real
Default       = $temporary/junk.dat
**PROGRAMMER ERROR** Evaluating -HELP should only throw this exception during a unitTest.

Testing inclusive min and max, lessThan, lessThanOrEqual, internalDefault
ParameterName      = TESTONE
Brief              = "unitTest test 1"
Type               = integer
InternalDefault    = None
GreaterThanOrEqual = 0
LessThanOrEqual    = 100
LessThan           = TESTTWO
LessThanOrEqual    = TESTTHREE
**PROGRAMMER ERROR** Evaluating -HELP should only throw this exception during a unitTest.

Testing odd, noninclusive min and max, greaterThan, greaterThanOrEqual
ParameterName      = TESTTWO
Brief              = "unitTest test 2"
Type               = integer
Default            = 1
GreaterThan        = 0
LessThan           = 100
GreaterThan        = TESTONE
GreaterThanOrEqual = TESTTHREE
Odd                = TRUE
**PROGRAMMER ERROR** Evaluating -HELP should only throw this exception during a unitTest.

Testing inclusions, exclusions
ParameterName = TESTTHREE
Brief         = "unitTest test 3"
Type          = integer
Default       = 1
NotEqual      = 10
Inclusions    = (FROM, TO)
Exclusions    = EXCLUDEDTEST
**PROGRAMMER ERROR** Evaluating -HELP should only throw this exception during a unitTest.

Testing list inclusions, exclusions, defaults
ParameterName = LISTTEST
Brief         = "unitTest list test"
Type          = string
Default       = INCLUDEOPT

Group = INCLUDEOPT
  Brief      = "unitTest list inclusions"
  Inclusions = (FROM, TO)
End_Group

Group = EXCLUDEOPT
  Brief      = "unitTest list exclusions"
  Exclusions = EXCLUDEDTEST
End_Group
**PROGRAMMER ERROR** Evaluating -HELP should only throw this exception during a unitTest.

...End testing -HELP=value

Testing -INFO
GetInfoFlag() returns: 1
GetInfoFileName() returns: 

Testing -INFO=value
GetInfoFlag() returns: 1
GetInfoFileName() returns: debug.log

Testing -LAST
FROM:    It
TO:      Worked
GUI:     0

**USER ERROR** Invalid command line.
**USER ERROR** Unknown parameter [bogus].
Testing -LAST with other app parameters
FROM:    otherParam
TO:      Worked
GUI:     0

Testing -LOG
FileOutput = On
FileName = print.prt

Testing -LOG=value
FileOutput = On
FileName = unitTest.prt

Testing -RESTORE with valid (existing) .par file
FROM:    It
TO:      Worked
GUI:     0

Testing -RESTORE with corrupt .par file
**USER ERROR** The history file [unitTestCorrupt.par] is corrupt, please fix or delete this file.

Testing -RESTORE with invalid (non-existing) .par file
**USER ERROR** The history file [junk.par] does not exist.

Testing -RESTORE with an empty .par file

Testing -RESTORE with a more populated .par file

Testing -SAVE with HistoryRecording Off

Starting -SAVE, -PREFERECE, and -RESTORE Test
Testing -SAVE=value with HistoryRecording On
FROM:    saveParam
TO:      works
GUI:     0

Restoring Saved Parameters:
FROM:    saveParam
TO:      works
GUI:     0

Finished -SAVE, PREFERENCE, and -RESTORE Test

Testing SetBatchList()...
Testing with param=array-value
./unitTest from=$peaks.cub to=(out1.txt
,out1.txtcopy
) 

Testing with param= 
./unitTest from=peaks.cub to

...End SetBatchList() Test

Testing SetErrorList() with p_errList == ""

Testing -VERBOSE
TerminalOutput = On

Testing -WEBHELP
**PROGRAMMER ERROR** Evaluating -WEBHELP should only throw this exception during a unitTest.
+754 −59

File changed.

Preview size limit exceeded, changes collapsed.

Loading