From eeec6de69840767bdff8fac6299d10b6fc469836 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 30 Jan 2020 15:29:57 +0800 Subject: [PATCH] Update the PDF demo and test cases --- .../SDWebImage Demo/MasterViewController.m | 1 + .../project.pbxproj | 8 +++++ Tests/Tests/Images/TestImage.pdf | Bin 0 -> 1018 bytes Tests/Tests/SDImageCoderTests.m | 33 +++++++++++++++--- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 Tests/Tests/Images/TestImage.pdf diff --git a/Examples/SDWebImage Demo/MasterViewController.m b/Examples/SDWebImage Demo/MasterViewController.m index f131f55f..b82b17c0 100644 --- a/Examples/SDWebImage Demo/MasterViewController.m +++ b/Examples/SDWebImage Demo/MasterViewController.m @@ -75,6 +75,7 @@ @"https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic", @"https://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic", @"https://s2.ax1x.com/2019/11/01/KHYIgJ.gif", + @"https://raw.githubusercontent.com/icons8/flat-color-icons/master/pdf/stack_of_photos.pdf", @"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png", @"http://via.placeholder.com/200x200.jpg", nil]; diff --git a/Tests/SDWebImage Tests.xcodeproj/project.pbxproj b/Tests/SDWebImage Tests.xcodeproj/project.pbxproj index c98bbde1..ac80009d 100644 --- a/Tests/SDWebImage Tests.xcodeproj/project.pbxproj +++ b/Tests/SDWebImage Tests.xcodeproj/project.pbxproj @@ -14,6 +14,9 @@ 322241802272F808002429DB /* SDUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3222417E2272F808002429DB /* SDUtilsTests.m */; }; 3226ECBB20754F7700FAFACF /* SDWebImageTestDownloadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 3226ECBA20754F7700FAFACF /* SDWebImageTestDownloadOperation.m */; }; 3226ECBC20754F7700FAFACF /* SDWebImageTestDownloadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 3226ECBA20754F7700FAFACF /* SDWebImageTestDownloadOperation.m */; }; + 3234306223E2BAC800C290C8 /* TestImage.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 3234306123E2BAC800C290C8 /* TestImage.pdf */; }; + 3234306323E2BAC800C290C8 /* TestImage.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 3234306123E2BAC800C290C8 /* TestImage.pdf */; }; + 3234306423E2BAC800C290C8 /* TestImage.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 3234306123E2BAC800C290C8 /* TestImage.pdf */; }; 323B8E1F20862322008952BE /* SDWebImageTestLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 323B8E1E20862322008952BE /* SDWebImageTestLoader.m */; }; 323B8E2020862322008952BE /* SDWebImageTestLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 323B8E1E20862322008952BE /* SDWebImageTestLoader.m */; }; 324047442271956F007C53E1 /* TestEXIF.png in Resources */ = {isa = PBXBuildFile; fileRef = 324047432271956F007C53E1 /* TestEXIF.png */; }; @@ -107,6 +110,7 @@ 3222417E2272F808002429DB /* SDUtilsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDUtilsTests.m; sourceTree = ""; }; 3226ECB920754F7700FAFACF /* SDWebImageTestDownloadOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageTestDownloadOperation.h; sourceTree = ""; }; 3226ECBA20754F7700FAFACF /* SDWebImageTestDownloadOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTestDownloadOperation.m; sourceTree = ""; }; + 3234306123E2BAC800C290C8 /* TestImage.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = TestImage.pdf; sourceTree = ""; }; 323B8E1D20862322008952BE /* SDWebImageTestLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageTestLoader.h; sourceTree = ""; }; 323B8E1E20862322008952BE /* SDWebImageTestLoader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTestLoader.m; sourceTree = ""; }; 324047432271956F007C53E1 /* TestEXIF.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = TestEXIF.png; sourceTree = ""; }; @@ -238,6 +242,7 @@ 433BBBB81D7EF8260086B6E9 /* TestImage.png */, 327A418B211D660600495442 /* TestImage.heic */, 32905E63211D786E00460FCF /* TestImage.heif */, + 3234306123E2BAC800C290C8 /* TestImage.pdf */, 327054E1206CEFF3006EA328 /* TestImageAnimated.apng */, 3297A09E23374D1600814590 /* TestImageAnimated.heic */, ); @@ -443,6 +448,7 @@ 3299228B2365DC6C00EAFD97 /* TestImage.heic in Resources */, 329922872365DC6C00EAFD97 /* TestLoopCount.gif in Resources */, 3299228C2365DC6C00EAFD97 /* TestImage.heif in Resources */, + 3234306423E2BAC800C290C8 /* TestImage.pdf in Resources */, 329922892365DC6C00EAFD97 /* TestImageLarge.jpg in Resources */, 3299228A2365DC6C00EAFD97 /* TestImage.png in Resources */, 329922842365DC6C00EAFD97 /* MonochromeTestImage.jpg in Resources */, @@ -461,6 +467,7 @@ 32B99EA3203B31360017FD66 /* TestImage.gif in Resources */, 324047452271956F007C53E1 /* TestEXIF.png in Resources */, 32B99EA4203B31360017FD66 /* TestImage.jpg in Resources */, + 3234306323E2BAC800C290C8 /* TestImage.pdf in Resources */, 32B99EA6203B31360017FD66 /* TestImage.png in Resources */, 3297A0A023374D1700814590 /* TestImageAnimated.heic in Resources */, 32B99EA2203B31360017FD66 /* MonochromeTestImage.jpg in Resources */, @@ -479,6 +486,7 @@ 5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */, 32905E64211D786E00460FCF /* TestImage.heif in Resources */, 43828A451DA67F9900000E62 /* TestImageLarge.jpg in Resources */, + 3234306223E2BAC800C290C8 /* TestImage.pdf in Resources */, 433BBBB71D7EF8200086B6E9 /* TestImage.gif in Resources */, 433BBBB91D7EF8260086B6E9 /* TestImage.png in Resources */, 3297A09F23374D1700814590 /* TestImageAnimated.heic in Resources */, diff --git a/Tests/Tests/Images/TestImage.pdf b/Tests/Tests/Images/TestImage.pdf new file mode 100644 index 0000000000000000000000000000000000000000..132681b067d4be6b5415f062924037811b926d9a GIT binary patch literal 1018 zcma)5O=uHA6c!I6>kmb-t$KMvqb+E5lkFyH357OIg1-$LMZ^{zH`8P#-HEf4k}6(2 zhzhnK>Y>!1s#HAGqTofL2t9~+5PA_24;H)#MGt}pf8T6=8rqA)FthW`oAitZz#TJi;sUQI%vR7omQezP!CWiD{|0|kf{KGny~YNa@_Mo&|Ye>3{|?i6jyLc zhLqC8k+JTLt9PuA|Cm^~b9a8eF>*1fwTy0W`to}-Y2NvK;l`iYshNgH<4t{+TKva` zR=LA-=jJ{)J~@A(dFz8~&9@sSGyHo0>!&@zk>Nu37@y9a+_mMzt(TYk-;7^*I5YX; z>QU=g-`wb##2P)lY4M)_{ry)T4(;o-*1h|_d&-EL(`((2ZwEGv{nfvI+BSRhTR5pu zCsW~vUs9QrBX<-OXz!5s@)WG;_LRm;BAFJb5~5KF;82N%2T)_(5CGL8xT1Evz!hi3 zk5Tgj>fwK=eZHt=89toCtt0r|>kz3RSsotzpAvspNU`d7R zQQL24Tx2YTnl-jXDXh*xsLnwQyF)MztroF4gMdGv`Ge4!6QaaDa#G0Img{Fc z+t%iVNpY4bTG(y>|7@uW;kxi;{xKp*o@L9fu_A7z4oh!JoDM1)L=>$yAY>T20fSJ* z3?1ts2RJn>7+Q&G0Zh+wyLQa#GE7JB%Q2%PvH}YS>+A$4cAj$Y7fst|DN>g0X)-22 e3NN?IUT2VjEQ429R}d~dh2d~m@%iF?3FRM0)gsma literal 0 HcmV?d00001 diff --git a/Tests/Tests/SDImageCoderTests.m b/Tests/Tests/SDImageCoderTests.m index 23dc6d56..95b8b5a2 100644 --- a/Tests/Tests/SDImageCoderTests.m +++ b/Tests/Tests/SDImageCoderTests.m @@ -156,22 +156,34 @@ withLocalImageURL:heicURL supportsEncoding:supportsEncoding encodingFormat:SDImageFormatHEIC - isAnimatedImage:isAnimatedImage]; + isAnimatedImage:isAnimatedImage + isVectorImage:NO]; } } +- (void)test17ThatPDFWorks { + NSURL *pdfURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"pdf"]; + [self verifyCoder:[SDImageIOCoder sharedCoder] + withLocalImageURL:pdfURL + supportsEncoding:NO + encodingFormat:SDImageFormatUndefined + isAnimatedImage:NO + isVectorImage:YES]; +} + - (void)verifyCoder:(id)coder withLocalImageURL:(NSURL *)imageUrl supportsEncoding:(BOOL)supportsEncoding isAnimatedImage:(BOOL)isAnimated { - [self verifyCoder:coder withLocalImageURL:imageUrl supportsEncoding:supportsEncoding encodingFormat:SDImageFormatUndefined isAnimatedImage:isAnimated]; + [self verifyCoder:coder withLocalImageURL:imageUrl supportsEncoding:supportsEncoding encodingFormat:SDImageFormatUndefined isAnimatedImage:isAnimated isVectorImage:NO]; } - (void)verifyCoder:(id)coder withLocalImageURL:(NSURL *)imageUrl supportsEncoding:(BOOL)supportsEncoding encodingFormat:(SDImageFormat)encodingFormat - isAnimatedImage:(BOOL)isAnimated { + isAnimatedImage:(BOOL)isAnimated + isVectorImage:(BOOL)isVector { NSData *inputImageData = [NSData dataWithContentsOfURL:imageUrl]; expect(inputImageData).toNot.beNil(); SDImageFormat inputImageFormat = [NSData sd_imageFormatForImageData:inputImageData]; @@ -204,7 +216,18 @@ withLocalImageURL:(NSURL *)imageUrl CGFloat pixelHeight = inputImage.size.height; expect(pixelWidth).beGreaterThan(0); expect(pixelHeight).beGreaterThan(0); - // check thumnail with scratch + // check vector format supports thumbnail with screen size + if (isVector) { +#if SD_UIKIT + CGFloat maxScreenSize = MAX(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height); +#else + CGFloat maxScreenSize = MAX(NSScreen.mainScreen.frame.size.width, NSScreen.mainScreen.frame.size.height); +#endif + expect(pixelWidth).equal(maxScreenSize); + expect(pixelHeight).equal(maxScreenSize); + } + + // check thumbnail with scratch CGFloat thumbnailWidth = 50; CGFloat thumbnailHeight = 50; UIImage *thumbImage = [coder decodedImageWithData:inputImageData options:@{ @@ -213,7 +236,7 @@ withLocalImageURL:(NSURL *)imageUrl }]; expect(thumbImage).toNot.beNil(); expect(thumbImage.size).equal(CGSizeMake(thumbnailWidth, thumbnailHeight)); - // check thumnail with aspect ratio limit + // check thumbnail with aspect ratio limit thumbImage = [coder decodedImageWithData:inputImageData options:@{ SDImageCoderDecodeThumbnailPixelSize : @(CGSizeMake(thumbnailWidth, thumbnailHeight)), SDImageCoderDecodePreserveAspectRatio : @(YES)