Unverified Commit 24e277c4 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

added error tests for jigsaw (#4093)

* added error tests

* added some other error tests

* added last test

* addressed comments

* missed a thing

* removed useless test
parent bee0df24
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ namespace Isis {
    QString cubeList = ui.GetFileName("FROMLIST");

    // retrieve settings from jigsaw gui

    BundleSettingsQsp settings = bundleSettings(ui);
    settings->setCubeList(cubeList);
    BundleAdjust *bundleAdjustment = NULL;
@@ -73,7 +72,6 @@ namespace Isis {
      throw;
    }


    // Bundle adjust the network
    try {

@@ -103,7 +101,6 @@ namespace Isis {
      bundleAdjustment->controlNet()->Write(ui.GetFileName("ONET"));

      PvlGroup gp("JigsawResults");

      // Update the cube pointing if requested but ONLY if bundle has converged
      if (ui.GetBoolean("UPDATE") ) {
        if ( !bundleAdjustment->isConverged() ) {
+0 −78
Original line number Diff line number Diff line
# This tests the errors that can occur when running jigsaw.
#   TEST A: "Must either solve for camera pointing or spacecraft position."
#   UNTESTED, not sure how to force exception during bundle adjust
#     TEST B: "Unable to bundle adjust network"
#   TEST C: "Input Target parameters file missing main Target object."
#   TEST D: "Must solve for at least one target body option."
#
# 2016-08-22 Ian Humphrey - Original version. Fixes #4269.
# 2016-10-13 Ian Humphrey - Removed TEST E: "Input SC_PARAMETERS file missing SensorParameters
#                object," as USEPVL and SC_PARAMETERS have been turned off. References #4292,
#                #4293."
APPNAME = jigsaw

include $(ISISROOT)/make/isismake.tsts

commands:
	$(LS) -1 $(INPUT)/*cub > $(OUTPUT)/cubes.lis;
# TEST A: CAMSOLVE=None and SPSOLVE=None
	echo -e "Error Test A:" > $(OUTPUT)/error_temp.txt;
	if [[ `$(APPNAME) \
	  fromlist=$(INPUT)/empty.lis \
	  cnet=$(INPUT)/empty.net \
	  onet=$(OUTPUT)/out.net \
	  camsolve=None \
	  spsolve=None \
	  2>> $(OUTPUT)/error_temp.txt \
	  > /dev/null` ]]; \
	then \
	  true; \
	fi;
# TEST B: exception occurs when performing bundle adjust
#         TODO: This still needs to be tested.
# TEST C: SOLVETARGETBODY=yes and TBPARAMETERS file missing Target object
	echo -e "Error Test C:" >> $(OUTPUT)/error_temp.txt;
	if [[ `$(APPNAME) \
	  fromlist=$(OUTPUT)/cubes.lis \
	  cnet=$(INPUT)/empty.net \
	  onet=$(OUTPUT)/out.net \
	  solvetargetbody=yes \
	  tbparameters=$(INPUT)/invalidTargetParameters.pvl \
	  2>> $(OUTPUT)/error_temp.txt \
	  > /dev/null` ]]; \
	then \
	  true; \
	fi;
# TEST D: SOLVETARGETBODY=yes and # of parameters to solve is 0
	echo -e "Error Test D:" >> $(OUTPUT)/error_temp.txt;
	if [[ `$(APPNAME) \
	  fromlist=$(OUTPUT)/cubes.lis \
	  cnet=$(INPUT)/empty.net \
	  onet=$(OUTPUT)/out.net \
	  solvetargetbody=yes \
	  tbparameters=$(INPUT)/zeroTargetParameters.pvl \
	  2>> $(OUTPUT)/error_temp.txt \
	  > /dev/null` ]]; \
	then \
	  true; \
	fi;
# TEST F: CNET=[invalid control net file]
	echo -e "Error Test F:" >> $(OUTPUT)/error_temp.txt;
	if [[ `$(APPNAME) \
	  fromlist=$(OUTPUT)/cubes.lis \
	  cnet=$(INPUT)/notacnet.net \
	  onet=$(OUTPUT)/out.net \
	  radius=yes \
	  spsolve=positions \
	  point_radius_sigma=500 \
	  spacecraft_position_sigma=500 \
	  camera_angles_sigma=2 \
	  2>> $(OUTPUT)/error_temp.txt \
	  > /dev/null` ]]; \
	then \
	  true; \
	fi;
# Remove paths from errors file
	$(SED) 's/\(\[\)\/.*\(input\)/\1\2/g' $(OUTPUT)/error_temp.txt > $(OUTPUT)/error.txt;
	$(RM) $(OUTPUT)/error_temp.txt;
	$(RM) $(OUTPUT)/cubes.lis > /dev/null;
+80 −4
Original line number Diff line number Diff line
#include "Fixtures.h"
#include "Pvl.h"
#include "PvlGroup.h"
#include "TestUtilities.h"
#include "ControlNet.h"
#include "Statistics.h"

#include "jigsaw.h"

#include "gtest/gtest.h"
#include "TestUtilities.h"
#include "Fixtures.h"
#include "gmock/gmock.h"

using namespace Isis;
using namespace testing; 


static QString APP_XML = FileName("$ISISROOT/bin/xml/jigsaw.xml").expanded();

@@ -144,3 +146,77 @@ TEST_F(ObservationPair, FunctionalTestJigsawCamSolveAll) {
  EXPECT_NEAR(elems.at(56).toDouble(), 0.365717165,          0.00001); 
  
}

TEST_F(ObservationPair, FunctionalTestJigsawErrorNoSolve) {
  QTemporaryDir prefix;
  QString outCnetFileName = prefix.path() + "/outTemp.net";
  QVector<QString> args = {"fromlist="+cubeListFile, "cnet="+cnetPath, "onet="+outCnetFileName, 
                           "camsolve=None", "spsolve=None"};

  UserInterface options(APP_XML, args);
  
  Pvl log; 
  
  try {
    jigsaw(options, &log);
    FAIL() << "Should throw" << std::endl;
  }
  catch (IException &e) {
    EXPECT_THAT(e.what(), HasSubstr("Must either solve for camera pointing or spacecraft position"));
  }
}


TEST_F(ObservationPair, FunctionalTestJigsawErrorTBParamsNoTarget) {
  QTemporaryDir prefix;
  QString outCnetFileName = prefix.path() + "/outTemp.net";
  
  // just use isdPath for a valid PVL file without the wanted groups
  QVector<QString> args = {"fromlist="+cubeListFile, "cnet="+cnetPath, "onet="+outCnetFileName, "SOLVETARGETBODY=TRUE", "tbparameters="+cubeRPath};

  UserInterface options(APP_XML, args);
  
  Pvl log; 
  
  try {
    jigsaw(options, &log);
    FAIL() << "Should throw an exception" << std::endl;
  }
  catch (IException &e) {
    EXPECT_THAT(e.what(), HasSubstr("Input Target parameters file missing main Target object"));
  } 
}


TEST_F(ObservationPair, FunctionalTestJigsawErrorTBParamsNoSolve) {
  QTemporaryDir prefix;
  QString outCnetFileName = prefix.path() + "/outTemp.net";
  
  std::istringstream iss(R"(
    Object = Target
    Group = "NAME"
       Name=Enceladus
    EndGroup
    END_OBJECT
  )"); 
  
  QString tbsolvepath = prefix.path() + "/tbsolve.pvl";
  Pvl tbsolve; 
  iss >> tbsolve; 
  tbsolve.write(tbsolvepath);

  // just use isdPath for a valid PVL file without the wanted groups
  QVector<QString> args = {"fromlist="+cubeListFile, "cnet="+cnetPath, "onet="+outCnetFileName, "SOLVETARGETBODY=TRUE", "tbparameters="+tbsolvepath};

  UserInterface options(APP_XML, args);
  
  Pvl log; 
  
  try {
    jigsaw(options, &log);
    FAIL() << "Should throw an exception" << std::endl;
  }
  catch (IException &e) {
    EXPECT_THAT(e.what(), HasSubstr("Must solve for at least one target body option"));
  } 
}