Commit 1f125c6c authored by Julien Osman's avatar Julien Osman
Browse files

Merge branch '2288-python_segfault' into 'develop'

Fix Segfault when reaching output image informations before calling Execute()

Closes #2288

See merge request !932
parents 95a5b5e1 34a0fdbb
Pipeline #11566 passed with stage
in 23 minutes and 33 seconds
......@@ -1703,6 +1703,10 @@ ImageBaseType* Application::GetParameterImageBase(const std::string& key, unsign
}
else if (dynamic_cast<OutputImageParameter*>(param))
{
if (!m_ExecuteDone)
itkExceptionMacro(
"Call Execute() or ExecuteAndWriteOutput() before "
"trying to reach output image information.");
OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*>(param);
return paramDown->GetValue();
}
......
......@@ -116,6 +116,12 @@ otb_add_test(NAME owTvOutputImageParameter COMMAND otbApplicationEngineTestDrive
"my description"
)
otb_add_test(NAME owTvOutputImageParameter2 COMMAND otbApplicationEngineTestDriver
otbWrapperOutputImageParameterTest2
${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif
$<TARGET_FILE_DIR:otbapp_BandMath>
)
#~ otb_add_test(NAME owTvOutputImageParameterConversion COMMAND otbApplicationEngineTestDriver
#~ otbWrapperOutputImageParameterConversionTest
#~ ${INPUTDATA}/poupees.tif
......
......@@ -38,6 +38,7 @@ void RegisterTests()
REGISTER_TEST(otbWrapperInputVectorDataListParameterTest1);
REGISTER_TEST(otbWrapperApplicationDocTest);
REGISTER_TEST(otbWrapperOutputImageParameterTest1);
REGISTER_TEST(otbWrapperOutputImageParameterTest2);
//~ REGISTER_TEST(otbWrapperOutputImageParameterConversionTest);
REGISTER_TEST(otbApplicationMemoryConnectTest);
REGISTER_TEST(otbWrapperImageInterface);
......
......@@ -26,6 +26,9 @@
#include "otbWrapperInputImageParameter.h"
#include "otbImageFileReader.h"
#include "otbWrapperTypes.h"
#include "otbWrapperApplicationRegistry.h"
#include "itkExceptionObject.h"
#include <boost/test/unit_test.hpp>
#include <vector>
......@@ -55,6 +58,34 @@ int otbWrapperOutputImageParameterTest1(int itkNotUsed(argc), char* argv[])
}
int otbWrapperOutputImageParameterTest2(int argc, char* argv[])
{
if (argc != 3)
{
std::cout << "Usage: otbWrapperOutputImageParameterTest2 TestImage PathToBandMathApp\n";
return EXIT_FAILURE;
}
otb::Wrapper::ApplicationRegistry::SetApplicationPath(argv[2]);
auto app = otb::Wrapper::ApplicationRegistry::CreateApplication("BandMath");
app->SetParameterStringList("il", {argv[1]});
otb::Wrapper::ImageBaseType::RegionType region;
const otb::ImageMetadata imd;
// The following instructions should raise an exception
BOOST_CHECK_THROW (app->GetImageOrigin("out"), itk::ExceptionObject);
BOOST_CHECK_THROW (app->GetImageSpacing("out"), itk::ExceptionObject);
BOOST_CHECK_THROW (app->GetImageSize("out"), itk::ExceptionObject);
BOOST_CHECK_THROW (app->GetImageNbBands("out"), itk::ExceptionObject);
BOOST_CHECK_THROW (app->PropagateRequestedRegion("out", region), itk::ExceptionObject);
BOOST_CHECK_THROW (app->GetImageRequestedRegion("out"), itk::ExceptionObject);
BOOST_CHECK_THROW (app->SetImageMetadata(imd, "out"), itk::ExceptionObject);
BOOST_CHECK_THROW (app->GetMetadataDictionary("out"), itk::ExceptionObject);
BOOST_CHECK_THROW (app->GetImageBasePixelType("out"), itk::ExceptionObject);
return EXIT_SUCCESS;
}
// template < typename ImageType >
// void Cross( int p , std::string inputfilename, std::string outputfilename)
// {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment