From 22c9a4e549a43a2b4b9bab75f546dc034dc80c45 Mon Sep 17 00:00:00 2001 From: kinarobin Date: Thu, 7 Oct 2021 19:15:19 +0800 Subject: [PATCH] fix test error in tvos --- Podfile | 1 + Tests/SDWebImage Tests.xcodeproj/project.pbxproj | 14 ++++++++++++++ Tests/Tests/SDAnimatedImageTest.m | 6 ++++++ Tests/Tests/SDImageCoderTests.m | 11 +++++++++++ Tests/Tests/SDWebImageManagerTests.m | 4 ++-- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Podfile b/Podfile index 68c01b89..e58e7b39 100644 --- a/Podfile +++ b/Podfile @@ -14,6 +14,7 @@ def all_test_pods pod 'SDWebImage/MapKit', :path => './' pod 'Expecta' pod 'KVOController' + pod 'SDWebImageWebPCoder', :git => 'https://github.com/SDWebImage/SDWebImageWebPCoder.git', :branch => 'master' end example_project_path = 'Examples/SDWebImage Demo' diff --git a/Tests/SDWebImage Tests.xcodeproj/project.pbxproj b/Tests/SDWebImage Tests.xcodeproj/project.pbxproj index 1fb4b26c..e2a66dba 100644 --- a/Tests/SDWebImage Tests.xcodeproj/project.pbxproj +++ b/Tests/SDWebImage Tests.xcodeproj/project.pbxproj @@ -106,6 +106,7 @@ 5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */; }; 6B181A1B265757ED00BD06B3 /* TestAnimatedImageMemory.webp in Resources */ = {isa = PBXBuildFile; fileRef = 6B181A1A265757ED00BD06B3 /* TestAnimatedImageMemory.webp */; }; 6BC1C20F270F0193003FFAB1 /* TestAnimatedImageMemory.webp in Resources */ = {isa = PBXBuildFile; fileRef = 6B181A1A265757ED00BD06B3 /* TestAnimatedImageMemory.webp */; }; + 6BC1C210270F073A003FFAB1 /* TestAnimatedImageMemory.webp in Resources */ = {isa = PBXBuildFile; fileRef = 6B181A1A265757ED00BD06B3 /* TestAnimatedImageMemory.webp */; }; 770D3B9C7914D53EBA0524DB /* Pods_Tests_TV.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B73996BC299E8E0174661628 /* Pods_Tests_TV.framework */; }; AFDBD4044E95252B70FB85CE /* Pods_Tests_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD1BD830DA7388EB6C110B3B /* Pods_Tests_iOS.framework */; }; DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D56195472AA00390AB0 /* XCTest.framework */; }; @@ -468,6 +469,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6BC1C210270F073A003FFAB1 /* TestAnimatedImageMemory.webp in Resources */, 3299228D2365DC6C00EAFD97 /* TestImageAnimated.apng in Resources */, 3299228B2365DC6C00EAFD97 /* TestImage.heic in Resources */, 329922872365DC6C00EAFD97 /* TestLoopCount.gif in Resources */, @@ -564,12 +566,16 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Tests TV/Pods-Tests TV-frameworks.sh", "${BUILT_PRODUCTS_DIR}/SDWebImage-Core-MapKit-tvOS/SDWebImage.framework", + "${BUILT_PRODUCTS_DIR}/SDWebImageWebPCoder-tvOS/SDWebImageWebPCoder.framework", + "${BUILT_PRODUCTS_DIR}/libwebp-tvOS/libwebp.framework", "${BUILT_PRODUCTS_DIR}/Expecta-tvOS/Expecta.framework", "${BUILT_PRODUCTS_DIR}/KVOController-tvOS/KVOController.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageWebPCoder.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libwebp.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Expecta.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KVOController.framework", ); @@ -604,12 +610,16 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Tests Mac/Pods-Tests Mac-frameworks.sh", "${BUILT_PRODUCTS_DIR}/SDWebImage-Core-MapKit-macOS/SDWebImage.framework", + "${BUILT_PRODUCTS_DIR}/SDWebImageWebPCoder-macOS/SDWebImageWebPCoder.framework", + "${BUILT_PRODUCTS_DIR}/libwebp-macOS/libwebp.framework", "${BUILT_PRODUCTS_DIR}/Expecta-macOS/Expecta.framework", "${BUILT_PRODUCTS_DIR}/KVOController-macOS/KVOController.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageWebPCoder.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libwebp.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Expecta.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KVOController.framework", ); @@ -626,12 +636,16 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Tests iOS/Pods-Tests iOS-frameworks.sh", "${BUILT_PRODUCTS_DIR}/SDWebImage-Core-MapKit-iOS/SDWebImage.framework", + "${BUILT_PRODUCTS_DIR}/SDWebImageWebPCoder-iOS/SDWebImageWebPCoder.framework", + "${BUILT_PRODUCTS_DIR}/libwebp-iOS/libwebp.framework", "${BUILT_PRODUCTS_DIR}/Expecta-iOS/Expecta.framework", "${BUILT_PRODUCTS_DIR}/KVOController-iOS/KVOController.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageWebPCoder.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libwebp.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Expecta.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KVOController.framework", ); diff --git a/Tests/Tests/SDAnimatedImageTest.m b/Tests/Tests/SDAnimatedImageTest.m index 51d2e776..11e2390f 100644 --- a/Tests/Tests/SDAnimatedImageTest.m +++ b/Tests/Tests/SDAnimatedImageTest.m @@ -10,6 +10,7 @@ #import "SDTestCase.h" #import "SDInternalMacros.h" #import +#import static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop count @@ -767,7 +768,12 @@ static BOOL _isCalled; - (void)test36AnimatedImageMemoryCost { if (@available(iOS 14, tvOS 14, macOS 11, watchOS 7, *)) { +#if SD_TV + /// TV OS does not support ImageIO's webp. + [[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]]; +#else [[SDImageCodersManager sharedManager] addCoder:[SDImageAWebPCoder sharedCoder]]; +#endif UIImage *image = [UIImage sd_imageWithData:[NSData dataWithContentsOfFile:[self testMemotyCostImagePath]]]; NSUInteger cost = [image sd_memoryCost]; #if SD_UIKIT diff --git a/Tests/Tests/SDImageCoderTests.m b/Tests/Tests/SDImageCoderTests.m index 7ae1f717..ee2614d6 100644 --- a/Tests/Tests/SDImageCoderTests.m +++ b/Tests/Tests/SDImageCoderTests.m @@ -9,6 +9,7 @@ #import "SDTestCase.h" #import "UIColor+SDHexString.h" +#import @interface SDWebImageDecoderTests : SDTestCase @@ -246,7 +247,12 @@ - (void)test18ThatStaticWebPWorks { if (@available(iOS 14, tvOS 14, macOS 11, *)) { NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageStatic" withExtension:@"webp"]; +#if SD_TV + /// TV OS does not support ImageIO's webp. + [self verifyCoder:[SDImageWebPCoder sharedCoder] +#else [self verifyCoder:[SDImageAWebPCoder sharedCoder] +#endif withLocalImageURL:staticWebPURL supportsEncoding:NO // Currently (iOS 14.0) seems no encoding support encodingFormat:SDImageFormatWebP @@ -258,7 +264,12 @@ - (void)test19ThatAnimatedWebPWorks { if (@available(iOS 14, tvOS 14, macOS 11, *)) { NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageAnimated" withExtension:@"webp"]; +#if SD_TV + /// TV OS does not support ImageIO's webp. + [self verifyCoder:[SDImageWebPCoder sharedCoder] +#else [self verifyCoder:[SDImageAWebPCoder sharedCoder] +#endif withLocalImageURL:staticWebPURL supportsEncoding:NO // Currently (iOS 14.0) seems no encoding support encodingFormat:SDImageFormatWebP diff --git a/Tests/Tests/SDWebImageManagerTests.m b/Tests/Tests/SDWebImageManagerTests.m index 4b304b36..689b65c9 100644 --- a/Tests/Tests/SDWebImageManagerTests.m +++ b/Tests/Tests/SDWebImageManagerTests.m @@ -40,7 +40,7 @@ }]; expect([[SDWebImageManager sharedManager] isRunning]).to.equal(YES); - [self waitForExpectationsWithCommonTimeout]; + [self waitForExpectationsWithTimeout:kAsyncTestTimeout * 2 handler:nil]; } - (void)test03ThatDownloadWithIncorrectURLInvokesCompletionBlockWithAnErrorAsync { @@ -82,7 +82,7 @@ [expectation fulfill]; }); - [self waitForExpectationsWithCommonTimeout]; + [self waitForExpectationsWithTimeout:kAsyncTestTimeout * 2 handler:nil]; } - (void)test07ThatLoadImageWithSDWebImageRefreshCachedWorks {