diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-04-07 18:55:48 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-04-11 11:00:34 -0700 |
commit | 1c7c5af69df3edc19ba48697d350de087b9243cf (patch) | |
tree | c9538a61d974634db4aa6f3ae20d4ff9078ad75e /test | |
parent | c507b8a693d91dea1b0018f9105553128a245146 (diff) | |
download | qtlocation-mapboxgl-1c7c5af69df3edc19ba48697d350de087b9243cf.tar.gz |
[ios] Run core unit tests in CI
Diffstat (limited to 'test')
-rw-r--r-- | test/api/offline.cpp | 53 | ||||
-rw-r--r-- | test/include/mbgl/test.hpp | 7 | ||||
-rw-r--r-- | test/map/map.cpp | 45 | ||||
-rw-r--r-- | test/src/main.cpp | 7 | ||||
-rw-r--r-- | test/src/main.mm | 8 | ||||
-rw-r--r-- | test/src/mbgl/test/fixture_log_observer.cpp (renamed from test/src/fixture_log_observer.cpp) | 0 | ||||
-rw-r--r-- | test/src/mbgl/test/fixture_log_observer.hpp (renamed from test/include/mbgl/test/fixture_log_observer.hpp) | 0 | ||||
-rw-r--r-- | test/src/mbgl/test/mock_view.hpp (renamed from test/include/mbgl/test/mock_view.hpp) | 0 | ||||
-rw-r--r-- | test/src/mbgl/test/stub_file_source.cpp (renamed from test/src/stub_file_source.cpp) | 0 | ||||
-rw-r--r-- | test/src/mbgl/test/stub_file_source.hpp (renamed from test/include/mbgl/test/stub_file_source.hpp) | 0 | ||||
-rw-r--r-- | test/src/mbgl/test/stub_style_observer.hpp (renamed from test/include/mbgl/test/stub_style_observer.hpp) | 0 | ||||
-rw-r--r-- | test/src/mbgl/test/test.cpp | 11 | ||||
-rw-r--r-- | test/src/mbgl/test/util.cpp (renamed from test/src/util.cpp) | 0 | ||||
-rw-r--r-- | test/src/mbgl/test/util.hpp (renamed from test/include/mbgl/test/util.hpp) | 0 | ||||
-rw-r--r-- | test/test.gypi | 57 |
15 files changed, 100 insertions, 88 deletions
diff --git a/test/api/offline.cpp b/test/api/offline.cpp deleted file mode 100644 index fbbd9f12f3..0000000000 --- a/test/api/offline.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include <mbgl/test/util.hpp> - -#include <mbgl/platform/default/headless_display.hpp> -#include <mbgl/platform/default/headless_view.hpp> -#include <mbgl/storage/network_status.hpp> -#include <mbgl/storage/offline_database.hpp> -#include <mbgl/storage/default_file_source.hpp> - -#include <mbgl/platform/log.hpp> -#include <mbgl/util/work_request.hpp> -#include <mbgl/util/io.hpp> - -using namespace mbgl; -using namespace std::literals::chrono_literals; -using namespace std::literals::string_literals; - -namespace { - -Response expiredItem(const std::string& path) { - Response response; - response.data = std::make_shared<std::string>(util::read_file("test/fixtures/"s + path)); - response.expires = SystemClock::from_time_t(0); - return response; -} - -const std::string prefix = "http://127.0.0.1:3000"; - -} - -auto display = std::make_shared<mbgl::HeadlessDisplay>(); - -TEST(API, Offline) { - HeadlessView view(display, 1); - DefaultFileSource fileSource(":memory:", "."); - - fileSource.put(Resource::style(prefix + "/offline/style.json"), expiredItem("offline/style.json")); - fileSource.put(Resource::source(prefix + "/offline/streets.json"), expiredItem("offline/streets.json")); - fileSource.put(Resource::spriteJSON(prefix + "/offline/sprite", 1.0), expiredItem("offline/sprite.json")); - fileSource.put(Resource::spriteImage(prefix + "/offline/sprite", 1.0), expiredItem("offline/sprite.png")); - fileSource.put(Resource::tile(prefix + "/offline/{z}-{x}-{y}.vector.pbf", 1.0, 0, 0, 0), expiredItem("offline/0-0-0.vector.pbf")); - fileSource.put(Resource::glyphs(prefix + "/offline/{fontstack}/{range}.pbf", "Helvetica", {0, 255}), expiredItem("offline/glyph.pbf")); - NetworkStatus::Set(NetworkStatus::Status::Offline); - - Map map(view, fileSource, MapMode::Still); - map.setStyleURL(prefix + "/offline/style.json"); - - test::checkImage("test/fixtures/offline"s, - test::render(map), - 0.0015, - 0.1); - - NetworkStatus::Set(NetworkStatus::Status::Online); -} 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/map/map.cpp b/test/map/map.cpp index 68f7db3e7b..b1048e97e2 100644 --- a/test/map/map.cpp +++ b/test/map/map.cpp @@ -4,12 +4,15 @@ #include <mbgl/platform/default/headless_view.hpp> #include <mbgl/platform/default/headless_display.hpp> #include <mbgl/storage/online_file_source.hpp> +#include <mbgl/storage/network_status.hpp> +#include <mbgl/storage/offline_database.hpp> +#include <mbgl/storage/default_file_source.hpp> +#include <mbgl/util/io.hpp> using namespace mbgl; +using namespace std::literals::string_literals; TEST(Map, PauseResume) { - using namespace mbgl; - auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -21,8 +24,6 @@ TEST(Map, PauseResume) { } TEST(Map, DoublePause) { - using namespace mbgl; - auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -35,8 +36,6 @@ TEST(Map, DoublePause) { } TEST(Map, ResumeWithoutPause) { - using namespace mbgl; - auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -47,8 +46,6 @@ TEST(Map, ResumeWithoutPause) { } TEST(Map, DestroyPaused) { - using namespace mbgl; - auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -57,3 +54,35 @@ TEST(Map, DestroyPaused) { map.pause(); } + +TEST(Map, Offline) { + auto display = std::make_shared<mbgl::HeadlessDisplay>(); + HeadlessView view(display, 1); + DefaultFileSource fileSource(":memory:", "."); + + auto expiredItem = [] (const std::string& path) { + Response response; + response.data = std::make_shared<std::string>(util::read_file("test/fixtures/"s + path)); + response.expires = SystemClock::from_time_t(0); + return response; + }; + + const std::string prefix = "http://127.0.0.1:3000"; + fileSource.put(Resource::style(prefix + "/offline/style.json"), expiredItem("offline/style.json")); + fileSource.put(Resource::source(prefix + "/offline/streets.json"), expiredItem("offline/streets.json")); + fileSource.put(Resource::spriteJSON(prefix + "/offline/sprite", 1.0), expiredItem("offline/sprite.json")); + fileSource.put(Resource::spriteImage(prefix + "/offline/sprite", 1.0), expiredItem("offline/sprite.png")); + fileSource.put(Resource::tile(prefix + "/offline/{z}-{x}-{y}.vector.pbf", 1.0, 0, 0, 0), expiredItem("offline/0-0-0.vector.pbf")); + fileSource.put(Resource::glyphs(prefix + "/offline/{fontstack}/{range}.pbf", "Helvetica", {0, 255}), expiredItem("offline/glyph.pbf")); + NetworkStatus::Set(NetworkStatus::Status::Offline); + + Map map(view, fileSource, MapMode::Still); + map.setStyleURL(prefix + "/offline/style.json"); + + test::checkImage("test/fixtures/offline", + test::render(map), + 0.0015, + 0.1); + + NetworkStatus::Set(NetworkStatus::Status::Online); +} diff --git a/test/src/main.cpp b/test/src/main.cpp index f2d2944ec7..a481dc5dc3 100644 --- a/test/src/main.cpp +++ b/test/src/main.cpp @@ -1,6 +1,5 @@ -#include <mbgl/test/util.hpp> +#include <mbgl/test.hpp> -GTEST_API_ int main(int argc, char *argv[]) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char *argv[]) { + return mbgl::runTests(argc, argv); } diff --git a/test/src/main.mm b/test/src/main.mm index abfa62972b..12d5de4d5a 100644 --- a/test/src/main.mm +++ b/test/src/main.mm @@ -1,10 +1,8 @@ -#import <Foundation/Foundation.h> +#include <mbgl/test.hpp> -#include <mbgl/test/util.hpp> +#import <Foundation/Foundation.h> int main(int argc, char* argv[]) { [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] bundlePath]]; - - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return mbgl::runTests(argc, argv); } diff --git a/test/src/fixture_log_observer.cpp b/test/src/mbgl/test/fixture_log_observer.cpp index 302fdc7081..302fdc7081 100644 --- a/test/src/fixture_log_observer.cpp +++ b/test/src/mbgl/test/fixture_log_observer.cpp diff --git a/test/include/mbgl/test/fixture_log_observer.hpp b/test/src/mbgl/test/fixture_log_observer.hpp index f2ccb5cb58..f2ccb5cb58 100644 --- a/test/include/mbgl/test/fixture_log_observer.hpp +++ b/test/src/mbgl/test/fixture_log_observer.hpp diff --git a/test/include/mbgl/test/mock_view.hpp b/test/src/mbgl/test/mock_view.hpp index e608545da5..e608545da5 100644 --- a/test/include/mbgl/test/mock_view.hpp +++ b/test/src/mbgl/test/mock_view.hpp diff --git a/test/src/stub_file_source.cpp b/test/src/mbgl/test/stub_file_source.cpp index 89ccb3b335..89ccb3b335 100644 --- a/test/src/stub_file_source.cpp +++ b/test/src/mbgl/test/stub_file_source.cpp diff --git a/test/include/mbgl/test/stub_file_source.hpp b/test/src/mbgl/test/stub_file_source.hpp index 477f72ed42..477f72ed42 100644 --- a/test/include/mbgl/test/stub_file_source.hpp +++ b/test/src/mbgl/test/stub_file_source.hpp diff --git a/test/include/mbgl/test/stub_style_observer.hpp b/test/src/mbgl/test/stub_style_observer.hpp index 7236ca74f5..7236ca74f5 100644 --- a/test/include/mbgl/test/stub_style_observer.hpp +++ b/test/src/mbgl/test/stub_style_observer.hpp diff --git a/test/src/mbgl/test/test.cpp b/test/src/mbgl/test/test.cpp new file mode 100644 index 0000000000..cbc6cfb102 --- /dev/null +++ b/test/src/mbgl/test/test.cpp @@ -0,0 +1,11 @@ +#include <mbgl/test.hpp> +#include <gtest/gtest.h> + +namespace mbgl { + +int runTests(int argc, char *argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +} diff --git a/test/src/util.cpp b/test/src/mbgl/test/util.cpp index ca2282a4b5..ca2282a4b5 100644 --- a/test/src/util.cpp +++ b/test/src/mbgl/test/util.cpp diff --git a/test/include/mbgl/test/util.hpp b/test/src/mbgl/test/util.hpp index f778679cb8..f778679cb8 100644 --- a/test/include/mbgl/test/util.hpp +++ b/test/src/mbgl/test/util.hpp diff --git a/test/test.gypi b/test/test.gypi index 782d98e43f..42dab6432c 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -1,31 +1,20 @@ { 'targets': [ { - 'target_name': 'test', - 'type': 'executable', + 'target_name': 'test-lib', + 'type': 'static_library', + 'standalone_static_library': 1, + 'hard_dependency': 1, 'include_dirs': [ '../include', '../src', '../platform/default', 'include', - ], - - 'dependencies': [ - 'platform-lib', - 'copy_certificate_bundle', + 'src', ], 'sources': [ - # Test helper files - 'src/stub_file_source.cpp', - 'include/mbgl/test/stub_file_source.hpp', - 'include/mbgl/test/mock_view.hpp', - 'include/mbgl/test/util.hpp', - 'src/util.cpp', - 'include/mbgl/test/fixture_log_observer.hpp', - 'src/fixture_log_observer.cpp', - 'util/assert.cpp', 'util/async_task.cpp', 'util/clip_ids.cpp', @@ -49,7 +38,6 @@ 'api/render_missing.cpp', 'api/set_style.cpp', 'api/custom_layer.cpp', - 'api/offline.cpp', 'geometry/binpack.cpp', @@ -92,7 +80,14 @@ 'sprite/sprite_parser.cpp', 'sprite/sprite_store.cpp', - 'src/main.cpp', + 'src/mbgl/test/stub_file_source.hpp', + 'src/mbgl/test/stub_file_source.cpp', + 'src/mbgl/test/mock_view.hpp', + 'src/mbgl/test/util.hpp', + 'src/mbgl/test/util.cpp', + 'src/mbgl/test/fixture_log_observer.hpp', + 'src/mbgl/test/fixture_log_observer.cpp', + 'src/mbgl/test/test.cpp' ], 'variables': { @@ -136,6 +131,32 @@ }] ], }, + + 'direct_dependent_settings': { + 'include_dirs': [ + 'include', + ], + + # Force the linker to include all the objects from the lib-test archive. Otherwise they'd + # be discarded because there are no undefined symbols to pull them in, and the resulting + # executable would run zero tests. + + 'conditions': [ + ['OS == "mac"', { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-Wl,-force_load,<(PRODUCT_DIR)/libtest-lib.a', + ], + } + }, { + 'link_settings': { + 'ldflags': [ + '-Wl,-whole-archive <(PRODUCT_DIR)/libtest-lib.a -Wl,-no-whole-archive', + ], + }, + }], + ], + }, }, ] } |