From c735a4b1ef3d8cf66b623f849690cab717284272 Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Wed, 30 Sep 2009 08:46:25 +0800
Subject: [PATCH] TEST: add test checking the validity of the test system

---
 Testing/Code/TestSystem/CMakeLists.txt        | 37 ++++++++++++++
 .../Code/TestSystem/otbCompareAsciiTests3.cxx | 51 +++++++++++++++++++
 .../Code/TestSystem/otbTestSystemTests.cxx    |  1 +
 3 files changed, 89 insertions(+)
 create mode 100644 Testing/Code/TestSystem/otbCompareAsciiTests3.cxx

diff --git a/Testing/Code/TestSystem/CMakeLists.txt b/Testing/Code/TestSystem/CMakeLists.txt
index 406b041749..4338dab83a 100644
--- a/Testing/Code/TestSystem/CMakeLists.txt
+++ b/Testing/Code/TestSystem/CMakeLists.txt
@@ -19,6 +19,7 @@ SET(EPS 0.001)
 
 SET(TESTSYSTEM_TESTS ${CXX_TEST_PATH}/otbTestSystemTests)
 
+#Test a basic ascii comparison
 ADD_TEST(tsTvCompareAscii ${TESTSYSTEM_TESTS}
    --compare-ascii ${NOTOL}
        ${TEMP}/tsTvCompareAsciiRef.txt
@@ -28,6 +29,7 @@ ADD_TEST(tsTvCompareAscii ${TESTSYSTEM_TESTS}
        ${TEMP}/tsTvCompareAsciiTest.txt
   )
 
+#make sure that it fails when it has to.. (baseline shorter than test)
 ADD_TEST(tsTvCompareAscii2 ${TESTSYSTEM_TESTS}
    --compare-ascii ${NOTOL}
        ${TEMP}/tsTvCompareAsciiRef2.txt
@@ -39,11 +41,46 @@ ADD_TEST(tsTvCompareAscii2 ${TESTSYSTEM_TESTS}
 
 SET_TESTS_PROPERTIES(tsTvCompareAscii2 PROPERTIES WILL_FAIL true)
 
+#with reverse order (test shorter than baseline)
+ADD_TEST(tsTvCompareAscii2reverse ${TESTSYSTEM_TESTS}
+   --compare-ascii ${NOTOL}
+       ${TEMP}/tsTvCompareAsciiRef2reverse.txt
+       ${TEMP}/tsTvCompareAsciiTest2reverse.txt
+     otbCompareAsciiTests2
+       ${TEMP}/tsTvCompareAsciiTest2reverse.txt
+       ${TEMP}/tsTvCompareAsciiRef2reverse.txt
+  )
+
+SET_TESTS_PROPERTIES(tsTvCompareAscii2reverse PROPERTIES WILL_FAIL true)
+
+#ignoring the line order
+ADD_TEST(tsTvCompareAscii3 ${TESTSYSTEM_TESTS}
+   --ignore-order --compare-ascii ${NOTOL}
+       ${TEMP}/tsTvCompareAsciiRef3.txt
+       ${TEMP}/tsTvCompareAsciiTest3.txt
+     otbCompareAsciiTests3
+       ${TEMP}/tsTvCompareAsciiRef3.txt
+       ${TEMP}/tsTvCompareAsciiTest3.txt
+  )
+
+#fails if the line order is not ignored
+ADD_TEST(tsTvCompareAscii3order ${TESTSYSTEM_TESTS}
+   --compare-ascii ${NOTOL}
+       ${TEMP}/tsTvCompareAsciiRef3order.txt
+       ${TEMP}/tsTvCompareAsciiTest3order.txt
+     otbCompareAsciiTests3
+       ${TEMP}/tsTvCompareAsciiRef3order.txt
+       ${TEMP}/tsTvCompareAsciiTest3order.txt
+  )
+
+SET_TESTS_PROPERTIES(tsTvCompareAscii3order PROPERTIES WILL_FAIL true)
+
 # -------       CXX source files -----------------------------------
 SET(TESTSYSTEM_SRCS
 otbTestSystemTests.cxx
 otbCompareAsciiTests.cxx
 otbCompareAsciiTests2.cxx
+otbCompareAsciiTests3.cxx
 )
 
 INCLUDE_DIRECTORIES(${OTB_SOURCE_DIR}/Testing/Code)
diff --git a/Testing/Code/TestSystem/otbCompareAsciiTests3.cxx b/Testing/Code/TestSystem/otbCompareAsciiTests3.cxx
new file mode 100644
index 0000000000..441eddbc28
--- /dev/null
+++ b/Testing/Code/TestSystem/otbCompareAsciiTests3.cxx
@@ -0,0 +1,51 @@
+/*=========================================================================
+
+  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.
+
+=========================================================================*/
+#include <iostream>
+#include <fstream>
+
+#include "itkExceptionObject.h"
+#include "otbMacro.h"
+
+int otbCompareAsciiTests3(int argc, char * argv[])
+{
+  if ( argc != 3 )
+  {
+    std::cerr << "Usage: " << argv[0];
+    std::cerr << " referenceFile testFile" << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  std::ofstream fileRef;
+  fileRef.open(argv[1]);
+  fileRef << "1\n";
+  fileRef << "2\n";
+  fileRef << "3\n";
+  fileRef << "2\n";
+  fileRef.close();
+
+
+  std::ofstream fileTest;
+  fileTest.open(argv[2]);
+  fileTest << "2\n";
+  fileTest << "2\n";
+  fileTest << "3\n";
+  fileTest << "1\n";
+  fileTest.close();
+
+  return EXIT_SUCCESS;
+}
diff --git a/Testing/Code/TestSystem/otbTestSystemTests.cxx b/Testing/Code/TestSystem/otbTestSystemTests.cxx
index 655f0f265d..e5bfdd0c30 100644
--- a/Testing/Code/TestSystem/otbTestSystemTests.cxx
+++ b/Testing/Code/TestSystem/otbTestSystemTests.cxx
@@ -28,4 +28,5 @@ void RegisterTests()
 {
   REGISTER_TEST(otbCompareAsciiTests);
   REGISTER_TEST(otbCompareAsciiTests2);
+  REGISTER_TEST(otbCompareAsciiTests3);
 }
-- 
GitLab