comparison OrthancFramework/UnitTestsSources/FileStorageTests.cpp @ 4484:64f06e7d5fc7

new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 28 Jan 2021 19:03:19 +0100
parents d9473bd5ed43
children cff7fdfc83a4
comparison
equal deleted inserted replaced
4483:a926f8995d0b 4484:64f06e7d5fc7
56 56
57 std::string data = Toolbox::GenerateUuid(); 57 std::string data = Toolbox::GenerateUuid();
58 std::string uid = Toolbox::GenerateUuid(); 58 std::string uid = Toolbox::GenerateUuid();
59 s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown); 59 s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown);
60 std::string d; 60 std::string d;
61 s.Read(d, uid, FileContentType_Unknown); 61 {
62 std::unique_ptr<IMemoryBuffer> buffer(s.Read(uid, FileContentType_Unknown));
63 buffer->MoveToString(d);
64 }
62 ASSERT_EQ(d.size(), data.size()); 65 ASSERT_EQ(d.size(), data.size());
63 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size())); 66 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
64 ASSERT_EQ(s.GetSize(uid), data.size()); 67 ASSERT_EQ(s.GetSize(uid), data.size());
65 } 68 }
66 69
71 std::vector<uint8_t> data; 74 std::vector<uint8_t> data;
72 StringToVector(data, Toolbox::GenerateUuid()); 75 StringToVector(data, Toolbox::GenerateUuid());
73 std::string uid = Toolbox::GenerateUuid(); 76 std::string uid = Toolbox::GenerateUuid();
74 s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown); 77 s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown);
75 std::string d; 78 std::string d;
76 s.Read(d, uid, FileContentType_Unknown); 79 {
80 std::unique_ptr<IMemoryBuffer> buffer(s.Read(uid, FileContentType_Unknown));
81 buffer->MoveToString(d);
82 }
77 ASSERT_EQ(d.size(), data.size()); 83 ASSERT_EQ(d.size(), data.size());
78 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size())); 84 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
79 ASSERT_EQ(s.GetSize(uid), data.size()); 85 ASSERT_EQ(s.GetSize(uid), data.size());
80 } 86 }
81 87