初始化提交

This commit is contained in:
2026-02-03 16:52:44 +08:00
commit d2f9806384
512 changed files with 65167 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
@interface XCElementSnapshotDouble : NSObject<XCUIElementAttributes>
@property (readwrite, nullable) id value;
@property (readwrite, nullable, copy) NSString *label;
@property (nonatomic, assign) UIAccessibilityTraits traits;
@end

View File

@@ -0,0 +1,114 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "XCElementSnapshotDouble.h"
#import "FBXCAccessibilityElement.h"
#import "FBXCElementSnapshot.h"
#import "XCUIHitPointResult.h"
@implementation XCElementSnapshotDouble
- (id)init
{
self = [super init];
self->_value = @"magicValue";
self->_label = @"testLabel";
return self;
}
- (NSString *)identifier
{
return @"testName";
}
- (CGRect)frame
{
return CGRectZero;
}
- (NSString *)title
{
return @"testTitle";
}
- (XCUIElementType)elementType
{
return XCUIElementTypeOther;
}
- (BOOL)isEnabled
{
return YES;
}
- (XCUIUserInterfaceSizeClass)horizontalSizeClass
{
return XCUIUserInterfaceSizeClassUnspecified;
}
- (XCUIUserInterfaceSizeClass)verticalSizeClass
{
return XCUIUserInterfaceSizeClassUnspecified;
}
- (NSString *)placeholderValue
{
return @"testPlaceholderValue";
}
- (BOOL)isSelected
{
return YES;
}
- (BOOL)hasFocus
{
return YES;
}
- (NSDictionary *)additionalAttributes
{
return @{};
}
- (id<FBXCAccessibilityElement>)accessibilityElement
{
return nil;
}
- (id<FBXCElementSnapshot>)parent
{
return nil;
}
- (XCUIHitPointResult *)hitPoint:(NSError **)error
{
return [[XCUIHitPointResult alloc] initWithHitPoint:CGPointZero hittable:YES];
}
- (NSArray *)children
{
return @[];
}
- (NSArray *)_allDescendants
{
return @[];
}
- (CGRect)visibleFrame
{
return CGRectZero;
}
- (UIAccessibilityTraits)traits
{
return UIAccessibilityTraitButton;
}
@end

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
@interface XCUIApplicationDouble : NSObject
@property (nonatomic, assign, readonly) BOOL didTerminate;
@property (nonatomic, strong) NSString* bundleID;
@property (nonatomic) BOOL fb_shouldWaitForQuiescence;
- (BOOL)running;
@end

View File

@@ -0,0 +1,66 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "XCUIApplicationDouble.h"
@interface XCUIApplicationDouble ()
@property (nonatomic, assign, readwrite) BOOL didTerminate;
@end
@implementation XCUIApplicationDouble
- (instancetype)init
{
self = [super init];
if (self) {
_bundleID = @"some.bundle.identifier";
}
return self;
}
- (void)terminate
{
self.didTerminate = YES;
}
- (NSUInteger)processID
{
return 0;
}
- (NSString *)bundleID
{
return @"com.facebook.awesome";
}
- (void)fb_nativeResolve
{
}
- (id)query
{
return nil;
}
- (BOOL)fb_shouldWaitForQuiescence
{
return NO;
}
-(void)setFb_shouldWaitForQuiescence:(BOOL)value
{
}
- (BOOL)running
{
return NO;
}
@end

View File

@@ -0,0 +1,50 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
#import <WebDriverAgentLib/FBElement.h>
#import <XCTest/XCUIElementTypes.h>
@class XCUIApplication;
@interface XCUIElementDouble : NSObject<FBElement>
@property (nonatomic, strong, nonnull) XCUIApplication *application;
@property (nonatomic, readwrite, assign) CGRect frame;
@property (nonatomic, readwrite, nullable) id lastSnapshot;
@property (nonatomic, assign) BOOL fb_isObstructedByAlert;
@property (nonatomic, readonly, nonnull) NSString *fb_cacheId;
@property (nonatomic, readwrite, copy, nonnull) NSDictionary *wdRect;
@property (nonatomic, readwrite, assign) CGRect wdFrame;
@property (nonatomic, readwrite, copy, nonnull) NSString *wdUID;
@property (nonatomic, copy, readwrite, nullable) NSString *wdName;
@property (nonatomic, copy, readwrite, nullable) NSString *wdLabel;
@property (nonatomic, copy, readwrite, nonnull) NSString *wdType;
@property (nonatomic, strong, readwrite, nullable) NSString *wdValue;
@property (nonatomic, readwrite, getter=isWDEnabled) BOOL wdEnabled;
@property (nonatomic, readwrite, getter=isWDSelected) BOOL wdSelected;
@property (nonatomic, readwrite, assign) CGRect wdNativeFrame;
@property (nonatomic, readwrite) NSUInteger wdIndex;
@property (nonatomic, readwrite, getter=isWDVisible) BOOL wdVisible;
@property (nonatomic, readwrite, getter=isWDAccessible) BOOL wdAccessible;
@property (nonatomic, readwrite, getter = isWDFocused) BOOL wdFocused;
@property (nonatomic, readwrite, getter = isWDHittable) BOOL wdHittable;
@property (nonatomic, copy, readwrite, nullable) NSString *wdPlaceholderValue;
@property (copy, nonnull) NSArray *children;
@property (nonatomic, readwrite, assign) XCUIElementType elementType;
@property (nonatomic, readwrite, getter=isWDAccessibilityContainer) BOOL wdAccessibilityContainer;
@property (nonatomic, copy, readwrite, nullable) NSString *wdTraits;
- (void)resolve;
- (id _Nonnull)fb_standardSnapshot;
- (id _Nonnull)fb_customSnapshot;
- (nullable id)query;
// Checks
@property (nonatomic, assign, readonly) BOOL didResolve;
@end

View File

@@ -0,0 +1,103 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "XCUIElementDouble.h"
@interface XCUIElementDouble ()
@property (nonatomic, assign, readwrite) BOOL didResolve;
@end
@implementation XCUIElementDouble
- (id)init
{
self = [super init];
if (self) {
self.wdFrame = CGRectZero;
self.wdNativeFrame = CGRectZero;
self.wdName = @"testName";
self.wdLabel = @"testLabel";
self.wdValue = @"magicValue";
self.wdPlaceholderValue = @"testPlaceholderValue";
self.wdTraits = @"testTraits";
self.wdVisible = YES;
self.wdAccessible = YES;
self.wdEnabled = YES;
self.wdSelected = YES;
self.wdFocused = YES;
self.wdHittable = YES;
self.wdIndex = 0;
#if TARGET_OS_TV
self.wdFocused = YES;
#endif
self.children = @[];
self.wdRect = @{@"x": @0,
@"y": @0,
@"width": @0,
@"height": @0,
};
self.wdAccessibilityContainer = NO;
self.elementType = XCUIElementTypeOther;
self.wdType = @"XCUIElementTypeOther";
self.wdUID = @"0";
self.lastSnapshot = nil;
}
return self;
}
- (id)fb_valueForWDAttributeName:(NSString *)name
{
return @"test";
}
- (id)query
{
return nil;
}
- (void)resolve
{
self.didResolve = YES;
}
- (void)fb_nativeResolve
{
self.didResolve = YES;
}
- (id _Nonnull)fb_standardSnapshot;
{
return [self lastSnapshot];
}
- (id _Nonnull)fb_customSnapshot;
{
return [self lastSnapshot];
}
- (NSString *)fb_cacheId
{
return self.wdUID;
}
- (id)lastSnapshot
{
return self;
}
- (id)fb_uid
{
return self.wdUID;
}
- (NSString *)wdTraits
{
return self.wdTraits;
}
@end

View File

