diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-05-07 02:25:44 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-05-07 02:25:44 +0100 |
commit | 6b2132751f24ea65264fb2478cc40afa114ec248 (patch) | |
tree | 6345bae19a51e103ba754efbed2e89dde4946501 | |
parent | Add functions for calculating the block sizes for large read/writes (diff) | |
download | netfs-6b2132751f24ea65264fb2478cc40afa114ec248.tar.bz2 netfs-6b2132751f24ea65264fb2478cc40afa114ec248.tar.xz netfs-6b2132751f24ea65264fb2478cc40afa114ec248.zip |
Helper function to generate a vector of random data of a given size
-rw-r--r-- | netfs/unittests/mockFuse.cpp | 14 | ||||
-rw-r--r-- | netfs/unittests/mockFuse.h | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/netfs/unittests/mockFuse.cpp b/netfs/unittests/mockFuse.cpp index a1cf29b..0de5cf2 100644 --- a/netfs/unittests/mockFuse.cpp +++ b/netfs/unittests/mockFuse.cpp @@ -1,6 +1,7 @@ #include "mockFuse.h" #include <boost/test/test_tools.hpp> #include <buffer.h> +#include <random> FuseMock::FuseMock(std::string ep, Ice::StringSeq a) : NetFS::FuseApp(std::move(a)), testEndpoint(std::move(ep)), context({}) @@ -36,6 +37,19 @@ FuseMock::connectToService() } } +std::vector<char> +FuseMock::genRandomData(size_t size) +{ + std::vector<char> buf(size); + std::generate(begin(buf), end(buf), + [dist = std::uniform_int_distribution<char>( + std::numeric_limits<char>::min(), std::numeric_limits<char>::max()), + mersenne_engine = std::mt19937(std::random_device()())]() mutable { + return dist(mersenne_engine); + }); + return buf; +} + void FuseMock::vlogf(int, const char * fmt, va_list args) const noexcept { diff --git a/netfs/unittests/mockFuse.h b/netfs/unittests/mockFuse.h index cb69816..7a380eb 100644 --- a/netfs/unittests/mockFuse.h +++ b/netfs/unittests/mockFuse.h @@ -1,6 +1,7 @@ #pragma once #include <fuseApp.h> +#include <vector> #include <visibility.h> class DLL_PUBLIC FuseMock : public NetFS::FuseApp { @@ -11,6 +12,7 @@ public: void vlogf(int, const char *, va_list) const throw() override; void connectToService() override; + [[nodiscard]] static std::vector<char> genRandomData(size_t); private: const std::string testEndpoint; |