Peter 3b155750f5 Add 'submodules/lottie-ios/' from commit 'd40e390fbe6d7ef3b417876af6fdce5e4d2aa335'
git-subtree-dir: submodules/lottie-ios
git-subtree-mainline: 76e5a7fab6b0222780f346530cdbeeff96f3e105
git-subtree-split: d40e390fbe6d7ef3b417876af6fdce5e4d2aa335
2019-06-11 18:54:21 +01:00

128 lines
5.5 KiB
Objective-C

//
// LAKeypathTest.m
// lottie-ios_Tests
//
// Created by brandon_withrow on 12/14/17.
// Copyright © 2017 Brandon Withrow. All rights reserved.
//
#import <XCTest/XCTest.h>
#import <Lottie/Lottie.h>
@interface LAKeypathTest : XCTestCase
@property (nonatomic, strong) LOTAnimationView *animationView;
@end
@implementation LAKeypathTest
- (void)setUp {
[super setUp];
self.animationView = [LOTAnimationView animationNamed:@"keypathTest"];
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testAnimationLoaded {
XCTAssertNotNil(self.animationView.sceneModel, @"Animation Composition is nil");
}
- (void)testExplicitSearch {
NSString *searchTerm = @"Shape Layer 1.Shape 1.Path 1";
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithString:searchTerm]];
XCTAssertTrue((results.count == 1), @"Wrong number of results");
NSString *firstObject = results.firstObject;
XCTAssertTrue([searchTerm isEqualToString:firstObject], @"Wrong keypath found");
}
- (void)testFuzzyKeySearch_Shape1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"**", @"Shape 1", nil]];
NSArray *expectedResults = @[@"Shape Layer 1.Shape 1",
@"WiggleLayer.Shape 1",
@"GroupShapeLayer.Group 1.Shape 1",
@"TwoShapeLayer.Shape 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 2.Group 1.Shape 1",
@"Precomp.GroupShape.Group 1.Shape 1",
@"Precomp.SingleShape.Shape 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 1.Group 1.Shape 1"];
NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}
- (void)testFuzzyKeySearch_Shape1_Path1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"**", @"Shape 1", @"Path 1", nil]];
NSArray *expectedResults = @[@"GroupShapeLayer.Group 1.Shape 1.Path 1",
@"Shape Layer 1.Shape 1.Path 1",
@"TwoShapeLayer.Shape 1.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 2.Group 1.Shape 1.Path 1",
@"Precomp.GroupShape.Group 1.Shape 1.Path 1",
@"Precomp.SingleShape.Shape 1.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 1.Group 1.Shape 1.Path 1"];
NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}
- (void)testWildcardKeySearch_Shape1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"*", @"Shape 1", nil]];
NSArray *expectedResults = @[@"Shape Layer 1.Shape 1",
@"WiggleLayer.Shape 1",
@"TwoShapeLayer.Shape 1"];
NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}
- (void)testCompoundFuzzyKeySearch_Shape1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"**", @"Shape 1", @"*", @"Stroke Width", nil]];
NSArray *expectedResults = @[@"Shape Layer 1.Shape 1.Stroke 1.Stroke Width",
@"WiggleLayer.Shape 1.Stroke 1.Stroke Width",
@"GroupShapeLayer.Group 1.Shape 1.Stroke 1.Stroke Width",
@"TwoShapeLayer.Shape 1.Stroke 1.Stroke Width"];
NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}
- (void)testDoubleFuzzyKeySearch_Shape1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"**", @"Group 1", @"**", @"Path 1", nil]];
NSArray *expectedResults = @[@"Precomp.DoubleGroupShape.TopGroup.Group 2.Group 1.Shape 1.Path 1",
@"Precomp.GroupShape.Group 1.Shape 2.Path 1",
@"Precomp.GroupShape.Group 1.Shape 1.Path 1",
@"GroupShapeLayer.Group 1.Shape 2.Path 1",
@"GroupShapeLayer.Group 1.Shape 1.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 1.Group 1.Shape 2.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 1.Group 1.Shape 1.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 2.Group 1.Shape 2.Path 1"];
NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}
- (void)testKeySearch_Precomp {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"Precomp", nil]];
NSArray *expectedResults = @[@"Precomp"];
NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}
- (void)testFuzzyKeySearch_Precomp {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"Precomp", @"**", nil]];
XCTAssertTrue((results.count == 33), @"Wrong number of results Sorry");
}
@end