5#ifdef CPP_UTILITIES_HAS_OPENSSL_CRYPTO
17#include "resources/version.h"
19#include <cppunit/TestFixture.h>
20#include <cppunit/extensions/HelperMacros.h>
27using namespace CPPUNIT_NS;
30#if CPP_UTILITIES_VERSION_CHECK(5, 2, 1) > CPP_UTILITIES_VERSION_CHECK(6, 0, 0)
31#error "Check for major version doesn't work"
33#if CPP_UTILITIES_VERSION_CHECK(5, 2, 2) > CPP_UTILITIES_VERSION_CHECK(5, 3, 0)
34#error "Check for minor version doesn't work"
36#if CPP_UTILITIES_VERSION_CHECK(5, 2, 1) > CPP_UTILITIES_VERSION_CHECK(5, 2, 2)
37#error "Check for path version doesn't work"
39#if CPP_UTILITIES_VERSION < CPP_UTILITIES_VERSION_CHECK(5, 0, 0)
40#error "Library version seems wrongly defined, should be already >= 5.0.0"
51#ifdef CPP_UTILITIES_HAS_OPENSSL_CRYPTO
52 CPPUNIT_TEST(testVerification);
54 CPPUNIT_TEST_SUITE_END();
67#ifdef CPP_UTILITIES_HAS_OPENSSL_CRYPTO
68 void testVerification();
77 static_assert(
decltype(
makeMultiArray<char>(3, 2))::dimensionCount() == 2,
"dimension count 2D");
78 static_assert(
decltype(
makeMultiArray<char>(3, 2, 3))::dimensionCount() == 3,
"dimension count 3D");
81 CPPUNIT_ASSERT_EQUAL(3_st, array1d.dimensionSize<0>());
82 CPPUNIT_ASSERT_EQUAL(3_st, array1d.totalSize());
86 CPPUNIT_ASSERT_EQUAL(
"abc"s,
string(array1d.data(), 3));
89 CPPUNIT_ASSERT_EQUAL(3_st, array2d.dimensionSize<0>());
90 CPPUNIT_ASSERT_EQUAL(2_st, array2d.dimensionSize<1>());
91 CPPUNIT_ASSERT_EQUAL(6_st, array2d.totalSize());
92 const char *
const data(array2d.data());
93 array2d.at(0, 0) =
'a';
94 array2d.at(0, 1) =
'b';
95 array2d.at(1, 0) =
'c';
96 array2d.at(1, 1) =
'd';
97 array2d.at(2, 0) =
'e';
98 array2d.at(2, 1) =
'f';
99 CPPUNIT_ASSERT_EQUAL(
"abcdef"s,
string(data, 6));
102 CPPUNIT_ASSERT_EQUAL(3_st, array3d.dimensionSize<0>());
103 CPPUNIT_ASSERT_EQUAL(2_st, array3d.dimensionSize<1>());
104 CPPUNIT_ASSERT_EQUAL(3_st, array3d.dimensionSize<2>());
105 CPPUNIT_ASSERT_EQUAL(18_st, array3d.totalSize());
106 array3d.at(0, 0, 0) =
'a';
107 array3d.at(0, 0, 1) =
'b';
108 array3d.at(0, 0, 2) =
'c';
109 array3d.at(0, 1, 0) =
'd';
110 array3d.at(0, 1, 1) =
'e';
111 array3d.at(0, 1, 2) =
'f';
112 array3d.at(1, 0, 0) =
'g';
113 array3d.at(1, 0, 1) =
'h';
114 array3d.at(1, 0, 2) =
'i';
115 array3d.at(1, 1, 0) =
'j';
116 array3d.at(1, 1, 1) =
'k';
117 array3d.at(1, 1, 2) =
'l';
118 array3d.at(2, 0, 0) =
'm';
119 array3d.at(2, 0, 1) =
'n';
120 array3d.at(2, 0, 2) =
'o';
121 array3d.at(2, 1, 0) =
'p';
122 array3d.at(2, 1, 1) =
'q';
123 array3d.at(2, 1, 2) =
'r';
124 CPPUNIT_ASSERT_EQUAL(
"abcdefghijklmnopqr"s,
string(array3d.data(), 18));
127 CPPUNIT_ASSERT_EQUAL(3_st, stackMultiArray.dimensionSize<0>());
128 CPPUNIT_ASSERT_EQUAL(3_st, stackMultiArray.dimensionSize<1>());
129 CPPUNIT_ASSERT_EQUAL(9_st, stackMultiArray.totalSize());
130 stackMultiArray.at(0, 0) =
'a';
131 stackMultiArray.at(0, 1) =
'b';
132 stackMultiArray.at(0, 2) =
'c';
133 stackMultiArray.at(1, 0) =
'd';
134 stackMultiArray.at(1, 1) =
'e';
135 stackMultiArray.at(1, 2) =
'f';
136 stackMultiArray.at(2, 0) =
'g';
137 stackMultiArray.at(2, 1) =
'h';
138 stackMultiArray.at(2, 2) =
'i';
139 CPPUNIT_ASSERT_EQUAL(
"abcdefghi"s,
string(stackMultiArray.data(), 9));
169 const auto workingCopyPathForNestedTestFile =
workingCopyPath(
"subdir/nested-testfile.txt");
170 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"creation of subdirectories in working dir",
"some file\n"s,
readFile(workingCopyPathForNestedTestFile));
172 const auto workingCopyPathUnderDifferentNameForNestedTestFile =
workingCopyPathAs(
"subdir/nested-testfile.txt",
"subdir2/foo.txt");
174 CPPUNIT_ASSERT_GREATEREQUAL(2_st, splittedPath.size());
175 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"different subdir",
"subdir2"s, splittedPath[splittedPath.size() - 2]);
176 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"different file name",
"foo.txt"s, splittedPath[splittedPath.size() - 1]);
177 CPPUNIT_ASSERT_EQUAL_MESSAGE(
178 "creation of subdirectories in working dir",
"some file\n"s,
readFile(workingCopyPathUnderDifferentNameForNestedTestFile));
182 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"printing hex numbers",
"0x10"s, ss.str());
187#ifdef CPP_UTILITIES_HAS_OPENSSL_CRYPTO
188void MiscTests::testVerification()
190 const auto key = std::string_view(
191 R
"(-----BEGIN PUBLIC KEY-----
192MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQAWJAn1E7ZE5Q6H69oaV5sqCIppJdg
1934bXDan9dJv6GOg70/t7q2CvwcwUXhV4FvCZxCHo25+rWYINfqKU2Utul8koAx8tK
19459ohfOzI63I+CC76GfX41uRGU0P5i6hS7o/hgBLiVXqT0FgS2BMfmnLMUvUjqnI2
196-----END PUBLIC KEY-----)");
197 const auto signature = std::string_view(
198 R
"(-----BEGIN SIGNATURE-----
199MIGIAkIB+LB01DduBFMVs7Ea2McD7/kXpP0XktDNR7WpVgkOn4+/ilR8b8lpO9dd
200FGmxKj5UVr2GpcWX6I216PjaVL9tr5oCQgFMpvNjSgFQ/KFaE+0d+QCegr3V7Uz6
201sWB0iGdPa+oXbRish7HoNCU/k0lD3ffXaf8ueC78Zme9NFO18Ol+NWXJDA==
202-----END SIGNATURE-----)");
204 auto message = std::string(
"test message");
205 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"valid message", std::string(),
verifySignature(key, signature, message));
208 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"manipulate message",
"incorrect signature"s,
verifySignature(key, signature, message));
209 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"manipulate message",
"incorrect signature"s,
verifySignature(key, signature, message));
211 CPPUNIT_ASSERT_EQUAL_MESSAGE(
213 CPPUNIT_ASSERT_EQUAL_MESSAGE(
214 "verifySignature can be called with empty vector",
"no keys provided"s,
verifySignature(std::vector<std::string_view>(), signature, message));
The MiscTests class tests misc functions and classes (mainly of files contained by the misc directory...
void testTestUtilities()
Tests helper from TestUtilities namespace which aren't used in other tests anyways.
CPPUNIT_TEST_SUITE_REGISTRATION(ConversionTests)
#define CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(Namespace, EnumClassType)
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
Contains all utilities provided by the c++utilities library.
CPP_UTILITIES_EXPORT std::string readFile(const std::string &path, std::string::size_type maxSize=std::string::npos)
Reads all contents of the specified file in a single call.
CPP_UTILITIES_EXPORT std::string workingCopyPath(const std::string &relativeTestFilePath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
Convenience function to invoke TestApplication::workingCopyPath().
constexpr bool checkFlagEnum(FlagEnumClass flagVariable, FlagEnumClass flagsToCheck)
Returns whether the specified flagVariable has set all flags specified via flagsToCheck to true.
auto makeFixedSizeMultiArray(DimensionSizes... dimensionSizes)
Constructs a new N-dimensional array using a fixed size array as underlying container....
auto makeMultiArray(DimensionSizes... dimensionSizes)
Constructs a new N-dimensional array using an std::vector with std::allocator as underlying container...
std::string verifySignature(std::string_view publicKeyPem, std::string_view signaturePem, std::string_view data)
Verifies data with the specified public key publicKeyPem and signature signaturePem.
AsHexNumber< T > asHexNumber(const T &value)
Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or sim...
CPP_UTILITIES_EXPORT std::string workingCopyPathAs(const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
Convenience function to invoke TestApplication::workingCopyPathAs().
constexpr FlagEnumClass & modFlagEnum(FlagEnumClass &flagVariable, FlagEnumClass relevantFlags, bool value)
Sets the specified relevantFlags in the specified flagVariable to the specified value.
CPP_UTILITIES_EXPORT std::size_t computeDamerauLevenshteinDistance(const char *str1, std::size_t size1, const char *str2, std::size_t size2)
Container splitString(Detail::StringParamForContainer< Container > string, Detail::StringParamForContainer< Container > delimiter, EmptyPartsTreat emptyPartsRole=EmptyPartsTreat::Keep, int maxParts=-1)
Splits the given string at the specified delimiter.
constexpr bool testFlagEnumClass()
#define TESTUTILS_ASSERT_LIKE(message, expectedRegex, actualString)
Asserts whether the specified string matches the specified regex.