Commit 7079a414 authored by Jesse Mapel's avatar Jesse Mapel Committed by jlaura
Browse files

Fixed state being written out and read in differently (#183)

* Fixed state being written out and read in differently

* Fixed canModelBeConstructedFromState
parent 19c29897
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -252,6 +252,7 @@ std::string UsgsAstroLsSensorModel::getModelNameFromModelState(

std::string UsgsAstroLsSensorModel::getModelState() const {
      json state;
      state["m_modelName"] = _SENSOR_MODEL_NAME;
      state["m_imageIdentifier"] = m_imageIdentifier;
      state["m_sensorType"] = m_sensorType;
      state["m_totalLines"] = m_totalLines;
@@ -306,9 +307,9 @@ std::string UsgsAstroLsSensorModel::getModelState() const {
      state["m_imageFlipFlag"] = m_imageFlipFlag;

      state["m_referencePointXyz"] = json();
      state["m_referencePointXyz"]["x"] = m_referencePointXyz.x;
      state["m_referencePointXyz"]["y"] = m_referencePointXyz.y;
      state["m_referencePointXyz"]["z"] = m_referencePointXyz.z;
      state["m_referencePointXyz"][0] = m_referencePointXyz.x;
      state["m_referencePointXyz"][1] = m_referencePointXyz.y;
      state["m_referencePointXyz"][2] = m_referencePointXyz.z;

      return state.dump();
 }
+2 −2
Original line number Diff line number Diff line
@@ -201,7 +201,7 @@ bool UsgsAstroPlugin::canISDBeConvertedToModelState(const csm::Isd &imageSupport
std::string UsgsAstroPlugin::getStateFromISD(csm::Isd imageSupportData) const {
    std::string stringIsd = loadImageSupportData(imageSupportData);
    json jsonIsd = json::parse(stringIsd);
    return convertISDToModelState(imageSupportData, jsonIsd.at("modelName"));
    return convertISDToModelState(imageSupportData, jsonIsd.at("name_model"));
}


@@ -259,7 +259,7 @@ csm::Model *UsgsAstroPlugin::constructModelFromState(const std::string& modelSta
                                                csm::WarningList *warnings) const {

    json state = json::parse(modelState);
    std::string modelName = state["modelName"];
    std::string modelName = state["m_modelName"];

    if (modelName == UsgsAstroFrameSensorModel::_SENSOR_MODEL_NAME) {
         UsgsAstroFrameSensorModel* model = new UsgsAstroFrameSensorModel();
+2 −4
Original line number Diff line number Diff line
@@ -15,14 +15,12 @@ using json = nlohmann::json;

TEST_F(ConstVelocityLineScanSensorModel, State) {
   std::string modelState = sensorModel->getModelState();
   // EXPECT_NO_THROW(
   //       sensorModel->replaceModelState(modelState)
   // );
   sensorModel->replaceModelState(modelState);

   // When this is different, the output is very hard to parse
   // TODO implement JSON diff for gtest

   // EXPECT_EQ(sensorModel->getModelState(), modelState);
   EXPECT_EQ(sensorModel->getModelState(), modelState);
}

// Fly by tests
+16 −0
Original line number Diff line number Diff line
@@ -82,6 +82,14 @@ TEST_F(FrameIsdTest, Constructible) {
               "USGS_ASTRO_FRAME_SENSOR_MODEL"));
}

TEST_F(FrameIsdTest, ConstructibleFromState) {
   UsgsAstroPlugin testPlugin;
   std::string modelState = testPlugin.getStateFromISD(isd);
   EXPECT_TRUE(testPlugin.canModelBeConstructedFromState(
        "USGS_ASTRO_FRAME_SENSOR_MODEL",
        modelState));
}

TEST_F(FrameIsdTest, NotConstructible) {
   UsgsAstroPlugin testPlugin;
   isd.setFilename("data/constVelocityLineScan.img");
@@ -142,6 +150,14 @@ TEST_F(ConstVelLineScanIsdTest, Constructible) {
               "USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL"));
}

TEST_F(ConstVelLineScanIsdTest, ConstructibleFromState) {
   UsgsAstroPlugin testPlugin;
   std::string modelState = testPlugin.getStateFromISD(isd);
   EXPECT_TRUE(testPlugin.canModelBeConstructedFromState(
         "USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL",
         modelState));
}

TEST_F(ConstVelLineScanIsdTest, NotConstructible) {
   UsgsAstroPlugin testPlugin;
   isd.setFilename("data/simpleFramerISD.img");