Skip to content

Commit

Permalink
improve color conversion; add basic animation unit tests; facebookarc…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimon Tsinteris committed May 2, 2014
1 parent 9d2b04c commit 701b47d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
13 changes: 13 additions & 0 deletions pop-tests/POPBaseAnimationTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#import <SenTestingKit/SenTestingKit.h>
#import "POPCGUtils.h"

@class CALayer;
@class POPAnimator;
Expand Down Expand Up @@ -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]); \
}
47 changes: 47 additions & 0 deletions pop-tests/POPBasicAnimationTests.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// POPBasicAnimationTests.m
// pop
//
// Created by Kimon Tsinteris on 5/2/14.
// Copyright (c) 2014 Facebook. All rights reserved.
//

#import <SenTestingKit/SenTestingKit.h>

#import <OCMock/OCMock.h>
#import <POP/POPBasicAnimation.h>

#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
8 changes: 2 additions & 6 deletions pop-tests/POPSpringAnimationTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -231,6 +233,7 @@
EC68858C18C7B60000C6194C /* pop-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "pop-Prefix.pch"; sourceTree = "<group>"; };
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 = "<group>"; };
EC6F55A1175E654B008D995D /* POPDecayAnimationTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = POPDecayAnimationTests.mm; sourceTree = "<group>"; };
EC6F55A3175E6641008D995D /* POPBaseAnimationTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = POPBaseAnimationTests.h; sourceTree = "<group>"; };
EC6F55A4175E6641008D995D /* POPBaseAnimationTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = POPBaseAnimationTests.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -521,6 +524,7 @@
EC6F55AA175E6B11008D995D /* POPSpringAnimationTests.mm */,
EC7D2CFB1795AB3100E50A78 /* POPEaseInEaseOutAnimationTests.mm */,
EC72875418E13348006EEE54 /* POPCustomAnimationTests.mm */,
EC6C098819141BBD00F8EA96 /* POPBasicAnimationTests.mm */,
EC7E319C18C93D6500B38170 /* Supporting Files - OSX */,
EC882A7618C91983007829CC /* Supporting Files - iOS */,
);
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down
8 changes: 6 additions & 2 deletions pop/POPCGUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 701b47d

Please sign in to comment.