@@ -0,0 +1,313 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "XCUIElementDouble.h"
#import "FBClassChainQueryParser.h"
@interface FBClassChainTests : XCTestCase
@end
@implementation FBClassChainTests
- (void)testValidChain
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow/XCUIElementTypeButton" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 2);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeWindow);
XCTAssertNil(firstElement.position);
XCTAssertFalse(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeButton);
XCTAssertNil(secondElement.position);
XCTAssertFalse(secondElement.isDescendant);
}
- (void)testValidChainWithStar
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow/XCUIElementTypeButton[3]/*[4]/*[5]/XCUIElementTypeAlert" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 5);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeWindow);
XCTAssertNil(firstElement.position);
XCTAssertFalse(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeButton);
XCTAssertEqual(secondElement.position.integerValue, 3);
XCTAssertFalse(secondElement.isDescendant);
FBClassChainItem *thirdElement = [result.elements objectAtIndex:2];
XCTAssertEqual(thirdElement.type, XCUIElementTypeAny);
XCTAssertEqual(thirdElement.position.integerValue, 4);
XCTAssertFalse(thirdElement.isDescendant);
FBClassChainItem *fourthElement = [result.elements objectAtIndex:3];
XCTAssertEqual(fourthElement.type, XCUIElementTypeAny);
XCTAssertEqual(fourthElement.position.integerValue, 5);
XCTAssertFalse(fourthElement.isDescendant);
FBClassChainItem *fifthsElement = [result.elements objectAtIndex:4];
XCTAssertEqual(fifthsElement.type, XCUIElementTypeAlert);
XCTAssertNil(fifthsElement.position);
XCTAssertFalse(fifthsElement.isDescendant);
}
- (void)testValidSingleStarChain
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"*" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 1);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeAny);
XCTAssertNil(firstElement.position);
XCTAssertFalse(firstElement.isDescendant);
}
- (void)testValidSingleStarIndirectChain
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"**/*/*/XCUIElementTypeButton" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 3);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeAny);
XCTAssertNil(firstElement.position);
XCTAssertTrue(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeAny);
XCTAssertNil(secondElement.position);
XCTAssertFalse(secondElement.isDescendant);
FBClassChainItem *thirdElement = [result.elements objectAtIndex:2];
XCTAssertEqual(thirdElement.type, XCUIElementTypeButton);
XCTAssertNil(thirdElement.position);
XCTAssertFalse(thirdElement.isDescendant);
}
- (void)testValidDoubleIndirectChainAndStar
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"**/XCUIElementTypeButton/**/*" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 2);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeButton);
XCTAssertNil(firstElement.position);
XCTAssertTrue(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeAny);
XCTAssertNil(secondElement.position);
XCTAssertTrue(secondElement.isDescendant);
}
- (void)testValidDoubleIndirectChainAndClassName
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"**/XCUIElementTypeButton/**/XCUIElementTypeImage" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 2);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeButton);
XCTAssertNil(firstElement.position);
XCTAssertTrue(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeImage);
XCTAssertNil(secondElement.position);
XCTAssertTrue(secondElement.isDescendant);
}
- (void)testValidChainWithNegativeIndex
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow/XCUIElementTypeButton[-1]" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 2);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeWindow);
XCTAssertNil(firstElement.position);
XCTAssertEqual(firstElement.predicates.count, 0);
XCTAssertFalse(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeButton);
XCTAssertEqual(secondElement.position.integerValue, -1);
XCTAssertEqual(secondElement.predicates.count, 0);
XCTAssertFalse(secondElement.isDescendant);
}
- (void)testValidChainWithSinglePredicate
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow[`name == 'blabla'`]/XCUIElementTypeButton" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 2);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeWindow);
XCTAssertNil(firstElement.position);
XCTAssertEqual(firstElement.predicates.count, 1);
XCTAssertFalse(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeButton);
XCTAssertNil(secondElement.position);
XCTAssertEqual(secondElement.predicates.count, 0);
XCTAssertFalse(secondElement.isDescendant);
}
- (void)testValidChainWithMultiplePredicates
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"XCUIElementTypeWindow[`name == 'blabla'`]/XCUIElementTypeButton[`value == 'blabla'`]" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 2);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeWindow);
XCTAssertNil(firstElement.position);
XCTAssertEqual(firstElement.predicates.count, 1);
XCTAssertFalse(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeButton);
XCTAssertNil(secondElement.position);
XCTAssertEqual(secondElement.predicates.count, 1);
XCTAssertFalse(secondElement.isDescendant);
}
- (void)testValidChainWithIndirectSearchAndPredicates
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"**/XCUIElementTypeTable[`name == 'blabla'`][10]/**/XCUIElementTypeButton[`value == 'blabla'`]" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 2);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeTable);
XCTAssertEqual(firstElement.position.integerValue, 10);
XCTAssertEqual(firstElement.predicates.count, 1);
XCTAssertTrue(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeButton);
XCTAssertNil(secondElement.position);
XCTAssertEqual(secondElement.predicates.count, 1);
XCTAssertTrue(secondElement.isDescendant);
}
- (void)testValidChainWithMultiplePredicatesAndPositions
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"*[`name == \"к``ири````'лиця\"`][3]/XCUIElementTypeButton[`value == \"blabla\"`][-1]" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 2);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeAny);
XCTAssertEqual(firstElement.position.integerValue, 3);
XCTAssertEqual(firstElement.predicates.count, 1);
XCTAssertFalse(firstElement.isDescendant);
FBClassChainItem *secondElement = [result.elements objectAtIndex:1];
XCTAssertEqual(secondElement.type, XCUIElementTypeButton);
XCTAssertEqual(secondElement.position.integerValue, -1);
XCTAssertEqual(secondElement.predicates.count, 1);
XCTAssertFalse(secondElement.isDescendant);
}
- (void)testValidChainWithDescendantPredicate
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"**/XCUIElementTypeTable[$type == 'XCUIElementTypeImage' AND name == 'olala'$][`name == 'blabla'`][10]" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 1);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeTable);
XCTAssertEqual(firstElement.position.integerValue, 10);
XCTAssertEqual(firstElement.predicates.count, 2);
XCTAssertTrue(firstElement.isDescendant);
}
- (void)testValidChainWithMultipleDescendantPredicates
{
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:@"**/XCUIElementTypeTable[$type == 'XCUIElementTypeImage' AND name == 'olala'$][`value == 'peace'`][$value == 'yolo'$][`name == 'blabla'`][10]" error:&error];
XCTAssertNotNil(result);
XCTAssertEqual(result.elements.count, 1);
FBClassChainItem *firstElement = [result.elements firstObject];
XCTAssertEqual(firstElement.type, XCUIElementTypeTable);
XCTAssertEqual(firstElement.position.integerValue, 10);
XCTAssertEqual(firstElement.predicates.count, 4);
XCTAssertTrue(firstElement.isDescendant);
}
- (void)testInvalidChains
{
NSArray *invalidQueries = @[
@"/XCUIElementTypeWindow"
,@"XCUIElementTypeWindow/"
,@"XCUIElementTypeWindow//*"
,@"XCUIElementTypeWindow*/*"
,@"**"
,@"***"
,@"**/*/**"
,@"/**"
,@"XCUIElementTypeWindow/**"
,@"**[1]/XCUIElementTypeWindow"
,@"**[`name == '1'`]/XCUIElementTypeWindow"
,@"XCUIElementTypeWindow[0]"
,@"XCUIElementTypeWindow[1][1]"
,@"blabla"
,@"XCUIElementTypeWindow/blabla"
,@" XCUIElementTypeWindow"
,@"XCUIElementTypeWindow[ 2 ]"
,@"XCUIElementTypeWindow[[2]"
,@"XCUIElementTypeWindow[2]]"
,@"XCUIElementType[Window[2]]"
,@"XCUIElementTypeWindow[visible = 1]"
,@"XCUIElementTypeWindow[1][`visible = 1`]"
,@"XCUIElementTypeWindow[1] [`visible = 1`]"
,@"XCUIElementTypeWindow[ `visible = 1`]"
,@"XCUIElementTypeWindow[`visible = 1][`name = \"bla\"`]"
,@"XCUIElementTypeWindow[`visible = 1]"
,@"XCUIElementTypeWindow[$visible = 1]"
,@"XCUIElementTypeWindow[``]"
,@"XCUIElementTypeWindow[$$]"
,@"XCUIElementTypeWindow[`name = \"bla```bla\"`]"
,@"XCUIElementTypeWindow[$name = \"bla$$$bla\"$]"
];
for (NSString *invalidQuery in invalidQueries) {
NSError *error;
FBClassChain *result = [FBClassChainQueryParser parseQuery:invalidQuery error:&error];
XCTAssertNil(result);
XCTAssertNotNil(error);
}
}
@end

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBConfiguration.h"
@interface FBConfigurationTests : XCTestCase
@end
@implementation FBConfigurationTests
- (void)setUp
{
[super setUp];
unsetenv("USE_PORT");
unsetenv("VERBOSE_LOGGING");
}
- (void)testBindingPortDefault
{
XCTAssertTrue(NSEqualRanges([FBConfiguration bindingPortRange], NSMakeRange(8100, 100)));
}
- (void)testBindingPortEnvironmentOverwrite
{
setenv("USE_PORT", "1000", 1);
XCTAssertTrue(NSEqualRanges([FBConfiguration bindingPortRange], NSMakeRange(1000, 1)));
}
- (void)testVerboseLoggingDefault
{
XCTAssertFalse([FBConfiguration verboseLoggingEnabled]);
}
- (void)testVerboseLoggingEnvironmentOverwrite
{
setenv("VERBOSE_LOGGING", "YES", 1);
XCTAssertTrue([FBConfiguration verboseLoggingEnabled]);
}
@end

