diff --git a/Device/Histo/IntensityDataIOFactory.cpp b/Device/Histo/IntensityDataIOFactory.cpp index 3e10bc2c7c1b9fd5c3b59a5f602d9c2d20e306d8..a01dc61ac1f513a3216eac99c7119a97b5ad62c4 100644 --- a/Device/Histo/IntensityDataIOFactory.cpp +++ b/Device/Histo/IntensityDataIOFactory.cpp @@ -76,7 +76,7 @@ IHistogram* IntensityDataIOFactory::readIntensityData(const std::string& file_na { std::unique_ptr<OutputData<double>> data(readOutputData(file_name)); if (!data) - throw std::runtime_error("Could not read " + file_name); + throw std::runtime_error("Cannot read intensity data from file: " + file_name); return IHistogram::createHistogram(*data); } @@ -115,12 +115,9 @@ void IntensityDataIOFactory::writeOutputData(const std::string& file_name, #endif if (!fout.is_open()) - throw std::runtime_error("IntensityDataIOFactory::writeOutputData() -> Error. " - "Can't open file '" - + file_name + "' for writing."); + throw std::runtime_error("Cannot open file for writing: " + file_name); if (!fout.good()) - throw std::runtime_error("IntensityDataIOFactory::writeOutputData() -> Error! " - "File is not good, probably it is a directory."); + throw std::runtime_error("File is not good, probably it is a directory: " + file_name); std::stringstream ss; writeData(ss); @@ -173,7 +170,7 @@ IntensityDataIOFactory::readOutputData(const std::string& file_name, { if (!BaseUtils::Filesystem::IsFileExists(file_name)) - return nullptr; + throw std::runtime_error("File does not exist: " + file_name); using namespace DataUtils::Format; std::ifstream input_stream; @@ -188,12 +185,9 @@ IntensityDataIOFactory::readOutputData(const std::string& file_name, #endif if (!input_stream.is_open()) - throw std::runtime_error( - "IntensityDataIOFactory::getFromFilteredStream() -> Error. Can't open file '" - + file_name + "' for reading."); + throw std::runtime_error("Cannot open file for reading: " + file_name); if (!input_stream.good()) - throw std::runtime_error("IntensityDataIOFactory::getFromFilteredStream() -> Error! " - "File is not good, probably it is a directory."); + throw std::runtime_error("File is not good, probably it is a directory:" + file_name); boost::iostreams::filtering_streambuf<boost::iostreams::input> input_filtered; if (DataUtils::Format::isGZipped(file_name)) diff --git a/Tests/Unit/Device/ReadSANSDRawTest.cpp b/Tests/Unit/Device/ReadSANSDRawTest.cpp index f34812af9f713e6d2fe7d196cd0c23c5dfcd5242..8f5a6ce438d69d6916af57261c5752debbdf0b50 100644 --- a/Tests/Unit/Device/ReadSANSDRawTest.cpp +++ b/Tests/Unit/Device/ReadSANSDRawTest.cpp @@ -2,16 +2,22 @@ #include "Device/Data/OutputData.h" #include "BATesting.h" #include "Tests/GTestWrapper/google_test.h" +#include <cstdio> class ReadSANSDRawTest : public ::testing::Test { }; TEST_F(ReadSANSDRawTest, Read) { - const auto fname = BATesting::ExampleDataDir() + "SANSDRaw.001"; + const auto fname = BATesting::ExampleDataDir() + "/SANSDRaw.001"; OutputData<double>* data = IntensityDataIOFactory::readOutputData(fname, IntensityDataIOFactory::automatic); + EXPECT_NE(data, nullptr); + if (!data) + return; EXPECT_EQ(data->rank(), 2); EXPECT_EQ(data->getAllocatedSize(), 16384); - EXPECT_EQ((*data)[128*128-1], 3); + for(int i=0; i<16384; ++i) + printf("%5i %5i\n", i, (int)(*data)[i]); + EXPECT_EQ((*data)[64*64-1], 3); }