Replace std::filesystem::path by std::string_view in Files::getHash argument

fix-osga-rotate-wildly
elsid 10 months ago
parent 79b73e45a1
commit a98ce7f76a
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -10,6 +10,8 @@
#include <sstream>
#include <string>
#include <components/files/conversion.hpp>
#include "../testing_util.hpp"
namespace
@ -35,7 +37,8 @@ namespace
std::fill_n(std::back_inserter(content), 1, 'a');
std::istringstream stream(content);
stream.exceptions(std::ios::failbit | std::ios::badbit);
EXPECT_THAT(getHash(fileName, stream), ElementsAre(9607679276477937801ull, 16624257681780017498ull));
EXPECT_THAT(getHash(Files::pathToUnicodeString(fileName), stream),
ElementsAre(9607679276477937801ull, 16624257681780017498ull));
}
TEST_P(FilesGetHash, shouldReturnHashForStringStream)
@ -44,7 +47,7 @@ namespace
std::string content;
std::fill_n(std::back_inserter(content), GetParam().mSize, 'a');
std::istringstream stream(content);
EXPECT_EQ(getHash(fileName, stream), GetParam().mHash);
EXPECT_EQ(getHash(Files::pathToUnicodeString(fileName), stream), GetParam().mHash);
}
TEST_P(FilesGetHash, shouldReturnHashForConstrainedFileStream)
@ -57,7 +60,7 @@ namespace
std::fstream(file, std::ios_base::out | std::ios_base::binary)
.write(content.data(), static_cast<std::streamsize>(content.size()));
const auto stream = Files::openConstrainedFileStream(file, 0, content.size());
EXPECT_EQ(getHash(file, *stream), GetParam().mHash);
EXPECT_EQ(getHash(Files::pathToUnicodeString(file), *stream), GetParam().mHash);
}
INSTANTIATE_TEST_SUITE_P(Params, FilesGetHash,

@ -1,5 +1,4 @@
#include "hash.hpp"
#include "conversion.hpp"
#include <extern/smhasher/MurmurHash3.h>
@ -10,7 +9,7 @@
namespace Files
{
std::array<std::uint64_t, 2> getHash(const std::filesystem::path& fileName, std::istream& stream)
std::array<std::uint64_t, 2> getHash(std::string_view fileName, std::istream& stream)
{
std::array<std::uint64_t, 2> hash{ 0, 0 };
try
@ -35,8 +34,11 @@ namespace Files
}
catch (const std::exception& e)
{
throw std::runtime_error(
"Error while reading \"" + Files::pathToUnicodeString(fileName) + "\" to get hash: " + e.what());
std::string message = "Error while reading \"";
message += fileName;
message += "\" to get hash: ";
message += e.what();
throw std::runtime_error(message);
}
return hash;
}

@ -3,12 +3,12 @@
#include <array>
#include <cstdint>
#include <filesystem>
#include <iosfwd>
#include <string_view>
namespace Files
{
std::array<std::uint64_t, 2> getHash(const std::filesystem::path& fileName, std::istream& stream);
std::array<std::uint64_t, 2> getHash(std::string_view fileName, std::istream& stream);
}
#endif

Loading…
Cancel
Save