-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTestSink.hpp
67 lines (58 loc) · 1.62 KB
/
TestSink.hpp
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
// Copyright (c) Borislav Stanimirov
// SPDX-License-Identifier: MIT
//
#include <doctest/doctest.h>
#include <jalog/Sink.hpp>
#include <jalog/Entry.hpp>
#include "TestTime.hpp"
#include <string>
#include <cstdint>
#include <vector>
#include <algorithm>
class TestSink final : public jalog::Sink
{
public:
virtual void record(const jalog::Entry& entry) override
{
entries.emplace_back(entry);
}
struct EntryCopy
{
EntryCopy() = default;
EntryCopy(const jalog::Entry& e)
: scope(e.scope)
, level(e.level)
, timestamp(tonano(e.timestamp))
, text(e.text)
{}
jalog::ScopeDesc scope;
jalog::Level level;
uint64_t timestamp;
std::string text;
};
std::vector<EntryCopy> entries;
void checkSameEntries(const TestSink& other) const
{
auto& es0 = entries;
auto& es = other.entries;
CHECK(es0.size() == es.size());
for (size_t ei = 0; ei < es0.size(); ++ei)
{
auto& e0 = es0[ei];
auto& e = es[ei];
CHECK(&e0 != &e);
CHECK(e0.scope.label() == e.scope.label());
CHECK(e0.scope.id() == e.scope.id());
CHECK(e0.scope.userData == e.scope.userData);
CHECK(e0.level == e.level);
CHECK(e0.timestamp == e.timestamp);
CHECK(e0.text == e.text);
}
}
static void checkSortedEntries(const std::vector<EntryCopy>& es)
{
CHECK(std::is_sorted(es.begin(), es.end(), [](auto& a, auto& b) {
return a.timestamp < b.timestamp;
}));
}
};