# HG changeset patch # User Sebastien Jodogne # Date 1399447751 -7200 # Node ID 4689e400e0fa046919012095cfd19274213776ef # Parent 82b07ab959f462cdf8b5ddd27df4f54558985b01 directory to store the results of the unit tests diff -r 82b07ab959f4 -r 4689e400e0fa Core/FileStorage/FileStorage.cpp --- a/Core/FileStorage/FileStorage.cpp Tue May 06 17:09:32 2014 +0200 +++ b/Core/FileStorage/FileStorage.cpp Wed May 07 09:29:11 2014 +0200 @@ -78,25 +78,10 @@ FileStorage::FileStorage(std::string root) { - namespace fs = boost::filesystem; - //root_ = boost::filesystem::absolute(root).string(); root_ = root; - if (fs::exists(root)) - { - if (!fs::is_directory(root)) - { - throw OrthancException("The file storage root directory is a file"); - } - } - else - { - if (!fs::create_directories(root)) - { - throw OrthancException("Unable to create the file storage root directory"); - } - } + Toolbox::CreateDirectory(root); } std::string FileStorage::CreateFileWithoutCompression(const void* content, size_t size) diff -r 82b07ab959f4 -r 4689e400e0fa Core/Toolbox.cpp --- a/Core/Toolbox.cpp Tue May 06 17:09:32 2014 +0200 +++ b/Core/Toolbox.cpp Wed May 07 09:29:11 2014 +0200 @@ -824,5 +824,23 @@ } } + + void Toolbox::CreateDirectory(const std::string& path) + { + if (boost::filesystem::exists(path)) + { + if (!boost::filesystem::is_directory(path)) + { + throw OrthancException("Cannot create the directory over an existing file: " + path); + } + } + else + { + if (!boost::filesystem::create_directories(path)) + { + throw OrthancException("Unable to create the directory: " + path); + } + } + } } diff -r 82b07ab959f4 -r 4689e400e0fa Core/Toolbox.h --- a/Core/Toolbox.h Tue May 06 17:09:32 2014 +0200 +++ b/Core/Toolbox.h Wed May 07 09:29:11 2014 +0200 @@ -126,5 +126,7 @@ void DecodeDataUriScheme(std::string& mime, std::string& content, const std::string& source); + + void CreateDirectory(const std::string& path); } } diff -r 82b07ab959f4 -r 4689e400e0fa UnitTestsSources/FromDcmtk.cpp --- a/UnitTestsSources/FromDcmtk.cpp Tue May 06 17:09:32 2014 +0200 +++ b/UnitTestsSources/FromDcmtk.cpp Wed May 07 09:29:11 2014 +0200 @@ -37,12 +37,12 @@ //m.Replace(DICOM_TAG_PATIENT_NAME, "coucou"); ParsedDicomFile o; - o.SaveToFile("anon.dcm"); + o.SaveToFile("UnitTestsResults/anon.dcm"); for (int i = 0; i < 10; i++) { char b[1024]; - sprintf(b, "anon%06d.dcm", i); + sprintf(b, "UnitTestsResults/anon%06d.dcm", i); std::auto_ptr f(o.Clone()); if (i > 4) o.Replace(DICOM_TAG_SERIES_INSTANCE_UID, "coucou"); @@ -78,18 +78,18 @@ ParsedDicomFile o; o.EmbedImage(s); - o.SaveToFile("png1.dcm"); + o.SaveToFile("UnitTestsResults/png1.dcm"); // Red dot, without alpha channel s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDTcIn2+8BgAAACJJREFUCNdj/P//PwMjIwME/P/P+J8BBTAxEOL/R9Lx/z8AynoKAXOeiV8AAAAASUVORK5CYII="; o.EmbedImage(s); - o.SaveToFile("png2.dcm"); + o.SaveToFile("UnitTestsResults/png2.dcm"); // Check box in Graylevel8 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="; o.EmbedImage(s); //o.Replace(DICOM_TAG_SOP_CLASS_UID, UID_DigitalXRayImageStorageForProcessing); - o.SaveToFile("png3.dcm"); + o.SaveToFile("UnitTestsResults/png3.dcm"); { @@ -111,6 +111,6 @@ } o.EmbedImage(img.GetAccessor()); - o.SaveToFile("png4.dcm"); + o.SaveToFile("UnitTestsResults/png4.dcm"); } } diff -r 82b07ab959f4 -r 4689e400e0fa UnitTestsSources/Png.cpp --- a/UnitTestsSources/Png.cpp Tue May 06 17:09:32 2014 +0200 +++ b/UnitTestsSources/Png.cpp Wed May 07 09:29:11 2014 +0200 @@ -26,10 +26,10 @@ } } - w.WriteToFile("ColorPattern.png", width, height, pitch, Orthanc::PixelFormat_RGB24, &image[0]); + w.WriteToFile("UnitTestsResults/ColorPattern.png", width, height, pitch, Orthanc::PixelFormat_RGB24, &image[0]); std::string f, md5; - Orthanc::Toolbox::ReadFile(f, "ColorPattern.png"); + Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/ColorPattern.png"); Orthanc::Toolbox::ComputeMD5(md5, f); ASSERT_EQ("604e785f53c99cae6ea4584870b2c41d", md5); } @@ -51,10 +51,10 @@ } } - w.WriteToFile("Gray8Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale8, &image[0]); + w.WriteToFile("UnitTestsResults/Gray8Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale8, &image[0]); std::string f, md5; - Orthanc::Toolbox::ReadFile(f, "Gray8Pattern.png"); + Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.png"); Orthanc::Toolbox::ComputeMD5(md5, f); ASSERT_EQ("5a9b98bea3d0a6d983980cc38bfbcdb3", md5); } @@ -78,10 +78,10 @@ } } - w.WriteToFile("Gray16Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]); + w.WriteToFile("UnitTestsResults/Gray16Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]); std::string f, md5; - Orthanc::Toolbox::ReadFile(f, "Gray16Pattern.png"); + Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.png"); Orthanc::Toolbox::ComputeMD5(md5, f); ASSERT_EQ("0785866a08bf0a02d2eeff87f658571c", md5); } diff -r 82b07ab959f4 -r 4689e400e0fa UnitTestsSources/SQLite.cpp --- a/UnitTestsSources/SQLite.cpp Tue May 06 17:09:32 2014 +0200 +++ b/UnitTestsSources/SQLite.cpp Wed May 07 09:29:11 2014 +0200 @@ -18,9 +18,9 @@ TEST(SQLite, Connection) { - Toolbox::RemoveFile("coucou"); + Toolbox::RemoveFile("UnitTestsResults/coucou"); SQLite::Connection c; - c.Open("coucou"); + c.Open("UnitTestsResults/coucou"); c.Execute("CREATE TABLE c(k INTEGER PRIMARY KEY AUTOINCREMENT, v INTEGER)"); c.Execute("INSERT INTO c VALUES(NULL, 42);"); } diff -r 82b07ab959f4 -r 4689e400e0fa UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Tue May 06 17:09:32 2014 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Wed May 07 09:29:11 2014 +0200 @@ -523,7 +523,7 @@ TEST(ServerIndex, AttachmentRecycling) { - const std::string path = "OrthancStorageUnitTests"; + const std::string path = "UnitTestsStorage"; Toolbox::RemoveFile(path + "/index"); ServerContext context(path, ":memory:"); // The SQLite DB is in memory ServerIndex& index = context.GetIndex(); diff -r 82b07ab959f4 -r 4689e400e0fa UnitTestsSources/UnitTestsMain.cpp --- a/UnitTestsSources/UnitTestsMain.cpp Tue May 06 17:09:32 2014 +0200 +++ b/UnitTestsSources/UnitTestsMain.cpp Wed May 07 09:29:11 2014 +0200 @@ -582,6 +582,8 @@ google::InitGoogleLogging("Orthanc"); + Toolbox::CreateDirectory("UnitTestsResults"); + OrthancInitialize(); ::testing::InitGoogleTest(&argc, argv); int result = RUN_ALL_TESTS(); diff -r 82b07ab959f4 -r 4689e400e0fa UnitTestsSources/Zip.cpp --- a/UnitTestsSources/Zip.cpp Tue May 06 17:09:32 2014 +0200 +++ b/UnitTestsSources/Zip.cpp Wed May 07 09:29:11 2014 +0200 @@ -11,7 +11,7 @@ TEST(ZipWriter, Basic) { Orthanc::ZipWriter w; - w.SetOutputPath("hello.zip"); + w.SetOutputPath("UnitTestsResults/hello.zip"); w.Open(); w.OpenFile("world/hello"); w.Write("Hello world"); @@ -21,7 +21,7 @@ TEST(ZipWriter, Basic64) { Orthanc::ZipWriter w; - w.SetOutputPath("hello64.zip"); + w.SetOutputPath("UnitTestsResults/hello64.zip"); w.SetZip64(true); w.Open(); w.OpenFile("world/hello"); @@ -33,7 +33,7 @@ { Orthanc::ZipWriter w; ASSERT_THROW(w.Open(), Orthanc::OrthancException); - w.SetOutputPath("hello3.zip"); + w.SetOutputPath("UnitTestsResults/hello3.zip"); w.Open(); ASSERT_THROW(w.Write("hello world"), Orthanc::OrthancException); } @@ -91,7 +91,7 @@ { static const std::string SPACES = " "; - HierarchicalZipWriter w("hello2.zip"); + HierarchicalZipWriter w("UnitTestsResults/hello2.zip"); w.SetCompressionLevel(0);