View File

@@ -0,0 +1,124 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBElementCache.h"
#import "XCUIElementDouble.h"
#import "XCUIElement+FBCaching.h"
#import "XCUIElement+FBUtilities.h"
@interface FBElementCacheTests : XCTestCase
@property (nonatomic, strong) FBElementCache *cache;
@end
@implementation FBElementCacheTests
- (void)setUp
{
[super setUp];
self.cache = [FBElementCache new];
}
- (void)testStoringElement
{
XCUIElementDouble *el1 = XCUIElementDouble.new;
el1.wdUID = @"1";
XCUIElementDouble *el2 = XCUIElementDouble.new;
el2.wdUID = @"2";
NSString *firstUUID = [self.cache storeElement:(XCUIElement *)el1];
NSString *secondUUID = [self.cache storeElement:(XCUIElement *)el2];
XCTAssertEqualObjects(firstUUID, el1.wdUID);
XCTAssertEqualObjects(secondUUID, el2.wdUID);
}
- (void)testFetchingElement
{
XCUIElement *element = (XCUIElement *)XCUIElementDouble.new;
NSString *uuid = [self.cache storeElement:element];
XCTAssertNotNil(uuid, @"Stored index should be higher than 0");
XCUIElement *cachedElement = [self.cache elementForUUID:uuid];
XCTAssertEqual(element, cachedElement);
}
- (void)testFetchingBadIndex
{
XCTAssertThrows([self.cache elementForUUID:@"random"]);
}
- (void)testLinearCacheExpulsion
{
const int ELEMENT_COUNT = 1050;
NSMutableArray *elements = [NSMutableArray arrayWithCapacity:ELEMENT_COUNT];
NSMutableArray *elementIds = [NSMutableArray arrayWithCapacity:ELEMENT_COUNT];
for(int i = 0; i < ELEMENT_COUNT; i++) {
XCUIElementDouble *el = XCUIElementDouble.new;
el.wdUID = [NSString stringWithFormat:@"%@", @(i)];
[elements addObject:(XCUIElement *)el];
}
// The capacity of the cache is limited to 1024 elements. Add 1050
// elements and make sure:
// - The first 26 elements are no longer present in the cache
// - The remaining 1024 elements are present in the cache
for(int i = 0; i < ELEMENT_COUNT; i++) {
[elementIds addObject:[self.cache storeElement:elements[i]]];
}
for(int i = 0; i < ELEMENT_COUNT - ELEMENT_CACHE_SIZE; i++) {
XCTAssertThrows([self.cache elementForUUID:elementIds[i]]);
}
for(int i = ELEMENT_COUNT - ELEMENT_CACHE_SIZE; i < ELEMENT_COUNT; i++) {
XCTAssertEqual(elements[i], [self.cache elementForUUID:elementIds[i]]);
}
}
- (void)testMRUCacheExpulsion
{
const int ELEMENT_COUNT = 1050;
const int ACCESSED_ELEMENT_COUNT = 24;
NSMutableArray *elements = [NSMutableArray arrayWithCapacity:ELEMENT_COUNT];
NSMutableArray *elementIds = [NSMutableArray arrayWithCapacity:ELEMENT_COUNT];
for(int i = 0; i < ELEMENT_COUNT; i++) {
XCUIElementDouble *el = XCUIElementDouble.new;
el.wdUID = [NSString stringWithFormat:@"%@", @(i)];
[elements addObject:(XCUIElement *)el];
}
// The capacity of the cache is limited to 1024 elements. Add 1050
// elements, but with a twist: access the first 24 elements before
// adding the last 50 elements. Then, make sure:
// - The first 24 elements are present in the cache
// - The next 26 elements are not present in the cache
// - The remaining 1000 elements are present in the cache
for(int i = 0; i < ELEMENT_CACHE_SIZE; i++) {
[elementIds addObject:[self.cache storeElement:elements[i]]];
}
for(int i = 0; i < ACCESSED_ELEMENT_COUNT; i++) {
[self.cache elementForUUID:elementIds[i]];
}
for(int i = ELEMENT_CACHE_SIZE; i < ELEMENT_COUNT; i++) {
[elementIds addObject:[self.cache storeElement:elements[i]]];
}
for(int i = 0; i < ACCESSED_ELEMENT_COUNT; i++) {
XCTAssertEqual(elements[i], [self.cache elementForUUID:elementIds[i]]);
}
for(int i = ACCESSED_ELEMENT_COUNT; i < ELEMENT_COUNT - ELEMENT_CACHE_SIZE + ACCESSED_ELEMENT_COUNT; i++) {
XCTAssertThrows([self.cache elementForUUID:elementIds[i]]);
}
for(int i = ELEMENT_COUNT - ELEMENT_CACHE_SIZE + ACCESSED_ELEMENT_COUNT; i < ELEMENT_COUNT; i++) {
XCTAssertEqual(elements[i], [self.cache elementForUUID:elementIds[i]]);
}
}
@end

View File

@@ -0,0 +1,45 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBElementTypeTransformer.h"
@interface FBElementTypeTransformerTests : XCTestCase
@end
@implementation FBElementTypeTransformerTests
- (void)testStringWithElementType
{
XCTAssertEqualObjects(@"XCUIElementTypeAny", [FBElementTypeTransformer stringWithElementType:XCUIElementTypeAny]);
XCTAssertEqualObjects(@"XCUIElementTypeIcon", [FBElementTypeTransformer stringWithElementType:XCUIElementTypeIcon]);
XCTAssertEqualObjects(@"XCUIElementTypeTab", [FBElementTypeTransformer stringWithElementType:XCUIElementTypeTab]);
XCTAssertEqualObjects(@"XCUIElementTypeOther", [FBElementTypeTransformer stringWithElementType:XCUIElementTypeOther]);
}
- (void)testShortStringWithElementType
{
XCTAssertEqualObjects(@"Any", [FBElementTypeTransformer shortStringWithElementType:XCUIElementTypeAny]);
XCTAssertEqualObjects(@"Icon", [FBElementTypeTransformer shortStringWithElementType:XCUIElementTypeIcon]);
XCTAssertEqualObjects(@"Tab", [FBElementTypeTransformer shortStringWithElementType:XCUIElementTypeTab]);
XCTAssertEqualObjects(@"Other", [FBElementTypeTransformer shortStringWithElementType:XCUIElementTypeOther]);
}
- (void)testElementTypeWithElementTypeName
{
XCTAssertEqual(XCUIElementTypeAny, [FBElementTypeTransformer elementTypeWithTypeName:@"XCUIElementTypeAny"]);
XCTAssertEqual(XCUIElementTypeIcon, [FBElementTypeTransformer elementTypeWithTypeName:@"XCUIElementTypeIcon"]);
XCTAssertEqual(XCUIElementTypeTab, [FBElementTypeTransformer elementTypeWithTypeName:@"XCUIElementTypeTab"]);
XCTAssertEqual(XCUIElementTypeOther, [FBElementTypeTransformer elementTypeWithTypeName:@"XCUIElementTypeOther"]);
XCTAssertThrows([FBElementTypeTransformer elementTypeWithTypeName:@"Whatever"]);
XCTAssertThrows([FBElementTypeTransformer elementTypeWithTypeName:nil]);
XCTAssertEqual(XCUIElementTypeOther, [FBElementTypeTransformer elementTypeWithTypeName:@"XCUIElementTypeNewType"]);
}
@end

View File

@@ -0,0 +1,36 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBElement.h"
#import "XCUIElementDouble.h"
#import "FBElementUtils.h"
@interface FBElementUtilitiesTests : XCTestCase
@end
@implementation FBElementUtilitiesTests
- (void)testTypesFiltering {
NSMutableArray *elements = [NSMutableArray new];
XCUIElementDouble *el1 = [XCUIElementDouble new];
[elements addObject:el1];
XCUIElementDouble *el2 = [XCUIElementDouble new];
el2.elementType = XCUIElementTypeAlert;
el2.wdType = @"XCUIElementTypeAlert";
[elements addObject:el2];
XCUIElementDouble *el3 = [XCUIElementDouble new];
[elements addObject:el3];
NSSet *result = [FBElementUtils uniqueElementTypesWithElements:elements];
XCTAssertEqual([result count], 2);
}
@end

View File

