-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated project file and added GTXResult API
- Loading branch information
Sid Janga
committed
Feb 20, 2020
1 parent
641200f
commit 02a890f
Showing
14 changed files
with
607 additions
and
225 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
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,64 @@ | ||
// | ||
// Copyright 2020 Google Inc. | ||
// | ||
// 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 <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
GTXResult encapsulates results (and any other associated info) of a single pass of accessibility | ||
checks. | ||
*/ | ||
@interface GTXResult : NSObject | ||
|
||
/** | ||
An array of all the errors encountered during the accessibility check(s). | ||
*/ | ||
@property(nonatomic, strong, readonly) NSArray<NSError *> *errorsFound; | ||
|
||
/** | ||
Total number of elements that passed through accessibilty check(s). | ||
*/ | ||
@property(nonatomic, assign, readonly) NSInteger elementsScanned; | ||
|
||
/** | ||
Use -initWithErrorsFound:elementsScanned: | ||
*/ | ||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
/** | ||
Initializes a new GTXResult object. | ||
@param errorsFound Array of errors found. | ||
@param elementsScanned Total number of elements scanned. | ||
@return A newly created GTXResult object. | ||
*/ | ||
- (instancetype)initWithErrorsFound:(NSArray<NSError *> *)errorsFound | ||
elementsScanned:(NSInteger)elementsScanned; | ||
|
||
/** | ||
@return @YES if none of the checks failed, @NO otherwise. | ||
*/ | ||
- (BOOL)allChecksPassed; | ||
|
||
/** | ||
@return The aggregated error of all the errors in this result, or @c nil if no errors were found. | ||
*/ | ||
- (NSError *)aggregatedError; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
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,83 @@ | ||
// | ||
// Copyright 2020 Google Inc. | ||
// | ||
// 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 "GTXResult.h" | ||
#import "NSError+GTXAdditions.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface GTXResult () | ||
|
||
@property(nonatomic, strong) NSArray<NSError *> *errorsFound; | ||
@property(nonatomic, assign) NSInteger elementsScanned; | ||
|
||
@end | ||
|
||
@implementation GTXResult { | ||
NSError *_aggregatedError; | ||
} | ||
|
||
- (instancetype)initWithErrorsFound:(NSArray<NSError *> *)errorsFound | ||
elementsScanned:(NSInteger)elementsScanned { | ||
self = [super init]; | ||
if (self) { | ||
_errorsFound = errorsFound; | ||
_elementsScanned = elementsScanned; | ||
} | ||
return self; | ||
} | ||
|
||
- (BOOL)allChecksPassed { | ||
return self.errorsFound.count == 0; | ||
} | ||
|
||
- (NSError *)aggregatedError { | ||
if (![self allChecksPassed]) { | ||
// Combine the error descriptions from all the errors into the following format ('.' is an | ||
// indent): | ||
// . . Element: <element description> | ||
// . . . . Error: <error description> | ||
// . . . . Error: <error description> | ||
// . . Element: <element description> | ||
// . . . . Error: <error description> | ||
// . . . . Error: <error description> | ||
|
||
NSMutableString *errorString = | ||
[[NSMutableString alloc] initWithString:@"One or more elements FAILED the accessibility " | ||
@"checks:\n"]; | ||
for (NSError *error in self.errorsFound) { | ||
id element = [[error userInfo] objectForKey:kGTXErrorFailingElementKey]; | ||
if (element) { | ||
// Add element description with an indent. | ||
[errorString appendFormat:@" %@\n", element]; | ||
for (NSError *underlyingError in | ||
// Add element's error description with twice the indent. | ||
[[error userInfo] objectForKey:kGTXErrorUnderlyingErrorsKey]) { | ||
[errorString appendFormat:@" + %@\n", [underlyingError localizedDescription]]; | ||
} | ||
} | ||
} | ||
[NSError gtx_logOrSetError:&_aggregatedError | ||
description:errorString | ||
code:GTXCheckErrorCodeGenericError | ||
userInfo:@{kGTXErrorUnderlyingErrorsKey : self.errorsFound}]; | ||
} | ||
return _aggregatedError; | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
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
Oops, something went wrong.