This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add CALayer behavioral tests. * Remove unnecessary transaction blocks.
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
Copyright 2017-present The Material Motion Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import XCTest | ||
#if IS_BAZEL_BUILD | ||
import _MotionAnimator | ||
#else | ||
import MotionAnimator | ||
#endif | ||
|
||
class QuartzCoreBehavioralTests: XCTestCase { | ||
var layer: CAShapeLayer! | ||
|
||
var originalImplementation: IMP? | ||
override func setUp() { | ||
super.setUp() | ||
|
||
let window = UIWindow() | ||
window.makeKeyAndVisible() | ||
layer = CAShapeLayer() | ||
window.layer.addSublayer(layer) | ||
|
||
rebuildLayer() | ||
} | ||
|
||
override func tearDown() { | ||
layer = nil | ||
|
||
super.tearDown() | ||
} | ||
|
||
private func rebuildLayer() { | ||
let oldSuperlayer = layer.superlayer! | ||
layer.removeFromSuperlayer() | ||
layer = CAShapeLayer() | ||
oldSuperlayer.addSublayer(layer) | ||
|
||
// Connect our layers to the render server. | ||
CATransaction.flush() | ||
} | ||
|
||
func testWhichPropertiesImplicitlyAnimateAdditively() { | ||
let properties: [AnimatableKeyPath: Any] = [:] | ||
for (keyPath, value) in properties { | ||
rebuildLayer() | ||
|
||
layer.setValue(value, forKeyPath: keyPath.rawValue) | ||
|
||
XCTAssertNotNil(layer.animationKeys(), | ||
"Expected \(keyPath.rawValue) to generate at least one animation.") | ||
if let animationKeys = layer.animationKeys() { | ||
for key in animationKeys { | ||
let animation = layer.animation(forKey: key) as! CABasicAnimation | ||
XCTAssertTrue(animation.isAdditive, | ||
"Expected \(key) to be additive as a result of animating " | ||
+ "\(keyPath.rawValue), but it was not: \(animation.debugDescription).") | ||
} | ||
} | ||
} | ||
} | ||
|
||
func testWhichPropertiesImplicitlyAnimateButNotAdditively() { | ||
let properties: [AnimatableKeyPath: Any] = [ | ||
.cornerRadius: 3, | ||
.height: 100, | ||
.opacity: 0.5, | ||
.position: CGPoint(x: 50, y: 20), | ||
.rotation: 42, | ||
.scale: 2.5, | ||
.strokeStart: 0.2, | ||
.strokeEnd: 0.5, | ||
.width: 25, | ||
.x: 12, | ||
.y: 23, | ||
] | ||
for (keyPath, value) in properties { | ||
rebuildLayer() | ||
|
||
layer.setValue(value, forKeyPath: keyPath.rawValue) | ||
|
||
XCTAssertNotNil(layer.animationKeys(), | ||
"Expected \(keyPath.rawValue) to generate at least one animation.") | ||
if let animationKeys = layer.animationKeys() { | ||
for key in animationKeys { | ||
let animation = layer.animation(forKey: key) as! CABasicAnimation | ||
XCTAssertFalse(animation.isAdditive, | ||
"Expected \(key) not to be additive as a result of animating " | ||
+ "\(keyPath.rawValue), but it was: \(animation.debugDescription).") | ||
} | ||
} | ||
} | ||
} | ||
|
||
func testWhichPropertiesDoNotImplicitlyAnimate() { | ||
let properties: [AnimatableKeyPath: Any] = [ | ||
.backgroundColor: UIColor.blue, | ||
] | ||
for (keyPath, value) in properties { | ||
rebuildLayer() | ||
|
||
layer.setValue(value, forKeyPath: keyPath.rawValue) | ||
|
||
XCTAssertNil(layer.animationKeys(), | ||
"Expected \(keyPath.rawValue) not to generate any animations.") | ||
} | ||
} | ||
} | ||
|