24 #include <itksys/SystemTools.hxx>
28 CPPUNIT_TEST_SUITE(mitkIOUtilTestSuite);
36 MITK_TEST(TestTempMethodsForUniqueFilenames);
37 MITK_TEST(TestTempMethodsForUniqueFilenames);
38 CPPUNIT_TEST_SUITE_END();
41 std::string m_ImagePath;
42 std::string m_SurfacePath;
43 std::string m_PointSetPath;
53 void TestSaveEmptyData()
59 void TestTempMethods()
62 CPPUNIT_ASSERT(!tmpPath.empty());
64 std::ofstream tmpFile;
66 CPPUNIT_ASSERT(tmpFile && tmpFile.is_open());
67 CPPUNIT_ASSERT(tmpFilePath.size() > tmpPath.size());
68 CPPUNIT_ASSERT(tmpFilePath.substr(0, tmpPath.size()) == tmpPath);
71 CPPUNIT_ASSERT(std::remove(tmpFilePath.c_str()) == 0);
74 CPPUNIT_ASSERT(!programPath.empty());
75 std::ofstream tmpFile2;
77 CPPUNIT_ASSERT(tmpFile2 && tmpFile2.is_open());
78 CPPUNIT_ASSERT(tmpFilePath2.size() > programPath.size());
79 CPPUNIT_ASSERT(tmpFilePath2.substr(0, programPath.size()) == programPath);
81 CPPUNIT_ASSERT(std::remove(tmpFilePath2.c_str()) == 0);
83 std::ofstream tmpFile3;
84 std::string tmpFilePath3 =
86 CPPUNIT_ASSERT(tmpFile3 && tmpFile3.is_open());
87 CPPUNIT_ASSERT(tmpFilePath3.size() > programPath.size());
88 CPPUNIT_ASSERT(tmpFilePath3.substr(0, programPath.size()) == programPath);
89 CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 13, 3) ==
"my-");
90 CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 4) ==
".TXT");
96 file.open(tmpFilePath4.c_str());
97 CPPUNIT_ASSERT_MESSAGE(
"Testing if file exists after CreateTemporaryFile()", file.is_open());
102 CPPUNIT_ASSERT(tmpDir.size() > tmpPath.size());
103 CPPUNIT_ASSERT(tmpDir.substr(0, tmpPath.size()) == tmpPath);
104 CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir.c_str()));
107 CPPUNIT_ASSERT(tmpDir2.size() > programPath.size());
108 CPPUNIT_ASSERT(tmpDir2.substr(0, programPath.size()) == programPath);
109 CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir2.c_str()));
112 void TestTempMethodsForUniqueFilenames()
114 int numberOfFiles = 100;
117 std::vector<std::string> v100filenames;
118 for (
int i = 0; i < numberOfFiles; i++)
124 for (
int i = 0; i < numberOfFiles; i++)
125 for (
int j = 0; j < numberOfFiles; j++)
129 std::stringstream message;
130 message <<
"Checking if file " << i <<
" and file " << j
131 <<
" are different, which should be the case because each of them should be unique.";
132 CPPUNIT_ASSERT_MESSAGE(message.str(), (v100filenames.at(i) != v100filenames.at(j)));
137 for (
int i = 0; i < numberOfFiles; i++)
139 std::remove(v100filenames.at(i).c_str());
143 void TestLoadAndSaveImage()
146 CPPUNIT_ASSERT(img1.IsNotNull());
148 std::ofstream tmpStream;
162 std::remove(imagePath.c_str());
163 std::remove(imagePath2.c_str());
165 mitk::Image::Pointer relativImage = mitk::ImageGenerator::GenerateGradientImage<float>(4, 4, 4, 1);
170 std::remove(imagePath3.c_str());
196 void TestLoadAndSavePointSet()
199 CPPUNIT_ASSERT(pointset.IsNotNull());
201 std::ofstream tmpStream;
210 CPPUNIT_ASSERT_NO_THROW(
mitk::IOUtil::Save(pointset, pointSetPathWithDefaultExtension));
213 CPPUNIT_ASSERT_NO_THROW(
mitk::IOUtil::Save(pointset, pointSetPathWithoutDefaultExtension.c_str()));
216 std::remove(pointSetPath.c_str());
217 std::remove(pointSetPathWithDefaultExtension.c_str());
218 std::remove(pointSetPathWithoutDefaultExtension.c_str());
221 void TestLoadAndSaveSurface()
224 CPPUNIT_ASSERT(surface.IsNotNull());
226 std::ofstream tmpStream;
236 std::remove(surfacePath.c_str());
static mitk::Surface::Pointer LoadSurface(const std::string &path)
LoadSurface Convenience method to load an arbitrary mitkSurface.
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
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.
static bool SaveImage(mitk::Image::Pointer image, const std::string &path)
SaveImage Convenience method to save an arbitrary mitkImage.
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Test fixture for parameterized tests.
static mitk::PointSet::Pointer LoadPointSet(const std::string &path)
LoadPointSet Convenience method to load an arbitrary mitkPointSet.
static std::string CreateTemporaryDirectory(const std::string &templateName="XXXXXX", std::string path=std::string())
static std::string GetProgramPath()
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)
Load a file into the given DataStorage.
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.