Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ios groundoverlay pr improvements #13

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ - (void)testExtractIconFromDataAssetAuto {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);

XCTAssertNotNil(resultImage);
XCTAssertEqual(resultImage.scale, 1.0);
XCTAssertEqual(resultImage.size.width, 1.0);
Expand All @@ -58,9 +58,8 @@ - (void)testExtractIconFromDataAssetAutoWithScale {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);

XCTAssertNotNil(resultImage);
XCTAssertEqual(resultImage.scale, 10);
Expand Down Expand Up @@ -88,9 +87,8 @@ - (void)testExtractIconFromDataAssetAutoAndSizeWithSameAspectRatio {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);
XCTAssertNotNil(resultImage);
XCTAssertEqual(testImage.scale, 1.0);

Expand Down Expand Up @@ -123,9 +121,8 @@ - (void)testExtractIconFromDataAssetAutoAndSizeWithDifferentAspectRatio {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);
XCTAssertNotNil(resultImage);
XCTAssertEqual(resultImage.scale, screenScale);
XCTAssertEqual(resultImage.size.width, width);
Expand All @@ -150,9 +147,8 @@ - (void)testExtractIconFromDataAssetNoScaling {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);

XCTAssertNotNil(resultImage);
XCTAssertEqual(resultImage.scale, 1.0);
Expand All @@ -177,9 +173,8 @@ - (void)testExtractIconFromDataBytesAuto {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);

XCTAssertNotNil(resultImage);
XCTAssertEqual(resultImage.scale, 1.0);
Expand All @@ -204,9 +199,8 @@ - (void)testExtractIconFromDataBytesAutoWithScaling {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);
XCTAssertNotNil(resultImage);
XCTAssertEqual(resultImage.scale, 10);
XCTAssertEqual(resultImage.size.width, 0.1);
Expand All @@ -232,9 +226,8 @@ - (void)testExtractIconFromDataBytesAutoAndSizeWithSameAspectRatio {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);

