26#ifndef MYSQL_HARNESS_HELPERS_INCLUDED
27#define MYSQL_HARNESS_HELPERS_INCLUDED
36#include <gtest/gtest.h>
41std::ostream &
operator<<(std::ostream &out,
const std::vector<T> &v) {
43 for (
auto &&elem : v) out <<
" " << elem;
49std::ostream &
operator<<(std::ostream &out,
const std::list<T> &v) {
51 for (
auto &&elem : v) out <<
" " << elem;
56template <
typename A,
typename B>
57std::ostream &
operator<<(std::ostream &out,
const std::pair<A, B> &
p) {
58 return out <<
p.first <<
":" <<
p.second;
61template <
typename SeqCont1,
typename SeqCont2>
63 const char *seq2_expr,
65 const SeqCont2 &seq2) {
66 std::vector<typename SeqCont1::value_type> c1(seq1.begin(), seq1.end());
67 std::vector<typename SeqCont2::value_type> c2(seq2.begin(), seq2.end());
68 std::sort(c1.begin(), c1.end());
69 std::sort(c2.begin(), c2.end());
72 std::vector<typename SeqCont2::value_type> c1_not_c2;
73 std::set_difference(c1.begin(), c1.end(), c2.begin(), c2.end(),
74 std::back_inserter(c1_not_c2));
75 if (c1_not_c2.size() > 0) {
76 auto result = ::testing::AssertionFailure();
77 result << seq1_expr <<
" had elements not in " << seq2_expr <<
": ";
78 for (
auto elem : c1_not_c2)
result << elem <<
" ";
83 std::vector<typename SeqCont2::value_type> c2_not_c1;
84 std::set_difference(c2.begin(), c2.end(), c1.begin(), c1.end(),
85 std::back_inserter(c2_not_c1));
86 if (c2_not_c1.size() > 0) {
87 auto result = ::testing::AssertionFailure();
88 result << seq2_expr <<
" had elements not in " << seq1_expr <<
": ";
89 for (
auto elem : c2_not_c1)
result << elem <<
" ";
93 return ::testing::AssertionSuccess();
96#define EXPECT_SETEQ(S1, S2) EXPECT_PRED_FORMAT2(AssertSetEqual, S1, S2)
99 const char *loader_expr,
const char *section_expr,
102#define EXPECT_SECTION_AVAILABLE(S, L) \
103 EXPECT_PRED_FORMAT2(AssertLoaderSectionAvailable, L, S)
119void init_test_logger(
const std::list<std::string> &additional_log_domains = {},
120 const std::string &log_folder =
"",
static Mysys_charset_loader * loader
Definition: charset.cc:185
const char * p
Definition: ctype-mb.cc:1235
void init_test_logger(const std::list< std::string > &additional_log_domains={}, const std::string &log_folder="", const std::string &log_filename="")
Register + init logger for unit tests.
Definition: test_helpers.cc:68
void register_test_logger()
Just register logger with DIM for unit tests (unlike init_log(), which also initializes it)
Definition: test_helpers.cc:57
::testing::AssertionResult AssertLoaderSectionAvailable(const char *loader_expr, const char *section_expr, mysql_harness::Loader *loader, const std::string §ion_name)
Definition: test_helpers.cc:32
std::ostream & operator<<(std::ostream &out, const std::vector< T > &v)
Definition: helpers.h:41
::testing::AssertionResult AssertSetEqual(const char *seq1_expr, const char *seq2_expr, const SeqCont1 &seq1, const SeqCont2 &seq2)
Definition: helpers.h:62
static const char * log_filename
Definition: myisamlog.cc:97
struct result result
Definition: result.h:34