Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Added image stretching tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Mar 10, 2020
1 parent 6020cf4 commit cbb21ab
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
81 changes: 81 additions & 0 deletions platform/darwin/test/MGLImageTests.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#import <XCTest/XCTest.h>
#import <Mapbox/Mapbox.h>

#if TARGET_OS_IPHONE
#import "UIImage+MGLAdditions.h"
#else
#import "NSImage+MGLAdditions.h"
#endif

@interface MGLImageTests : XCTestCase

@end

@implementation MGLImageTests

- (void)testStretching {
#if TARGET_OS_IPHONE
CGRect rect = CGRectMake(0, 0, 24, 24);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, UIScreen.mainScreen.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, UIColor.blackColor.CGColor);
CGContextStrokeRectWithWidth(context, rect, 2);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
#else
NSImage *image = [NSImage imageWithSize:NSMakeSize(24, 24) flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
// A little more fanciful than the iOS version, but we aren’t testing the actual contents of the image anyways.
NSRectEdge allSides[] = {NSMinYEdge, NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge, NSMaxXEdge};
CGFloat grays[] = {NSBlack, NSBlack, NSWhite, NSWhite, NSDarkGray, NSDarkGray};
dstRect = NSDrawTiledRects(dstRect, dstRect, allSides, grays, sizeof(grays) / sizeof(grays[0]));
[NSColor.grayColor set];
NSRectFill(dstRect);
return YES;
}];
#endif

{
auto styleImage = [image mgl_styleImageWithIdentifier:@"box"];
XCTAssert(styleImage);
if (styleImage) {
XCTAssert(!styleImage->getContent());
XCTAssertFalse(styleImage->isSdf());
}
}

#if TARGET_OS_IPHONE
image = [image resizableImageWithCapInsets:UIEdgeInsetsZero];
#else
image.capInsets = NSEdgeInsetsZero;
#endif
{
auto styleImage = [image mgl_styleImageWithIdentifier:@"box"];
XCTAssert(styleImage);
if (styleImage) {
XCTAssert(!styleImage->getContent());
}
}

#if TARGET_OS_IPHONE
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(1, 2, 3, 4)];
#else
image.capInsets = NSEdgeInsetsMake(1, 2, 3, 4);
#endif
{
auto styleImage = [image mgl_styleImageWithIdentifier:@"box"];
XCTAssert(styleImage);
if (styleImage) {
auto scale = styleImage->getPixelRatio();
auto content = styleImage->getContent();
XCTAssert(content);
if (content) {
XCTAssertEqual(content->top, 1 * scale);
XCTAssertEqual(content->left, 2 * scale);
XCTAssertEqual(content->bottom, 21 * scale);
XCTAssertEqual(content->right, 20 * scale);
}
}
}
}

