Skip to content
Snippets Groups Projects
Commit 6fa8fb49 authored by Russell Taylor's avatar Russell Taylor
Browse files

Try to get MD tests passing on Hudson. Re #2511.

parent 9c86a72e
No related merge requests found
This diff is collapsed.
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
#include <cxxtest/TestSuite.h> #include <cxxtest/TestSuite.h>
#include "MDDataObjects/MD_FileFormatFactory.h" #include "MDDataObjects/MD_FileFormatFactory.h"
#include "MantidAPI/FileFinder.h"
#include <Poco/Path.h> #include <Poco/Path.h>
#include "MantidKernel/System.h"
#include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/case_conv.hpp>
// existing file formats // existing file formats
...@@ -19,88 +19,65 @@ class MD_FileFactoryTest : public CxxTest::TestSuite ...@@ -19,88 +19,65 @@ class MD_FileFactoryTest : public CxxTest::TestSuite
{ {
public: public:
void testFormatImplemented(){ void testFormatImplemented(){
std::auto_ptr<IMD_FileFormat> testFormat; std::auto_ptr<IMD_FileFormat> testFormat;
TSM_ASSERT_THROWS_NOTHING("test data format should be initiated without throwing",testFormat=MD_FileFormatFactory::getFileReader("testFile",test_data)); TSM_ASSERT_THROWS_NOTHING("test data format should be initiated without throwing",testFormat=MD_FileFormatFactory::getFileReader("testFile",test_data));
TSM_ASSERT("FileFormat factory returned a pointer to a wrong file reader, should be test data ",dynamic_cast<MD_FileTestDataGenerator*>(testFormat.get())!=0); TSM_ASSERT("FileFormat factory returned a pointer to a wrong file reader, should be test data ",dynamic_cast<MD_FileTestDataGenerator*>(testFormat.get())!=0);
} }
void testGetUniqueFileName(){ void testGetUniqueFileName(){
std::vector<std::string> f_names(2); std::vector<std::string> f_names(2);
f_names[0] = "tmp_data_0.sqw"; f_names[0] = "tmp_data_0.sqw";
f_names[1] = "tmp_data_1.sqw"; f_names[1] = "tmp_data_1.sqw";
// create temporary files // create temporary files
for(size_t i=0;i<f_names.size();i++){ for(size_t i=0;i<f_names.size();i++){
std::ofstream tmp_file(f_names[i].c_str()); std::ofstream tmp_file(f_names[i].c_str());
tmp_file.close(); tmp_file.close();
}
// get the file name which is not among the above
std::string new_tmp_file = get_unique_tmp_fileName();
TSM_ASSERT_EQUALS("next temporary file has to be tmp_data_2.sqw but it is not it","tmp_data_2.sqw",new_tmp_file);
// delete temporary files (not to leave rubbish)
for(size_t i=0;i<f_names.size();i++){
std::remove(f_names[i].c_str());
}
} }
void testReturnsNewHDFV1format(){ // get the file name which is not among the above
std::auto_ptr<IMD_FileFormat> newFormat; std::string new_tmp_file = get_unique_tmp_fileName();
std::string new_sqw_file("newDataFile.sqw"); TSM_ASSERT_EQUALS("next temporary file has to be tmp_data_2.sqw but it is not it","tmp_data_2.sqw",new_tmp_file);
// delete temporary files (not to leave rubbish)
TS_ASSERT_THROWS_NOTHING(newFormat=MD_FileFormatFactory::getFileReader(best_fit,new_sqw_file.c_str())); for(size_t i=0;i<f_names.size();i++){
TSM_ASSERT("FileFormat factory should returned a pointer to new file format ",dynamic_cast<MD_File_hdfV1*>(newFormat.get())!=0); std::remove(f_names[i].c_str());
// clear the pointer and deleted test file for future tests not to fail or work independently;
newFormat.reset();
std::remove(new_sqw_file.c_str());
}
void testReturnsMatlabReader(){
std::auto_ptr<IMD_FileFormat> oldFormat;
std::string testFile = findTestFileLocation("../../../../Test/VATES/fe_demo.sqw","fe_demo.sqw");
TS_ASSERT_THROWS_NOTHING(oldFormat=MD_FileFormatFactory::getFileReader(testFile.c_str()));
TSM_ASSERT("FileFormat factory returned a pointer to a wrong file reader ",dynamic_cast<MD_File_hdfMatlab*>(oldFormat.get())!=0);
}
//void t__tReturnsOldMatlabReader(){
// std::auto_ptr<IMD_FileFormat> oldFormat;
// std::string testFile = findTestFileLocation("../../../../Test/VATES/fe_demo.sqw","fe_demo.sqw");
// TS_ASSERT_THROWS_NOTHING(oldFormat=MD_FileFormatFactory::getFileReader(testFile.c_str(),old_4DMatlabReader));
// TSM_ASSERT("FileFormat factory returned a pointer to a wrong file reader ",dynamic_cast<MD_File_hdfMatlab4D*>(oldFormat.get())!=0);
//}
void testHoraceFileFound(){
std::auto_ptr<IMD_FileFormat> horaceFormat;
std::string testFile = findTestFileLocation("../../../../Test/VATES/fe_demo_bin.sqw","fe_demo_bin.sqw");
TS_ASSERT_THROWS_NOTHING(horaceFormat= MD_FileFormatFactory::getFileReader(testFile.c_str()));
TSM_ASSERT("FileFormat factory have not returned a pointer to a Horace file reader ",dynamic_cast<HoraceReader::MD_FileHoraceReader*>(horaceFormat.get())!=0);
}
private:
std::string findTestFileLocation(const char *filePath,const std::string &fileName){
std::string search_path = Mantid::Kernel::getDirectoryOfExecutable();
std::string real_path = search_path;
boost::to_upper(search_path);
char pps[2];
pps[0]=Poco::Path::separator();
pps[1]=0;
std::string sps(pps);
std::string root_path;
size_t nPos = search_path.find("MANTID"+sps+"CODE");
if(nPos==std::string::npos){
std::cout <<" can not identify application location\n";
root_path.assign(filePath);
}else{
root_path=real_path.substr(0,nPos)+"Mantid/Test/VATES/"+fileName;
} }
std::cout << "\n\n test file location: "<< root_path<< std::endl;
return root_path; }
void testReturnsNewHDFV1format(){
std::auto_ptr<IMD_FileFormat> newFormat;
std::string new_sqw_file("newDataFile.sqw");
TS_ASSERT_THROWS_NOTHING(newFormat=MD_FileFormatFactory::getFileReader(best_fit,new_sqw_file.c_str()));
TSM_ASSERT("FileFormat factory should returned a pointer to new file format ",dynamic_cast<MD_File_hdfV1*>(newFormat.get())!=0);
// clear the pointer and deleted test file for future tests not to fail or work independently;
newFormat.reset();
std::remove(new_sqw_file.c_str());
} }
void testReturnsMatlabReader(){
std::auto_ptr<IMD_FileFormat> oldFormat;
std::string testFile = API::FileFinder::Instance().getFullPath("fe_demo.sqw");
TS_ASSERT_THROWS_NOTHING(oldFormat=MD_FileFormatFactory::getFileReader(testFile.c_str()));
TSM_ASSERT("FileFormat factory returned a pointer to a wrong file reader ",dynamic_cast<MD_File_hdfMatlab*>(oldFormat.get())!=0);
}
//void t__tReturnsOldMatlabReader(){
// std::auto_ptr<IMD_FileFormat> oldFormat;
// std::string testFile = findTestFileLocation("../../../../Test/VATES/fe_demo.sqw","fe_demo.sqw");
// TS_ASSERT_THROWS_NOTHING(oldFormat=MD_FileFormatFactory::getFileReader(testFile.c_str(),old_4DMatlabReader));
// TSM_ASSERT("FileFormat factory returned a pointer to a wrong file reader ",dynamic_cast<MD_File_hdfMatlab4D*>(oldFormat.get())!=0);
//}
void testHoraceFileFound(){
std::auto_ptr<IMD_FileFormat> horaceFormat;
std::string testFile = API::FileFinder::Instance().getFullPath("fe_demo_bin.sqw");
TS_ASSERT_THROWS_NOTHING(horaceFormat= MD_FileFormatFactory::getFileReader(testFile.c_str()));
TSM_ASSERT("FileFormat factory have not returned a pointer to a Horace file reader ",dynamic_cast<HoraceReader::MD_FileHoraceReader*>(horaceFormat.get())!=0);
}
}; };
......
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