@@ -0,0 +1,61 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBErrorBuilder.h"
@interface FBErrorBuilderTests : XCTestCase
@end
@implementation FBErrorBuilderTests
- (void)testErrorWithDescription
{
NSString *expectedDescription = @"Magic description";
NSError *error =
[[[FBErrorBuilder builder]
withDescription:expectedDescription]
build];
XCTAssertNotNil(error);
XCTAssertEqualObjects([error localizedDescription], expectedDescription);
}
- (void)testErrorWithDescriptionFormat
{
NSError *error =
[[[FBErrorBuilder builder]
withDescriptionFormat:@"Magic %@", @"bob"]
build];
XCTAssertEqualObjects([error localizedDescription], @"Magic bob");
}
- (void)testInnerError
{
NSError *innerError = [NSError errorWithDomain:@"Domain" code:1 userInfo:@{}];
NSError *error =
[[[FBErrorBuilder builder]
withInnerError:innerError]
build];
XCTAssertEqual(error.userInfo[NSUnderlyingErrorKey], innerError);
}
- (void)testBuildWithError
{
NSString *expectedDescription = @"Magic description";
NSError *error;
BOOL result =
[[[FBErrorBuilder builder]
withDescription:expectedDescription]
buildError:&error];
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.localizedDescription, expectedDescription);
XCTAssertFalse(result);
}
@end

View File

@@ -0,0 +1,59 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBAlert.h"
#import "FBExceptionHandler.h"
#import "FBExceptions.h"
@interface RouteResponseDouble : NSObject
- (void)setHeader:(NSString *)field value:(NSString *)value;
- (void)setStatusCode:(NSUInteger)code;
- (void)respondWithData:(NSData *)data;
@end
@implementation RouteResponseDouble
- (void)setHeader:(NSString *)field value:(NSString *)value {}
- (void)setStatusCode:(NSUInteger)code {}
- (void)respondWithData:(NSData *)data {}
@end
@interface FBExceptionHandlerTests : XCTestCase
@property (nonatomic) FBExceptionHandler *exceptionHandler;
@end
@implementation FBExceptionHandlerTests
- (void)setUp
{
self.exceptionHandler = [FBExceptionHandler new];
}
- (void)testMatchingErrorHandling
{
NSException *exception = [NSException exceptionWithName:FBElementNotVisibleException
reason:@"reason"
userInfo:@{}];
[self.exceptionHandler handleException:exception
forResponse:(RouteResponse *)[RouteResponseDouble new]];
}
- (void)testNonMatchingErrorHandling
{
NSException *exception = [NSException exceptionWithName:@"something"
reason:@"reason"
userInfo:@{}];
[self.exceptionHandler handleException:exception
forResponse:(RouteResponse *)[RouteResponseDouble new]];
}
@end

View File

@@ -0,0 +1,127 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "LRUCache.h"
@interface FBLRUCacheTests : XCTestCase
@end
@implementation FBLRUCacheTests
- (void)assertArray:(NSArray *)array1 equalsTo:(NSArray *)array2
{
XCTAssertEqualObjects(array1, array2);
}
- (void)testRecentlyInsertedObjectReplacesTheOldestOne
{
LRUCache *cache = [[LRUCache alloc] initWithCapacity:1];
[cache setObject:@"foo" forKey:@"bar"];
[cache setObject:@"foo2" forKey:@"bar2"];
[cache setObject:@"foo3" forKey:@"bar3"];
XCTAssertEqualObjects(@[@"foo3"], cache.allObjects);
}
- (void)testRecentObjectReplacementAndBump
{
LRUCache *cache = [[LRUCache alloc] initWithCapacity:2];
[cache setObject:@"foo" forKey:@"bar"];
[cache setObject:@"foo2" forKey:@"bar2"];
[self assertArray:@[@"foo2", @"foo"] equalsTo:cache.allObjects];
XCTAssertNotNil([cache objectForKey:@"bar"]);
[self assertArray:@[@"foo", @"foo2"] equalsTo:cache.allObjects];
[cache setObject:@"foo3" forKey:@"bar3"];
[self assertArray:@[@"foo3", @"foo"] equalsTo:cache.allObjects];
[cache setObject:@"foo0" forKey:@"bar"];
[self assertArray:@[@"foo0", @"foo3"] equalsTo:cache.allObjects];
[cache setObject:@"foo4" forKey:@"bar4"];
[self assertArray:@[@"foo4", @"foo0"] equalsTo:cache.allObjects];
}
- (void)testBumpFromHead
{
LRUCache *cache = [[LRUCache alloc] initWithCapacity:3];
[cache setObject:@"foo" forKey:@"bar"];
[cache setObject:@"foo2" forKey:@"bar2"];
[cache setObject:@"foo3" forKey:@"bar3"];
XCTAssertNotNil([cache objectForKey:@"bar3"]);
[self assertArray:@[@"foo3", @"foo2", @"foo"] equalsTo:cache.allObjects];
[cache setObject:@"foo4" forKey:@"bar4"];
[cache setObject:@"foo5" forKey:@"bar5"];
[self assertArray:@[@"foo5", @"foo4", @"foo3"] equalsTo:cache.allObjects];
}
- (void)testBumpFromMiddle
{
LRUCache *cache = [[LRUCache alloc] initWithCapacity:3];
[cache setObject:@"foo" forKey:@"bar"];
[cache setObject:@"foo2" forKey:@"bar2"];
[cache setObject:@"foo3" forKey:@"bar3"];
XCTAssertNotNil([cache objectForKey:@"bar2"]);
[self assertArray:@[@"foo2", @"foo3", @"foo"] equalsTo:cache.allObjects];
[cache setObject:@"foo4" forKey:@"bar4"];
[cache setObject:@"foo5" forKey:@"bar5"];
[self assertArray:@[@"foo5", @"foo4", @"foo2"] equalsTo:cache.allObjects];
}
- (void)testBumpFromTail
{
LRUCache *cache = [[LRUCache alloc] initWithCapacity:3];
[cache setObject:@"foo" forKey:@"bar"];
[cache setObject:@"foo2" forKey:@"bar2"];
[cache setObject:@"foo3" forKey:@"bar3"];
XCTAssertNotNil([cache objectForKey:@"bar3"]);
[self assertArray:@[@"foo3", @"foo2", @"foo"] equalsTo:cache.allObjects];
[cache setObject:@"foo4" forKey:@"bar4"];
[cache setObject:@"foo5" forKey:@"bar5"];
[self assertArray:@[@"foo5", @"foo4", @"foo3"] equalsTo:cache.allObjects];
}
- (void)testInsertionLoop
{
LRUCache *cache = [[LRUCache alloc] initWithCapacity:1];
NSUInteger count = 100;
for (NSUInteger i = 0; i <= count; ++i) {
[cache setObject:@(i) forKey:@(i)];
XCTAssertNotNil([cache objectForKey:@(i)]);
}
XCTAssertEqualObjects(@[@(count)], cache.allObjects);
}
- (void)testRemoveExistingObjectForKey {
LRUCache *cache = [[LRUCache alloc] initWithCapacity:3];
[cache setObject:@"foo" forKey:@"bar"];
[cache setObject:@"foo2" forKey:@"bar2"];
[cache setObject:@"foo3" forKey:@"bar3"];
[self assertArray:@[@"foo3", @"foo2", @"foo"] equalsTo:cache.allObjects];
[cache removeObjectForKey:@"bar2"];
XCTAssertNil([cache objectForKey:@"bar2"]);
[self assertArray:@[@"foo3", @"foo"] equalsTo:cache.allObjects];
}
- (void)testRemoveNonExistingObjectForKey {
LRUCache *cache = [[LRUCache alloc] initWithCapacity:2];
[cache setObject:@"foo" forKey:@"bar"];
[cache removeObjectForKey:@"nonExisting"];
XCTAssertNotNil([cache objectForKey:@"bar"]);
[self assertArray:@[@"foo"] equalsTo:cache.allObjects];
}
- (void)testRemoveAndInsertFlow {
LRUCache *cache = [[LRUCache alloc] initWithCapacity:2];
[cache setObject:@"foo" forKey:@"bar"];
[cache setObject:@"foo2" forKey:@"bar2"];
[cache removeObjectForKey:@"bar"];
XCTAssertNil([cache objectForKey:@"bar"]);
[cache setObject:@"foo3" forKey:@"bar3"];
[self assertArray:@[@"foo3", @"foo2"] equalsTo:cache.allObjects];
}
@end

View File

