From 7fb3d6ff0f22176c689778d283cc7d159a61ba6d Mon Sep 17 00:00:00 2001
From: Nick Draper <nick.draper@stfc.ac.uk>
Date: Wed, 5 Nov 2014 12:57:41 +0000
Subject: [PATCH] re #10489_instrument_directories

---
 Code/Mantid/Framework/Kernel/CMakeLists.txt   |  2 +-
 .../Framework/Kernel/src/ConfigService.cpp    |  5 +++
 .../Framework/Kernel/test/ConfigServiceTest.h | 40 +++++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/Code/Mantid/Framework/Kernel/CMakeLists.txt b/Code/Mantid/Framework/Kernel/CMakeLists.txt
index 2a662b61e67..eb69cdb6b0b 100644
--- a/Code/Mantid/Framework/Kernel/CMakeLists.txt
+++ b/Code/Mantid/Framework/Kernel/CMakeLists.txt
@@ -364,7 +364,7 @@ set_property ( TARGET Kernel PROPERTY FOLDER "MantidFramework" )
 
 target_link_libraries ( Kernel ${MANTIDLIBS} ${GSL_LIBRARIES} ${NEXUS_LIBRARIES} )
 if ( WIN32 )
-  target_link_libraries ( Kernel Psapi.lib shell32.lib ) # For memory usage queries
+  target_link_libraries ( Kernel Psapi.lib ) # For memory usage queries
 endif()
 
 # Add the unit tests directory
diff --git a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
index 4674ee60ce0..6a61bf6c4d1 100644
--- a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
+++ b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
@@ -1607,6 +1607,11 @@ bool ConfigServiceImpl::addDirectoryifExists(const std::string& directoryName, s
     }
   }
   catch (Poco::PathNotFoundException&)
+  {
+    g_log.information("Unable to locate directory at: " + directoryName);
+    return false;
+  }   
+  catch (Poco::FileNotFoundException&)
   {
     g_log.information("Unable to locate directory at: " + directoryName);
     return false;
diff --git a/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h b/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h
index 5af09a06f00..541e926c14c 100644
--- a/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h
+++ b/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h
@@ -187,6 +187,46 @@ public:
     TS_ASSERT_LESS_THAN(0, ConfigService::Instance().getCurrentDir().length()); //check that the string is not empty
 //        TS_ASSERT_LESS_THAN(0, ConfigService::Instance().getHomeDir().length()); //check that the string is not empty
     TS_ASSERT_LESS_THAN(0, ConfigService::Instance().getTempDir().length()); //check that the string is not empty
+
+	std::string appdataDir = ConfigService::Instance().getAppDataDir();
+	TS_ASSERT_LESS_THAN(0, appdataDir.length());
+#ifdef _WIN32
+	std::string::size_type index = appdataDir.find("\\AppData\\Roaming\\mantidproject\\mantid");
+	TSM_ASSERT_LESS_THAN("Could not find correct path in getAppDataDir()",index,appdataDir.size());
+#else
+	std::string::size_type index = appdataDir.find("/.mantid");
+	TSM_ASSERT_LESS_THAN("Could not find correct path in getAppDataDir()",index,appdataDir.size());
+#endif
+
+  }
+
+  void TestInstrumentDirectory()
+  {
+	  
+    auto directories = ConfigService::Instance().getInstrumentDirectories();
+	TS_ASSERT_LESS_THAN(1,directories.size());
+	//the first entry should be the AppDataDir + instrument
+	std::cout<<std::endl<<directories[0]<<std::endl;
+	std::cout<<std::endl<<ConfigService::Instance().getAppDataDir()<<std::endl;
+	std::cout<<std::endl<<directories[0].find("instruxxment")<<std::endl;
+	TSM_ASSERT_LESS_THAN("Could not find the appData directory in getInstrumentDirectories()[0]",directories[0].find(ConfigService::Instance().getAppDataDir()),directories[0].size());
+	TSM_ASSERT_LESS_THAN("Could not find the 'instrument' directory in getInstrumentDirectories()[0]",directories[0].find("instrument"),directories[0].size());
+
+	if (directories.size() == 3)
+	{
+		// The middle entry should be /etc/mantid/instrument
+		TSM_ASSERT_LESS_THAN("Could not find /etc/mantid/instrument path in getInstrumentDirectories()[1]",directories[1].find("etc/mantid/instrument"),directories[1].size());
+	}
+	//Check that the last directory matches that returned by getInstrumentDirectory
+	TS_ASSERT_EQUALS(directories[directories.size()-1],ConfigService::Instance().getInstrumentDirectory());
+
+	//check all of the directory entries actually exist
+	for (auto it = directories.begin(); it != directories.end(); ++it)
+	{
+		Poco::File directory(*it);
+		TSM_ASSERT(*it + " does not exist", directory.exists());
+	}
+
   }
 
   void TestCustomProperty()
-- 
GitLab