@end
4 changes: 4 additions & 0 deletions platform/ios/ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
DA0BDD202407C12600DAA576 /* libmbgl-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F78399D235AA1E600D4D606 /* libmbgl-core.a */; };
DA0BDD212407C13000DAA576 /* libmbgl-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F78399D235AA1E600D4D606 /* libmbgl-core.a */; };
DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; };
DA0E9F3F2411AC9B007C75D4 /* MGLImageTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0E9F3E2411AC9B007C75D4 /* MGLImageTests.mm */; };
DA17BE301CC4BAC300402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; };
DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; };
DA1DC96A1CB6C6B7006E619F /* MBXCustomCalloutView.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1DC9671CB6C6B7006E619F /* MBXCustomCalloutView.m */; };
Expand Down Expand Up @@ -1075,6 +1076,7 @@
DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = "<group>"; };
DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = "<group>"; };
DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = "<group>"; };
DA0E9F3E2411AC9B007C75D4 /* MGLImageTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLImageTests.mm; path = ../../darwin/test/MGLImageTests.mm; sourceTree = "<group>"; };
DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapView_Private.h; sourceTree = "<group>"; };
DA1AC01B1E5B8774006DF1D6 /* lt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = lt; path = lt.lproj/Localizable.strings; sourceTree = "<group>"; };
DA1AC0201E5B8917006DF1D6 /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = uk; path = uk.lproj/Foundation.stringsdict; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1858,6 +1860,7 @@
DD58A4C51D822BD000E1F038 /* MGLExpressionTests.mm */,
DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */,
DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */,
DA0E9F3E2411AC9B007C75D4 /* MGLImageTests.mm */,
DA5DB1291FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m */,
DA695425215B1E75002041A4 /* MGLMapCameraTests.m */,
96E6145522CC135200109F14 /* MGLMapViewCompassViewTests.mm */,
Expand Down Expand Up @@ -3014,6 +3017,7 @@
357579801D501E09000B822E /* MGLFillStyleLayerTests.mm in Sources */,
35D9DDE21DA25EEC00DAAD69 /* MGLCodingTests.mm in Sources */,
DA1F8F3D1EBD287B00367E42 /* MGLDocumentationGuideTests.swift in Sources */,
DA0E9F3F2411AC9B007C75D4 /* MGLImageTests.mm in Sources */,
076171C32139C70900668A35 /* MGLMapViewTests.m in Sources */,
3598544D1E1D38AA00B29F84 /* MGLDistanceFormatterTests.m in Sources */,
071BBB071EE77631001FB02A /* MGLImageSourceTests.m in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions platform/macos/macos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
DA00FC8A1D5EEAC3009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
DA00FC8B1D5EEAC3009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */; };
DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */; };
DA0E9F3B24119F6B007C75D4 /* MGLImageTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0E9F3A24119F6B007C75D4 /* MGLImageTests.mm */; };
DA2784FE1DF03060001D5B8D /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DA2784FD1DF03060001D5B8D /* Media.xcassets */; };
DA29875A1E1A4290002299F5 /* MGLDocumentationExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2987591E1A4290002299F5 /* MGLDocumentationExampleTests.swift */; };
DA35A2A41CC9EB1A00E826B2 /* MGLCoordinateFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = DA35A2A31CC9EB1A00E826B2 /* MGLCoordinateFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -480,6 +481,7 @@
DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = "<group>"; };
DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = "<group>"; };
DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = "<group>"; };
DA0E9F3A24119F6B007C75D4 /* MGLImageTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLImageTests.mm; path = ../../darwin/test/MGLImageTests.mm; sourceTree = "<group>"; };
DA1AC01E1E5B8826006DF1D6 /* lt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = lt; path = lt.lproj/Localizable.strings; sourceTree = "<group>"; };
DA1AC01F1E5B8904006DF1D6 /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = uk; path = uk.lproj/Foundation.stringsdict; sourceTree = "<group>"; };
DA2207BA1DC076930002F84D /* test-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "test-Bridging-Header.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1206,6 +1208,7 @@
DD58A4C71D822C6200E1F038 /* MGLExpressionTests.mm */,
DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */,
DAE6C3C81CC34BD800DB3429 /* MGLGeometryTests.mm */,
DA0E9F3A24119F6B007C75D4 /* MGLImageTests.mm */,
DA695423215B1E6C002041A4 /* MGLMapCameraTests.m */,
076171C4213A0DC200668A35 /* MGLMapViewTests.m */,
1F95931A1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm */,
Expand Down Expand Up @@ -1768,6 +1771,7 @@
DA695424215B1E6C002041A4 /* MGLMapCameraTests.m in Sources */,
920A3E591E6F859D00C16EFC /* MGLSourceQueryTests.m in Sources */,
DA35A2B61CCA14D700E826B2 /* MGLCompassDirectionFormatterTests.m in Sources */,
DA0E9F3B24119F6B007C75D4 /* MGLImageTests.mm in Sources */,
35C6DF871E214C1800ACA483 /* MGLDistanceFormatterTests.m in Sources */,
CAD9D0AC22A88A32001B25EE /* MGLResourceTests.mm in Sources */,
DAE6C3D21CC34C9900DB3429 /* MGLGeometryTests.mm in Sources */,
Expand Down

0 comments on commit cbb21ab

Please sign in to comment.