@@ -0,0 +1,113 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBMathUtils.h"
@interface FBMathUtilsTests : XCTestCase
@end
@implementation FBMathUtilsTests
- (void)testGetCenter
{
XCTAssertTrue(CGPointEqualToPoint(FBRectGetCenter(CGRectMake(0, 0, 4, 4)), CGPointMake(2, 2)));
XCTAssertTrue(CGPointEqualToPoint(FBRectGetCenter(CGRectMake(1, 1, 4, 4)), CGPointMake(3, 3)));
XCTAssertTrue(CGPointEqualToPoint(FBRectGetCenter(CGRectMake(1, 3, 6, 14)), CGPointMake(4, 10)));
}
- (void)testFuzzyEqualFloats
{
XCTAssertTrue(FBFloatFuzzyEqualToFloat(0, 0, 0));
XCTAssertTrue(FBFloatFuzzyEqualToFloat(0.5, 0.6, 0.2));
XCTAssertTrue(FBFloatFuzzyEqualToFloat(0.6, 0.5, 0.2));
XCTAssertTrue(FBFloatFuzzyEqualToFloat(0.5, 0.6, 0.10001));
}
- (void)testFuzzyNotEqualFloats
{
XCTAssertFalse(FBFloatFuzzyEqualToFloat(0, 1, 0));
XCTAssertFalse(FBFloatFuzzyEqualToFloat(1, 0, 0));
XCTAssertFalse(FBFloatFuzzyEqualToFloat(0.5, 0.6, 0.05));
XCTAssertFalse(FBFloatFuzzyEqualToFloat(0.6, 0.5, 0.05));
}
- (void)testFuzzyEqualPoints
{
CGPoint referencePoint = CGPointMake(3, 3);
XCTAssertTrue(FBPointFuzzyEqualToPoint(referencePoint, CGPointMake(3, 3), 2));
XCTAssertTrue(FBPointFuzzyEqualToPoint(referencePoint, CGPointMake(3, 4), 2));
XCTAssertTrue(FBPointFuzzyEqualToPoint(referencePoint, CGPointMake(4, 3), 2));
}
- (void)testFuzzyNotEqualPoints
{
CGPoint referencePoint = CGPointMake(3, 3);
XCTAssertFalse(FBPointFuzzyEqualToPoint(referencePoint, CGPointMake(5, 5), 1));
XCTAssertFalse(FBPointFuzzyEqualToPoint(referencePoint, CGPointMake(3, 5), 1));
XCTAssertFalse(FBPointFuzzyEqualToPoint(referencePoint, CGPointMake(5, 3), 1));
}
- (void)testFuzzyEqualSizes
{
CGSize referenceSize = CGSizeMake(3, 3);
XCTAssertTrue(FBSizeFuzzyEqualToSize(referenceSize, CGSizeMake(3, 3), 2));
XCTAssertTrue(FBSizeFuzzyEqualToSize(referenceSize, CGSizeMake(3, 4), 2));
XCTAssertTrue(FBSizeFuzzyEqualToSize(referenceSize, CGSizeMake(4, 3), 2));
}
- (void)testFuzzyNotEqualSizes
{
CGSize referenceSize = CGSizeMake(3, 3);
XCTAssertFalse(FBSizeFuzzyEqualToSize(referenceSize, CGSizeMake(5, 5), 1));
XCTAssertFalse(FBSizeFuzzyEqualToSize(referenceSize, CGSizeMake(3, 5), 1));
XCTAssertFalse(FBSizeFuzzyEqualToSize(referenceSize, CGSizeMake(5, 3), 1));
}
- (void)testFuzzyEqualRects
{
CGRect referenceRect = CGRectMake(3, 3, 3, 3);
XCTAssertTrue(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(3, 3, 3, 3), 2));
XCTAssertTrue(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(3, 4, 3, 3), 2));
XCTAssertTrue(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(4, 3, 3, 3), 2));
XCTAssertTrue(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(3, 3, 3, 4), 2));
XCTAssertTrue(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(3, 3, 4, 3), 2));
}
- (void)testFuzzyNotEqualRects
{
CGRect referenceRect = CGRectMake(3, 3, 3, 3);
XCTAssertFalse(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(5, 5, 5, 5), 1));
XCTAssertFalse(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(3, 5, 3, 3), 1));
XCTAssertFalse(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(5, 3, 3, 3), 1));
XCTAssertFalse(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(3, 3, 3, 5), 1));
XCTAssertFalse(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(3, 3, 5, 3), 1));
}
- (void)testFuzzyEqualRectsSymmetry
{
CGRect referenceRect = CGRectMake(0, 0, 2, 2);
XCTAssertFalse(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(1, 1, 3, 3), 1));
XCTAssertFalse(FBRectFuzzyEqualToRect(referenceRect, CGRectMake(-1, -1, 1, 1), 1));
}
- (void)testSizeInversion
{
const CGSize screenSizePortrait = CGSizeMake(10, 15);
const CGSize screenSizeLandscape = CGSizeMake(15, 10);
const CGFloat t = FBDefaultFrameFuzzyThreshold;
XCTAssertTrue(FBSizeFuzzyEqualToSize(screenSizePortrait, FBAdjustDimensionsForApplication(screenSizePortrait, UIInterfaceOrientationPortrait), t));
XCTAssertTrue(FBSizeFuzzyEqualToSize(screenSizePortrait, FBAdjustDimensionsForApplication(screenSizePortrait, UIInterfaceOrientationPortraitUpsideDown), t));
XCTAssertTrue(FBSizeFuzzyEqualToSize(screenSizeLandscape, FBAdjustDimensionsForApplication(screenSizePortrait, UIInterfaceOrientationLandscapeLeft), t));
XCTAssertTrue(FBSizeFuzzyEqualToSize(screenSizeLandscape, FBAdjustDimensionsForApplication(screenSizePortrait, UIInterfaceOrientationLandscapeRight), t));
XCTAssertTrue(FBSizeFuzzyEqualToSize(screenSizeLandscape, FBAdjustDimensionsForApplication(screenSizeLandscape, UIInterfaceOrientationLandscapeLeft), t));
XCTAssertTrue(FBSizeFuzzyEqualToSize(screenSizeLandscape, FBAdjustDimensionsForApplication(screenSizeLandscape, UIInterfaceOrientationLandscapeRight), t));
}
@end

View File

@@ -0,0 +1,81 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBProtocolHelpers.h"
@interface FBProtocolHelpersTests : XCTestCase
@end
@implementation FBProtocolHelpersTests
- (void)testValidPrefixedCapsParsing
{
NSError *error = nil;
NSDictionary<NSString *, id> *parsedCaps = FBParseCapabilities(@{
@"firstMatch": @[@{
@"appium:bundleId": @"com.example.id"
}]
}, &error);
XCTAssertNil(error);
XCTAssertEqualObjects(parsedCaps[@"bundleId"], @"com.example.id");
}
- (void)testValidPrefixedCapsMerging
{
NSError *error = nil;
NSDictionary<NSString *, id> *parsedCaps = FBParseCapabilities(@{
@"firstMatch": @[@{
@"bundleId": @"com.example.id"
}],
@"alwaysMatch": @{
@"google:cap": @"super"
}
}, &error);
XCTAssertNil(error);
XCTAssertEqualObjects(parsedCaps[@"bundleId"], @"com.example.id");
XCTAssertEqualObjects(parsedCaps[@"google:cap"], @"super");
}
- (void)testEmptyCaps
{
NSError *error = nil;
NSDictionary<NSString *, id> *parsedCaps = FBParseCapabilities(@{}, &error);
XCTAssertNil(error);
XCTAssertEqual(parsedCaps.count, 0);
}
- (void)testCapsMergingFailure
{
NSError *error = nil;
NSDictionary<NSString *, id> *parsedCaps = FBParseCapabilities(@{
@"firstMatch": @[@{
@"appium:bundleId": @"com.example.id"
}],
@"alwaysMatch": @{
@"bundleId": @"other"
}
}, &error);
XCTAssertNil(parsedCaps);
XCTAssertNotNil(error);
}
- (void)testPrefixingStandardCapability
{
NSError *error = nil;
NSDictionary<NSString *, id> *parsedCaps = FBParseCapabilities(@{
@"firstMatch": @[@{
@"appium:platformName": @"com.example.id"
}]
}, &error);
XCTAssertNil(parsedCaps);
XCTAssertNotNil(error);
}
@end

View File

