lokinet/test/test_util.hpp
dan 13b01c86a6 Updated RpcServer Initialization and Logic
-- Moved all RPCServer initialization logic to rpcserver constructor
    -- Fixed config logic, fxn binding to rpc address, fxn adding rpc cats
    -- router hive failed CI/CD resulting from outdated reference to rpcBindAddr
    -- ipc socket as default hidden from windows (for now)
refactored config endpoint
    - added rpc call script (contrib/omq-rpc.py)
    - added new fxns to .ini config stuff
    - added delete .ini file functionality to config endpoint
    - added edge case control for config endpoint

add commented out line in clang-form for header reorg later
2023-01-24 06:50:46 -08:00

115 lines
1.8 KiB
C++

#ifndef TEST_UTIL_HPP
#define TEST_UTIL_HPP
#include <llarp/util/fs.hpp>
#include <llarp/util/types.hpp>
#include <bitset>
#include <vector>
namespace llarp
{
namespace test
{
std::string
randFilename();
template < typename Buf >
Buf
makeBuf(byte_t val)
{
Buf b;
b.Fill(val);
return b;
}
struct FileGuard
{
const fs::path p;
FileGuard(const fs::path &_p) : p(_p)
{
}
~FileGuard()
{
if(fs::exists(fs::status(p)))
{
fs::remove_all(p);
}
}
};
inline void
randbytes_impl(byte_t *ptr, size_t sz)
{
std::fill_n(ptr, sz, 0xAA);
}
template < typename T >
inline void
keygen_val(T &val, byte_t x)
{
val.Fill(x);
}
template < typename T >
inline void
keygen(T &val)
{
keygen_val(val, 0xAA);
}
template < typename T >
struct CombinationIterator
{
std::vector< T > toCombine;
std::vector< T > currentCombo;
int bits;
int maxBits;
void
createCombo()
{
currentCombo.clear();
for(size_t i = 0; i < toCombine.size(); ++i)
{
if(bits & (1 << i))
{
currentCombo.push_back(toCombine[i]);
}
}
}
CombinationIterator(const std::vector< T > &values)
: toCombine(values), bits(0), maxBits((1 << values.size()) - 1)
{
currentCombo.reserve(values.size());
createCombo();
}
bool
next()
{
if(bits >= maxBits)
{
return false;
}
++bits;
createCombo();
return true;
}
bool
includesElement(size_t index)
{
return bits & (1 << index);
}
};
} // namespace test
} // namespace llarp
#endif