Commit 6d331383 authored by Jesse Mapel's avatar Jesse Mapel Committed by Summer Stapleton
Browse files

Added tests to check that the framer logs (#227)

* Added logger mutator for testing

* Added basic logging testing

* Added tests that all RasterGM methods log

* Added two more logging tests

* Made private framer methods public for testing

* Fixed segfault if null warning passed to isValidModelState

* Added tests for new public methods
parent 0a954716
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -324,6 +324,16 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, virtual public csm::Sett
        csm::param::Set pSet = csm::param::VALID,
        const GeometricModelList &otherModels = GeometricModelList()) const;
    virtual std::shared_ptr<spdlog::logger> getLogger();
    virtual void setLogger(std::shared_ptr<spdlog::logger> logger);
    double getValue(int index, const std::vector<double> &adjustments) const;
    void calcRotationMatrix(double m[3][3]) const;
    void calcRotationMatrix(double m[3][3], const std::vector<double> &adjustments) const;

    void losEllipsoidIntersect (double height,double xc,
                                double yc, double zc,
                                double xl, double yl,
                                double zl,
                                double& x,double& y, double&  z) const;

    static const std::string _SENSOR_MODEL_NAME;

@@ -385,16 +395,6 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, virtual public csm::Sett

    csm::NoCorrelationModel _no_corr_model;

    double getValue(int index,const std::vector<double> &adjustments) const;
    void calcRotationMatrix(double m[3][3]) const;
    void calcRotationMatrix(double m[3][3], const std::vector<double> &adjustments) const;

    void losEllipsoidIntersect (double height,double xc,
                                double yc, double zc,
                                double xl, double yl,
                                double zl,
                                double& x,double& y, double&  z) const;

};

#endif
+18 −2
Original line number Diff line number Diff line
@@ -773,7 +773,7 @@ bool UsgsAstroFrameSensorModel::isValidModelState(const std::string& stringState
    }
  }

  if (!missingKeywords.empty()) {
  if (!missingKeywords.empty() && warnings) {
    std::ostringstream oss;
    std::copy(missingKeywords.begin(), missingKeywords.end(), std::ostream_iterator<std::string>(oss, " "));
    warnings->push_back(csm::Warning(
@@ -785,7 +785,7 @@ bool UsgsAstroFrameSensorModel::isValidModelState(const std::string& stringState

  std::string modelName = jsonState.value<std::string>("m_modelName", "");

  if (modelName != _SENSOR_MODEL_NAME) {
  if (modelName != _SENSOR_MODEL_NAME && warnings) {
    warnings->push_back(csm::Warning(
      csm::Warning::DATA_NOT_AVAILABLE,
      "Incorrect model name in state, expected " + _SENSOR_MODEL_NAME + " but got " + modelName,
@@ -1071,6 +1071,8 @@ bool UsgsAstroFrameSensorModel::isParameterShareable(int index) const {


csm::SharingCriteria UsgsAstroFrameSensorModel::getParameterSharingCriteria(int index) const {
   MESSAGE_LOG(this->m_logger, "Checking sharing criteria for parameter {}. "
               "Sharing is not supported, throwing exception", index);
   // Parameter sharing is not supported for this sensor,
   // all indices are out of range
   throw csm::Error(
@@ -1127,6 +1129,9 @@ int UsgsAstroFrameSensorModel::getNumGeometricCorrectionSwitches() const {


std::string UsgsAstroFrameSensorModel::getGeometricCorrectionName(int index) const {
   MESSAGE_LOG(this->m_logger, "Accessing name of geometric correction switch {}. "
               "Geometric correction switches are not supported, throwing exception",
               index);
   // Since there are no geometric corrections, all indices are out of range
   throw csm::Error(
      csm::Error::INDEX_OUT_OF_RANGE,
@@ -1138,6 +1143,10 @@ std::string UsgsAstroFrameSensorModel::getGeometricCorrectionName(int index) con
void UsgsAstroFrameSensorModel::setGeometricCorrectionSwitch(int index,
                                                      bool value,
                                                      csm::param::Type pType) {
   MESSAGE_LOG(this->m_logger, "Setting geometric correction switch {} to {} "
               "with parameter type {}. "
               "Geometric correction switches are not supported, throwing exception",
               index, value, pType);
   // Since there are no geometric corrections, all indices are out of range
   throw csm::Error(
      csm::Error::INDEX_OUT_OF_RANGE,
@@ -1147,6 +1156,9 @@ void UsgsAstroFrameSensorModel::setGeometricCorrectionSwitch(int index,


bool UsgsAstroFrameSensorModel::getGeometricCorrectionSwitch(int index) const {
   MESSAGE_LOG(this->m_logger, "Accessing value of geometric correction switch {}. "
               "Geometric correction switches are not supported, throwing exception",
               index);
   // Since there are no geometric corrections, all indices are out of range
   throw csm::Error(
      csm::Error::INDEX_OUT_OF_RANGE,
@@ -1298,3 +1310,7 @@ double UsgsAstroFrameSensorModel::getValue(
std::shared_ptr<spdlog::logger> UsgsAstroFrameSensorModel::getLogger() {
  return m_logger;
}

void UsgsAstroFrameSensorModel::setLogger(std::shared_ptr<spdlog::logger> logger) {
  m_logger = logger;
}
+40 −0
Original line number Diff line number Diff line
@@ -9,10 +9,13 @@

#include <map>
#include <sstream>
#include <string>
#include <fstream>

#include <gtest/gtest.h>

#include <spdlog/sinks/ostream_sink.h>

using json = nlohmann::json;

// Should this be positioned somewhere in the public API?
@@ -62,6 +65,43 @@ class FrameSensorModel : public ::testing::Test {
      }
};

class FrameSensorModelLogging : public ::testing::Test {
   protected:
      csm::Isd isd;
      UsgsAstroFrameSensorModel *sensorModel;
      std::ostringstream oss;

      void SetUp() override {
         sensorModel = NULL;

         isd.setFilename("data/simpleFramerISD.img");
         UsgsAstroPlugin frameCameraPlugin;

         csm::Model *model = frameCameraPlugin.constructModelFromISD(
               isd,
               "USGS_ASTRO_FRAME_SENSOR_MODEL");
         sensorModel = dynamic_cast<UsgsAstroFrameSensorModel *>(model);

         ASSERT_NE(sensorModel, nullptr);

         auto ostream_sink = std::make_shared<spdlog::sinks::ostream_sink_mt> (oss);
         // We need a unique ID for the sensor model so that we don't have
         // logger name collisions. Use the sensor model's memory addresss.
         std::uintptr_t sensorId = reinterpret_cast<std::uintptr_t>(sensorModel);
         auto logger = std::make_shared<spdlog::logger>(std::to_string(sensorId), ostream_sink);
         sensorModel->setLogger(logger);
      }

      void TearDown() override {
         if (sensorModel) {
            delete sensorModel;
            sensorModel = NULL;
         }

         EXPECT_FALSE(oss.str().empty());
      }
};

class OrbitalFrameSensorModel : public ::testing::Test {
   protected:
      csm::Isd isd;
+435 −94

File changed.

Preview size limit exceeded, changes collapsed.