@@ -0,0 +1,129 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBRoute.h"
@class RouteResponse;
@interface FBHandlerMock : NSObject
@property (nonatomic, assign) BOOL didCallSomeSelector;
@end
@implementation FBHandlerMock
- (id)someSelector:(id)arg
{
self.didCallSomeSelector = YES;
return nil;
};
@end
@interface FBRouteTests : XCTestCase
@end
@implementation FBRouteTests
- (void)testGetRoute
{
FBRoute *route = [FBRoute GET:@"/"];
XCTAssertEqualObjects(route.verb, @"GET");
}
- (void)testPostRoute
{
FBRoute *route = [FBRoute POST:@"/"];
XCTAssertEqualObjects(route.verb, @"POST");
}
- (void)testPutRoute
{
FBRoute *route = [FBRoute PUT:@"/"];
XCTAssertEqualObjects(route.verb, @"PUT");
}
- (void)testDeleteRoute
{
FBRoute *route = [FBRoute DELETE:@"/"];
XCTAssertEqualObjects(route.verb, @"DELETE");
}
- (void)testTargetAction
{
FBHandlerMock *mock = [FBHandlerMock new];
FBRoute *route = [[FBRoute new] respondWithTarget:mock action:@selector(someSelector:)];
[route mountRequest:(id)NSObject.new intoResponse:(id)NSObject.new];
XCTAssertTrue(mock.didCallSomeSelector);
}
- (void)testRespond
{
XCTestExpectation *expectation = [self expectationWithDescription:@"Calling respond block works!"];
FBRoute *route = [[FBRoute new] respondWithBlock:^id<FBResponsePayload>(FBRouteRequest *request) {
[expectation fulfill];
return nil;
}];
[route mountRequest:(id)NSObject.new intoResponse:(id)NSObject.new];
[self waitForExpectationsWithTimeout:0.0 handler:nil];
}
- (void)testRouteWithSessionWithSlash
{
FBRoute *route = [[FBRoute POST:@"/deactivateApp"] respondWithTarget:self action:@selector(dummyHandler:)];
XCTAssertEqualObjects(route.path, @"/session/:sessionID/deactivateApp");
}
- (void)testRouteWithSession
{
FBRoute *route = [[FBRoute POST:@"deactivateApp"] respondWithTarget:self action:@selector(dummyHandler:)];
XCTAssertEqualObjects(route.path, @"/session/:sessionID/deactivateApp");
}
- (void)testRouteWithoutSessionWithSlash
{
FBRoute *route = [[FBRoute POST:@"/deactivateApp"].withoutSession respondWithTarget:self action:@selector(dummyHandler:)];
XCTAssertEqualObjects(route.path, @"/deactivateApp");
}
- (void)testRouteWithoutSession
{
FBRoute *route = [[FBRoute POST:@"deactivateApp"].withoutSession respondWithTarget:self action:@selector(dummyHandler:)];
XCTAssertEqualObjects(route.path, @"/deactivateApp");
}
- (void)testEmptyRouteWithSession
{
FBRoute *route = [[FBRoute POST:@""] respondWithTarget:self action:@selector(dummyHandler:)];
XCTAssertEqualObjects(route.path, @"/session/:sessionID");
}
- (void)testEmptyRouteWithoutSession
{
FBRoute *route = [[FBRoute POST:@""].withoutSession respondWithTarget:self action:@selector(dummyHandler:)];
XCTAssertEqualObjects(route.path, @"/");
}
- (void)testEmptyRouteWithSessionWithSlash
{
FBRoute *route = [[FBRoute POST:@"/"] respondWithTarget:self action:@selector(dummyHandler:)];
XCTAssertEqualObjects(route.path, @"/session/:sessionID");
}
- (void)testEmptyRouteWithoutSessionWithSlash
{
FBRoute *route = [[FBRoute POST:@"/"].withoutSession respondWithTarget:self action:@selector(dummyHandler:)];
XCTAssertEqualObjects(route.path, @"/");
}
+ (id<FBResponsePayload>)dummyHandler:(FBRouteRequest *)request
{
return nil;
}
@end

View File

@@ -0,0 +1,98 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBRunLoopSpinner.h"
@interface FBRunLoopSpinnerTests : XCTestCase
@property (nonatomic, strong) FBRunLoopSpinner *spinner;
@end
/**
Non of the test methods should block testing thread.
If they do, that means they are broken
*/
@implementation FBRunLoopSpinnerTests
- (void)setUp
{
[super setUp];
self.spinner = [[FBRunLoopSpinner new] timeout:0.1];
}
- (void)testSpinUntilCompletion
{
__block BOOL _didExecuteBlock = NO;
[FBRunLoopSpinner spinUntilCompletion:^(void (^completion)(void)) {
_didExecuteBlock = YES;
completion();
}];
XCTAssertTrue(_didExecuteBlock);
}
- (void)testSpinUntilTrue
{
__block BOOL _didExecuteBlock = NO;
BOOL didSucceed =
[self.spinner spinUntilTrue:^BOOL{
_didExecuteBlock = YES;
return YES;
}];
XCTAssertTrue(didSucceed);
XCTAssertTrue(_didExecuteBlock);
}
- (void)testSpinUntilTrueTimeout
{
NSError *error;
BOOL didSucceed =
[self.spinner spinUntilTrue:^BOOL{
return NO;
} error:&error];
XCTAssertFalse(didSucceed);
XCTAssertNotNil(error);
}
- (void)testSpinUntilTrueTimeoutMessage
{
NSString *expectedMessage = @"Magic message";
NSError *error;
BOOL didSucceed =
[[self.spinner timeoutErrorMessage:expectedMessage]
spinUntilTrue:^BOOL{
return NO;
} error:&error];
XCTAssertFalse(didSucceed);
XCTAssertEqual(error.localizedDescription, expectedMessage);
}
- (void)testSpinUntilNotNil
{
__block id expectedObject = NSObject.new;
NSError *error;
id returnedObject =
[self.spinner spinUntilNotNil:^id{
return expectedObject;
} error:&error];
XCTAssertNil(error);
XCTAssertEqual(returnedObject, expectedObject);
}
- (void)testSpinUntilNotNilTimeout
{
NSError *error;
id element =
[self.spinner spinUntilNotNil:^id{
return nil;
} error:&error];
XCTAssertNil(element);
XCTAssertNotNil(error);
}
@end

View File

@@ -0,0 +1,45 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBRuntimeUtils.h"
#import "XCTestPrivateSymbols.h"
@protocol FBMagicProtocol <NSObject>
@end
const NSString *FBRuntimeUtilsTestsConstString = @"FBRuntimeUtilsTestsConstString";
@interface FBRuntimeUtilsTests : XCTestCase <FBMagicProtocol>
@end
@implementation FBRuntimeUtilsTests
- (void)testClassesThatConformsToProtocol
{
XCTAssertEqualObjects(@[self.class], FBClassesThatConformsToProtocol(@protocol(FBMagicProtocol)));
}
- (void)testRetrievingFrameworkSymbols
{
NSString *binaryPath = [NSBundle bundleForClass:self.class].executablePath;
NSString *symbolPointer = *(NSString*__autoreleasing*)FBRetrieveSymbolFromBinary(binaryPath.UTF8String, "FBRuntimeUtilsTestsConstString");
XCTAssertNotNil(symbolPointer);
XCTAssertEqualObjects(symbolPointer, FBRuntimeUtilsTestsConstString);
}
- (void)testXCTestSymbols
{
XCTAssertTrue(XCDebugLogger != NULL);
XCTAssertTrue(XCSetDebugLogger != NULL);
XCTAssertNotNil(FB_XCAXAIsVisibleAttribute);
XCTAssertNotNil(FB_XCAXAIsElementAttribute);
}
@end

View File

@@ -0,0 +1,66 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBRuntimeUtils.h"
@interface FBSDKVersionTests : XCTestCase
@property (nonatomic, readonly) NSString *currentSDKVersion;
@property (nonatomic, readonly) NSString *lowerSDKVersion;
@property (nonatomic, readonly) NSString *higherSDKVersion;
@end
@implementation FBSDKVersionTests
- (void)setUp
{
[super setUp];
NSDictionary *bundleDict = [[NSBundle mainBundle] infoDictionary];
[bundleDict setValue:@"11.0" forKey:@"DTSDKName"];
_currentSDKVersion = FBSDKVersion();
_lowerSDKVersion = [NSString stringWithFormat:@"%@", @((int)[self.currentSDKVersion doubleValue] - 1)];
_higherSDKVersion = [NSString stringWithFormat:@"%@", @((int)[self.currentSDKVersion doubleValue] + 1)];
}
- (void)testIsSDKVersionLessThanOrEqualTo
{
XCTAssertTrue(isSDKVersionLessThanOrEqualTo(self.higherSDKVersion));
XCTAssertFalse(isSDKVersionLessThanOrEqualTo(self.lowerSDKVersion));
XCTAssertTrue(isSDKVersionLessThanOrEqualTo(self.currentSDKVersion));
}
- (void)testIsSDKVersionLessThan
{
XCTAssertTrue(isSDKVersionLessThan(self.higherSDKVersion));
XCTAssertFalse(isSDKVersionLessThan(self.lowerSDKVersion));
XCTAssertFalse(isSDKVersionLessThan(self.currentSDKVersion));
}
- (void)testIsSDKVersionEqualTo
{
XCTAssertFalse(isSDKVersionEqualTo(self.higherSDKVersion));
XCTAssertFalse(isSDKVersionEqualTo(self.lowerSDKVersion));
XCTAssertTrue(isSDKVersionEqualTo(self.currentSDKVersion));
}
- (void)testIsSDKVersionGreaterThanOrEqualTo
{
XCTAssertFalse(isSDKVersionGreaterThanOrEqualTo(self.higherSDKVersion));
XCTAssertTrue(isSDKVersionGreaterThanOrEqualTo(self.lowerSDKVersion));
XCTAssertTrue(isSDKVersionGreaterThanOrEqualTo(self.currentSDKVersion));
}
- (void)testIsSDKVersionGreaterThan
{
XCTAssertFalse(isSDKVersionGreaterThan(self.higherSDKVersion));
XCTAssertTrue(isSDKVersionGreaterThan(self.lowerSDKVersion));
XCTAssertFalse(isSDKVersionGreaterThan(self.currentSDKVersion));
}
@end

