From 77f6fe1c31d919baefab8cda943d1fe9d22d2272 Mon Sep 17 00:00:00 2001 From: quellish Date: Wed, 2 Mar 2016 12:27:03 -0800 Subject: [PATCH 1/8] Added AFImageResponseSerializerTests class. --- AFNetworking.xcodeproj/project.pbxproj | 4 ++ Tests/Tests/AFImageResponseSerializerTests.m | 45 ++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Tests/Tests/AFImageResponseSerializerTests.m diff --git a/AFNetworking.xcodeproj/project.pbxproj b/AFNetworking.xcodeproj/project.pbxproj index 337d87070e..6fb2024d4f 100644 --- a/AFNetworking.xcodeproj/project.pbxproj +++ b/AFNetworking.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 1BF9F9601C87832B00F1F35A /* AFImageResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BF9F95F1C87832B00F1F35A /* AFImageResponseSerializerTests.m */; }; 1FE783011C5857A100A73B7C /* httpbinorg_01192017.cer in Resources */ = {isa = PBXBuildFile; fileRef = 1FE783001C58579D00A73B7C /* httpbinorg_01192017.cer */; }; 1FE783021C5857A100A73B7C /* httpbinorg_01192017.cer in Resources */ = {isa = PBXBuildFile; fileRef = 1FE783001C58579D00A73B7C /* httpbinorg_01192017.cer */; }; 1FE783031C5857A200A73B7C /* httpbinorg_01192017.cer in Resources */ = {isa = PBXBuildFile; fileRef = 1FE783001C58579D00A73B7C /* httpbinorg_01192017.cer */; }; @@ -221,6 +222,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 1BF9F95F1C87832B00F1F35A /* AFImageResponseSerializerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFImageResponseSerializerTests.m; sourceTree = ""; }; 1FE783001C58579D00A73B7C /* httpbinorg_01192017.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = httpbinorg_01192017.cer; sourceTree = ""; }; 2960BAC21C1B2F1A00BA02F0 /* AFUIButtonTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFUIButtonTests.m; sourceTree = ""; }; 297824A01BC2D69A0041C395 /* adn_0.cer */ = {isa = PBXFileReference; lastKnownFileType = file; name = adn_0.cer; path = ADNNetServerTrustChain/adn_0.cer; sourceTree = ""; }; @@ -433,6 +435,7 @@ 298D7C851BC2C88F00FD3B3E /* AFJSONSerializationTests.m */, 298D7C881BC2C88F00FD3B3E /* AFPropertyListResponseSerializerTests.m */, 29D3413E1C20D46400A7D266 /* AFCompoundResponseSerializerTests.m */, + 1BF9F95F1C87832B00F1F35A /* AFImageResponseSerializerTests.m */, 298D7C871BC2C88F00FD3B3E /* AFNetworkReachabilityManagerTests.m */, 298D7C891BC2C88F00FD3B3E /* AFSecurityPolicyTests.m */, 298D7C8F1BC2C88F00FD3B3E /* AFURLSessionManagerTests.m */, @@ -975,6 +978,7 @@ 298D7CB11BC2CA6E00FD3B3E /* AFHTTPRequestSerializationTests.m in Sources */, 297824AE1BC2DBD80041C395 /* AFUIActivityIndicatorViewTests.m in Sources */, 297824AD1BC2DBA40041C395 /* AFNetworkActivityManagerTests.m in Sources */, + 1BF9F9601C87832B00F1F35A /* AFImageResponseSerializerTests.m in Sources */, 298D7CDD1BC2CAF700FD3B3E /* AFSecurityPolicyTests.m in Sources */, 298D7CD31BC2CAE800FD3B3E /* AFHTTPResponseSerializationTests.m in Sources */, 297824B01BC2DC2D0041C395 /* AFUIImageViewTests.m in Sources */, diff --git a/Tests/Tests/AFImageResponseSerializerTests.m b/Tests/Tests/AFImageResponseSerializerTests.m new file mode 100644 index 0000000000..b19df3261a --- /dev/null +++ b/Tests/Tests/AFImageResponseSerializerTests.m @@ -0,0 +1,45 @@ +// AFImageResponseSerializerTests.m +// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import +#import "AFTestCase.h" +#import "AFURLResponseSerialization.h" + +@interface AFImageResponseSerializerTests : AFTestCase + +@end + +@implementation AFImageResponseSerializerTests + +- (void)testCanBeCopied { + AFImageResponseSerializer *responseSerializer = [AFImageResponseSerializer serializer]; + AFImageResponseSerializer *copiedSerializer = [responseSerializer copy]; + XCTAssertNotNil(copiedSerializer); + XCTAssertNotEqual(copiedSerializer, responseSerializer); + XCTAssertTrue(copiedSerializer.acceptableContentTypes.count == responseSerializer.acceptableContentTypes.count); + XCTAssertTrue(copiedSerializer.acceptableStatusCodes.count == responseSerializer.acceptableStatusCodes.count); +} + +- (void)testSupportsSecureCoding { + XCTAssertTrue([AFImageResponseSerializer supportsSecureCoding]); +} + +@end From 723cf3237a621645e2edfaf09602dd17c570c72f Mon Sep 17 00:00:00 2001 From: quellish Date: Wed, 2 Mar 2016 12:27:52 -0800 Subject: [PATCH 2/8] Added AFImageResponseSerializerTests to MacOS and tvOS test targets --- AFNetworking.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AFNetworking.xcodeproj/project.pbxproj b/AFNetworking.xcodeproj/project.pbxproj index 6fb2024d4f..6543773173 100644 --- a/AFNetworking.xcodeproj/project.pbxproj +++ b/AFNetworking.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 1BF9F9601C87832B00F1F35A /* AFImageResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BF9F95F1C87832B00F1F35A /* AFImageResponseSerializerTests.m */; }; + 1BF9F9611C87843200F1F35A /* AFImageResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BF9F95F1C87832B00F1F35A /* AFImageResponseSerializerTests.m */; }; + 1BF9F9621C87843300F1F35A /* AFImageResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BF9F95F1C87832B00F1F35A /* AFImageResponseSerializerTests.m */; }; 1FE783011C5857A100A73B7C /* httpbinorg_01192017.cer in Resources */ = {isa = PBXBuildFile; fileRef = 1FE783001C58579D00A73B7C /* httpbinorg_01192017.cer */; }; 1FE783021C5857A100A73B7C /* httpbinorg_01192017.cer in Resources */ = {isa = PBXBuildFile; fileRef = 1FE783001C58579D00A73B7C /* httpbinorg_01192017.cer */; }; 1FE783031C5857A200A73B7C /* httpbinorg_01192017.cer in Resources */ = {isa = PBXBuildFile; fileRef = 1FE783001C58579D00A73B7C /* httpbinorg_01192017.cer */; }; @@ -957,6 +959,7 @@ 2987B0E31BC40B0900179A4C /* AFUIActivityIndicatorViewTests.m in Sources */, 2987B0D01BC40A7600179A4C /* AFSecurityPolicyTests.m in Sources */, 2987B0CB1BC40A7600179A4C /* AFHTTPResponseSerializationTests.m in Sources */, + 1BF9F9621C87843300F1F35A /* AFImageResponseSerializerTests.m in Sources */, 2987B0CE1BC40A7600179A4C /* AFNetworkReachabilityManagerTests.m in Sources */, 2987B0E01BC40B0900179A4C /* AFAutoPurgingImageCacheTests.m in Sources */, 2987B0CA1BC40A7600179A4C /* AFHTTPRequestSerializationTests.m in Sources */, @@ -1002,6 +1005,7 @@ 29D341401C20D46400A7D266 /* AFCompoundResponseSerializerTests.m in Sources */, 298D7CB21BC2CA6E00FD3B3E /* AFHTTPRequestSerializationTests.m in Sources */, 298D7CDE1BC2CAF800FD3B3E /* AFSecurityPolicyTests.m in Sources */, + 1BF9F9611C87843200F1F35A /* AFImageResponseSerializerTests.m in Sources */, 298D7C971BC2C94500FD3B3E /* AFTestCase.m in Sources */, 298D7CD81BC2CAF000FD3B3E /* AFJSONSerializationTests.m in Sources */, 298D7CDC1BC2CAF500FD3B3E /* AFPropertyListResponseSerializerTests.m in Sources */, From e0052338d62f3fbfabc53cfc17a0105347465ff2 Mon Sep 17 00:00:00 2001 From: quellish Date: Wed, 2 Mar 2016 12:34:31 -0800 Subject: [PATCH 3/8] Added test assertions for automaticallyInflatesResponseImage and imageScale of AFImageResponseSerializer --- Tests/Tests/AFImageResponseSerializerTests.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/Tests/AFImageResponseSerializerTests.m b/Tests/Tests/AFImageResponseSerializerTests.m index b19df3261a..a098d9172f 100644 --- a/Tests/Tests/AFImageResponseSerializerTests.m +++ b/Tests/Tests/AFImageResponseSerializerTests.m @@ -36,6 +36,9 @@ - (void)testCanBeCopied { XCTAssertNotEqual(copiedSerializer, responseSerializer); XCTAssertTrue(copiedSerializer.acceptableContentTypes.count == responseSerializer.acceptableContentTypes.count); XCTAssertTrue(copiedSerializer.acceptableStatusCodes.count == responseSerializer.acceptableStatusCodes.count); + XCTAssertTrue(copiedSerializer.automaticallyInflatesResponseImage == responseSerializer.automaticallyInflatesResponseImage); + XCTAssertTrue(fabs(copiedSerializer.imageScale - responseSerializer.imageScale) <= 0.001); + } - (void)testSupportsSecureCoding { From 2e790eb9177d3abc874b5fa539dc5530048058a2 Mon Sep 17 00:00:00 2001 From: quellish Date: Wed, 2 Mar 2016 12:35:34 -0800 Subject: [PATCH 4/8] Changed test names to be more descriptive --- Tests/Tests/AFImageResponseSerializerTests.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Tests/AFImageResponseSerializerTests.m b/Tests/Tests/AFImageResponseSerializerTests.m index a098d9172f..ac319b7376 100644 --- a/Tests/Tests/AFImageResponseSerializerTests.m +++ b/Tests/Tests/AFImageResponseSerializerTests.m @@ -29,7 +29,7 @@ @interface AFImageResponseSerializerTests : AFTestCase @implementation AFImageResponseSerializerTests -- (void)testCanBeCopied { +- (void)testImageSerializerCanBeCopied { AFImageResponseSerializer *responseSerializer = [AFImageResponseSerializer serializer]; AFImageResponseSerializer *copiedSerializer = [responseSerializer copy]; XCTAssertNotNil(copiedSerializer); @@ -41,7 +41,7 @@ - (void)testCanBeCopied { } -- (void)testSupportsSecureCoding { +- (void)testImageSerializerSupportsSecureCoding { XCTAssertTrue([AFImageResponseSerializer supportsSecureCoding]); } From dfbe3edab4790685e7a498e18fa235643d4c614c Mon Sep 17 00:00:00 2001 From: quellish Date: Wed, 2 Mar 2016 12:44:28 -0800 Subject: [PATCH 5/8] Added test to ensure that archiving an image serializer with non-default property values produces the expected result. --- Tests/Tests/AFImageResponseSerializerTests.m | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Tests/Tests/AFImageResponseSerializerTests.m b/Tests/Tests/AFImageResponseSerializerTests.m index ac319b7376..798f954836 100644 --- a/Tests/Tests/AFImageResponseSerializerTests.m +++ b/Tests/Tests/AFImageResponseSerializerTests.m @@ -29,6 +29,8 @@ @interface AFImageResponseSerializerTests : AFTestCase @implementation AFImageResponseSerializerTests +#pragma mark NSCopying + - (void)testImageSerializerCanBeCopied { AFImageResponseSerializer *responseSerializer = [AFImageResponseSerializer serializer]; AFImageResponseSerializer *copiedSerializer = [responseSerializer copy]; @@ -41,8 +43,40 @@ - (void)testImageSerializerCanBeCopied { } +#pragma mark NSSecureCoding + - (void)testImageSerializerSupportsSecureCoding { XCTAssertTrue([AFImageResponseSerializer supportsSecureCoding]); } +- (void)testImageSerializerCanBeArchivedAndUnarchived { + AFImageResponseSerializer *responseSerializer = [AFImageResponseSerializer serializer]; + NSData *archive = nil; + + archive = [NSKeyedArchiver archivedDataWithRootObject:responseSerializer]; + XCTAssertNotNil(archive); + AFImageResponseSerializer *unarchivedSerializer = [NSKeyedUnarchiver unarchiveObjectWithData:archive]; + XCTAssertNotNil(unarchivedSerializer); + XCTAssertNotEqual(unarchivedSerializer, responseSerializer); + XCTAssertTrue(unarchivedSerializer.automaticallyInflatesResponseImage == responseSerializer.automaticallyInflatesResponseImage); + XCTAssertTrue(fabs(unarchivedSerializer.imageScale - responseSerializer.imageScale) <= 0.001); +} + +- (void)testImageSerializerCanBeArchivedAndUnarchivedWithNonDefaultPropertyValues { + AFImageResponseSerializer *responseSerializer = [AFImageResponseSerializer serializer]; + NSData *archive = nil; + + // Customize the default property values + responseSerializer.automaticallyInflatesResponseImage = !responseSerializer.automaticallyInflatesResponseImage; + responseSerializer.imageScale = responseSerializer.imageScale * 2.0f; + + archive = [NSKeyedArchiver archivedDataWithRootObject:responseSerializer]; + XCTAssertNotNil(archive); + AFImageResponseSerializer *unarchivedSerializer = [NSKeyedUnarchiver unarchiveObjectWithData:archive]; + XCTAssertNotNil(unarchivedSerializer); + XCTAssertNotEqual(unarchivedSerializer, responseSerializer); + XCTAssertTrue(unarchivedSerializer.automaticallyInflatesResponseImage == responseSerializer.automaticallyInflatesResponseImage); + XCTAssertTrue(fabs(unarchivedSerializer.imageScale - responseSerializer.imageScale) <= 0.001); +} + @end From f3a7adf1472dc9b027c8b96cefac97185bc4aaa3 Mon Sep 17 00:00:00 2001 From: quellish Date: Wed, 2 Mar 2016 13:14:39 -0800 Subject: [PATCH 6/8] Added additional assertions to compare the acceptableContentTypes and acceptableStatusCodes properties for copying and archiving. --- Tests/Tests/AFImageResponseSerializerTests.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/Tests/AFImageResponseSerializerTests.m b/Tests/Tests/AFImageResponseSerializerTests.m index 798f954836..c4e4fa494d 100644 --- a/Tests/Tests/AFImageResponseSerializerTests.m +++ b/Tests/Tests/AFImageResponseSerializerTests.m @@ -38,6 +38,8 @@ - (void)testImageSerializerCanBeCopied { XCTAssertNotEqual(copiedSerializer, responseSerializer); XCTAssertTrue(copiedSerializer.acceptableContentTypes.count == responseSerializer.acceptableContentTypes.count); XCTAssertTrue(copiedSerializer.acceptableStatusCodes.count == responseSerializer.acceptableStatusCodes.count); + XCTAssertTrue([copiedSerializer.acceptableContentTypes isEqualToSet:responseSerializer.acceptableContentTypes]); + XCTAssertTrue([copiedSerializer.acceptableStatusCodes isEqualToIndexSet:responseSerializer.acceptableStatusCodes]); XCTAssertTrue(copiedSerializer.automaticallyInflatesResponseImage == responseSerializer.automaticallyInflatesResponseImage); XCTAssertTrue(fabs(copiedSerializer.imageScale - responseSerializer.imageScale) <= 0.001); @@ -58,6 +60,8 @@ - (void)testImageSerializerCanBeArchivedAndUnarchived { AFImageResponseSerializer *unarchivedSerializer = [NSKeyedUnarchiver unarchiveObjectWithData:archive]; XCTAssertNotNil(unarchivedSerializer); XCTAssertNotEqual(unarchivedSerializer, responseSerializer); + XCTAssertTrue([unarchivedSerializer.acceptableContentTypes isEqualToSet:responseSerializer.acceptableContentTypes]); + XCTAssertTrue([unarchivedSerializer.acceptableStatusCodes isEqualToIndexSet:responseSerializer.acceptableStatusCodes]); XCTAssertTrue(unarchivedSerializer.automaticallyInflatesResponseImage == responseSerializer.automaticallyInflatesResponseImage); XCTAssertTrue(fabs(unarchivedSerializer.imageScale - responseSerializer.imageScale) <= 0.001); } From ca22ad539de3b0a20388386bde1ef3e3c9820be3 Mon Sep 17 00:00:00 2001 From: quellish Date: Wed, 2 Mar 2016 14:30:02 -0800 Subject: [PATCH 7/8] Removed assertions on acceptableContentTypes.count and acceptableStatusCodes.count as this is now handled by isEqual assertions --- Tests/Tests/AFImageResponseSerializerTests.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/Tests/AFImageResponseSerializerTests.m b/Tests/Tests/AFImageResponseSerializerTests.m index c4e4fa494d..7869b06ddd 100644 --- a/Tests/Tests/AFImageResponseSerializerTests.m +++ b/Tests/Tests/AFImageResponseSerializerTests.m @@ -36,8 +36,6 @@ - (void)testImageSerializerCanBeCopied { AFImageResponseSerializer *copiedSerializer = [responseSerializer copy]; XCTAssertNotNil(copiedSerializer); XCTAssertNotEqual(copiedSerializer, responseSerializer); - XCTAssertTrue(copiedSerializer.acceptableContentTypes.count == responseSerializer.acceptableContentTypes.count); - XCTAssertTrue(copiedSerializer.acceptableStatusCodes.count == responseSerializer.acceptableStatusCodes.count); XCTAssertTrue([copiedSerializer.acceptableContentTypes isEqualToSet:responseSerializer.acceptableContentTypes]); XCTAssertTrue([copiedSerializer.acceptableStatusCodes isEqualToIndexSet:responseSerializer.acceptableStatusCodes]); XCTAssertTrue(copiedSerializer.automaticallyInflatesResponseImage == responseSerializer.automaticallyInflatesResponseImage); From c297688068b545e686fe8cdb3deabdfc81a0f2d5 Mon Sep 17 00:00:00 2001 From: quellish Date: Wed, 2 Mar 2016 15:25:03 -0800 Subject: [PATCH 8/8] automaticallyInflatesResponseImage and imageScale properties are not available on MacOS X, using the preprocessor to handle that correctly. --- Tests/Tests/AFImageResponseSerializerTests.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Tests/Tests/AFImageResponseSerializerTests.m b/Tests/Tests/AFImageResponseSerializerTests.m index 7869b06ddd..93ef3fbdad 100644 --- a/Tests/Tests/AFImageResponseSerializerTests.m +++ b/Tests/Tests/AFImageResponseSerializerTests.m @@ -38,8 +38,10 @@ - (void)testImageSerializerCanBeCopied { XCTAssertNotEqual(copiedSerializer, responseSerializer); XCTAssertTrue([copiedSerializer.acceptableContentTypes isEqualToSet:responseSerializer.acceptableContentTypes]); XCTAssertTrue([copiedSerializer.acceptableStatusCodes isEqualToIndexSet:responseSerializer.acceptableStatusCodes]); +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH XCTAssertTrue(copiedSerializer.automaticallyInflatesResponseImage == responseSerializer.automaticallyInflatesResponseImage); XCTAssertTrue(fabs(copiedSerializer.imageScale - responseSerializer.imageScale) <= 0.001); +#endif } @@ -60,8 +62,12 @@ - (void)testImageSerializerCanBeArchivedAndUnarchived { XCTAssertNotEqual(unarchivedSerializer, responseSerializer); XCTAssertTrue([unarchivedSerializer.acceptableContentTypes isEqualToSet:responseSerializer.acceptableContentTypes]); XCTAssertTrue([unarchivedSerializer.acceptableStatusCodes isEqualToIndexSet:responseSerializer.acceptableStatusCodes]); + +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH XCTAssertTrue(unarchivedSerializer.automaticallyInflatesResponseImage == responseSerializer.automaticallyInflatesResponseImage); XCTAssertTrue(fabs(unarchivedSerializer.imageScale - responseSerializer.imageScale) <= 0.001); +#endif + } - (void)testImageSerializerCanBeArchivedAndUnarchivedWithNonDefaultPropertyValues { @@ -69,16 +75,21 @@ - (void)testImageSerializerCanBeArchivedAndUnarchivedWithNonDefaultPropertyValue NSData *archive = nil; // Customize the default property values +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH responseSerializer.automaticallyInflatesResponseImage = !responseSerializer.automaticallyInflatesResponseImage; responseSerializer.imageScale = responseSerializer.imageScale * 2.0f; +#endif archive = [NSKeyedArchiver archivedDataWithRootObject:responseSerializer]; XCTAssertNotNil(archive); AFImageResponseSerializer *unarchivedSerializer = [NSKeyedUnarchiver unarchiveObjectWithData:archive]; XCTAssertNotNil(unarchivedSerializer); XCTAssertNotEqual(unarchivedSerializer, responseSerializer); + +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH XCTAssertTrue(unarchivedSerializer.automaticallyInflatesResponseImage == responseSerializer.automaticallyInflatesResponseImage); XCTAssertTrue(fabs(unarchivedSerializer.imageScale - responseSerializer.imageScale) <= 0.001); +#endif } @end