summaryrefslogtreecommitdiff
path: root/test/fixtures/fixture_log.cpp
blob: c2c10fc9eb89ecc26980ace3da189bc3835c2214 (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
#include "fixture_log.hpp"

#include <iostream>

namespace mbgl {

FixtureLogBackend::~FixtureLogBackend() {
    std::cerr << unchecked();
}

size_t FixtureLogBackend::count(const LogMessage &message) const {
    size_t count = 0;
    for (const LogMessage &msg : messages) {
        if (msg == message) {
            count++;
            msg.checked = true;
        }
    }
    return count;
}

std::vector<FixtureLogBackend::LogMessage> FixtureLogBackend::unchecked() const {
    std::vector<LogMessage> unchecked;
    for (const LogMessage &msg : messages) {
        if (!msg.checked) {
            unchecked.push_back(msg);
            msg.checked = true;
        }
    }
    return unchecked;
}

::std::ostream& operator<<(::std::ostream& os, const std::vector<FixtureLogBackend::LogMessage>& messages) {
    for (const FixtureLogBackend::LogMessage &message : messages) {
        os << "- " << message;
    }
    return os;
}

::std::ostream& operator<<(::std::ostream& os, const FixtureLogBackend::LogMessage& message) {
    os << "[\"" << message.severity.get() << "\", \"" << message.event.get() << "\"";
    if (message.code) os << ", " << message.code.get();
    if (message.msg) os << ", \"" << message.msg.get() << "\"";
    return os << "]" << std::endl;
}

}