20 #include <itksys/SystemTools.hxx> 24 CPPUNIT_TEST_SUITE(mitkIOUtilTestSuite);
32 MITK_TEST(TestTempMethodsForUniqueFilenames);
33 MITK_TEST(TestTempMethodsForUniqueFilenames);
34 CPPUNIT_TEST_SUITE_END();
37 std::string m_ImagePath;
38 std::string m_SurfacePath;
39 std::string m_PointSetPath;
49 void TestSaveEmptyData()
55 void TestTempMethods()
58 CPPUNIT_ASSERT(!tmpPath.empty());
60 std::ofstream tmpFile;
62 CPPUNIT_ASSERT(tmpFile && tmpFile.is_open());
63 CPPUNIT_ASSERT(tmpFilePath.size() > tmpPath.size());
64 CPPUNIT_ASSERT(tmpFilePath.substr(0, tmpPath.size()) == tmpPath);
67 CPPUNIT_ASSERT(std::remove(tmpFilePath.c_str()) == 0);
70 CPPUNIT_ASSERT(!programPath.empty());
71 std::ofstream tmpFile2;
73 CPPUNIT_ASSERT(tmpFile2 && tmpFile2.is_open());
74 CPPUNIT_ASSERT(tmpFilePath2.size() > programPath.size());
75 CPPUNIT_ASSERT(tmpFilePath2.substr(0, programPath.size()) == programPath);
77 CPPUNIT_ASSERT(std::remove(tmpFilePath2.c_str()) == 0);
79 std::ofstream tmpFile3;
80 std::string tmpFilePath3 =
82 CPPUNIT_ASSERT(tmpFile3 && tmpFile3.is_open());
83 CPPUNIT_ASSERT(tmpFilePath3.size() > programPath.size());
84 CPPUNIT_ASSERT(tmpFilePath3.substr(0, programPath.size()) == programPath);
85 CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 13, 3) ==
"my-");
86 CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 4) ==
".TXT");
92 file.open(tmpFilePath4.c_str());
93 CPPUNIT_ASSERT_MESSAGE(
"Testing if file exists after CreateTemporaryFile()", file.is_open());
98 CPPUNIT_ASSERT(tmpDir.size() > tmpPath.size());
99 CPPUNIT_ASSERT(tmpDir.substr(0, tmpPath.size()) == tmpPath);
100 CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir.c_str()));
103 CPPUNIT_ASSERT(tmpDir2.size() > programPath.size());
104 CPPUNIT_ASSERT(tmpDir2.substr(0, programPath.size()) == programPath);
105 CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir2.c_str()));
108 void TestTempMethodsForUniqueFilenames()
110 int numberOfFiles = 100;
113 std::vector<std::string> v100filenames;
114 for (
int i = 0; i < numberOfFiles; i++)
120 for (
int i = 0; i < numberOfFiles; i++)
121 for (
int j = 0; j < numberOfFiles; j++)
125 std::stringstream message;
126 message <<
"Checking if file " << i <<
" and file " << j
127 <<
" are different, which should be the case because each of them should be unique.";
128 CPPUNIT_ASSERT_MESSAGE(message.str(), (v100filenames.at(i) != v100filenames.at(j)));
133 for (
int i = 0; i < numberOfFiles; i++)
135 std::remove(v100filenames.at(i).c_str());
139 void TestLoadAndSaveImage()
142 CPPUNIT_ASSERT(img1.IsNotNull());
144 std::ofstream tmpStream;
158 std::remove(imagePath.c_str());
159 std::remove(imagePath2.c_str());
161 mitk::Image::Pointer relativImage = mitk::ImageGenerator::GenerateGradientImage<float>(4, 4, 4, 1);
166 std::remove(imagePath3.c_str());
187 void TestLoadAndSavePointSet()
190 CPPUNIT_ASSERT(pointset.IsNotNull());
192 std::ofstream tmpStream;
201 CPPUNIT_ASSERT_NO_THROW(
mitk::IOUtil::Save(pointset, pointSetPathWithDefaultExtension));
204 CPPUNIT_ASSERT_NO_THROW(
mitk::IOUtil::Save(pointset, pointSetPathWithoutDefaultExtension.c_str()));
207 std::remove(pointSetPath.c_str());
208 std::remove(pointSetPathWithDefaultExtension.c_str());
209 std::remove(pointSetPathWithoutDefaultExtension.c_str());
212 void TestLoadAndSaveSurface()
215 CPPUNIT_ASSERT(surface.IsNotNull());
217 std::ofstream tmpStream;
227 std::remove(surfacePath.c_str());
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
static std::string GetTempPath()
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Test fixture for parameterized tests.
static std::string CreateTemporaryDirectory(const std::string &templateName="XXXXXX", std::string path=std::string())
static std::string GetProgramPath()
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
static std::string CreateTemporaryFile(std::ofstream &tmpStream, const std::string &templateName="XXXXXX", std::string path=std::string())
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.