[test] rearrange test files so they're not in the fixtures folder
This commit is contained in:
committed by
John Firebaugh
parent
61920071cd
commit
db5ac4785f
71
test/include/mbgl/test/fixture_log_observer.hpp
Normal file
71
test/include/mbgl/test/fixture_log_observer.hpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef MBGL_TEST_FIXTURE_LOG_OBSERVER
|
||||
#define MBGL_TEST_FIXTURE_LOG_OBSERVER
|
||||
|
||||
#include <mbgl/platform/log.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <cstdarg>
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class FixtureLog {
|
||||
public:
|
||||
struct Message {
|
||||
Message(EventSeverity severity_, Event event_, int64_t code_, const std::string &msg_);
|
||||
Message();
|
||||
|
||||
bool operator==(const Message& rhs) const;
|
||||
|
||||
const EventSeverity severity;
|
||||
const Event event;
|
||||
const int64_t code;
|
||||
const std::string msg;
|
||||
|
||||
mutable bool checked = false;
|
||||
};
|
||||
|
||||
class Observer : public Log::Observer {
|
||||
public:
|
||||
using LogMessage = Message;
|
||||
|
||||
Observer(FixtureLog* log = nullptr);
|
||||
~Observer();
|
||||
|
||||
// Log::Observer implementation
|
||||
virtual bool onRecord(EventSeverity severity,
|
||||
Event event,
|
||||
int64_t code,
|
||||
const std::string& msg) override;
|
||||
|
||||
bool empty() const;
|
||||
size_t count(const Message& message) const;
|
||||
std::vector<Message> unchecked() const;
|
||||
|
||||
private:
|
||||
FixtureLog* log;
|
||||
std::vector<Message> messages;
|
||||
mutable std::mutex messagesMutex;
|
||||
};
|
||||
|
||||
FixtureLog();
|
||||
|
||||
bool empty() const;
|
||||
size_t count(const Message& message) const;
|
||||
|
||||
~FixtureLog();
|
||||
|
||||
private:
|
||||
Observer* observer;
|
||||
};
|
||||
|
||||
::std::ostream &operator<<(::std::ostream &os,
|
||||
const std::vector<FixtureLog::Observer::LogMessage> &messages);
|
||||
::std::ostream &operator<<(::std::ostream &os, const FixtureLog::Observer::LogMessage &message);
|
||||
|
||||
using FixtureLogObserver = FixtureLog::Observer;
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
#endif
|
||||
29
test/include/mbgl/test/mock_view.hpp
Normal file
29
test/include/mbgl/test/mock_view.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef TEST_FIXTURES_MOCK_VIEW
|
||||
#define TEST_FIXTURES_MOCK_VIEW
|
||||
|
||||
#include <mbgl/map/view.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class MockView : public View {
|
||||
public:
|
||||
MockView() = default;
|
||||
|
||||
// View implementation.
|
||||
float getPixelRatio() const override { return 1; }
|
||||
std::array<uint16_t, 2> getSize() const override { return {{ 0, 0 }}; }
|
||||
std::array<uint16_t, 2> getFramebufferSize() const override { return {{ 0, 0 }}; }
|
||||
|
||||
void activate() override {};
|
||||
void deactivate() override {};
|
||||
void notify() override {};
|
||||
void invalidate() override {}
|
||||
void beforeRender() override {}
|
||||
void afterRender() override {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
45
test/include/mbgl/test/stub_file_source.hpp
Normal file
45
test/include/mbgl/test/stub_file_source.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef TEST_RESOURCES_STUB_FILE_SOURCE
|
||||
#define TEST_RESOURCES_STUB_FILE_SOURCE
|
||||
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/util/timer.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class StubFileSource : public FileSource {
|
||||
public:
|
||||
StubFileSource();
|
||||
~StubFileSource() override;
|
||||
|
||||
std::unique_ptr<FileRequest> request(const Resource&, Callback) override;
|
||||
|
||||
using ResponseFunction = std::function<optional<Response> (const Resource&)>;
|
||||
|
||||
// You can set the response callback on a global level by assigning this callback:
|
||||
ResponseFunction response = [this] (const Resource& resource) {
|
||||
return defaultResponse(resource);
|
||||
};
|
||||
|
||||
// Or set per-kind responses by setting these callbacks:
|
||||
ResponseFunction styleResponse;
|
||||
ResponseFunction sourceResponse;
|
||||
ResponseFunction tileResponse;
|
||||
ResponseFunction glyphsResponse;
|
||||
ResponseFunction spriteJSONResponse;
|
||||
ResponseFunction spriteImageResponse;
|
||||
|
||||
private:
|
||||
friend class StubFileRequest;
|
||||
|
||||
// The default behavior is to throw if no per-kind callback has been set.
|
||||
optional<Response> defaultResponse(const Resource&);
|
||||
|
||||
std::unordered_map<FileRequest*, std::tuple<Resource, ResponseFunction, Callback>> pending;
|
||||
util::Timer timer;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
67
test/include/mbgl/test/stub_style_observer.hpp
Normal file
67
test/include/mbgl/test/stub_style_observer.hpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef MBGL_TEST_STUB_STYLE_OBSERVER
|
||||
#define MBGL_TEST_STUB_STYLE_OBSERVER
|
||||
|
||||
#include <mbgl/style/style.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
/**
|
||||
* An implementation of Style::Observer that forwards all methods to dynamically-settable lambas.
|
||||
*/
|
||||
class StubStyleObserver : public Style::Observer {
|
||||
public:
|
||||
void onGlyphsLoaded(const std::string& fontStack, const GlyphRange& glyphRange) override {
|
||||
if (glyphsLoaded) glyphsLoaded(fontStack, glyphRange);
|
||||
}
|
||||
|
||||
void onGlyphsError(const std::string& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) override {
|
||||
if (glyphsError) glyphsError(fontStack, glyphRange, error);
|
||||
}
|
||||
|
||||
void onSpriteLoaded() override {
|
||||
if (spriteLoaded) spriteLoaded();
|
||||
}
|
||||
|
||||
void onSpriteError(std::exception_ptr error) override {
|
||||
if (spriteError) spriteError(error);
|
||||
}
|
||||
|
||||
void onSourceLoaded(Source& source) override {
|
||||
if (sourceLoaded) sourceLoaded(source);
|
||||
}
|
||||
|
||||
void onSourceError(Source& source, std::exception_ptr error) override {
|
||||
if (sourceError) sourceError(source, error);
|
||||
}
|
||||
|
||||
void onTileLoaded(Source& source, const TileID& tileID, bool isNewTile) override {
|
||||
if (tileLoaded) tileLoaded(source, tileID, isNewTile);
|
||||
}
|
||||
|
||||
void onTileError(Source& source, const TileID& tileID, std::exception_ptr error) override {
|
||||
if (tileError) tileError(source, tileID, error);
|
||||
}
|
||||
|
||||
void onResourceLoaded() override {
|
||||
if (resourceLoaded) resourceLoaded();
|
||||
};
|
||||
|
||||
void onResourceError(std::exception_ptr error) override {
|
||||
if (resourceError) resourceError(error);
|
||||
};
|
||||
|
||||
std::function<void (const std::string& fontStack, const GlyphRange&)> glyphsLoaded;
|
||||
std::function<void (const std::string& fontStack, const GlyphRange&, std::exception_ptr)> glyphsError;
|
||||
std::function<void ()> spriteLoaded;
|
||||
std::function<void (std::exception_ptr)> spriteError;
|
||||
std::function<void (Source&)> sourceLoaded;
|
||||
std::function<void (Source&, std::exception_ptr)> sourceError;
|
||||
std::function<void (Source&, const TileID&, bool isNewTile)> tileLoaded;
|
||||
std::function<void (Source&, const TileID&, std::exception_ptr)> tileError;
|
||||
std::function<void ()> resourceLoaded;
|
||||
std::function<void (std::exception_ptr)> resourceError;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
#endif
|
||||
44
test/include/mbgl/test/util.hpp
Normal file
44
test/include/mbgl/test/util.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef MBGL_TEST_UTIL
|
||||
#define MBGL_TEST_UTIL
|
||||
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define SCOPED_TEST(name) \
|
||||
static class name { \
|
||||
bool completed = false; \
|
||||
public: \
|
||||
void finish() { EXPECT_FALSE(completed) << #name " was already completed."; completed = true; } \
|
||||
~name() { if (!completed) ADD_FAILURE() << #name " didn't complete."; } \
|
||||
} name;
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class Map;
|
||||
|
||||
namespace test {
|
||||
|
||||
class Server {
|
||||
public:
|
||||
Server(const char* executable);
|
||||
~Server();
|
||||
|
||||
private:
|
||||
int fd = -1;
|
||||
};
|
||||
|
||||
PremultipliedImage render(Map&);
|
||||
|
||||
void checkImage(const std::string& base,
|
||||
const PremultipliedImage& actual,
|
||||
double imageThreshold = 0,
|
||||
double pixelThreshold = 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user