summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-05-07 02:25:44 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-05-07 02:25:44 +0100
commit6b2132751f24ea65264fb2478cc40afa114ec248 (patch)
tree6345bae19a51e103ba754efbed2e89dde4946501
parentAdd functions for calculating the block sizes for large read/writes (diff)
downloadnetfs-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.cpp14
-rw-r--r--netfs/unittests/mockFuse.h2
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;