3#include <catch2/catch_all.hpp>
6TEST_CASE(
"toInt(protocol_value_t)",
"[Utils]")
8 auto rawValue = GENERATE(-42, 0, 2, 1000);
13TEST_CASE(
"toDouble(protocol_value_t)",
"[Utils]")
15 auto rawValue = GENERATE(-42.6, 0.3, 2.2, 1000.1231231);
20TEST_CASE(
"toString(protocol_value_t)",
"[Utils]")
22 std::string rawValue = GENERATE(
"",
"hello",
"hello world!");
29 std::set<std::string> results;
30 for(
size_t i = 0; i < 10000; ++i) {
32 CHECK(results.find(uuid) == results.end());
40 std::string inString =
"Hello world";
44 std::vector<std::string>
expected{
"Hello",
"world"};
50 std::vector<std::string>
expected{
"Hello world"};
56 std::vector<std::string>
expected{
"He",
"o wor",
"d"};
64 std::string inString =
" \tHello world\n \r";
67 std::string
expected =
"Hello world";
72 std::string delimiters =
"d";
79 std::string inString =
"Hello world";
82 std::string
expected =
"Hello world";
87 std::string delimiters =
"d";
94 std::string delimiters =
"Hd";
100 std::string delimiters =
"Hello ";
111 std::string inString =
"Hello world";
113 std::string strippedString =
"";
115 std::string
expected =
"Hello world";
120 std::string strippedString =
"d";
122 std::string
expected =
"Hello worl";
127 std::string strippedString =
"Hd";
129 std::string
expected =
"Hello world";
133 std::string strippedString =
"Hello ";
140TEST_CASE(
"durationToString()",
"[Utils]")
196 std::string singleChar =
"a";
202 std::string longerString = GENERATE(
"hello",
"world",
"How are you?");
205 for(
size_t i = 0; i < longerString.size(); ++i) {
216 std::vector<irsol::types::byte_t> bytes;
clock_t::duration duration_t
Alias for a duration of time as defined by clock_t.
std::variant< int, double, std::string > protocol_value_t
Variant type representing protocol values that can be one of several types.
std::byte byte_t
Alias for a single byte used in serialization or binary data handling.
double toDouble(const irsol::types::protocol_value_t &x)
Converts a protocol value to a double.
std::string bytesToString(const std::vector< irsol::types::byte_t > &input)
Converts a std::vector of irsol::types::byte_t to a std::string.
std::string strip(const std::string &s, const std::string &delimiters=" \t\r\n")
Removes leading and trailing characters from a string.
int toInt(const irsol::types::protocol_value_t &x)
Converts a protocol value to an integer.
std::string stripString(const std::string &s, const std::string &strippedString)
Removes all occurrences of a specific substring from the start and end of a string.
std::string uuid()
Generates a new UUID string.
std::vector< std::string > split(const std::string &s, char delimiter)
Splits a string into tokens based on a delimiter.
std::vector< irsol::types::byte_t > stringToBytes(const std::string &s)
Converts a std::string to a std::vector of irsol::types::byte_t.
std::string toString(const irsol::types::protocol_value_t &x)
Converts a protocol value to a string.
std::string durationToString(irsol::types::duration_t dr)
Converts a duration to a human-readable string.
TEST_CASE("fromString<int>", "[Protocol][Protocol::Utils]")
std::vector< std::string > expected
CHECK(irsol::utils::toInt(protocolValue)==rawValue)
General utility functions used throughout the irsol library.