From 6b2132751f24ea65264fb2478cc40afa114ec248 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 7 May 2022 02:25:44 +0100 Subject: Helper function to generate a vector of random data of a given size --- netfs/unittests/mockFuse.cpp | 14 ++++++++++++++ netfs/unittests/mockFuse.h | 2 ++ 2 files changed, 16 insertions(+) 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 #include +#include 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 +FuseMock::genRandomData(size_t size) +{ + std::vector buf(size); + std::generate(begin(buf), end(buf), + [dist = std::uniform_int_distribution( + std::numeric_limits::min(), std::numeric_limits::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 +#include #include 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 genRandomData(size_t); private: const std::string testEndpoint; -- cgit v1.2.3