// // Tests/ASThrashUtility.h // Texture // // Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. // Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved. // Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0 // #import #import NS_ASSUME_NONNULL_BEGIN #define kInitialSectionCount 10 #define kInitialItemCount 10 #define kMinimumItemCount 5 #define kMinimumSectionCount 3 #define kFickleness 0.1 #define kThrashingIterationCount 10 // Set to 1 to use UITableView and see if the issue still exists. #define USE_UIKIT_REFERENCE 0 #if USE_UIKIT_REFERENCE #define TableView UITableView #define CollectionView UICollectionView #define kCellReuseID @"ASThrashTestCellReuseID" #else #define TableView ASTableView #define CollectionView ASCollectionNode #endif static NSInteger ASThrashUpdateCurrentSerializationVersion = 1; @class ASThrashTestSection; static atomic_uint ASThrashTestItemNextID; @interface ASThrashTestItem: NSObject @property (nonatomic, readonly) NSInteger itemID; + (NSMutableArray *)itemsWithCount:(NSInteger)count; - (CGFloat)rowHeight; @end @interface ASThrashTestSection: NSObject @property (nonatomic, readonly) NSMutableArray *items; @property (nonatomic, readonly) NSInteger sectionID; + (NSMutableArray *)sectionsWithCount:(NSInteger)count; - (instancetype)initWithCount:(NSInteger)count; - (CGFloat)headerHeight; @end @interface ASThrashDataSource: NSObject #if USE_UIKIT_REFERENCE #else #endif @property (nonatomic, readonly) UIWindow *window; @property (nonatomic, readonly) TableView *tableView; @property (nonatomic, readonly) CollectionView *collectionView; @property (nonatomic) NSArray *data; // Only access on main @property (nonatomic) ASWeakSet *allNodes; - (instancetype)initTableViewDataSourceWithData:(NSArray *)data; - (instancetype)initCollectionViewDataSourceWithData:(NSArray * _Nullable)data; - (NSPredicate *)predicateForDeallocatedHierarchy; @end @interface NSIndexSet (ASThrashHelpers) - (NSArray *)indexPathsInSection:(NSInteger)section; /// `insertMode` means that for each index selected, the max goes up by one. + (NSMutableIndexSet *)randomIndexesLessThan:(NSInteger)max probability:(float)probability insertMode:(BOOL)insertMode; @end #if !USE_UIKIT_REFERENCE @interface ASThrashTestNode: ASCellNode @property (nonatomic) ASThrashTestItem *item; @end #endif @interface ASThrashUpdate : NSObject @property (nonatomic, readonly) NSArray *oldData; @property (nonatomic, readonly) NSMutableArray *data; @property (nonatomic, readonly) NSMutableIndexSet *deletedSectionIndexes; @property (nonatomic, readonly) NSMutableIndexSet *replacedSectionIndexes; /// The sections used to replace the replaced sections. @property (nonatomic, readonly) NSMutableArray *replacingSections; @property (nonatomic, readonly) NSMutableIndexSet *insertedSectionIndexes; @property (nonatomic, readonly) NSMutableArray *insertedSections; @property (nonatomic, readonly) NSMutableArray *deletedItemIndexes; @property (nonatomic, readonly) NSMutableArray *replacedItemIndexes; /// The items used to replace the replaced items. @property (nonatomic, readonly) NSMutableArray *> *replacingItems; @property (nonatomic, readonly) NSMutableArray *insertedItemIndexes; @property (nonatomic, readonly) NSMutableArray *> *insertedItems; - (instancetype)initWithData:(NSArray *)data; + (ASThrashUpdate *)thrashUpdateWithBase64String:(NSString *)base64; - (NSString *)base64Representation; - (NSString *)logFriendlyBase64Representation; @end NS_ASSUME_NONNULL_END