XCTAssertNotNil(resultImage);
XCTAssertEqual(testImage.scale, 1.0);
Expand Down Expand Up @@ -267,9 +260,8 @@ - (void)testExtractIconFromDataBytesAutoAndSizeWithDifferentAspectRatio {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);
XCTAssertNotNil(resultImage);
XCTAssertEqual(resultImage.scale, screenScale);
XCTAssertEqual(resultImage.size.width, width);
Expand All @@ -293,9 +285,8 @@ - (void)testExtractIconFromDataBytesNoScaling {

CGFloat screenScale = 3.0;

UIImage *resultImage = [FGMUtils iconFromBitmap:[FGMPlatformBitmap makeWithBitmap:bitmap]
registrar:mockRegistrar
screenScale:screenScale];
UIImage *resultImage =
FGMIconFromBitmap([FGMPlatformBitmap makeWithBitmap:bitmap], mockRegistrar, screenScale);
XCTAssertNotNil(resultImage);
XCTAssertEqual(resultImage.scale, 1.0);
XCTAssertEqual(resultImage.size.width, 1.0);
Expand All @@ -305,43 +296,43 @@ - (void)testExtractIconFromDataBytesNoScaling {
- (void)testIsScalableWithScaleFactorFromSize100x100to10x100 {
CGSize originalSize = CGSizeMake(100.0, 100.0);
CGSize targetSize = CGSizeMake(10.0, 100.0);
XCTAssertFalse([FGMUtils isScalableWithScaleFactorFromSize:originalSize toSize:targetSize]);
XCTAssertFalse(FGMIsScalableWithScaleFactorFromSize(originalSize, targetSize));
}

- (void)testIsScalableWithScaleFactorFromSize100x100to10x10 {
CGSize originalSize = CGSizeMake(100.0, 100.0);
CGSize targetSize = CGSizeMake(10.0, 10.0);
XCTAssertTrue([FGMUtils isScalableWithScaleFactorFromSize:originalSize toSize:targetSize]);
XCTAssertTrue(FGMIsScalableWithScaleFactorFromSize(originalSize, targetSize));
}

- (void)testIsScalableWithScaleFactorFromSize233x200to23x20 {
CGSize originalSize = CGSizeMake(233.0, 200.0);
CGSize targetSize = CGSizeMake(23.0, 20.0);
XCTAssertTrue([FGMUtils isScalableWithScaleFactorFromSize:originalSize toSize:targetSize]);
XCTAssertTrue(FGMIsScalableWithScaleFactorFromSize(originalSize, targetSize));
}

- (void)testIsScalableWithScaleFactorFromSize233x200to22x20 {
CGSize originalSize = CGSizeMake(233.0, 200.0);
CGSize targetSize = CGSizeMake(22.0, 20.0);
XCTAssertFalse([FGMUtils isScalableWithScaleFactorFromSize:originalSize toSize:targetSize]);
XCTAssertFalse(FGMIsScalableWithScaleFactorFromSize(originalSize, targetSize));
}

- (void)testIsScalableWithScaleFactorFromSize200x233to20x23 {
CGSize originalSize = CGSizeMake(200.0, 233.0);
CGSize targetSize = CGSizeMake(20.0, 23.0);
XCTAssertTrue([FGMUtils isScalableWithScaleFactorFromSize:originalSize toSize:targetSize]);
XCTAssertTrue(FGMIsScalableWithScaleFactorFromSize(originalSize, targetSize));
}

- (void)testIsScalableWithScaleFactorFromSize200x233to20x22 {
CGSize originalSize = CGSizeMake(200.0, 233.0);
CGSize targetSize = CGSizeMake(20.0, 22.0);
XCTAssertFalse([FGMUtils isScalableWithScaleFactorFromSize:originalSize toSize:targetSize]);
XCTAssertFalse(FGMIsScalableWithScaleFactorFromSize(originalSize, targetSize));
}

- (void)testIsScalableWithScaleFactorFromSize1024x768to500x250 {
CGSize originalSize = CGSizeMake(1024.0, 768.0);
CGSize targetSize = CGSizeMake(500.0, 250.0);
XCTAssertFalse([FGMUtils isScalableWithScaleFactorFromSize:originalSize toSize:targetSize]);
XCTAssertFalse(FGMIsScalableWithScaleFactorFromSize(originalSize, targetSize));
}

- (UIImage *)createOnePixelImage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
@import XCTest;
@import GoogleMaps;

#import <OCMock/OCMock.h>
#import <google_maps_flutter_ios/FGMGroundOverlayController_Test.h>

#import <OCMock/OCMock.h>
#import <google_maps_flutter_ios/messages.g.h>
#import "PartiallyMockedMapView.h"

Expand All @@ -18,10 +19,10 @@ @interface GoogleMapsGroundOverlayControllerTests : XCTestCase
@implementation GoogleMapsGroundOverlayControllerTests

/// Returns GoogleMapGroundOverlayController object instantiated with position and a mocked map
/// instance
/// instance.
///
/// @return An object of FLTGoogleMapGroundOverlayController
- (FGMGroundOverlayController *)groundOverlayControllerWithPositionWithMockedMap {
+ (FGMGroundOverlayController *)groundOverlayControllerWithPositionWithMockedMap {
NSString *imagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"widegamut"
ofType:@"png"
inDirectory:@"assets"];
Expand All @@ -46,10 +47,10 @@ - (FGMGroundOverlayController *)groundOverlayControllerWithPositionWithMockedMap
}

/// Returns GoogleMapGroundOverlayController object instantiated with bounds and a mocked map
/// instance
/// instance.
///
/// @return An object of FLTGoogleMapGroundOverlayController
- (FGMGroundOverlayController *)groundOverlayControllerWithBoundsWithMockedMap {
+ (FGMGroundOverlayController *)groundOverlayControllerWithBoundsWithMockedMap {
NSString *imagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"widegamut"
ofType:@"png"
inDirectory:@"assets"];
Expand All @@ -76,7 +77,7 @@ - (FGMGroundOverlayController *)groundOverlayControllerWithBoundsWithMockedMap {

- (void)testUpdatingGroundOverlayWithPosition {
FGMGroundOverlayController *groundOverlayController =
[self groundOverlayControllerWithPositionWithMockedMap];
[GoogleMapsGroundOverlayControllerTests groundOverlayControllerWithPositionWithMockedMap];

FGMPlatformLatLng *position = [FGMPlatformLatLng makeWithLatitude:52.4816 longitude:3.1791];

Expand Down Expand Up @@ -111,7 +112,7 @@ - (void)testUpdatingGroundOverlayWithPosition {

- (void)testUpdatingGroundOverlayWithBounds {
FGMGroundOverlayController *groundOverlayController =
[self groundOverlayControllerWithBoundsWithMockedMap];
[GoogleMapsGroundOverlayControllerTests groundOverlayControllerWithBoundsWithMockedMap];

FGMPlatformLatLngBounds *bounds = [FGMPlatformLatLngBounds
makeWithNortheast:[FGMPlatformLatLng makeWithLatitude:54.4816 longitude:5.1791]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@

#import "messages.g.h"

NS_ASSUME_NONNULL_BEGIN

/// Controller of a single ground overlay on the map.
@interface FGMGroundOverlayController : NSObject

/// The ground overlay this controller handles.
@property(strong, nonatomic) GMSGroundOverlay *_Nonnull groundOverlay;
@property(strong, nonatomic) GMSGroundOverlay *groundOverlay;

/// Whether ground overlay is created with bounds or position.
@property(nonatomic, assign) BOOL isCreatedWithBounds;
@property(nonatomic, assign, getter=isCreatedWithBounds) BOOL createdWithBounds;

/// Zoom level when ground overlay is initialized with position.
@property(nonatomic, strong, nullable) NSNumber *zoomLevel;

/// Initializes an instance of this class with a GMSGroundOverlay, a map view, and identifier.
- (instancetype _Nullable)initWithGroundOverlay:(GMSGroundOverlay *_Nonnull)groundOverlay
identifier:(NSString *_Nonnull)identifier
mapView:(GMSMapView *_Nonnull)mapView
- (instancetype _Nullable)initWithGroundOverlay:(GMSGroundOverlay *)groundOverlay
identifier:(NSString *)identifier
mapView:(GMSMapView *)mapView
isCreatedWithBounds:(BOOL)isCreatedWithBounds;

/// Removes this ground overlay from the map.
Expand All @@ -33,25 +35,27 @@
@interface FLTGroundOverlaysController : NSObject

/// Initializes the controller with a GMSMapView, callback handler and registrar.
- (instancetype _Nullable)initWithMapView:(GMSMapView *_Nonnull)mapView
callbackHandler:(FGMMapsCallbackApi *_Nonnull)callbackHandler
registrar:(NSObject<FlutterPluginRegistrar> *_Nonnull)registrar;
- (instancetype _Nullable)initWithMapView:(GMSMapView *)mapView
callbackHandler:(FGMMapsCallbackApi *)callbackHandler
registrar:(NSObject<FlutterPluginRegistrar> *)registrar;

/// Adds ground overlays to the map.
- (void)addGroundOverlays:(NSArray<FGMPlatformGroundOverlay *> *_Nonnull)groundOverlaysToAdd;
- (void)addGroundOverlays:(NSArray<FGMPlatformGroundOverlay *> *)groundOverlaysToAdd;

/// Updates ground overlays on the map.
- (void)changeGroundOverlays:(NSArray<FGMPlatformGroundOverlay *> *_Nonnull)groundOverlaysToChange;
- (void)changeGroundOverlays:(NSArray<FGMPlatformGroundOverlay *> *)groundOverlaysToChange;

/// Removes ground overlays from the map.
- (void)removeGroundOverlaysWithIdentifiers:(NSArray<NSString *> *_Nonnull)identifiers;
- (void)removeGroundOverlaysWithIdentifiers:(NSArray<NSString *> *)identifiers;

/// Called when a ground overlay is tapped on the map.
- (void)didTapGroundOverlayWithIdentifier:(NSString *_Nonnull)identifier;
- (void)didTapGroundOverlayWithIdentifier:(NSString *)identifier;

/// Returns true if a ground overlay with the given identifier exists on the map.
- (bool)hasGroundOverlaysWithIdentifier:(NSString *_Nonnull)identifier;
- (bool)hasGroundOverlaysWithIdentifier:(NSString *)identifier;

/// Returns FGMPlatformGroundOverlay for identifier.
- (nullable FGMPlatformGroundOverlay *)groundOverlayWithIdentifier:(NSString *_Nonnull)identifier;
- (nullable FGMPlatformGroundOverlay *)groundOverlayWithIdentifier:(NSString *)identifier;
@end

NS_ASSUME_NONNULL_END
Loading
Loading