Mercurial > hg > orthanc
changeset 222:bd934af46ba4
unit test of storagearea in separate file
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2012 18:03:37 +0100 |
parents | e7432706b354 |
children | 6f0e4a8ebb0f |
files | CMakeLists.txt UnitTests/FileStorage.cpp UnitTests/RestApi.cpp UnitTests/main.cpp |
diffstat | 4 files changed, 135 insertions(+), 131 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Thu Nov 29 18:01:06 2012 +0100 +++ b/CMakeLists.txt Thu Nov 29 18:03:37 2012 +0100 @@ -177,6 +177,7 @@ UnitTests/ServerIndex.cpp UnitTests/Versions.cpp UnitTests/Zip.cpp + UnitTests/FileStorage.cpp UnitTests/main.cpp ) target_link_libraries(UnitTests ServerLibrary CoreLibrary)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UnitTests/FileStorage.cpp Thu Nov 29 18:03:37 2012 +0100 @@ -0,0 +1,134 @@ +#include "gtest/gtest.h" + +#include <ctype.h> +#include <glog/logging.h> + +#include "../Core/FileStorage.h" +#include "../Core/Toolbox.h" +#include "../Core/OrthancException.h" +#include "../Core/Uuid.h" +#include "../Core/HttpServer/FilesystemHttpSender.h" +#include "../Core/HttpServer/BufferHttpSender.h" +#include "../Core/FileStorage/FileStorageAccessor.h" +#include "../Core/FileStorage/CompressedFileStorageAccessor.h" + +using namespace Orthanc; + +TEST(FileStorage, Basic) +{ + FileStorage s("FileStorageUnitTests"); + + std::string data = Toolbox::GenerateUuid(); + std::string uid = s.Create(data); + std::string d; + s.ReadFile(d, uid); + ASSERT_EQ(d.size(), data.size()); + ASSERT_FALSE(memcmp(&d[0], &data[0], data.size())); +} + +TEST(FileStorage, EndToEnd) +{ + FileStorage s("FileStorageUnitTests"); + s.Clear(); + + std::list<std::string> u; + for (unsigned int i = 0; i < 10; i++) + { + u.push_back(s.Create(Toolbox::GenerateUuid())); + } + + std::set<std::string> ss; + s.ListAllFiles(ss); + ASSERT_EQ(10u, ss.size()); + + unsigned int c = 0; + for (std::list<std::string>::iterator + i = u.begin(); i != u.end(); i++, c++) + { + ASSERT_TRUE(ss.find(*i) != ss.end()); + if (c < 5) + s.Remove(*i); + } + + s.ListAllFiles(ss); + ASSERT_EQ(5u, ss.size()); + + s.Clear(); + s.ListAllFiles(ss); + ASSERT_EQ(0u, ss.size()); +} + + +TEST(FileStorageAccessor, Simple) +{ + FileStorage s("FileStorageUnitTests"); + FileStorageAccessor accessor(s); + + std::string data = "Hello world"; + std::string id = accessor.Write(data); + + std::string r; + accessor.Read(r, id); + + ASSERT_EQ(data, r); +} + + +TEST(FileStorageAccessor, NoCompression) +{ + FileStorage s("FileStorageUnitTests"); + CompressedFileStorageAccessor accessor(s); + + accessor.SetCompressionForNextOperations(CompressionType_None); + std::string data = "Hello world"; + std::string id = accessor.Write(data); + + std::string r; + accessor.Read(r, id); + + ASSERT_EQ(data, r); +} + + +TEST(FileStorageAccessor, Compression) +{ + FileStorage s("FileStorageUnitTests"); + CompressedFileStorageAccessor accessor(s); + + accessor.SetCompressionForNextOperations(CompressionType_Zlib); + std::string data = "Hello world"; + std::string id = accessor.Write(data); + + std::string r; + accessor.Read(r, id); + + ASSERT_EQ(data, r); +} + + +TEST(FileStorageAccessor, Mix) +{ + FileStorage s("FileStorageUnitTests"); + CompressedFileStorageAccessor accessor(s); + + std::string r; + std::string compressedData = "Hello"; + std::string uncompressedData = "HelloWorld"; + + accessor.SetCompressionForNextOperations(CompressionType_Zlib); + std::string compressedId = accessor.Write(compressedData); + + accessor.SetCompressionForNextOperations(CompressionType_None); + std::string uncompressedId = accessor.Write(uncompressedData); + + accessor.SetCompressionForNextOperations(CompressionType_Zlib); + accessor.Read(r, compressedId); + ASSERT_EQ(compressedData, r); + + accessor.SetCompressionForNextOperations(CompressionType_None); + accessor.Read(r, compressedId); + ASSERT_NE(compressedData, r); + + accessor.SetCompressionForNextOperations(CompressionType_Zlib); + ASSERT_THROW(accessor.Read(r, uncompressedId), OrthancException); +}
--- a/UnitTests/RestApi.cpp Thu Nov 29 18:01:06 2012 +0100 +++ b/UnitTests/RestApi.cpp Thu Nov 29 18:03:37 2012 +0100 @@ -88,88 +88,3 @@ } #endif - - - -#include "../Core/FileStorage.h" -#include "../Core/HttpServer/FilesystemHttpSender.h" -#include "../Core/HttpServer/BufferHttpSender.h" -#include "../Core/FileStorage/FileStorageAccessor.h" -#include "../Core/FileStorage/CompressedFileStorageAccessor.h" - - - -TEST(FileStorageAccessor, Simple) -{ - FileStorage s("FileStorageUnitTests"); - FileStorageAccessor accessor(s); - - std::string data = "Hello world"; - std::string id = accessor.Write(data); - - std::string r; - accessor.Read(r, id); - - ASSERT_EQ(data, r); -} - - - -TEST(FileStorageAccessor, NoCompression) -{ - FileStorage s("FileStorageUnitTests"); - CompressedFileStorageAccessor accessor(s); - - accessor.SetCompressionForNextOperations(CompressionType_None); - std::string data = "Hello world"; - std::string id = accessor.Write(data); - - std::string r; - accessor.Read(r, id); - - ASSERT_EQ(data, r); -} - - -TEST(FileStorageAccessor, Compression) -{ - FileStorage s("FileStorageUnitTests"); - CompressedFileStorageAccessor accessor(s); - - accessor.SetCompressionForNextOperations(CompressionType_Zlib); - std::string data = "Hello world"; - std::string id = accessor.Write(data); - - std::string r; - accessor.Read(r, id); - - ASSERT_EQ(data, r); -} - - -TEST(FileStorageAccessor, Mix) -{ - FileStorage s("FileStorageUnitTests"); - CompressedFileStorageAccessor accessor(s); - - std::string r; - std::string compressedData = "Hello"; - std::string uncompressedData = "HelloWorld"; - - accessor.SetCompressionForNextOperations(CompressionType_Zlib); - std::string compressedId = accessor.Write(compressedData); - - accessor.SetCompressionForNextOperations(CompressionType_None); - std::string uncompressedId = accessor.Write(uncompressedData); - - accessor.SetCompressionForNextOperations(CompressionType_Zlib); - accessor.Read(r, compressedId); - ASSERT_EQ(compressedData, r); - - accessor.SetCompressionForNextOperations(CompressionType_None); - accessor.Read(r, compressedId); - ASSERT_NE(compressedData, r); - - accessor.SetCompressionForNextOperations(CompressionType_Zlib); - ASSERT_THROW(accessor.Read(r, uncompressedId), OrthancException); -}
--- a/UnitTests/main.cpp Thu Nov 29 18:01:06 2012 +0100 +++ b/UnitTests/main.cpp Thu Nov 29 18:03:37 2012 +0100 @@ -4,7 +4,6 @@ #include "../Core/Compression/ZlibCompressor.h" #include "../Core/DicomFormat/DicomTag.h" -#include "../Core/FileStorage.h" #include "../OrthancCppClient/HttpClient.h" #include "../Core/HttpServer/HttpHandler.h" #include "../Core/OrthancException.h" @@ -98,51 +97,6 @@ ASSERT_EQ(a["aaa"], ""); } -TEST(FileStorage, Basic) -{ - FileStorage s("FileStorageUnitTests"); - - std::string data = Toolbox::GenerateUuid(); - std::string uid = s.Create(data); - std::string d; - s.ReadFile(d, uid); - ASSERT_EQ(d.size(), data.size()); - ASSERT_FALSE(memcmp(&d[0], &data[0], data.size())); -} - -TEST(FileStorage, EndToEnd) -{ - FileStorage s("FileStorageUnitTests"); - s.Clear(); - - std::list<std::string> u; - for (unsigned int i = 0; i < 10; i++) - { - u.push_back(s.Create(Toolbox::GenerateUuid())); - } - - std::set<std::string> ss; - s.ListAllFiles(ss); - ASSERT_EQ(10u, ss.size()); - - unsigned int c = 0; - for (std::list<std::string>::iterator - i = u.begin(); i != u.end(); i++, c++) - { - ASSERT_TRUE(ss.find(*i) != ss.end()); - if (c < 5) - s.Remove(*i); - } - - s.ListAllFiles(ss); - ASSERT_EQ(5u, ss.size()); - - s.Clear(); - s.ListAllFiles(ss); - ASSERT_EQ(0u, ss.size()); -} - - TEST(DicomFormat, Tag) { ASSERT_EQ("PatientName", FromDcmtkBridge::GetName(DicomTag(0x0010, 0x0010)));