diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-04-14 14:16:00 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-04-16 22:46:24 -0700 |
commit | be8f83770d0a86e15ff395958b970cd69ab9c2d7 (patch) | |
tree | 6ed8ce4f634ac0704b5f795c66aa0b70bdd1980c /platform/osx | |
parent | f791eb32b9ebe96845e87e5a6acd3ee46182c1d5 (diff) | |
download | qtlocation-mapboxgl-be8f83770d0a86e15ff395958b970cd69ab9c2d7.tar.gz |
[ios, osx] Shared test bundle
The iOS and OS X SDKs now share a non-UI test bundle. Moved the iOS UI test bundle into a uitest/ subdirectory and moved the OS X SDK tests into the darwin/ subdirectory.
Upgraded KIF to v3.4.2.
Diffstat (limited to 'platform/osx')
-rw-r--r-- | platform/osx/platform.gyp | 10 | ||||
-rw-r--r-- | platform/osx/test/MGLGeometryTests.mm | 58 | ||||
-rw-r--r-- | platform/osx/test/MGLOfflinePackTests.m | 40 | ||||
-rw-r--r-- | platform/osx/test/MGLOfflineRegionTests.m | 35 | ||||
-rw-r--r-- | platform/osx/test/MGLOfflineStorageTests.m | 126 | ||||
-rw-r--r-- | platform/osx/test/MGLStyleTests.mm | 29 |
6 files changed, 5 insertions, 293 deletions
diff --git a/platform/osx/platform.gyp b/platform/osx/platform.gyp index b5b12b70c1..a8c6ce0704 100644 --- a/platform/osx/platform.gyp +++ b/platform/osx/platform.gyp @@ -230,11 +230,11 @@ }, 'sources': [ - 'test/MGLGeometryTests.mm', - 'test/MGLOfflinePackTests.m', - 'test/MGLOfflineRegionTests.m', - 'test/MGLOfflineStorageTests.m', - 'test/MGLStyleTests.mm', + '../darwin/test/MGLGeometryTests.mm', + '../darwin/test/MGLOfflinePackTests.m', + '../darwin/test/MGLOfflineRegionTests.m', + '../darwin/test/MGLOfflineStorageTests.m', + '../darwin/test/MGLStyleTests.mm', ], 'include_dirs': [ diff --git a/platform/osx/test/MGLGeometryTests.mm b/platform/osx/test/MGLGeometryTests.mm deleted file mode 100644 index e6e7c4b45c..0000000000 --- a/platform/osx/test/MGLGeometryTests.mm +++ /dev/null @@ -1,58 +0,0 @@ -#import "../../darwin/src/MGLGeometry_Private.h" - -#pragma clang diagnostic ignored "-Wgnu-statement-expression" -#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" - -#import <XCTest/XCTest.h> - -@interface MGLGeometryTests : XCTestCase -@end - -@implementation MGLGeometryTests - -- (void)testCoordinateBoundsIsEmpty { - MGLCoordinateBounds emptyBounds = MGLCoordinateBoundsMake(CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 0)); - XCTAssertTrue(MGLCoordinateBoundsIsEmpty(emptyBounds)); - XCTAssertFalse(MGLCoordinateSpanEqualToCoordinateSpan(MGLCoordinateSpanZero, MGLCoordinateBoundsGetCoordinateSpan(emptyBounds))); -} - -- (void)testAngleConversions { - XCTAssertEqual(-180, MGLDegreesFromRadians(-M_PI)); - XCTAssertEqual(0, MGLDegreesFromRadians(0)); - XCTAssertEqual(45, MGLDegreesFromRadians(M_PI_4)); - XCTAssertEqual(90, MGLDegreesFromRadians(M_PI_2)); - XCTAssertEqual(180, MGLDegreesFromRadians(M_PI)); - XCTAssertEqual(360, MGLDegreesFromRadians(2 * M_PI)); - XCTAssertEqual(720, MGLDegreesFromRadians(4 * M_PI)); - - XCTAssertEqual(-360, MGLDegreesFromRadians(MGLRadiansFromDegrees(-360))); - XCTAssertEqual(-180, MGLDegreesFromRadians(MGLRadiansFromDegrees(-180))); - XCTAssertEqual(-90, MGLDegreesFromRadians(MGLRadiansFromDegrees(-90))); - XCTAssertEqual(-45, MGLDegreesFromRadians(MGLRadiansFromDegrees(-45))); - XCTAssertEqual(0, MGLDegreesFromRadians(MGLRadiansFromDegrees(0))); - XCTAssertEqual(45, MGLDegreesFromRadians(MGLRadiansFromDegrees(45))); - XCTAssertEqual(90, MGLDegreesFromRadians(MGLRadiansFromDegrees(90))); - XCTAssertEqual(180, MGLDegreesFromRadians(MGLRadiansFromDegrees(180))); - XCTAssertEqual(360, MGLDegreesFromRadians(MGLRadiansFromDegrees(360))); -} - -- (void)testAltitudeConversions { - CGSize tallSize = CGSizeMake(600, 1200); - CGSize midSize = CGSizeMake(600, 800); - CGSize shortSize = CGSizeMake(600, 400); - - XCTAssertEqualWithAccuracy(1800, MGLAltitudeForZoomLevel(MGLZoomLevelForAltitude(1800, 0, 0, midSize), 0, 0, midSize), 1); - XCTAssertLessThan(MGLZoomLevelForAltitude(1800, 0, 0, midSize), MGLZoomLevelForAltitude(1800, 0, 0, tallSize)); - XCTAssertGreaterThan(MGLZoomLevelForAltitude(1800, 0, 0, midSize), MGLZoomLevelForAltitude(1800, 0, 0, shortSize)); - - XCTAssertEqualWithAccuracy(0, MGLZoomLevelForAltitude(MGLAltitudeForZoomLevel(0, 0, 0, midSize), 0, 0, midSize), 3); - XCTAssertEqualWithAccuracy(18, MGLZoomLevelForAltitude(MGLAltitudeForZoomLevel(18, 0, 0, midSize), 0, 0, midSize), 3); - - XCTAssertEqualWithAccuracy(0, MGLZoomLevelForAltitude(MGLAltitudeForZoomLevel(0, 0, 40, midSize), 0, 40, midSize), 3); - XCTAssertEqualWithAccuracy(18, MGLZoomLevelForAltitude(MGLAltitudeForZoomLevel(18, 0, 40, midSize), 0, 40, midSize), 3); - - XCTAssertEqualWithAccuracy(0, MGLZoomLevelForAltitude(MGLAltitudeForZoomLevel(0, 60, 40, midSize), 60, 40, midSize), 3); - XCTAssertEqualWithAccuracy(18, MGLZoomLevelForAltitude(MGLAltitudeForZoomLevel(18, 60, 40, midSize), 60, 40, midSize), 3); -} - -@end diff --git a/platform/osx/test/MGLOfflinePackTests.m b/platform/osx/test/MGLOfflinePackTests.m deleted file mode 100644 index 41262d16c7..0000000000 --- a/platform/osx/test/MGLOfflinePackTests.m +++ /dev/null @@ -1,40 +0,0 @@ -#import <Mapbox/Mapbox.h> - -#pragma clang diagnostic ignored "-Wgnu-statement-expression" -#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" - -#import <XCTest/XCTest.h> - -@interface MGLOfflinePackTests : XCTestCase - -@end - -@implementation MGLOfflinePackTests - -- (void)testInvalidation { - MGLOfflinePack *invalidPack = [[MGLOfflinePack alloc] init]; - - XCTAssertEqual(invalidPack.state, MGLOfflinePackStateInvalid, @"Offline pack should be invalid when initialized independently of MGLOfflineStorage."); - - XCTAssertThrowsSpecificNamed(invalidPack.region, NSException, @"Invalid offline pack", @"Invalid offline pack should raise an exception when accessing its region."); - XCTAssertThrowsSpecificNamed(invalidPack.context, NSException, @"Invalid offline pack", @"Invalid offline pack should raise an exception when accessing its context."); - XCTAssertThrowsSpecificNamed([invalidPack resume], NSException, @"Invalid offline pack", @"Invalid offline pack should raise an exception when being resumed."); - XCTAssertThrowsSpecificNamed([invalidPack suspend], NSException, @"Invalid offline pack", @"Invalid offline pack should raise an exception when being suspended."); -} - -- (void)testProgressBoxing { - MGLOfflinePackProgress progress = { - .countOfResourcesCompleted = 1, - .countOfResourcesExpected = 2, - .countOfBytesCompleted = 7, - .maximumResourcesExpected = UINT64_MAX, - }; - MGLOfflinePackProgress roundTrippedProgress = [NSValue valueWithMGLOfflinePackProgress:progress].MGLOfflinePackProgressValue; - - XCTAssertEqual(progress.countOfResourcesCompleted, roundTrippedProgress.countOfResourcesCompleted, @"Completed resources should round-trip."); - XCTAssertEqual(progress.countOfResourcesExpected, roundTrippedProgress.countOfResourcesExpected, @"Expected resources should round-trip."); - XCTAssertEqual(progress.countOfBytesCompleted, roundTrippedProgress.countOfBytesCompleted, @"Completed bytes should round-trip."); - XCTAssertEqual(progress.maximumResourcesExpected, roundTrippedProgress.maximumResourcesExpected, @"Maximum expected resources should round-trip."); -} - -@end diff --git a/platform/osx/test/MGLOfflineRegionTests.m b/platform/osx/test/MGLOfflineRegionTests.m deleted file mode 100644 index 63befdf14c..0000000000 --- a/platform/osx/test/MGLOfflineRegionTests.m +++ /dev/null @@ -1,35 +0,0 @@ -#import <Mapbox/Mapbox.h> - -#pragma clang diagnostic ignored "-Wgnu-statement-expression" -#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" - -#import <XCTest/XCTest.h> - -@interface MGLOfflineRegionTests : XCTestCase - -@end - -@implementation MGLOfflineRegionTests - -- (void)testStyleURLs { - MGLCoordinateBounds bounds = MGLCoordinateBoundsMake(kCLLocationCoordinate2DInvalid, kCLLocationCoordinate2DInvalid); - MGLTilePyramidOfflineRegion *region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:nil bounds:bounds fromZoomLevel:0 toZoomLevel:DBL_MAX]; - XCTAssertEqualObjects(region.styleURL, [MGLStyle streetsStyleURL], @"Streets isn’t the default style."); - - NSURL *localURL = [NSURL URLWithString:@"beautiful.style"]; - XCTAssertThrowsSpecificNamed([[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:localURL bounds:bounds fromZoomLevel:0 toZoomLevel:DBL_MAX], NSException, @"Invalid style URL", @"No exception raised when initializing region with a local file URL as the style URL."); -} - -- (void)testEquality { - MGLCoordinateBounds bounds = MGLCoordinateBoundsMake(kCLLocationCoordinate2DInvalid, kCLLocationCoordinate2DInvalid); - MGLTilePyramidOfflineRegion *original = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:[MGLStyle lightStyleURL] bounds:bounds fromZoomLevel:5 toZoomLevel:10]; - MGLTilePyramidOfflineRegion *copy = [original copy]; - XCTAssertEqualObjects(original, copy, @"Tile pyramid region should be equal to its copy."); - - XCTAssertEqualObjects(original.styleURL, copy.styleURL, @"Style URL has changed."); - XCTAssert(MGLCoordinateBoundsEqualToCoordinateBounds(original.bounds, copy.bounds), @"Bounds have changed."); - XCTAssertEqual(original.minimumZoomLevel, original.minimumZoomLevel, @"Minimum zoom level has changed."); - XCTAssertEqual(original.maximumZoomLevel, original.maximumZoomLevel, @"Maximum zoom level has changed."); -} - -@end diff --git a/platform/osx/test/MGLOfflineStorageTests.m b/platform/osx/test/MGLOfflineStorageTests.m deleted file mode 100644 index 8ffa1207ce..0000000000 --- a/platform/osx/test/MGLOfflineStorageTests.m +++ /dev/null @@ -1,126 +0,0 @@ -#import <Mapbox/Mapbox.h> - -#pragma clang diagnostic ignored "-Wgnu-statement-expression" -#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" - -#import <XCTest/XCTest.h> - -@interface MGLOfflineStorageTests : XCTestCase - -@end - -@implementation MGLOfflineStorageTests - -- (void)testSharedObject { - XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage], [MGLOfflineStorage sharedOfflineStorage], @"There should only be one shared offline storage object."); -} - -// This test needs to come first so it can test the initial loading of packs. -- (void)testAAALoadPacks { - XCTestExpectation *kvoExpectation = [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { - NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; - return changeKind = NSKeyValueChangeSetting; - }]; - - [self waitForExpectationsWithTimeout:1 handler:nil]; - - XCTAssertNotNil([MGLOfflineStorage sharedOfflineStorage].packs, @"Shared offline storage object should have a non-nil collection of packs by this point."); -} - -- (void)testAddPack { - NSUInteger countOfPacks = [MGLOfflineStorage sharedOfflineStorage].packs.count; - - NSURL *styleURL = [MGLStyle lightStyleURL]; - /// Somewhere near Grape Grove, Ohio, United States. - MGLCoordinateBounds bounds = { - { 39.70358155855172, -83.69506472545841 }, - { 39.703818870225376, -83.69420641857361 }, - }; - double zoomLevel = 20; - MGLTilePyramidOfflineRegion *region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:styleURL bounds:bounds fromZoomLevel:zoomLevel toZoomLevel:zoomLevel]; - - NSString *nameKey = @"Name"; - NSString *name = @"🍇 Grape Grove"; - - NSData *context = [NSKeyedArchiver archivedDataWithRootObject:@{ - nameKey: name, - }]; - - __block MGLOfflinePack *pack; - [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { - NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; - NSIndexSet *indices = change[NSKeyValueChangeIndexesKey]; - return changeKind == NSKeyValueChangeInsertion && indices.count == 1; - }]; - XCTestExpectation *additionCompletionHandlerExpectation = [self expectationWithDescription:@"add pack completion handler"]; - [[MGLOfflineStorage sharedOfflineStorage] addPackForRegion:region withContext:context completionHandler:^(MGLOfflinePack * _Nullable completionHandlerPack, NSError * _Nullable error) { - XCTAssertNotNil(completionHandlerPack, @"Added pack should exist."); - XCTAssertEqual(completionHandlerPack.state, MGLOfflinePackStateInactive, @"New pack should initially have inactive state."); - pack = completionHandlerPack; - [additionCompletionHandlerExpectation fulfill]; - }]; - [self waitForExpectationsWithTimeout:1 handler:nil]; - - XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage].packs.count, countOfPacks + 1, @"Added pack should have been added to the canonical collection of packs owned by the shared offline storage object. This assertion can fail if this test is run before -testAAALoadPacks."); - - XCTAssertEqual(pack, [MGLOfflineStorage sharedOfflineStorage].packs.lastObject, @"Pack should be appended to end of packs array."); - - XCTAssertEqualObjects(pack.region, region, @"Added pack’s region has changed."); - - NSDictionary *userInfo = [NSKeyedUnarchiver unarchiveObjectWithData:pack.context]; - XCTAssert([userInfo isKindOfClass:[NSDictionary class]], @"Context of offline pack isn’t a dictionary."); - XCTAssert([userInfo[nameKey] isKindOfClass:[NSString class]], @"Name of offline pack isn’t a string."); - XCTAssertEqualObjects(userInfo[nameKey], name, @"Name of offline pack has changed."); - - XCTAssertEqual(pack.state, MGLOfflinePackStateInactive, @"New pack should initially have inactive state."); - - [self keyValueObservingExpectationForObject:pack keyPath:@"state" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { - NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; - MGLOfflinePackState state = [change[NSKeyValueChangeNewKey] integerValue]; - return changeKind == NSKeyValueChangeSetting && state == MGLOfflinePackStateInactive; - }]; - [self expectationForNotification:MGLOfflinePackProgressChangedNotification object:pack handler:^BOOL(NSNotification * _Nonnull notification) { - MGLOfflinePack *notificationPack = notification.object; - XCTAssert([notificationPack isKindOfClass:[MGLOfflinePack class]], @"Object of notification should be an MGLOfflinePack."); - - NSDictionary *userInfo = notification.userInfo; - XCTAssertNotNil(userInfo, @"Progress change notification should have a userInfo dictionary."); - - NSNumber *stateNumber = userInfo[MGLOfflinePackStateUserInfoKey]; - XCTAssert([stateNumber isKindOfClass:[NSNumber class]], @"Progress change notification’s state should be an NSNumber."); - XCTAssertEqual(stateNumber.integerValue, pack.state, @"State in a progress change notification should match the pack’s state."); - - NSValue *progressValue = userInfo[MGLOfflinePackProgressUserInfoKey]; - XCTAssert([progressValue isKindOfClass:[NSValue class]], @"Progress change notification’s progress should be an NSValue."); - XCTAssertEqualObjects(progressValue, [NSValue valueWithMGLOfflinePackProgress:pack.progress], @"Progress change notification’s progress should match pack’s progress."); - - return notificationPack == pack && pack.state == MGLOfflinePackStateInactive; - }]; - [pack requestProgress]; - [self waitForExpectationsWithTimeout:1 handler:nil]; -} - -- (void)testRemovePack { - NSUInteger countOfPacks = [MGLOfflineStorage sharedOfflineStorage].packs.count; - - MGLOfflinePack *pack = [MGLOfflineStorage sharedOfflineStorage].packs.lastObject; - XCTAssertNotNil(pack, @"Added pack should still exist."); - - XCTestExpectation *kvoExpectation = [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { - NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; - NSIndexSet *indices = change[NSKeyValueChangeIndexesKey]; - return changeKind = NSKeyValueChangeRemoval && indices.count == 1; - }]; - XCTestExpectation *completionHandlerExpectation = [self expectationWithDescription:@"remove pack completion handler"]; - [[MGLOfflineStorage sharedOfflineStorage] removePack:pack withCompletionHandler:^(NSError * _Nullable error) { - XCTAssertEqual(pack.state, MGLOfflinePackStateInvalid, @"Removed pack should be invalid in the completion handler."); - [completionHandlerExpectation fulfill]; - }]; - [self waitForExpectationsWithTimeout:1 handler:nil]; - - XCTAssertEqual(pack.state, MGLOfflinePackStateInvalid, @"Removed pack should have been invalidated synchronously."); - - XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage].packs.count, countOfPacks - 1, @"Removed pack should have been removed from the canonical collection of packs owned by the shared offline storage object. This assertion can fail if this test is run before -testAAALoadPacks or -testAddPack."); -} - -@end diff --git a/platform/osx/test/MGLStyleTests.mm b/platform/osx/test/MGLStyleTests.mm deleted file mode 100644 index 69c9ef6091..0000000000 --- a/platform/osx/test/MGLStyleTests.mm +++ /dev/null @@ -1,29 +0,0 @@ -#import "MGLStyle.h" - -#import <mbgl/util/default_styles.hpp> - -#pragma clang diagnostic ignored "-Wgnu-statement-expression" -#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" - -#import <XCTest/XCTest.h> - -@interface MGLStyleTests : XCTestCase -@end - -@implementation MGLStyleTests - -- (void)testStyleURLs { - // Test that all the default styles have publicly-declared MGLStyle class - // methods and that the URLs are all well-formed. - XCTAssertEqualObjects([MGLStyle streetsStyleURL].absoluteString, @(mbgl::util::default_styles::streets.url)); - XCTAssertEqualObjects([MGLStyle emeraldStyleURL].absoluteString, @(mbgl::util::default_styles::emerald.url)); - XCTAssertEqualObjects([MGLStyle lightStyleURL].absoluteString, @(mbgl::util::default_styles::light.url)); - XCTAssertEqualObjects([MGLStyle darkStyleURL].absoluteString, @(mbgl::util::default_styles::dark.url)); - XCTAssertEqualObjects([MGLStyle satelliteStyleURL].absoluteString, @(mbgl::util::default_styles::satellite.url)); - XCTAssertEqualObjects([MGLStyle hybridStyleURL].absoluteString, @(mbgl::util::default_styles::hybrid.url)); - - static_assert(6 == mbgl::util::default_styles::numOrderedStyles, - "MGLStyleTests isn’t testing all the styles in mbgl::util::default_styles."); -} - -@end |