summaryrefslogtreecommitdiff
path: root/test/helpers.h
blob: 9596e124d064393bf3d9f7a038fec694ea88c080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef MYGRATE_TEST_HELPERS_H
#define MYGRATE_TEST_HELPERS_H

#include <concepts>
#include <cstddef>
#include <cstdio>
#include <ctime>
#include <eventCounter.h>
#include <iostream>
#include <memory>
#include <optional>

inline constexpr std::byte operator""_b(const unsigned long long hex)
{
	return std::byte(hex);
}

inline constexpr bool
operator==(const struct tm & a, const struct tm & b)
{
	return (a.tm_year == b.tm_year) && (a.tm_mon == b.tm_mon) && (a.tm_mday == b.tm_mday) && (a.tm_hour == b.tm_hour)
			&& (a.tm_min == b.tm_min) && (a.tm_sec == b.tm_sec);
}

namespace std {
	template<integral T>
	inline constexpr bool
	operator!=(const byte b, const T i)
	{
		return to_integer<T>(b) != i;
	}

	template<typename T>
	ostream &
	operator<<(ostream & s, const std::optional<T> & o)
	{
		if (o) {
			return s << *o;
		}
		else {
			return s << "-";
		}
	}
}

inline struct tm
make_tm(int year, int mon, int day, int hr, int min, int sec)
{
	struct tm tm {
	};
	tm.tm_year = year - 1900;
	tm.tm_mon = mon - 1;
	tm.tm_mday = day;
	tm.tm_hour = hr;
	tm.tm_min = min;
	tm.tm_sec = sec;
	mktime(&tm);
	return tm;
}

struct MemStream {
	MemStream();
	virtual ~MemStream();

	void flush();

	char * out;
	size_t len;
	FILE * s;
};

class EventCounterTarget : public MyGrate::EventCounter {
public:
	EventCounterTarget & add(mariadb_rpl_event, unsigned long);
};

#endif