Commit e0519368 authored by Jesse Mapel's avatar Jesse Mapel Committed by amystamile-usgs
Browse files

Moved old ISIS unitTests into core (#4351)

* First pass at old unitTests

* re-removed old files

* Slim down and unittest port

* installing IsisPreferences

* Fixed tests in a full build
parent 14fa9fca
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ find files of those names at the top level of this repository. **/
#include <fstream>

#include "FileName.h"
#include "PvlTokenizer.h"
#include "PvlTranslationTable.h"

namespace Isis {
+59 −0
Original line number Diff line number Diff line
Testing LabelTranslationManager object

Testing Translate method:

Translating Extra: Test Input, Index 0

Testing Auto method:

Object = IsisCube
  Object = BandBin
    BandName = "Test Input, Index 0"
  End_Object

  Group = Dimensions
    NumberOfLines = "Test Input, Index 0"
    NumberOfBands = "Test Input, Index 0"
  End_Group
End_Object

Group = Mapping
  CenterLongitude = "Test Input, Index 0"
End_Group
End

Testing parseSpecification method: att@name|value

Testing parseSpecification method: tag@name|value

Testing parseSpecification method: att@name

Testing parseSpecification method: new@name

Testing parseSpecification method: name|value

Testing parseSpecification method: value

Testing parseSpecification method: namespace:name

Testing parseSpecification method: namespace:name|value

Testing parseSpecification method: att@namespace:name|value

Testing parseSpecification method: tag@name|value

Testing parseSpecification method: att|name|value
**PROGRAMMER ERROR** Malformed dependency specification [att|name|value].
**PROGRAMMER ERROR** [att|name|value] has unexpected number of '@' or '|' delimiters.

Testing parseSpecification method: att@name@value
**PROGRAMMER ERROR** Malformed dependency specification [att@name@value].
**PROGRAMMER ERROR** [att@name@value] has unexpected number of '@' or '|' delimiters.

Testing parseSpecification method: not@name|value
**PROGRAMMER ERROR** Malformed dependency specification [not@name|value].
**PROGRAMMER ERROR** Dependency type specification [not] is invalid. Valid types are [att], [tag] and [new].

Testing parseSpecification method: att@name|value1|value2
**PROGRAMMER ERROR** Malformed dependency specification [att@name|value1|value2].
**PROGRAMMER ERROR** Malformed dependency specification [att@name|value1|value2].
+7 −0
Original line number Diff line number Diff line
ifeq ($(ISISROOT), $(BLANK))
.SILENT:
error:
	echo "Please set ISISROOT";
else
	include $(ISISROOT)/make/isismake.objs
endif
 No newline at end of file
+191 −0
Original line number Diff line number Diff line
#include <sstream>
#include "LabelTranslationManager.h"
#include "Preference.h"
#include "IException.h"
#include "IString.h"
#include "Preference.h"

using namespace Isis;
using namespace std;
/**
 * Child class of LabelTranslationManager to implement pure virtual methods.
 *
 * @author 2017-01-11 Jeannie Backer
 *
 * @internal
 *  @history 2017-01-11 Jeannie Backer - Original Version. Fixes #4584.
 *  @history 2017-10-16 Kristin Berry - Updated for changes to dependency specification format and
 *                        the addition of xml namspaces. References #5202
 */
class TestTranslationManager : public LabelTranslationManager {
  public:

    TestTranslationManager(const QString &transFile) : LabelTranslationManager() {
    AddTable(transFile);
    }

    TestTranslationManager(std::istream &transStrm) : LabelTranslationManager() {
    AddTable(transStrm);
    }

    ~TestTranslationManager() {
    }

    virtual QString Translate(QString nName, int findex = 0) {
      QString inputValue = "Test Input, Index " + toString(findex);
      return PvlTranslationTable::Translate(nName, inputValue);
    }
};

int main(void) {

  Preference::Preferences(true);
  stringstream trnsStrm;
  trnsStrm << "Group = NumberOfLines" << endl;
  trnsStrm << "  Auto" << endl;
  trnsStrm << "  OutputName = Lines" << endl;
  trnsStrm << "  OutputPosition = (\"Object\",\"IsisCube\",";
  trnsStrm <<                      "\"Group\",\"Dimensions\")" << endl;
  trnsStrm << "  InputPosition = (Image,Size)" << endl;
  trnsStrm << "  InputKey = NL" << endl;
  trnsStrm << "  Translation = (*,*)" << endl;
  trnsStrm << "EndGroup" << endl;
  trnsStrm << "Group = NumberOfBands" << endl;
  trnsStrm << "  Auto" << endl;
  trnsStrm << "  Optional" << endl;
  trnsStrm << "  OutputName = Bands" << endl;
  trnsStrm << "  OutputPosition = (\"Object\",\"IsisCube\",";
  trnsStrm <<                      "\"Group\",\"Dimensions\")" << endl;
  trnsStrm << "  InputPosition = (Image,Size)" << endl;
  trnsStrm << "  InputKey = Nb" << endl;
  trnsStrm << "  InputDefault = 1" << endl;
  trnsStrm << "  Translation = (*,*)" << endl;
  trnsStrm << "EndGroup" << endl;
  trnsStrm << "Group = Bonus" << endl;
  trnsStrm << "  Auto" << endl;
  trnsStrm << "  Optional" << endl;
  trnsStrm << "  InputPosition = (Image,Pixel)" << endl;
  trnsStrm << "  InputKey = Bonus" << endl;
  trnsStrm << "  Translation = (*,*)" << endl;
  trnsStrm << "EndGroup" << endl;
  trnsStrm << "Group = Extra" << endl;
  trnsStrm << "  Optional" << endl;
  trnsStrm << "  InputPosition = (Image,Bogus)" << endl;
  trnsStrm << "  InputKey = Extra" << endl;
  trnsStrm << "  Translation = (*,*)" << endl;
  trnsStrm << "EndGroup" << endl;
  trnsStrm << "Group = PixelResolution" << endl;
  trnsStrm << "  InputPosition = (Image,Pixel)" << endl;
  trnsStrm << "  InputKey = Resolution" << endl;
  trnsStrm << "  InputDefault = 1" << endl;
  trnsStrm << "  Translation = (*,*)" << endl;
  trnsStrm << "EndGroup" << endl;
  trnsStrm << "Group = BandName" << endl;
  trnsStrm << "  Auto" << endl;
  trnsStrm << "  OutputName = Band" << endl;
  trnsStrm << "  OutputPosition = (\"Object\",\"IsisCube\",";
  trnsStrm <<                      "\"Object\",\"BandBin\")" << endl;
  trnsStrm << "  InputPosition = (Image,BandInfo)" << endl;
  trnsStrm << "  InputKey = Band" << endl;
  trnsStrm << "  Translation = (*,*)" << endl;
  trnsStrm << "EndGroup" << endl;
  trnsStrm << "Group = CenterLongitude" << endl;
  trnsStrm << "  Auto" << endl;
  trnsStrm << "  OutputPosition = (\"Group\",\"Mapping\")" << endl;
  trnsStrm << "  OutputName = CenterLongitude" << endl;
  trnsStrm << "  InputPosition = IMAGE_MAP_PROJECTION" << endl;
  trnsStrm << "  InputPosition = (QUBE,IMAGE_MAP_PROJECTION)" << endl;
  trnsStrm << "  InputPosition = (SPECTRAL_QUBE,IMAGE_MAP_PROJECTION)" << endl;
  trnsStrm << "  InputKey = CENTER_LONGITUDE" << endl;
  trnsStrm << "  Translation = (*,*)" << endl;
  trnsStrm << "EndGroup" << endl;

  trnsStrm << "End" << endl;

  TestTranslationManager transMgr(trnsStrm);

  try {
    cout << "Testing LabelTranslationManager object" << endl;

    cout << endl << "Testing Translate method:" << endl;
    cout << endl << "Translating Extra: ";
    cout << transMgr.Translate("Extra") << endl;

    cout << endl << "Testing Auto method:" << endl;
    Pvl translatedLabel;
    transMgr.Auto(translatedLabel);
    cout << endl << translatedLabel << endl;
  }
  catch(IException &e) {
    e.print();
  }
  try {
    cout << endl << "Testing parseSpecification method: att@name|value" << endl;
    transMgr.parseSpecification((QString)"att@name:value");

    cout << endl << "Testing parseSpecification method: tag@name|value" << endl;
    transMgr.parseSpecification((QString)"tag@name|value");

    cout << endl << "Testing parseSpecification method: att@name" << endl;
    transMgr.parseSpecification((QString)"att@name");

    cout << endl << "Testing parseSpecification method: new@name" << endl;
    transMgr.parseSpecification((QString)"new@name");

    cout << endl << "Testing parseSpecification method: name|value" << endl;
    transMgr.parseSpecification((QString)"name|value");

    cout << endl << "Testing parseSpecification method: value" << endl;
    transMgr.parseSpecification((QString)"value");

    cout << endl << "Testing parseSpecification method: namespace:name" << endl;
    transMgr.parseSpecification((QString)"namespace:name");

    cout << endl << "Testing parseSpecification method: namespace:name|value" << endl;
    transMgr.parseSpecification((QString)"namespace:name|value");

    cout << endl << "Testing parseSpecification method: att@namespace:name|value" << endl;
    transMgr.parseSpecification((QString)"att@namepsace:name|value");

    cout << endl << "Testing parseSpecification method: tag@name|value" << endl;
    transMgr.parseSpecification((QString)"tag@namespace:name|value");
  }
  catch(IException &e) {
    e.print();
  }


  try {
    cout << endl << "Testing parseSpecification method: att|name|value" << endl;
    transMgr.parseSpecification((QString)"att|name|value");
  }
  catch(IException &e) {
    e.print();
  }


  try {
    cout << endl << "Testing parseSpecification method: att@name@value" << endl;
    transMgr.parseSpecification((QString)"att@name@value");
  }
  catch(IException &e) {
    e.print();
  }

  try {
    cout << endl << "Testing parseSpecification method: not@name|value" << endl;
    transMgr.parseSpecification((QString)"not@name|value");
  }
  catch(IException &e) {
    e.print();
  }

  try {
    cout << endl << "Testing parseSpecification method: att@name|value1|value2" << endl;
    transMgr.parseSpecification((QString)"att@name|value1|value2");
  }
  catch(IException &e) {
    e.print();
  }
  return 0;
}
Loading