summaryrefslogtreecommitdiff
path: root/render-test/runner.hpp
blob: 4f0db4f2f9a3edd661df068e1fc566c60413d9af (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
#pragma once

#include <mbgl/gfx/headless_frontend.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/storage/file_source.hpp>

#include "manifest_parser.hpp"

#include <memory>
#include <string>

class TestRunnerMapObserver;
struct TestMetadata;

class TestRunnerMapObserver : public mbgl::MapObserver {
public:
    TestRunnerMapObserver() = default;
    void onDidFailLoadingMap(mbgl::MapLoadError, const std::string&) override { mapLoadFailure = true; }

    void onDidFinishRenderingMap(RenderMode mode) override final {
        if (!finishRenderingMap) finishRenderingMap = mode == RenderMode::Full;
    }

    void onDidBecomeIdle() override final { idle = true; }

    void reset() {
        mapLoadFailure = false;
        finishRenderingMap = false;
        idle = false;
    }

    bool mapLoadFailure;
    bool finishRenderingMap;
    bool idle;
};

class TestRunner {
public:
    enum class UpdateResults { NO, DEFAULT, PLATFORM, METRICS, REBASELINE };

    TestRunner(Manifest, UpdateResults);
    void run(TestMetadata&);
    void reset();

    // Manifest
    const Manifest& getManifest() const;
    void doShuffle(uint32_t seed);

private:
    mbgl::HeadlessFrontend::RenderResult runTest(TestMetadata& metadata, TestContext& ctx);
    void checkQueryTestResults(mbgl::PremultipliedImage&& actualImage,
                               std::vector<mbgl::Feature>&& features,
                               TestMetadata&);
    void checkRenderTestResults(mbgl::PremultipliedImage&& image, TestMetadata&);
    void checkProbingResults(TestMetadata&);
    void appendLabelCutOffResults(TestMetadata&, const std::string&, const std::string&);
    void registerProxyFileSource();

    struct Impl {
        Impl(const TestMetadata&, const mbgl::ResourceOptions&);
        ~Impl();

        std::unique_ptr<TestRunnerMapObserver> observer;
        mbgl::HeadlessFrontend frontend;
        std::shared_ptr<mbgl::FileSource> fileSource;
        mbgl::Map map;
    };
    std::unordered_map<std::string, std::unique_ptr<Impl>> maps;
    Manifest manifest;
    UpdateResults updateResults;
};