Commit 4bff9a5f authored by Antoine Regimbeau's avatar Antoine Regimbeau

TEST: add log

parent e1501ddb
......@@ -50,48 +50,60 @@ VectorImageType::Pointer create_vector_image( int pxl_s , int nb_comp , unsigned
return image;
}
#define dyn_cast( im_base , vect_im ) \
{ \
vect_im = dynamic_cast<otb::VectorImage<float> *>(im_base); \
if( ! vect_im ) \
{ \
std::cout<<"Not the right conversion, cannot retrieve the output"<<std::endl; \
return EXIT_FAILURE ; \
} \
}
int main(int , char * argv[] )
{
std::cout<<"Begin bandMathX Test"<<std::endl;
int return_val = 0;
auto img1 = create_vector_image(5,2,1);
auto img2 = create_vector_image(5,1,2);
VectorImageType::IndexType index;
index.Fill(3); // Center of the images
std::cout<<"Create application"<<std::endl;
auto app = otb::Wrapper::ApplicationRegistry::CreateApplication("BandMathX");
app->AddImageToParameterInputImageList("il", img1);
app->UpdateParameters();
app->AddImageToParameterInputImageList("il", img2);
app->UpdateParameters();
std::cout<<"Inputs are set"<<std::endl;
// Case one: only expression
app->SetParameterString("exp", "im1b1+im2b1");
app->UpdateParameters();
app->SetParameterOutputImagePixelType("out", otb::Wrapper::ImagePixelType::ImagePixelType_uint8);
std::cout<<"Case one: parameter exp is set"<<std::endl;
app->Execute();
auto output = app->GetParameterImageBase("out");
output->Update();
float im_val = 0;
// We need to be carefull as we are taking the direct output of the underlying
// filter in the application
auto output_int = dynamic_cast<otb::VectorImage<float> *>(output);
if( output_int ) // this need to crash if not the case
otb::VectorImage<float> * output_int = nullptr;
dyn_cast( output , output_int )
im_val = output_int->GetPixel(index).GetElement(0);
if ( im_val != 3 )
{
im_val = output_int->GetPixel(index).GetElement(0);
if ( im_val != 3 )
{
std::cout<<"Wrong value in test, was expecting 3, got "<<im_val<<std::endl;
return_val++;
}
std::cout<<"Wrong value in test, was expecting 3, got "<<im_val<<std::endl;
return_val++;
}
else
{
std::cout<<"Not the right conversion, cannot retrieve the output"<<std::endl;
return EXIT_FAILURE;
std::cout<<"Case one passed"<<std::endl;
}
// Case two: expression and context
app->SetParameterString("exp", "im1b1+val-im2b1");
app->UpdateParameters();
std::cout<<"Case two: use context to define a constant"<<std::endl;
auto desc = app->GetParameterDescription("exp");
if (desc.find("Following variables not allowed : val") == std::string::npos)
{
......@@ -119,25 +131,22 @@ int main(int , char * argv[] )
output->Update();
// We need to be carefull as we are taking the direct output of the underlying
// filter in the application
output_int = dynamic_cast<otb::VectorImage<float> *>(output);
if( output_int ) // this need to crash if not the case
dyn_cast( output , output_int )
im_val = output_int->GetPixel(index).GetElement(0);
if ( im_val != 0 )
{
im_val = output_int->GetPixel(index).GetElement(0);
if ( im_val != 0 )
{
std::cout<<"Wrong value in test, was expecting 0, got "<<im_val<<std::endl;
return_val++;
}
std::cout<<"Wrong value in test, was expecting 0, got "<<im_val<<std::endl;
return_val++;
}
else
{
std::cout<<"Not the right conversion, cannot retrieve the output"<<std::endl;
return EXIT_FAILURE;
std::cout<<"Case two passed"<<std::endl;
}
// Case three: no expression and context
app->SetParameterString("exp", "");
app->UpdateParameters();
std::cout<<"Case three: no parameter exp"<<std::endl;
auto exp = app->GetParameterString("exp");
if (exp.find("im1b1 + 2*val + im2b1") == std::string::npos )
{
......@@ -151,20 +160,16 @@ int main(int , char * argv[] )
output->Update();
// We need to be carefull as we are taking the direct output of the underlying
// filter in the application
output_int = dynamic_cast<otb::VectorImage<float> *>(output);
if( output_int ) // this need to crash if not the case
dyn_cast( output , output_int )
im_val = output_int->GetPixel(index).GetElement(0);
if (im_val != 5 )
{
im_val = output_int->GetPixel(index).GetElement(0);
if (im_val != 5 )
{
std::cout<<"Wrong value in test, was expecting 5, got "<<im_val<<std::endl;
return_val++;
}
std::cout<<"Wrong value in test, was expecting 5, got "<<im_val<<std::endl;
return_val++;
}
else
{
std::cout<<"Not the right conversion, cannot retrieve the output"<<std::endl;
return EXIT_FAILURE;
std::cout<<"Case three passed"<<std::endl;
}
return return_val;
}
\ No newline at end of file
Markdown is supported
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