summaryrefslogtreecommitdiff
path: root/test/include/mbgl/test/util.hpp
blob: 959b3e646f4e97ad40dda16d804ec4766d1b823a (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
78
79
80
81
82
#pragma once

#ifdef __APPLE__
#include <TargetConditionals.h>
#endif

#if ANDROID
    #define TEST_READ_ONLY 0
#elif TARGET_OS_IOS
    #define TEST_READ_ONLY 1
    #undef TEST_HAS_SERVER
    #define TEST_HAS_SERVER 0
#else
    #define TEST_READ_ONLY 0
    #ifndef TEST_HAS_SERVER
        #define TEST_HAS_SERVER 1
    #endif
#endif

#if TARGET_OS_SIMULATOR
    #define TEST_IS_SIMULATOR 1
#else
    #define TEST_IS_SIMULATOR 0
#endif

#if !TEST_IS_SIMULATOR && !CI_BUILD
#define TEST_REQUIRES_ACCURATE_TIMING(name) name
#else
#define TEST_REQUIRES_ACCURATE_TIMING(name) DISABLED_ ## name
#endif

#if !TEST_READ_ONLY
#define TEST_REQUIRES_WRITE(name) name
#else
#define TEST_REQUIRES_WRITE(name) DISABLED_ ## name
#endif

#if TEST_HAS_SERVER
#define TEST_REQUIRES_SERVER(name) name
#else
#define TEST_REQUIRES_SERVER(name) DISABLED_ ## name
#endif

#if !CI_BUILD
#define TEST_DISABLED_ON_CI(name) name
#else
#define TEST_DISABLED_ON_CI(name) DISABLED_ ## name
#endif

#include <mbgl/util/image.hpp>
#include <mbgl/util/chrono.hpp>

#include <cstdint>
#include <memory>
#include <thread>

#include <gtest/gtest.h>

namespace httplib {
class Server;
}

namespace mbgl {
namespace test {

class HttpServer {
public:
    HttpServer();
    ~HttpServer();

private:
    std::unique_ptr<httplib::Server> server;
    std::thread serverThread;
};

void checkImage(const std::string& base,
                const PremultipliedImage& actual,
                double imageThreshold = 0,
                double pixelThreshold = 0);

} // namespace test
} // namespace mbgl