#include "include/buffer.h"
#include "include/encoding.h"
+#include <fmt/format.h>
#include "gtest/gtest.h"
using namespace std;
}
}
-const char* expected_what[] = {
- "void lame_decoder(int) no longer understand old encoding version 100 < 200: Malformed input",
- "void lame_decoder(int) decode past end of struct encoding: Malformed input"
-};
-
-void lame_decoder(int which) {
- switch (which) {
- case 0:
- throw buffer::malformed_input(DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, 100, 200));
- case 1:
- throw buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__));
- }
-}
-
TEST(EncodingException, Macros) {
- for (unsigned i = 0; i < std::size(expected_what); i++) {
+ const struct {
+ buffer::malformed_input exc;
+ std::string expected_what;
+ } tests[] = {
+ {
+ DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, 100, 200),
+ fmt::format("{} no longer understand old encoding version 100 < 200: Malformed input",
+ __PRETTY_FUNCTION__)
+ },
+ {
+ DECODE_ERR_PAST(__PRETTY_FUNCTION__),
+ fmt::format("{} decode past end of struct encoding: Malformed input",
+ __PRETTY_FUNCTION__)
+ }
+ };
+ for (auto& [exec, expected_what] : tests) {
try {
- lame_decoder(i);
+ throw exec;
} catch (const exception& e) {
- ASSERT_NE(string(e.what()).find(expected_what[i]), string::npos);
+ ASSERT_NE(string(e.what()).find(expected_what), string::npos);
}
}
}