This file is indexed.

/usr/include/OTB-5.8/otbTestMain.h is in libotb-dev 5.8.0+dfsg-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef otbTestMain_h
#define otbTestMain_h

#include "otbConfigure.h"

#include <map>
#include <string>
#include <iostream>

#include "itkMultiThreader.h"
#include "itkMacro.h"

#include "otbOGRDriversInit.h"
#include "otbTestHelper.h"

#include "itkMersenneTwisterRandomVariateGenerator.h"

#ifdef OTB_USE_MPI
#include "otbMPIConfig.h"
#endif

typedef int (*MainFuncPointer)(int, char*[]);
std::map<std::string, MainFuncPointer> StringToTestFunctionMap;

#define REGISTER_TEST(test) \
  extern int test(int, char*[]); \
  StringToTestFunctionMap[# test] = test

void RegisterTests();
void PrintAvailableTests()
{
  std::cout << "Tests available:\n";
  std::map<std::string, MainFuncPointer>::iterator j = StringToTestFunctionMap.begin();
  int                                              i = 0;
  while (j != StringToTestFunctionMap.end())
    {
    std::cout << i << ". " << j->first << "\n";
    ++i;
    ++j;
    }
}

//apply dedicated treatment to test
void LoadTestEnv()
{
  //Set seed for rand and itk mersenne twister
  srand(1);
  itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance()->SetSeed(121212);
}

int main(int ac, char* av[])
{
  #ifdef OTB_USE_MPI
  otb::MPIConfig::Instance()->Init(ac,av);
  #endif
  
  bool   lFlagRegression(false);
  double lToleranceDiffValue(0);
  double lEpsilon(0);
  bool   lIgnoreOrder(false);
  double epsilonBoundary(0.0);

  typedef otb::TestHelper::StringList   StringList;
  StringList baselineFilenamesBinary;
  StringList testFilenamesBinary;
  StringList baselineFilenamesMetaData;
  StringList testFilenamesMetaData;
  StringList baselineFilenamesOgr;
  StringList testFilenamesOgr;

  StringList baselineFilenamesImage;
  StringList testFilenamesImage;
  StringList baselineFilenamesAscii;
  StringList testFilenamesAscii;
  StringList ignoredLines;
  ignoredLines.clear();

  otb::ogr::Drivers::Init();
  otb::TestHelper::Pointer testHelper = otb::TestHelper::New();

  RegisterTests();

  LoadTestEnv(); // load specific treatments for testing
  std::string testToRun;
  if (ac < 2)
    {
    PrintAvailableTests();
    std::cout << "To launch a test, enter its number: ";
    int testNum = 0;
    std::cin >> testNum;
    std::map<std::string, MainFuncPointer>::iterator j = StringToTestFunctionMap.begin();
    int                                              i = 0;
    while (j != StringToTestFunctionMap.end() && i < testNum)
      {
      ++i;
      ++j;
      }
    if (j == StringToTestFunctionMap.end())
      {
      std::cerr << testNum << " is not a valid test number\n";
      return -1;
      }
    testToRun = j->first;
    }
  else
    {
    if (strcmp(av[1], "--with-threads") == 0)
      {
      int numThreads = atoi(av[2]);
      itk::MultiThreader::SetGlobalDefaultNumberOfThreads(numThreads);
      av += 2;
      ac -= 2;
      }
    else if (strcmp(av[1], "--without-threads") == 0)
      {
      itk::MultiThreader::SetGlobalDefaultNumberOfThreads(1);
      av += 1;
      ac -= 1;
      }
    if (strcmp(av[1], "--ignore-order") == 0)
      {
      lIgnoreOrder = true;
      av += 1;
      ac -= 1;
      }
    if (strcmp(av[1], "--epsilon-boundary") == 0)
      {
      epsilonBoundary = atof(av[2]);
      av += 2;
      ac -= 2;
      }
    if (strcmp(av[1], "--compare-image") == 0)
      {
      lFlagRegression = true;
      lToleranceDiffValue = (double) (::atof(av[2]));
      baselineFilenamesImage.reserve(1);
      testFilenamesImage.reserve(1);
      baselineFilenamesImage.push_back(av[3]);
      testFilenamesImage.push_back(av[4]);
      av += 4;
      ac -= 4;
      }
    else if (strcmp(av[1], "--compare-n-images") == 0)
      {
      lFlagRegression = true;
      lToleranceDiffValue = (double) (::atof(av[2]));
      // Number of comparisons to do
      unsigned int nbComparisons = (unsigned int) (::atoi(av[3]));
      baselineFilenamesImage.reserve(nbComparisons);
      testFilenamesImage.reserve(nbComparisons);
      // Retrieve all the file names
      for (unsigned int i = 0; i < nbComparisons; ++i)
        {
        baselineFilenamesImage.push_back(av[4 + 2 * i]);
        testFilenamesImage.push_back(av[5 + 2 * i]);
        }
      av += 3 + 2 * nbComparisons;
      ac -= 3 + 2 * nbComparisons;
      }
    else if (strcmp(av[1], "--compare-binary") == 0)
      {
      lFlagRegression = true;
      baselineFilenamesBinary.reserve(1);
      testFilenamesBinary.reserve(1);
      baselineFilenamesBinary.push_back(av[2]);
      testFilenamesBinary.push_back(av[3]);
      av += 3;
      ac -= 3;
      }
    else if (strcmp(av[1], "--compare-n-binary") == 0)
      {
      lFlagRegression = true;
      unsigned int nbComparisons = (unsigned int) (::atoi(av[2]));
      baselineFilenamesBinary.reserve(nbComparisons);
      testFilenamesBinary.reserve(nbComparisons);
      // Retrieve all the file names
      for (unsigned int i = 0; i < nbComparisons; ++i)
        {
        baselineFilenamesBinary.push_back(av[3 + 2 * i]);
        testFilenamesBinary.push_back(av[4 + 2 * i]);
        }
      av += 2 + 2 * nbComparisons;
      ac -= 2 + 2 * nbComparisons;
      }
    /************************************************************************/
    // COMPARE ASCII
    else if (strcmp(av[1], "--compare-ascii") == 0)
      {
      lFlagRegression = true;
      lEpsilon = (double) (::atof(av[2]));
      baselineFilenamesAscii.reserve(1);
      testFilenamesAscii.reserve(1);
      baselineFilenamesAscii.push_back(av[3]);
      testFilenamesAscii.push_back(av[4]);
      av += 4;
      ac -= 4;

      if (ac > 1)
        {
        if (strcmp(av[1], "--ignore-lines-with") == 0)
          {
          unsigned int nbIgnoredLines = (unsigned int) (::atoi(av[2]));
          for (unsigned int i = 0; i < nbIgnoredLines; ++i)
            {
            ignoredLines.push_back(av[3 + i]);
            }
          av += 2 + nbIgnoredLines;
          ac -= 2 + nbIgnoredLines;
          }
        }
      }
    /************************************************************************/
    else if (strcmp(av[1], "--compare-n-ascii") == 0)
      {
      lFlagRegression = true;
      lEpsilon = (double) (::atof(av[2]));
      // Number of comparisons to do
      unsigned int nbComparisons = (unsigned int) (::atoi(av[3]));
      baselineFilenamesAscii.reserve(nbComparisons);
      testFilenamesAscii.reserve(nbComparisons);
      // Retrieve all the file names
      for (unsigned int i = 0; i < nbComparisons; ++i)
        {
        baselineFilenamesAscii.push_back(av[4 + 2 * i]);
        testFilenamesAscii.push_back(av[5 + 2 * i]);
        }
      av += 3 + 2 * nbComparisons;
      ac -= 3 + 2 * nbComparisons;

      if (ac > 1)
        {
        if (strcmp(av[1], "--ignore-lines-with") == 0)
          {
          unsigned int nbIgnoredLines = (unsigned int) (::atoi(av[2]));
          for (unsigned int i = 0; i < nbIgnoredLines; ++i)
            {
            ignoredLines.push_back(av[3 + i]);
            }
          av += 2 + nbIgnoredLines;
          ac -= 2 + nbIgnoredLines;
          }
        }

      }
    else if (strcmp(av[1], "--compare-metadata") == 0)
      {
      lFlagRegression = true;
      lToleranceDiffValue = (double) (::atof(av[2]));
      baselineFilenamesMetaData.reserve(1);
      testFilenamesMetaData.reserve(1);
      baselineFilenamesMetaData.push_back(av[3]);
      testFilenamesMetaData.push_back(av[4]);
      av += 4;
      ac -= 4;
      }

    else if (strcmp(av[1], "--compare-ogr") == 0)
      {
      lFlagRegression = true;
      lToleranceDiffValue = (double) (::atof(av[2]));
      baselineFilenamesOgr.reserve(1);
      testFilenamesOgr.reserve(1);
      baselineFilenamesOgr.push_back(av[3]);
      testFilenamesOgr.push_back(av[4]);
      av += 4;
      ac -= 4;
      }
    testToRun = av[1];
    }

  std::map<std::string, MainFuncPointer>::iterator j = StringToTestFunctionMap.find(testToRun);
  // If the test doesn't exists
  if ( j == StringToTestFunctionMap.end() )
      {
        PrintAvailableTests();
        std::cerr << "Failure: " << testToRun << ": no test identified " << testToRun << "\n";
        return -1;
      }
  else
    {
    MainFuncPointer f = j->second;
    int             result;
    try
      {
      // Invoke the test's "main" function.
      result = (*f)(ac - 1, av + 1);
      if (result != EXIT_SUCCESS )
        {
        std::cout << "-> Test EXIT FAILURE (" << result << ")." << std::endl;
        itkGenericExceptionMacro(<< "Function returns EXIT_FAILURE (not from regression, failure inside the test)");
        }
      }
    catch (itk::ExceptionObject& e)
      {
      std::cerr << "otbTestMain '" << testToRun << "': ITK Exception thrown:" << std::endl;
      std::cerr << e.GetFile() << ":" << e.GetLine() << ":" << std::endl;
      std::cerr << e.GetDescription() << std::endl;
      result = EXIT_FAILURE;
      }
    catch (std::bad_alloc& err)
      {
      std::cerr << "otbTestMain '" << testToRun << "': Exception bad_alloc thrown: " << std::endl;
      std::cerr << (char*) err.what() << std::endl;
      result = EXIT_FAILURE;
      }
    catch (const std::exception& e)
      {
      std::cerr << "otbTestMain '" << testToRun << "': std::exception  thrown:" << std::endl;
      std::cerr << e.what() <<  std::endl;
      result = EXIT_FAILURE;
      }
    catch (...)
      {
      std::cerr << "otbTestMain '" << testToRun << "': Unknown exception thrown !" << std::endl;
      result = EXIT_FAILURE;
      }

    if (result != EXIT_SUCCESS )
      {
        return -1;
      }


    result = EXIT_SUCCESS;
#ifdef OTB_USE_MPI
    otb::MPIConfig::Pointer mpiConfig = otb::MPIConfig::Instance();
    if (mpiConfig->GetMyRank() == 0)
    {
#endif
    std::cout << " -> Test EXIT SUCCESS." << std::endl;
    if (lFlagRegression == false)
      {
      std::cout << "-------------  No control baseline tests    -------------" << std::endl;
      return result;
      }

    try
      {
      std::cout << "-------------  Start control baseline tests    -------------" << std::endl;
      // Make a list of possible baselines

      testHelper->SetIgnoreLineOrder(lIgnoreOrder);
      testHelper->SetToleranceDiffValue(lToleranceDiffValue); // What's the difference
      testHelper->SetEpsilon(lEpsilon); // maybe we should consolidate...
      if (epsilonBoundary != 0.0)
        {
        testHelper->SetEpsilonBoundaryChecking(epsilonBoundary);
        }
      /***********************************************************************************/
      // Non regression test for images
      if ((baselineFilenamesImage.size() > 0) && (testFilenamesImage.size() > 0))
        {
        result += testHelper->RegressionTestAllImages(baselineFilenamesImage, testFilenamesImage);
        }
      /***********************************************************************************/
      // Non-regression test for metadata.
      if ((baselineFilenamesMetaData.size() > 0) && (testFilenamesMetaData.size() > 0))
        {
        result += testHelper->RegressionTestAllMetaData(baselineFilenamesMetaData, testFilenamesMetaData);
        }

      /***********************************************************************************/
      // Non regression test for ascii files
      if ((baselineFilenamesAscii.size() > 0) && (testFilenamesAscii.size() > 0))
        {
        //result += testHelper->RegressionTestAllAscii(baselineFilenamesAscii, testFilenamesAscii, ignoredLines);
        result += testHelper->RegressionTestAllDiff(baselineFilenamesAscii, testFilenamesAscii, ignoredLines);
        }
      /******************************************************************************/
      // Non regression test for binary files
      if ((baselineFilenamesBinary.size() > 0) && (testFilenamesBinary.size() > 0))
        {
        result += testHelper->RegressionTestAllBinary(baselineFilenamesBinary, testFilenamesBinary);
        }
      /******************************************************************************/
      // Non regression test for OGR files
      if ((baselineFilenamesOgr.size() > 0) && (testFilenamesOgr.size() > 0))
        {
        result += testHelper->RegressionTestAllOgr(baselineFilenamesOgr, testFilenamesOgr);
        }

      }
    catch (itk::ExceptionObject& e)
      {
      std::cerr << "otbTestMain 'control baseline test': ITK Exception thrown:" << std::endl;
      std::cerr << e.GetFile() << ":" << e.GetLine() << ":" << std::endl;
      std::cerr << e.GetDescription() << std::endl;
      return -1;
      }
    catch (std::bad_alloc& err)
      {
      std::cerr << "otbTestMain 'control baseline test': Exception bad_alloc thrown: " << std::endl;
      std::cerr << (char*) err.what() << std::endl;
      return -1;
      }
    catch (const std::exception& e)
      {
      std::cerr << "otbTestMain 'control baseline test': std::exception  thrown:" << std::endl;
      std::cerr << e.what() <<  std::endl;
      return -1;
      }
    catch (...)
      {
      std::cerr << "otbTestMain 'control baseline test': Unknown exception thrown !" << std::endl;
      return -1;
      }
    std::cout << "-------------  End control baseline tests    -------------" << std::endl;

#ifdef OTB_USE_MPI
    }
#endif
    return result;
    }
}

#endif