Skip to content
Snippets Groups Projects
Commit 4bff9a5f authored by Antoine Regimbeau's avatar Antoine Regimbeau
Browse files

TEST: add log

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