summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2015-06-03 19:20:41 -0400
committerAnsis Brammanis <brammanis@gmail.com>2015-06-03 19:20:41 -0400
commit9c03b396c0a36af28cbaf490c75850af18f780d2 (patch)
tree5c4d94933a2d12df30d1ce1af6eb87d27e024402 /test
parent2bd7e4550296ce5f58abef93667bb92464317dc9 (diff)
parent295dc73c1af288c85e75a4fcaccdd9cb1580afd2 (diff)
downloadqtlocation-mapboxgl-9c03b396c0a36af28cbaf490c75850af18f780d2.tar.gz
Merge remote-tracking branch 'origin/master' into HEAD
Conflicts: src/mbgl/renderer/painter_fill.cpp
Diffstat (limited to 'test')
-rw-r--r--test/ios/MetricsTests.m21
-rw-r--r--test/ios/ios-tests.xcodeproj/xcshareddata/xcschemes/Mapbox GL Tests.xcscheme9
-rw-r--r--test/miscellaneous/style_parser.cpp28
-rw-r--r--test/style/mock_file_source.cpp (renamed from test/resources/mock_file_source.cpp)0
-rw-r--r--test/style/mock_file_source.hpp (renamed from test/resources/mock_file_source.hpp)0
-rw-r--r--test/style/mock_view.hpp (renamed from test/resources/mock_view.hpp)0
-rw-r--r--test/style/resource_loading.cpp (renamed from test/resources/resource_loader.cpp)70
-rw-r--r--test/test.gypi10
8 files changed, 55 insertions, 83 deletions
diff --git a/test/ios/MetricsTests.m b/test/ios/MetricsTests.m
index 758cf1f5be..7c71ee6739 100644
--- a/test/ios/MetricsTests.m
+++ b/test/ios/MetricsTests.m
@@ -8,6 +8,9 @@
#import "MapboxGL.h"
#import "OHHTTPStubs.h"
+const NSUInteger MGLMaximumEventsPerFlush = 20;
+const NSTimeInterval MGLFlushInterval = 60;
+
@interface MGLMapboxEvents (Testing)
- (NSString *)appBundleId;
@@ -18,9 +21,6 @@
- (NSMutableArray *)eventQueue;
- (void)postEvents:(NSArray *)events;
- (NSTimer *)timer;
-- (NSUInteger)flushAt;
-- (NSTimeInterval)flushAfter;
-- (void)setFlushAfter:(NSTimeInterval)newFlushAfter;
- (void)flush;
- (void)startTimer;
@@ -28,15 +28,12 @@
@interface MetricsTests : KIFTestCase
-@property (nonatomic) NSTimeInterval defaultFlushAfter;
-
@end
@implementation MetricsTests
- (void)beforeAll {
[tester acknowledgeSystemAlert];
- self.defaultFlushAfter = [[MGLMapboxEvents sharedManager] flushAfter];
}
- (void)beforeEach {
@@ -44,8 +41,6 @@
[MGLMapboxEvents resumeMetricsCollection];
[MGLAccountManager setAccessToken:@"pk.eyJ1IjoianVzdGluIiwiYSI6IlpDbUJLSUEifQ.4mG8vhelFMju6HpIY-Hi5A"];
-
- [[MGLMapboxEvents sharedManager] setFlushAfter:self.defaultFlushAfter];
}
- (void)afterEach {
@@ -76,7 +71,6 @@
- (void)testFlushAtThreshold {
NSUInteger startCount = [[[MGLMapboxEvents sharedManager] eventQueue] count];
- NSUInteger flushAt = [[MGLMapboxEvents sharedManager] flushAt];
XCTestExpectation *queueItemsExpectation = [self expectationWithDescription:@"queue should contain events"];
@@ -89,7 +83,7 @@
}
});
- for (NSUInteger i = 0; i < (flushAt - startCount - 1); i++) {
+ for (NSUInteger i = 0; i < (MGLMaximumEventsPerFlush - startCount - 1); i++) {
[self pushFakeEvent];
}
@@ -146,8 +140,6 @@
[self waitForExpectationsWithTimeout:1.0 handler:nil];
- [[MGLMapboxEvents sharedManager] setFlushAfter:5];
-
id eventsMock = [OCMockObject partialMockForObject:[MGLMapboxEvents sharedManager]];
[[[eventsMock expect] andForwardToRealObject] startTimer];
[self pushFakeEvent];
@@ -155,7 +147,7 @@
XCTAssertEqual([[[MGLMapboxEvents sharedManager] eventQueue] count], 1);
XCTAssertNotNil([[MGLMapboxEvents sharedManager] timer]);
- XCTAssertEqual([[MGLMapboxEvents sharedManager] flushAfter], [[[MGLMapboxEvents sharedManager] timer] timeInterval]);
+ XCTAssertEqual(MGLFlushInterval, [[[MGLMapboxEvents sharedManager] timer] timeInterval]);
}
- (void)testTimerFiresFlush {
@@ -174,11 +166,10 @@
[self waitForExpectationsWithTimeout:1.0 handler:nil];
- [[MGLMapboxEvents sharedManager] setFlushAfter:5];
[self pushFakeEvent];
id eventsMock = [OCMockObject partialMockForObject:[MGLMapboxEvents sharedManager]];
[[eventsMock expect] flush];
- [eventsMock verifyWithDelay:[[MGLMapboxEvents sharedManager] flushAfter]];
+ [eventsMock verifyWithDelay:MGLFlushInterval];
}
- (void)testFlushPostsEvents {
diff --git a/test/ios/ios-tests.xcodeproj/xcshareddata/xcschemes/Mapbox GL Tests.xcscheme b/test/ios/ios-tests.xcodeproj/xcshareddata/xcschemes/Mapbox GL Tests.xcscheme
index 911f949fa0..0008282f89 100644
--- a/test/ios/ios-tests.xcodeproj/xcshareddata/xcschemes/Mapbox GL Tests.xcscheme
+++ b/test/ios/ios-tests.xcodeproj/xcshareddata/xcschemes/Mapbox GL Tests.xcscheme
@@ -55,6 +55,15 @@
<Test
Identifier = "MapViewTests/testDelegateRegionWillChange">
</Test>
+ <Test
+ Identifier = "MetricsTests/testFlushPostsEvents">
+ </Test>
+ <Test
+ Identifier = "MetricsTests/testPostEventsNetworkRequest">
+ </Test>
+ <Test
+ Identifier = "MetricsTests/testTimerFiresFlush">
+ </Test>
</SkippedTests>
</TestableReference>
</Testables>
diff --git a/test/miscellaneous/style_parser.cpp b/test/miscellaneous/style_parser.cpp
index f5b9bb7e63..7a38ba054d 100644
--- a/test/miscellaneous/style_parser.cpp
+++ b/test/miscellaneous/style_parser.cpp
@@ -1,6 +1,6 @@
#include "../fixtures/util.hpp"
-#include <mbgl/style/style.hpp>
+#include <mbgl/style/style_parser.hpp>
#include <mbgl/util/io.hpp>
#include <rapidjson/document.h>
@@ -22,27 +22,23 @@ class StyleParserTest : public ::testing::TestWithParam<std::string> {};
TEST_P(StyleParserTest, ParseStyle) {
const std::string &base = "test/fixtures/style_parser/" + GetParam();
- const std::string style_path = base + ".style.json";
- const std::string info = util::read_file(base + ".info.json");
+ rapidjson::Document infoDoc;
+ infoDoc.Parse<0>(util::read_file(base + ".info.json").c_str());
+ ASSERT_FALSE(infoDoc.HasParseError());
+ ASSERT_TRUE(infoDoc.IsObject());
- // Parse settings.
- rapidjson::Document doc;
- doc.Parse<0>((const char *const)info.c_str());
- ASSERT_FALSE(doc.HasParseError());
- ASSERT_TRUE(doc.IsObject());
-
- std::ifstream stylefile(style_path);
- ASSERT_TRUE(stylefile.good());
- std::stringstream stylejson;
- stylejson << stylefile.rdbuf();
+ rapidjson::Document styleDoc;
+ styleDoc.Parse<0>(util::read_file(base + ".style.json").c_str());
+ ASSERT_FALSE(styleDoc.HasParseError());
+ ASSERT_TRUE(styleDoc.IsObject());
FixtureLogObserver* observer = new FixtureLogObserver();
Log::setObserver(std::unique_ptr<Log::Observer>(observer));
- Style style;
- style.loadJSON((const uint8_t *)stylejson.str().c_str());
+ StyleParser parser;
+ parser.parse(styleDoc);
- for (auto it = doc.MemberBegin(), end = doc.MemberEnd(); it != end; it++) {
+ for (auto it = infoDoc.MemberBegin(), end = infoDoc.MemberEnd(); it != end; it++) {
const std::string name { it->name.GetString(), it->name.GetStringLength() };
const rapidjson::Value &value = it->value;
ASSERT_EQ(true, value.IsObject());
diff --git a/test/resources/mock_file_source.cpp b/test/style/mock_file_source.cpp
index 42067a2a73..42067a2a73 100644
--- a/test/resources/mock_file_source.cpp
+++ b/test/style/mock_file_source.cpp
diff --git a/test/resources/mock_file_source.hpp b/test/style/mock_file_source.hpp
index bb9fb55a30..bb9fb55a30 100644
--- a/test/resources/mock_file_source.hpp
+++ b/test/style/mock_file_source.hpp
diff --git a/test/resources/mock_view.hpp b/test/style/mock_view.hpp
index 865cd2da55..865cd2da55 100644
--- a/test/resources/mock_view.hpp
+++ b/test/style/mock_view.hpp
diff --git a/test/resources/resource_loader.cpp b/test/style/resource_loading.cpp
index 7d57f47ee6..de3e6b812e 100644
--- a/test/resources/resource_loader.cpp
+++ b/test/style/resource_loading.cpp
@@ -3,14 +3,10 @@
#include "mock_file_source.hpp"
#include "mock_view.hpp"
-#include <mbgl/geometry/glyph_atlas.hpp>
-#include <mbgl/geometry/sprite_atlas.hpp>
#include <mbgl/map/environment.hpp>
#include <mbgl/map/map_data.hpp>
-#include <mbgl/map/resource_loader.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/style/style.hpp>
-#include <mbgl/text/glyph_store.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -21,7 +17,7 @@ using namespace mbgl;
namespace {
-class MockMapContext : public ResourceLoader::Observer {
+class MockMapContext : public Style::Observer {
public:
MockMapContext(uv_loop_t* loop,
View& view,
@@ -30,36 +26,19 @@ public:
: env_(fileSource),
envScope_(env_, ThreadType::Map, "Map"),
data_(view, MapMode::Still),
- glyphStore_(std::make_unique<GlyphStore>(loop, env_)),
- glyphAtlas_(std::make_unique<GlyphAtlas>(1024, 1024)),
- spriteAtlas_(std::make_unique<SpriteAtlas>(512, 512)),
- texturePool_(std::make_unique<TexturePool>()),
- style_(std::make_unique<Style>()),
- resourceLoader_(std::make_unique<ResourceLoader>()),
- asyncUpdate(std::make_unique<uv::async>(loop, [this] { update(); })),
callback_(callback) {
- asyncUpdate->unref();
data_.transform.resize(1000, 1000, 1.0, 1000, 1000);
data_.transform.setLatLngZoom({0, 0}, 16);
const std::string style = util::read_file("test/fixtures/resources/style.json");
- style_->loadJSON(reinterpret_cast<const uint8_t *>(style.c_str()));
-
- glyphStore_->setURL(style_->glyph_url);
-
- resourceLoader_->setGlyphStore(glyphStore_.get());
- resourceLoader_->setObserver(this);
- resourceLoader_->setStyle(style_.get());
+ style_ = std::make_unique<Style>(style, "", loop, env_),
+ style_->setObserver(this);
}
~MockMapContext() {
- resourceLoader_.reset();
style_.reset();
- texturePool_.reset();
- spriteAtlas_.reset();
- glyphAtlas_.reset();
- glyphStore_.reset();
+ env_.performCleanup();
}
void update() {
@@ -69,19 +48,16 @@ public:
data_.transform.updateTransitions(now);
transformState_ = data_.transform.currentState();
-
- resourceLoader_->update(
- data_, transformState_, *glyphAtlas_, *spriteAtlas_, *texturePool_);
+ style_->update(data_, transformState_, texturePool_);
}
- // ResourceLoader::Observer implementation.
+ // Style::Observer implementation.
void onTileDataChanged() override {
- util::ptr<Sprite> sprite = resourceLoader_->getSprite();
- if (sprite && sprite->isLoaded() && style_->isLoaded()) {
+ update();
+
+ if (style_->isLoaded()) {
callback_(nullptr);
}
-
- asyncUpdate->send();
};
void onResourceLoadingFailed(std::exception_ptr error) override {
@@ -94,15 +70,9 @@ private:
MapData data_;
TransformState transformState_;
+ TexturePool texturePool_;
- std::unique_ptr<GlyphStore> glyphStore_;
- std::unique_ptr<GlyphAtlas> glyphAtlas_;
- std::unique_ptr<SpriteAtlas> spriteAtlas_;
- std::unique_ptr<TexturePool> texturePool_;
std::unique_ptr<Style> style_;
- std::unique_ptr<ResourceLoader> resourceLoader_;
-
- std::unique_ptr<uv::async> asyncUpdate;
std::function<void(std::exception_ptr error)> callback_;
};
@@ -118,7 +88,13 @@ void runTestCase(MockFileSource::Type type,
FixtureLogObserver* log = new FixtureLogObserver();
Log::setObserver(std::unique_ptr<Log::Observer>(log));
- auto callback = [&loop, &param](std::exception_ptr error) {
+ auto callback = [type, &loop, &param](std::exception_ptr error) {
+ if (type == MockFileSource::Success) {
+ EXPECT_TRUE(error == nullptr);
+ } else {
+ EXPECT_TRUE(error != nullptr);
+ }
+
try {
if (error) {
std::rethrow_exception(error);
@@ -150,7 +126,7 @@ void runTestCase(MockFileSource::Type type,
const FixtureLogObserver::LogMessage logMessage {
EventSeverity::Error,
- Event::ResourceLoader,
+ Event::Style,
int64_t(-1),
message,
};
@@ -167,21 +143,21 @@ void runTestCase(MockFileSource::Type type,
}
-class ResourceLoaderTest : public ::testing::TestWithParam<std::string> {
+class ResourceLoading : public ::testing::TestWithParam<std::string> {
};
-TEST_P(ResourceLoaderTest, Success) {
+TEST_P(ResourceLoading, Success) {
runTestCase(MockFileSource::Success, GetParam(), std::string());
}
-TEST_P(ResourceLoaderTest, RequestFail) {
+TEST_P(ResourceLoading, RequestFail) {
std::stringstream message;
message << "Failed to load [test/fixtures/resources/" << GetParam() << "]: Failed by the test case";
runTestCase(MockFileSource::RequestFail, GetParam(), message.str());
}
-TEST_P(ResourceLoaderTest, RequestWithCorruptedData) {
+TEST_P(ResourceLoading, RequestWithCorruptedData) {
const std::string param(GetParam());
std::stringstream message;
@@ -200,5 +176,5 @@ TEST_P(ResourceLoaderTest, RequestWithCorruptedData) {
runTestCase(MockFileSource::RequestWithCorruptedData, GetParam(), message.str());
}
-INSTANTIATE_TEST_CASE_P(ResourceLoader, ResourceLoaderTest,
+INSTANTIATE_TEST_CASE_P(Style, ResourceLoading,
::testing::Values("source.json", "sprite.json", "sprite.png", "vector.pbf", "glyphs.pbf"));
diff --git a/test/test.gypi b/test/test.gypi
index 24582df992..0e14ac0835 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -58,11 +58,6 @@
'miscellaneous/variant.cpp',
'miscellaneous/worker.cpp',
- 'resources/mock_file_source.cpp',
- 'resources/mock_file_source.hpp',
- 'resources/mock_view.hpp',
- 'resources/resource_loader.cpp',
-
'storage/storage.hpp',
'storage/storage.cpp',
'storage/cache_response.cpp',
@@ -78,6 +73,11 @@
'storage/http_load.cpp',
'storage/http_other_loop.cpp',
'storage/http_reading.cpp',
+
+ 'style/mock_file_source.cpp',
+ 'style/mock_file_source.hpp',
+ 'style/mock_view.hpp',
+ 'style/resource_loading.cpp',
],
'libraries': [
'<@(uv_static_libs)',