diff --git a/pop-tests/POPBaseAnimationTests.h b/pop-tests/POPBaseAnimationTests.h index 75bff862..29eccd15 100644 --- a/pop-tests/POPBaseAnimationTests.h +++ b/pop-tests/POPBaseAnimationTests.h @@ -8,6 +8,7 @@ */ #import +#import "POPCGUtils.h" @class CALayer; @class POPAnimator; @@ -37,3 +38,15 @@ extern NSUInteger POPAnimationCountLastEventValues(NSArray *events, NSNumber *va // returns YES if array of value events contain specified value extern BOOL POPAnimationEventsContainValue(NSArray *events, NSNumber *value); + +// equality with epsilon +#define _EQLF_(x, y, epsilon) (fabsf ((x) - (y)) < epsilon) + +// color equality assert +#define POPAssertColorEqual(c1, c2) \ +{ \ + CGFloat v1[4], v2[4]; \ + POPCGColorGetRGBAComponents(c1, v1); \ + POPCGColorGetRGBAComponents(c2, v2); \ + STAssertTrue(_EQLF_(v1[0], v2[0], 1e-6) && _EQLF_(v1[1], v2[1], 1e-6) && _EQLF_(v1[2], v2[2], 1e-6) && _EQLF_(v1[3], v2[3], 1e-6), @"not equal color:[r:%f g:%f b:%f a:%f] color:[r:%f g:%f b:%f a:%f]", v1[0], v1[1], v1[2], v1[3], v2[0], v2[1], v2[2], v2[3]); \ +} \ No newline at end of file diff --git a/pop-tests/POPBasicAnimationTests.mm b/pop-tests/POPBasicAnimationTests.mm new file mode 100644 index 00000000..eb7e70b5 --- /dev/null +++ b/pop-tests/POPBasicAnimationTests.mm @@ -0,0 +1,47 @@ +// +// POPBasicAnimationTests.m +// pop +// +// Created by Kimon Tsinteris on 5/2/14. +// Copyright (c) 2014 Facebook. All rights reserved. +// + +#import + +#import +#import + +#import "POPAnimatable.h" +#import "POPAnimationTestsExtras.h" +#import "POPBaseAnimationTests.h" + +@interface POPBasicAnimationTests : POPBaseAnimationTests + +@end + +@implementation POPBasicAnimationTests + +- (void)testColorInterpolation +{ + POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerBackgroundColor]; + anim.fromValue = [UIColor whiteColor]; + anim.toValue = [UIColor redColor]; + + POPAnimationTracer *tracer = anim.tracer; + [tracer start]; + + CALayer *layer = [CALayer layer]; + [layer pop_addAnimation:anim forKey:nil]; + + // run animation + POPAnimatorRenderDuration(self.animator, self.beginTime, 3, 1.0/60.0); + + // verify write events + NSArray *writeEvents = [tracer eventsWithType:kPOPAnimationEventPropertyWrite]; + STAssertTrue(writeEvents.count > 5, @"expected more write events %@", tracer.allEvents); + + // assert final value + POPAssertColorEqual((__bridge CGColorRef)anim.toValue, layer.backgroundColor); +} + +@end diff --git a/pop-tests/POPSpringAnimationTests.mm b/pop-tests/POPSpringAnimationTests.mm index e34cef7b..c48726b2 100644 --- a/pop-tests/POPSpringAnimationTests.mm +++ b/pop-tests/POPSpringAnimationTests.mm @@ -455,9 +455,7 @@ - (void)testColorSupport POPAnimationValueEvent *lastEvent = [writeEvents lastObject]; // verify last written color is to color - CGFloat lastValues[4]; - POPCGColorGetRGBAComponents((__bridge CGColorRef)lastEvent.value, lastValues); - STAssertTrue(lastValues[0] == toValues[0] && lastValues[1] == toValues[1] && lastValues[2] == toValues[2] && lastValues[3] == toValues[3], @"unexpected last color: [r:%f g:%f b:%f a:%f]", lastValues[0], lastValues[1], lastValues[2], lastValues[3]); + POPAssertColorEqual((__bridge CGColorRef)lastEvent.value, (__bridge CGColorRef)anim.toValue); } static BOOL _floatingPointEqual(CGFloat a, CGFloat b) @@ -556,9 +554,7 @@ - (void)testNilColor STAssertTrue(fromColor, @"unexpected value %p", fromColor); // verify from color clear - CGFloat components[4]; - POPCGColorGetRGBAComponents(fromColor, components); - STAssertTrue(components[0] == 0 && components[1] == 0 && components[2] == 0 && components[3] == 0, @"unexpected components {%f, %f, %f, %f}", components[0], components[1], components[2], components[3]); + POPAssertColorEqual(fromColor, [UIColor clearColor].CGColor); } - (void)testExcessiveJumpInTime diff --git a/pop.xcodeproj/project.pbxproj b/pop.xcodeproj/project.pbxproj index 9125aa78..0c6d1846 100644 --- a/pop.xcodeproj/project.pbxproj +++ b/pop.xcodeproj/project.pbxproj @@ -69,6 +69,8 @@ EC6885D118C7BD8500C6194C /* TransformationMatrix.h in Headers */ = {isa = PBXBuildFile; fileRef = EC94B07817D95447003CE2C8 /* TransformationMatrix.h */; }; EC6885D218C7BD8900C6194C /* TransformationMatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC94B07717D95447003CE2C8 /* TransformationMatrix.cpp */; }; EC6885D418C7C44E00C6194C /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EC6885D318C7C44E00C6194C /* QuartzCore.framework */; }; + EC6C098919141BBD00F8EA96 /* POPBasicAnimationTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = EC6C098819141BBD00F8EA96 /* POPBasicAnimationTests.mm */; }; + EC6C098A19141BBD00F8EA96 /* POPBasicAnimationTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = EC6C098819141BBD00F8EA96 /* POPBasicAnimationTests.mm */; }; EC70AC4418CCF4FC0067018C /* POPVector.mm in Sources */ = {isa = PBXBuildFile; fileRef = EC70AC4218CCF4FC0067018C /* POPVector.mm */; }; EC70AC4518CCF4FC0067018C /* POPVector.mm in Sources */ = {isa = PBXBuildFile; fileRef = EC70AC4218CCF4FC0067018C /* POPVector.mm */; }; EC70AC4618CCF4FC0067018C /* POPVector.h in Headers */ = {isa = PBXBuildFile; fileRef = EC70AC4318CCF4FC0067018C /* POPVector.h */; }; @@ -231,6 +233,7 @@ EC68858C18C7B60000C6194C /* pop-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "pop-Prefix.pch"; sourceTree = ""; }; EC68859518C7B60100C6194C /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; EC6885D318C7C44E00C6194C /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/QuartzCore.framework; sourceTree = DEVELOPER_DIR; }; + EC6C098819141BBD00F8EA96 /* POPBasicAnimationTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = POPBasicAnimationTests.mm; sourceTree = ""; }; EC6F55A1175E654B008D995D /* POPDecayAnimationTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = POPDecayAnimationTests.mm; sourceTree = ""; }; EC6F55A3175E6641008D995D /* POPBaseAnimationTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = POPBaseAnimationTests.h; sourceTree = ""; }; EC6F55A4175E6641008D995D /* POPBaseAnimationTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = POPBaseAnimationTests.mm; sourceTree = ""; }; @@ -521,6 +524,7 @@ EC6F55AA175E6B11008D995D /* POPSpringAnimationTests.mm */, EC7D2CFB1795AB3100E50A78 /* POPEaseInEaseOutAnimationTests.mm */, EC72875418E13348006EEE54 /* POPCustomAnimationTests.mm */, + EC6C098819141BBD00F8EA96 /* POPBasicAnimationTests.mm */, EC7E319C18C93D6500B38170 /* Supporting Files - OSX */, EC882A7618C91983007829CC /* Supporting Files - iOS */, ); @@ -1025,6 +1029,7 @@ EC72875618E13348006EEE54 /* POPCustomAnimationTests.mm in Sources */, EC7E31AB18C9419000B38170 /* POPAnimatable.mm in Sources */, EC7E31AD18C9419600B38170 /* POPAnimationTests.mm in Sources */, + EC6C098A19141BBD00F8EA96 /* POPBasicAnimationTests.mm in Sources */, EC7E31B318C941A700B38170 /* POPEaseInEaseOutAnimationTests.mm in Sources */, EC7E31AE18C9419900B38170 /* POPAnimationMRRTests.mm in Sources */, EC7E31AC18C9419200B38170 /* POPBaseAnimationTests.mm in Sources */, @@ -1043,6 +1048,7 @@ EC72875518E13348006EEE54 /* POPCustomAnimationTests.mm in Sources */, ECDA0CC618C92BC900D14897 /* POPAnimatable.mm in Sources */, ECDA0CC818C92BD200D14897 /* POPAnimationTests.mm in Sources */, + EC6C098919141BBD00F8EA96 /* POPBasicAnimationTests.mm in Sources */, ECDA0CCE18C92BD200D14897 /* POPEaseInEaseOutAnimationTests.mm in Sources */, ECDA0CC918C92BD200D14897 /* POPAnimationMRRTests.mm in Sources */, ECDA0CC718C92BD200D14897 /* POPBaseAnimationTests.mm in Sources */, diff --git a/pop/POPCGUtils.mm b/pop/POPCGUtils.mm index 08a748b5..c8a866a4 100644 --- a/pop/POPCGUtils.mm +++ b/pop/POPCGUtils.mm @@ -39,8 +39,12 @@ void POPCGColorGetRGBAComponents(CGColorRef color, CGFloat components[]) components[0] = components[1] = components[2] = colors[0]; components[3] = colors[1]; } else { - // TODO HSV and CMYK conversion - NSCAssert(NO, @"unsuported color space conversion, component count:%lu", count); + // Use CI to convert + CIColor *ciColor = [CIColor colorWithCGColor:color]; + components[0] = ciColor.red; + components[1] = ciColor.green; + components[2] = ciColor.blue; + components[3] = ciColor.alpha; } }