summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2019-03-11 08:57:53 -0400
committerNicoleYarroch <nicole@livio.io>2019-03-11 08:57:53 -0400
commit22e8843f632d62932bb824729f51cfd68eddeb0c (patch)
tree9e4606183b69d7e692ad07c67928fcae4d3ff787
parent5673287b975b8c4522c30314aeb9640a737b63d4 (diff)
downloadsdl_ios-22e8843f632d62932bb824729f51cfd68eddeb0c.tar.gz
Added conv. inits to `SDLLocationDetails`
-rw-r--r--SmartDeviceLink/SDLLocationDetails.h24
-rw-r--r--SmartDeviceLink/SDLLocationDetails.m27
-rw-r--r--SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationDetailsSpec.m45
3 files changed, 95 insertions, 1 deletions
diff --git a/SmartDeviceLink/SDLLocationDetails.h b/SmartDeviceLink/SDLLocationDetails.h
index f60e8db76..4b41d3f4d 100644
--- a/SmartDeviceLink/SDLLocationDetails.h
+++ b/SmartDeviceLink/SDLLocationDetails.h
@@ -10,11 +10,33 @@
NS_ASSUME_NONNULL_BEGIN
/**
- Describes a location, including its coordinate, name, etc. Used in WayPoints.
+ * Describes a location, including its coordinate, name, etc. Used in WayPoints.
*/
@interface SDLLocationDetails : SDLRPCStruct
/**
+ * Convenience init for location coordinate.
+ *
+ * @param coordinate Latitude/Longitude of the location
+ * @return A SDLLocationDetails object
+ */
+- (instancetype)initWithCoordinate:(SDLLocationCoordinate *)coordinate NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Convenience init for all parameters.
+ *
+ * @param coordinate Latitude/Longitude of the location
+ * @param locationName Name of location
+ * @param addressLines Location address for display purposes only
+ * @param locationDescription Description intended location / establishment
+ * @param phoneNumber Phone number of location / establishment
+ * @param locationImage Image / icon of intended location
+ * @param searchAddress Address to be used by navigation engines for search
+ * @return A SDLLocationDetails object
+ */
+- (instancetype)initWithCoordinate:(SDLLocationCoordinate *)coordinate locationName:(nullable NSString *)locationName addressLines:(nullable NSArray<NSString *> *)addressLines locationDescription:(nullable NSString *)locationDescription phoneNumber:(nullable NSString*)phoneNumber locationImage:(nullable SDLImage *)locationImage searchAddress:(nullable SDLOasisAddress *)searchAddress;
+
+/**
* Latitude/Longitude of the location
*
* @see SDLLocationCoordinate
diff --git a/SmartDeviceLink/SDLLocationDetails.m b/SmartDeviceLink/SDLLocationDetails.m
index 7a585a3de..7cc609851 100644
--- a/SmartDeviceLink/SDLLocationDetails.m
+++ b/SmartDeviceLink/SDLLocationDetails.m
@@ -13,6 +13,33 @@ NS_ASSUME_NONNULL_BEGIN
@implementation SDLLocationDetails
+- (instancetype)initWithCoordinate:(SDLLocationCoordinate *)coordinate {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+
+ self.coordinate = coordinate;
+
+ return self;
+}
+
+- (instancetype)initWithCoordinate:(SDLLocationCoordinate *)coordinate locationName:(nullable NSString *)locationName addressLines:(nullable NSArray<NSString *> *)addressLines locationDescription:(nullable NSString *)locationDescription phoneNumber:(nullable NSString*)phoneNumber locationImage:(nullable SDLImage *)locationImage searchAddress:(nullable SDLOasisAddress *)searchAddress {
+ self = [self initWithCoordinate:coordinate];
+ if (!self) {
+ return nil;
+ }
+
+ self.locationName = locationName;
+ self.addressLines = addressLines;
+ self.locationDescription = locationDescription;
+ self.phoneNumber = phoneNumber;
+ self.locationImage = locationImage;
+ self.searchAddress = searchAddress;
+
+ return self;
+}
+
- (void)setCoordinate:(nullable SDLLocationCoordinate *)coordinate {
[store sdl_setObject:coordinate forName:SDLRPCParameterNameLocationCoordinate];
}
diff --git a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationDetailsSpec.m b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationDetailsSpec.m
index 5737e595e..5bbdd7f00 100644
--- a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationDetailsSpec.m
+++ b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLLocationDetailsSpec.m
@@ -87,6 +87,51 @@ describe(@"Getter/Setter Tests", ^ {
});
});
+
+ context(@"when initialized with a convenience init", ^{
+ __block SDLLocationCoordinate *testCoordinate = nil;
+ __block NSString *testLocationName = nil;
+ __block NSArray<NSString *> *testAddressLines = nil;
+ __block NSString *testLocationDescription = nil;
+ __block NSString *testPhoneNumber = nil;
+ __block SDLImage *testLocationImage = nil;
+ __block SDLOasisAddress *testSearchAddress = nil;
+
+ beforeEach(^{
+ testCoordinate = [[SDLLocationCoordinate alloc] init];
+ testLocationName = @"testLocationName";
+ testAddressLines = @[@"testAddressLines1", @"testAddressLines2"];
+ testLocationDescription = @"testLocationDescription";
+ testPhoneNumber = @"testPhoneNumber";
+ testLocationImage = [[SDLImage alloc] initWithStaticIconName:SDLStaticIconNameKey];
+ testSearchAddress = [[SDLOasisAddress alloc] init];
+ });
+
+ it(@"should init correctly with initWithCoordinate:", ^{
+ testStruct = [[SDLLocationDetails alloc] initWithCoordinate:testCoordinate];
+
+ expect(testStruct.coordinate).to(equal(testCoordinate));
+ expect(testStruct.locationName).to(beNil());
+ expect(testStruct.addressLines).to(beNil());
+ expect(testStruct.locationDescription).to(beNil());
+ expect(testStruct.phoneNumber).to(beNil());
+ expect(testStruct.locationImage).to(beNil());
+ expect(testStruct.searchAddress).to(beNil());
+ });
+
+ it(@"should init correctly with all parameters", ^{
+ testStruct = [[SDLLocationDetails alloc] initWithCoordinate:testCoordinate locationName:testLocationName addressLines:testAddressLines locationDescription:testLocationDescription phoneNumber:testPhoneNumber locationImage:testLocationImage searchAddress:testSearchAddress];
+
+ expect(testStruct.coordinate).to(equal(testCoordinate));
+ expect(testStruct.locationName).to(equal(testLocationName));
+ expect(testStruct.addressLines).to(equal(testAddressLines));
+ expect(testStruct.locationDescription).to(equal(testLocationDescription));
+ expect(testStruct.phoneNumber).to(equal(testPhoneNumber));
+ expect(testStruct.locationImage).to(equal(testLocationImage));
+ expect(testStruct.searchAddress).to(equal(testSearchAddress));
+ });
+
+ });
describe(@"when initialized with a dictionary", ^{
context(@"when parameters are set correctly", ^{