View File

@@ -0,0 +1,67 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBSession.h"
#import "FBConfiguration.h"
#import "XCUIApplicationDouble.h"
@interface FBSessionTests : XCTestCase
@property (nonatomic, strong) FBSession *session;
@property (nonatomic, strong) XCUIApplication *testedApplication;
@property (nonatomic) BOOL shouldTerminateAppValue;
@end
@implementation FBSessionTests
- (void)setUp
{
[super setUp];
self.testedApplication = (id)XCUIApplicationDouble.new;
self.shouldTerminateAppValue = FBConfiguration.shouldTerminateApp;
[FBConfiguration setShouldTerminateApp:NO];
self.session = [FBSession initWithApplication:self.testedApplication];
}
- (void)tearDown
{
[self.session kill];
[FBConfiguration setShouldTerminateApp:self.shouldTerminateAppValue];
[super tearDown];
}
- (void)testSessionFetching
{
FBSession *fetchedSession = [FBSession sessionWithIdentifier:self.session.identifier];
XCTAssertEqual(self.session, fetchedSession);
}
- (void)testSessionFetchingBadIdentifier
{
XCTAssertNil([FBSession sessionWithIdentifier:@"FAKE_IDENTIFIER"]);
}
- (void)testSessionCreation
{
XCTAssertNotNil(self.session.identifier);
XCTAssertNotNil(self.session.elementCache);
}
- (void)testActiveSession
{
XCTAssertEqual(self.session, [FBSession activeSession]);
}
- (void)testActiveSessionIsNilAfterKilling
{
[self.session kill];
XCTAssertNil([FBSession activeSession]);
}
@end

View File

@@ -0,0 +1,35 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "NSString+FBXMLSafeString.h"
@interface FBXMLSafeStringTests : XCTestCase
@end
@implementation FBXMLSafeStringTests
- (void)testSafeXmlStringTransformationWithEmptyReplacement {
NSString *withInvalidChar = [NSString stringWithFormat:@"bla%@", @"\uFFFF"];
NSString *withoutInvalidChar = @"bla";
XCTAssertNotEqualObjects(withInvalidChar, withoutInvalidChar);
XCTAssertEqualObjects([withInvalidChar fb_xmlSafeStringWithReplacement:@""], withoutInvalidChar);
}
- (void)testSafeXmlStringTransformationWithNonEmptyReplacement {
NSString *withInvalidChar = [NSString stringWithFormat:@"bla%@", @"\uFFFF"];
XCTAssertEqualObjects([withInvalidChar fb_xmlSafeStringWithReplacement:@"1"], @"bla1");
}
- (void)testSafeXmlStringTransformationWithSmileys {
NSString *validString = @"Yo👿";
XCTAssertEqualObjects([validString fb_xmlSafeStringWithReplacement:@""], validString);
}
@end

View File

@@ -0,0 +1,152 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBMacros.h"
#import "FBXPath.h"
#import "FBXPath-Private.h"
#import "XCUIElementDouble.h"
#import "XCElementSnapshotDouble.h"
#import "FBXCElementSnapshotWrapper+Helpers.h"
@interface FBXPathTests : XCTestCase
@end
@implementation FBXPathTests
- (NSString *)xmlStringWithElement:(id<FBXCElementSnapshot>)snapshot
xpathQuery:(nullable NSString *)query
excludingAttributes:(nullable NSArray<NSString *> *)excludedAttributes
{
xmlDocPtr doc;
xmlTextWriterPtr writer = xmlNewTextWriterDoc(&doc, 0);
NSMutableDictionary *elementStore = [NSMutableDictionary dictionary];
int buffersize;
xmlChar *xmlbuff = NULL;
int rc = xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
if (rc >= 0) {
rc = [FBXPath xmlRepresentationWithRootElement:snapshot
writer:writer
elementStore:elementStore
query:query
excludingAttributes:excludedAttributes];
if (rc >= 0) {
rc = xmlTextWriterEndDocument(writer);
}
}
if (rc >= 0) {
xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
}
xmlFreeTextWriter(writer);
xmlFreeDoc(doc);
XCTAssertTrue(rc >= 0);
XCTAssertEqual(1, [elementStore count]);
NSString *result = [NSString stringWithCString:(const char *)xmlbuff encoding:NSUTF8StringEncoding];
xmlFree(xmlbuff);
return result;
}
- (void)testDefaultXPathPresentation
{
XCElementSnapshotDouble *snapshot = [XCElementSnapshotDouble new];
id<FBElement> element = (id<FBElement>)[FBXCElementSnapshotWrapper ensureWrapped:(id)snapshot];
NSString *resultXml = [self xmlStringWithElement:(id<FBXCElementSnapshot>)element
xpathQuery:nil
excludingAttributes:nil];
NSLog(@"[DefaultXPath] Result XML:\n%@", resultXml);
NSString *expectedXml = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%@ type=\"%@\" value=\"%@\" name=\"%@\" label=\"%@\" enabled=\"%@\" visible=\"%@\" accessible=\"%@\" x=\"%@\" y=\"%@\" width=\"%@\" height=\"%@\" index=\"%lu\" traits=\"%@\" private_indexPath=\"top\"/>\n",
element.wdType, element.wdType, element.wdValue, element.wdName, element.wdLabel, FBBoolToString(element.wdEnabled), FBBoolToString(element.wdVisible), FBBoolToString(element.wdAccessible), element.wdRect[@"x"], element.wdRect[@"y"], element.wdRect[@"width"], element.wdRect[@"height"], element.wdIndex, element.wdTraits];
XCTAssertTrue([resultXml isEqualToString: expectedXml]);
}
- (void)testtXPathPresentationWithSomeAttributesExcluded
{
XCElementSnapshotDouble *snapshot = [XCElementSnapshotDouble new];
id<FBElement> element = (id<FBElement>)[FBXCElementSnapshotWrapper ensureWrapped:(id)snapshot];
NSString *resultXml = [self xmlStringWithElement:(id<FBXCElementSnapshot>)element
xpathQuery:nil
excludingAttributes:@[@"type", @"visible", @"value", @"index", @"traits", @"nativeFrame"]];
NSString *expectedXml = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%@ name=\"%@\" label=\"%@\" enabled=\"%@\" accessible=\"%@\" x=\"%@\" y=\"%@\" width=\"%@\" height=\"%@\" private_indexPath=\"top\"/>\n",
element.wdType, element.wdName, element.wdLabel, FBBoolToString(element.wdEnabled), FBBoolToString(element.wdAccessible), element.wdRect[@"x"], element.wdRect[@"y"], element.wdRect[@"width"], element.wdRect[@"height"]];
XCTAssertEqualObjects(resultXml, expectedXml);
}
- (void)testXPathPresentationBasedOnQueryMatchingAllAttributes
{
XCElementSnapshotDouble *snapshot = [XCElementSnapshotDouble new];
snapshot.value = @"йоло<>&\"";
snapshot.label = @"a\nb";
id<FBElement> element = (id<FBElement>)[FBXCElementSnapshotWrapper ensureWrapped:(id)snapshot];
NSString *resultXml = [self xmlStringWithElement:(id<FBXCElementSnapshot>)element
xpathQuery:[NSString stringWithFormat:@"//%@[@*]", element.wdType]
excludingAttributes:@[@"visible"]];
NSString *expectedXml = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%@ type=\"%@\" value=\"%@\" name=\"%@\" label=\"%@\" enabled=\"%@\" visible=\"%@\" accessible=\"%@\" x=\"%@\" y=\"%@\" width=\"%@\" height=\"%@\" index=\"%lu\" hittable=\"%@\" traits=\"%@\" nativeFrame=\"%@\" private_indexPath=\"top\"/>\n",
element.wdType, element.wdType, @"йоло&lt;&gt;&amp;&quot;", element.wdName, @"a&#10;b", FBBoolToString(element.wdEnabled), FBBoolToString(element.wdVisible), FBBoolToString(element.wdAccessible), element.wdRect[@"x"], element.wdRect[@"y"], element.wdRect[@"width"], element.wdRect[@"height"], element.wdIndex, FBBoolToString(element.wdHittable), element.wdTraits, NSStringFromCGRect(element.wdNativeFrame)];
XCTAssertEqualObjects(expectedXml, resultXml);
}
- (void)testXPathPresentationBasedOnQueryMatchingSomeAttributes
{
XCElementSnapshotDouble *snapshot = [XCElementSnapshotDouble new];
id<FBElement> element = (id<FBElement>)[FBXCElementSnapshotWrapper ensureWrapped:(id)snapshot];
NSString *resultXml = [self xmlStringWithElement:(id<FBXCElementSnapshot>)element
xpathQuery:[NSString stringWithFormat:@"//%@[@%@ and contains(@%@, 'blabla')]", element.wdType, @"value", @"name"]
excludingAttributes:nil];
NSString *expectedXml = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%@ value=\"%@\" name=\"%@\" private_indexPath=\"top\"/>\n",
element.wdType, element.wdValue, element.wdName];
XCTAssertTrue([resultXml isEqualToString: expectedXml]);
}
- (void)testSnapshotXPathResultsMatching
{
xmlDocPtr doc;
xmlTextWriterPtr writer = xmlNewTextWriterDoc(&doc, 0);
NSMutableDictionary *elementStore = [NSMutableDictionary dictionary];
XCElementSnapshotDouble *snapshot = [XCElementSnapshotDouble new];
id<FBElement> root = (id<FBElement>)[FBXCElementSnapshotWrapper ensureWrapped:(id)snapshot];
NSString *query = [NSString stringWithFormat:@"//%@", root.wdType];
int rc = xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
if (rc >= 0) {
rc = [FBXPath xmlRepresentationWithRootElement:(id<FBXCElementSnapshot>)root
writer:writer
elementStore:elementStore
query:query
excludingAttributes:nil];
if (rc >= 0) {
rc = xmlTextWriterEndDocument(writer);
}
}
if (rc < 0) {
xmlFreeTextWriter(writer);
xmlFreeDoc(doc);
XCTFail(@"Unable to create the source XML document");
}
xmlXPathObjectPtr queryResult = [FBXPath evaluate:query document:doc contextNode:NULL];
if (NULL == queryResult) {
xmlFreeTextWriter(writer);
xmlFreeDoc(doc);
XCTAssertNotEqual(NULL, queryResult);
}
NSArray *matchingSnapshots = [FBXPath collectMatchingSnapshots:queryResult->nodesetval
elementStore:elementStore];
xmlXPathFreeObject(queryResult);
xmlFreeTextWriter(writer);
xmlFreeDoc(doc);
XCTAssertNotNil(matchingSnapshots);
XCTAssertEqual(1, [matchingSnapshots count]);
}
@end

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "NSDictionary+FBUtf8SafeDictionary.h"
@interface NSDictionaryFBUtf8SafeTests : XCTestCase
@end
@implementation NSDictionaryFBUtf8SafeTests
- (void)testEmptySafeDictConversion
{
NSDictionary *d = @{};
XCTAssertEqualObjects(d, d.fb_utf8SafeDictionary);
}
- (void)testNonEmptySafeDictConversion
{
NSDictionary *d = @{
@"1": @[@3, @4],
@"5": @{@"6": @7, @"8": @9},
@"10": @"11"
};
XCTAssertEqualObjects(d, d.fb_utf8SafeDictionary);
}
@end

