diff --git a/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp b/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp index c27c0d0e35adc9f4aa41ca9de1aa8c2af4c70145..7e8d81a46af88306d16032fc88c191208f85adbe 100644 --- a/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp +++ b/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp @@ -13,15 +13,64 @@ // ************************************************************************** // #include "CoreIOPathTest.h" +#include "BATesting.h" +#include "FileSystemUtils.h" +#include "IntensityDataIOFactory.h" +#include "OutputData.h" +#include "TestUtils.h" +#include <boost/filesystem.hpp> #include <iostream> +#include <memory> -CoreIOPathTest::CoreIOPathTest() +namespace { +std::unique_ptr<OutputData<double>> createTestData(); +bool test_io(const OutputData<double>* data, const std::string& file_name); +} // namespace -} +CoreIOPathTest::CoreIOPathTest() = default; bool CoreIOPathTest::runTest() { - std::cout << "Hello world" << std::endl; - return true; + const auto data = createTestData(); + const char filename_rus[] = "\xd0\xb4\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5\x2e\x69\x6e\x74"; + const char dirname_rus[] = + "\xd0\xb4\xd0\xb8\xd1\x80\xd0\xb5\xd0\xba\xd1\x82\xd0\xbe\xd1\x80\xd0\xb8\xd1\x8f"; + + const boost::filesystem::path test_dir(BATesting::CoreOutputDir()); + const boost::filesystem::path test_subdir("test_CoreIOPathTest"); + + FileSystemUtils::createDirectories((test_dir / test_subdir).string()); + + // tests file writing when file name contains cyrillic characters + bool success(true); + boost::filesystem::path test_file(filename_rus); + success &= test_io(data.get(), (test_dir / test_subdir / test_file).string()); + + // tests file writing and directory creation when dirname contains cyrillic characters + boost::filesystem::path test_subdir_rus(dirname_rus); + FileSystemUtils::createDirectories((test_dir / test_subdir / test_subdir_rus).string()); + success &= test_io(data.get(), (test_dir / test_subdir / test_subdir_rus / test_file).string()); + + return success; +} + +namespace +{ +std::unique_ptr<OutputData<double>> createTestData() +{ + std::unique_ptr<OutputData<double>> result(new OutputData<double>); + result->addAxis("x", 10, 0.0, 10.0); + for (size_t i = 0; i < result->getAllocatedSize(); ++i) + (*result)[i] = static_cast<double>(i); + return result; } + +bool test_io(const OutputData<double>* data, const std::string& file_name) +{ + IntensityDataIOFactory::writeOutputData(*data, file_name); + std::unique_ptr<OutputData<double>> loaded(IntensityDataIOFactory::readOutputData(file_name)); + return TestUtils::isTheSame(*data, *loaded, 1e-06); +} + +} // namespace diff --git a/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.h b/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.h index 3e7a17df25f83585a9fd0b0de805fc736fb02391..b468d0b3647e69cfe3cf341fe775af266aa2ca7e 100644 --- a/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.h +++ b/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.h @@ -25,7 +25,6 @@ public: CoreIOPathTest(); bool runTest(); - }; #endif // COREIOPATHTEST_H