From e11ac5e0804e2d4bfd55a76962ec4a45826e6bef Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Sun, 16 Jan 2011 10:53:51 -0800
Subject: [PATCH] TEST: add tests for parsing methods

---
 Testing/Code/Common/CMakeLists.txt      |  6 +++
 Testing/Code/Common/otbCommonTests1.cxx |  2 +
 Testing/Code/Common/otbSystemTest.cxx   | 53 +++++++++++++++++++++++++
 3 files changed, 61 insertions(+)

diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt
index fa43d270a4..36963efb75 100644
--- a/Testing/Code/Common/CMakeLists.txt
+++ b/Testing/Code/Common/CMakeLists.txt
@@ -46,6 +46,12 @@ ADD_TEST(coTuSystemTests_IsA_Methods ${COMMON_TESTS1}
         ${OTB_DATA_ROOT}
         )
 
+ADD_TEST(coTvParseHdfSubsetName ${COMMON_TESTS1}
+        otbParseHdfSubsetName)
+
+ADD_TEST(coTvParseHdfFileName ${COMMON_TESTS1}
+        otbParseHdfFileName)
+
 # -------            otb::Configuration  -------------
 ADD_TEST(coTuConfigurationTest ${COMMON_TESTS1}
         otbConfigurationTest
diff --git a/Testing/Code/Common/otbCommonTests1.cxx b/Testing/Code/Common/otbCommonTests1.cxx
index 9c8493e114..3a7576548f 100644
--- a/Testing/Code/Common/otbCommonTests1.cxx
+++ b/Testing/Code/Common/otbCommonTests1.cxx
@@ -33,4 +33,6 @@ void RegisterTests()
   REGISTER_TEST(otbTestCommandLineArgumentParserHelp);
   REGISTER_TEST(otbTestCommandLineArgumentParserList);
   REGISTER_TEST(otbTestCommandLineArgumentParserWithError);
+  REGISTER_TEST(otbParseHdfSubsetName);
+  REGISTER_TEST(otbParseHdfFileName);
 }
diff --git a/Testing/Code/Common/otbSystemTest.cxx b/Testing/Code/Common/otbSystemTest.cxx
index 349cd41364..1a652b6292 100644
--- a/Testing/Code/Common/otbSystemTest.cxx
+++ b/Testing/Code/Common/otbSystemTest.cxx
@@ -58,3 +58,56 @@ int otbSystemTest(int argc, char* argv[])
 
   return EXIT_SUCCESS;
 }
+
+
+int otbParseHdfSubsetName(int argc, char* argv [])
+{
+  std::string input("");
+  std::string key("");
+  std::string name("");
+
+  input = "SUBDATASET_7_NAME=HDF4_EOS:EOS_GRID:\"file/MOD13Q1.A2010001.h17v05.005.2010028003734.hdf\":MODIS_Grid_16DAY";
+  if ( !otb::System::ParseHdfSubsetName(input, key, name) ) return EXIT_FAILURE;
+  if (key.compare("SUBDATASET_7_NAME") != 0) return EXIT_FAILURE;
+  if (name.compare("HDF4_EOS:EOS_GRID:\"file/MOD13Q1.A2010001.h17v05.005.2010028003734.hdf\":MODIS_Grid_16DAY") != 0)
+    return EXIT_FAILURE;
+
+  input = "invalid";
+  if ( otb::System::ParseHdfSubsetName(input, key, name) ) return EXIT_FAILURE;
+
+  return EXIT_SUCCESS;
+}
+
+int otbParseHdfFileName(int argc, char* argv [])
+{
+  std::string id("");
+  std::string file("");
+  unsigned int num(0);
+
+  // Standard cases
+  id = "/some/file.hdf:6";
+  if ( !otb::System::ParseHdfFileName(id, file, num) ) return EXIT_FAILURE;
+  if (file.compare("/some/file.hdf") != 0) return EXIT_FAILURE;
+  if ( num != 6 ) return EXIT_FAILURE;
+
+  id = "/some/file.hdf:0";
+  if ( !otb::System::ParseHdfFileName(id, file, num) ) return EXIT_FAILURE;
+  if (file.compare("/some/file.hdf") != 0) return EXIT_FAILURE;
+  if ( num != 0 ) return EXIT_FAILURE;
+
+  // non specified
+  id = "/some/file.hdf";
+  if ( otb::System::ParseHdfFileName(id, file, num) ) return EXIT_FAILURE;
+
+  // playing with windows format
+  id = "C:\\some\\file.hdf";
+  if ( otb::System::ParseHdfFileName(id, file, num) ) return EXIT_FAILURE;
+  if (num != 0) return EXIT_FAILURE;
+
+  id = "C:\\some\\file.hdf:6";
+  if ( !otb::System::ParseHdfFileName(id, file, num) ) return EXIT_FAILURE;
+  if (file.compare("C:\\some\\file.hdf") != 0) return EXIT_FAILURE;
+  if ( num != 6 ) return EXIT_FAILURE;
+
+  return EXIT_SUCCESS;
+}
-- 
GitLab