View File

@@ -0,0 +1,60 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "NSExpression+FBFormat.h"
#import "FBElementUtils.h"
@interface NSExpressionFBFormatTests : XCTestCase
@end
@implementation NSExpressionFBFormatTests
- (void)testFormattingForExistingProperty
{
NSExpression *expr = [NSExpression expressionWithFormat:@"wdName"];
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop keyPath], @"wdName");
}
- (void)testFormattingForExistingPropertyShortcut
{
NSExpression *expr = [NSExpression expressionWithFormat:@"visible"];
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop keyPath], @"isWDVisible");
}
- (void)testFormattingForValidExpressionWOKeys
{
NSExpression *expr = [NSExpression expressionWithFormat:@"1"];
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop constantValue], [NSNumber numberWithInt:1]);
}
- (void)testFormattingForExistingComplexProperty
{
NSExpression *expr = [NSExpression expressionWithFormat:@"wdRect.x"];
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop keyPath], @"wdRect.x");
}
- (void)testFormattingForExistingComplexPropertyWOPrefix
{
NSExpression *expr = [NSExpression expressionWithFormat:@"rect.x"];
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop keyPath], @"wdRect.x");
}
- (void)testFormattingForPredicateWithUnknownKey
{
NSExpression *expr = [NSExpression expressionWithFormat:@"title"];
XCTAssertThrowsSpecificNamed([NSExpression fb_wdExpressionWithExpression:expr], NSException, FBUnknownAttributeException);
}
@end

View File

@@ -0,0 +1,72 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "NSPredicate+FBFormat.h"
@interface NSPredicateFBFormatTests : XCTestCase
@end
@implementation NSPredicateFBFormatTests
- (void)testFormattingForExistingProperty
{
NSPredicate *expr = [NSPredicate predicateWithFormat:@"wdName == 'blabla'"];
XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
}
- (void)testFormattingForExistingPropertyOnTheRightSide
{
NSPredicate *expr = [NSPredicate predicateWithFormat:@"0 == wdAccessible"];
XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
}
- (void)testFormattingForExistingPropertyShortcut
{
NSPredicate *expr = [NSPredicate predicateWithFormat:@"visible == 1"];
XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
}
- (void)testFormattingForComplexExpression
{
NSPredicate *expr = [NSPredicate predicateWithFormat:@"visible == 1 AND NOT (type == 'blabla' OR NOT (label IN {'3', '4'}))"];
XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
}
- (void)testFormattingForValidExpressionWOKeys
{
NSPredicate *expr = [NSPredicate predicateWithFormat:@"1 = 1"];
XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
}
- (void)testFormattingForExistingComplexProperty
{
NSPredicate *expr = [NSPredicate predicateWithFormat:@"wdRect.x == '0'"];
XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
}
- (void)testFormattingForExistingComplexPropertyWOPrefix
{
NSPredicate *expr = [NSPredicate predicateWithFormat:@"rect.x == '0'"];
XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
}
- (void)testFormattingForPredicateWithUnknownKey
{
NSPredicate *expr = [NSPredicate predicateWithFormat:@"title == 'blabla'"];
XCTAssertThrows([NSPredicate fb_formatSearchPredicate:expr]);
}
- (void)testBlockPredicateCreation
{
NSPredicate *expr = [NSPredicate predicateWithFormat:@"rect.x == '0'"];
XCTAssertNotNil([NSPredicate fb_snapshotBlockPredicateWithPredicate:expr]);
}
@end

View File

@@ -0,0 +1,50 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import "FBElementUtils.h"
@interface XCUIElementHelpersTests : XCTestCase
@property (nonatomic) NSDictionary *namesMapping;
@end
@implementation XCUIElementHelpersTests
- (void)setUp
{
[super setUp];
self.namesMapping = [FBElementUtils wdAttributeNamesMapping];
}
- (void)testMappingContainsNamesAndAliases
{
XCTAssertTrue([self.namesMapping.allKeys containsObject:@"wdName"]);
XCTAssertTrue([self.namesMapping.allKeys containsObject:@"name"]);
}
- (void)testMappingContainsCorrectValueForAttrbutesWithoutGetters
{
XCTAssertTrue([[self.namesMapping objectForKey:@"label"] isEqualToString:@"wdLabel"]);
XCTAssertTrue([[self.namesMapping objectForKey:@"wdLabel"] isEqualToString:@"wdLabel"]);
}
- (void)testMappingContainsCorrectValueForAttrbutesWithGetters
{
XCTAssertTrue([[self.namesMapping objectForKey:@"visible"] isEqualToString:@"isWDVisible"]);
XCTAssertTrue([[self.namesMapping objectForKey:@"wdVisible"] isEqualToString:@"isWDVisible"]);
}
- (void)testEachPropertyHasAlias
{
NSArray *aliases = [self.namesMapping.allKeys filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"NOT(SELF beginsWith[c] 'wd')"]];
NSArray *names = [self.namesMapping.allKeys filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginsWith[c] 'wd'"]];
XCTAssertEqual(aliases.count, names.count);
}
@end