From 7079a414ded88052f4e27d9c2d4c3247825a814e Mon Sep 17 00:00:00 2001 From: Jesse Mapel <jam826@nau.edu> Date: Tue, 19 Feb 2019 17:01:04 -0700 Subject: [PATCH] Fixed state being written out and read in differently (#183) * Fixed state being written out and read in differently * Fixed canModelBeConstructedFromState --- src/UsgsAstroLsSensorModel.cpp | 7 ++++--- src/UsgsAstroPlugin.cpp | 4 ++-- tests/LineScanCameraTests.cpp | 6 ++---- tests/PluginTests.cpp | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/UsgsAstroLsSensorModel.cpp b/src/UsgsAstroLsSensorModel.cpp index 3dd49a9..e65e58d 100644 --- a/src/UsgsAstroLsSensorModel.cpp +++ b/src/UsgsAstroLsSensorModel.cpp @@ -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(); } diff --git a/src/UsgsAstroPlugin.cpp b/src/UsgsAstroPlugin.cpp index ed97710..d731f6c 100644 --- a/src/UsgsAstroPlugin.cpp +++ b/src/UsgsAstroPlugin.cpp @@ -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(); diff --git a/tests/LineScanCameraTests.cpp b/tests/LineScanCameraTests.cpp index 025df5c..84a813b 100644 --- a/tests/LineScanCameraTests.cpp +++ b/tests/LineScanCameraTests.cpp @@ -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 diff --git a/tests/PluginTests.cpp b/tests/PluginTests.cpp index f805a8c..795201a 100644 --- a/tests/PluginTests.cpp +++ b/tests/PluginTests.cpp @@ -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"); -- GitLab