Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -324,6 +324,16 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, virtual public csm::Sett ...@@ -324,6 +324,16 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, virtual public csm::Sett
csm::param::Set pSet = csm::param::VALID, csm::param::Set pSet = csm::param::VALID,
const GeometricModelList &otherModels = GeometricModelList()) const; const GeometricModelList &otherModels = GeometricModelList()) const;
virtual std::shared_ptr<spdlog::logger> getLogger(); 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; static const std::string _SENSOR_MODEL_NAME;
...@@ -385,16 +395,6 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, virtual public csm::Sett ...@@ -385,16 +395,6 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, virtual public csm::Sett
csm::NoCorrelationModel _no_corr_model; 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 #endif
...@@ -773,7 +773,7 @@ bool UsgsAstroFrameSensorModel::isValidModelState(const std::string& stringState ...@@ -773,7 +773,7 @@ bool UsgsAstroFrameSensorModel::isValidModelState(const std::string& stringState
} }
} }
if (!missingKeywords.empty()) { if (!missingKeywords.empty() && warnings) {
std::ostringstream oss; std::ostringstream oss;
std::copy(missingKeywords.begin(), missingKeywords.end(), std::ostream_iterator<std::string>(oss, " ")); std::copy(missingKeywords.begin(), missingKeywords.end(), std::ostream_iterator<std::string>(oss, " "));
warnings->push_back(csm::Warning( warnings->push_back(csm::Warning(
...@@ -785,7 +785,7 @@ bool UsgsAstroFrameSensorModel::isValidModelState(const std::string& stringState ...@@ -785,7 +785,7 @@ bool UsgsAstroFrameSensorModel::isValidModelState(const std::string& stringState
std::string modelName = jsonState.value<std::string>("m_modelName", ""); 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( warnings->push_back(csm::Warning(
csm::Warning::DATA_NOT_AVAILABLE, csm::Warning::DATA_NOT_AVAILABLE,
"Incorrect model name in state, expected " + _SENSOR_MODEL_NAME + " but got " + modelName, "Incorrect model name in state, expected " + _SENSOR_MODEL_NAME + " but got " + modelName,
...@@ -1071,6 +1071,8 @@ bool UsgsAstroFrameSensorModel::isParameterShareable(int index) const { ...@@ -1071,6 +1071,8 @@ bool UsgsAstroFrameSensorModel::isParameterShareable(int index) const {
csm::SharingCriteria UsgsAstroFrameSensorModel::getParameterSharingCriteria(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, // Parameter sharing is not supported for this sensor,
// all indices are out of range // all indices are out of range
throw csm::Error( throw csm::Error(
...@@ -1127,6 +1129,9 @@ int UsgsAstroFrameSensorModel::getNumGeometricCorrectionSwitches() const { ...@@ -1127,6 +1129,9 @@ int UsgsAstroFrameSensorModel::getNumGeometricCorrectionSwitches() const {
std::string UsgsAstroFrameSensorModel::getGeometricCorrectionName(int index) 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 // Since there are no geometric corrections, all indices are out of range
throw csm::Error( throw csm::Error(
csm::Error::INDEX_OUT_OF_RANGE, csm::Error::INDEX_OUT_OF_RANGE,
...@@ -1138,6 +1143,10 @@ std::string UsgsAstroFrameSensorModel::getGeometricCorrectionName(int index) con ...@@ -1138,6 +1143,10 @@ std::string UsgsAstroFrameSensorModel::getGeometricCorrectionName(int index) con
void UsgsAstroFrameSensorModel::setGeometricCorrectionSwitch(int index, void UsgsAstroFrameSensorModel::setGeometricCorrectionSwitch(int index,
bool value, bool value,
csm::param::Type pType) { 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 // Since there are no geometric corrections, all indices are out of range
throw csm::Error( throw csm::Error(
csm::Error::INDEX_OUT_OF_RANGE, csm::Error::INDEX_OUT_OF_RANGE,
...@@ -1147,6 +1156,9 @@ void UsgsAstroFrameSensorModel::setGeometricCorrectionSwitch(int index, ...@@ -1147,6 +1156,9 @@ void UsgsAstroFrameSensorModel::setGeometricCorrectionSwitch(int index,
bool UsgsAstroFrameSensorModel::getGeometricCorrectionSwitch(int index) const { 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 // Since there are no geometric corrections, all indices are out of range
throw csm::Error( throw csm::Error(
csm::Error::INDEX_OUT_OF_RANGE, csm::Error::INDEX_OUT_OF_RANGE,
...@@ -1298,3 +1310,7 @@ double UsgsAstroFrameSensorModel::getValue( ...@@ -1298,3 +1310,7 @@ double UsgsAstroFrameSensorModel::getValue(
std::shared_ptr<spdlog::logger> UsgsAstroFrameSensorModel::getLogger() { std::shared_ptr<spdlog::logger> UsgsAstroFrameSensorModel::getLogger() {
return m_logger; return m_logger;
} }
void UsgsAstroFrameSensorModel::setLogger(std::shared_ptr<spdlog::logger> logger) {
m_logger = logger;
}
...@@ -9,10 +9,13 @@ ...@@ -9,10 +9,13 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
#include <string>
#include <fstream> #include <fstream>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <spdlog/sinks/ostream_sink.h>
using json = nlohmann::json; using json = nlohmann::json;
// Should this be positioned somewhere in the public API? // Should this be positioned somewhere in the public API?
...@@ -62,6 +65,43 @@ class FrameSensorModel : public ::testing::Test { ...@@ -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 { class OrbitalFrameSensorModel : public ::testing::Test {
protected: protected:
csm::Isd isd; csm::Isd isd;
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment