summaryrefslogtreecommitdiff
path: root/test/include
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-04-07 18:55:48 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-04-11 11:00:34 -0700
commit1c7c5af69df3edc19ba48697d350de087b9243cf (patch)
treec9538a61d974634db4aa6f3ae20d4ff9078ad75e /test/include
parentc507b8a693d91dea1b0018f9105553128a245146 (diff)
downloadqtlocation-mapboxgl-1c7c5af69df3edc19ba48697d350de087b9243cf.tar.gz
[ios] Run core unit tests in CI
Diffstat (limited to 'test/include')
-rw-r--r--test/include/mbgl/test.hpp7
-rw-r--r--test/include/mbgl/test/fixture_log_observer.hpp71
-rw-r--r--test/include/mbgl/test/mock_view.hpp29
-rw-r--r--test/include/mbgl/test/stub_file_source.hpp45
-rw-r--r--test/include/mbgl/test/stub_style_observer.hpp67
-rw-r--r--test/include/mbgl/test/util.hpp80
6 files changed, 7 insertions, 292 deletions
diff --git a/test/include/mbgl/test.hpp b/test/include/mbgl/test.hpp
new file mode 100644
index 0000000000..e398174ef7
--- /dev/null
+++ b/test/include/mbgl/test.hpp
@@ -0,0 +1,7 @@
+#pragma once
+
+namespace mbgl {
+
+int runTests(int argc, char* argv[]);
+
+}
diff --git a/test/include/mbgl/test/fixture_log_observer.hpp b/test/include/mbgl/test/fixture_log_observer.hpp
deleted file mode 100644
index f2ccb5cb58..0000000000
--- a/test/include/mbgl/test/fixture_log_observer.hpp
+++ /dev/null
@@ -1,71 +0,0 @@
-#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
diff --git a/test/include/mbgl/test/mock_view.hpp b/test/include/mbgl/test/mock_view.hpp
deleted file mode 100644
index e608545da5..0000000000
--- a/test/include/mbgl/test/mock_view.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#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
diff --git a/test/include/mbgl/test/stub_file_source.hpp b/test/include/mbgl/test/stub_file_source.hpp
deleted file mode 100644
index 477f72ed42..0000000000
--- a/test/include/mbgl/test/stub_file_source.hpp
+++ /dev/null
@@ -1,45 +0,0 @@
-#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<AsyncRequest> 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<AsyncRequest*, std::tuple<Resource, ResponseFunction, Callback>> pending;
- util::Timer timer;
-};
-
-}
-
-#endif
diff --git a/test/include/mbgl/test/stub_style_observer.hpp b/test/include/mbgl/test/stub_style_observer.hpp
deleted file mode 100644
index 7236ca74f5..0000000000
--- a/test/include/mbgl/test/stub_style_observer.hpp
+++ /dev/null
@@ -1,67 +0,0 @@
-#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
diff --git a/test/include/mbgl/test/util.hpp b/test/include/mbgl/test/util.hpp
deleted file mode 100644
index f778679cb8..0000000000
--- a/test/include/mbgl/test/util.hpp
+++ /dev/null
@@ -1,80 +0,0 @@
-#ifndef MBGL_TEST_UTIL
-#define MBGL_TEST_UTIL
-
-#ifdef __APPLE__
-#include <TargetConditionals.h>
-#endif
-
-#if TARGET_OS_IOS
-#define TEST_READ_ONLY 1
-#define TEST_HAS_SERVER 0
-#else
-#define TEST_READ_ONLY 0
-#define TEST_HAS_SERVER 1
-#endif
-
-#if TARGET_OS_SIMULATOR
-#define TEST_IS_SIMULATOR 1
-#else
-#define TEST_IS_SIMULATOR 0
-#endif
-
-#if !TEST_IS_SIMULATOR
-#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
-
-#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