Skip to content

Commit

Permalink
Rewrote UIScript to fix bugs, and reversed order in which views are r…
Browse files Browse the repository at this point in the history
…eturned so that views are more likely to be from top of screen to bottom - this may break your specs when updating to latest.

git-svn-id: http://uispec.googlecode.com/svn/trunk@51 63d4da46-1340-11de-a72a-edd3f5372759
  • Loading branch information
btknorr committed Nov 7, 2009
1 parent 1440ede commit fbf874e
Show file tree
Hide file tree
Showing 12 changed files with 868 additions and 1,077 deletions.
2 changes: 2 additions & 0 deletions bin/UISpec/Headers/UIBug.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

}

+(id)bugAtPoint:(CGPoint)point;

@end
2 changes: 1 addition & 1 deletion bin/UISpec/Headers/UIQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@class UIFilter, UIExpectation, UIRedoer;

UIQuery * $(NSString *script, ...);
UIQuery * $(NSMutableString *script, ...);

@interface UIQuery : ViewFilterSwizzler {
UIQuery *first, *last, *all, *redo;
Expand Down
Binary file modified bin/UISpec/UISpec_1_0.a
Binary file not shown.
2 changes: 1 addition & 1 deletion src/dsl/UIChildren.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ +(id)withTraversal {
-(NSArray *)collect:(NSArray *)views {
NSMutableArray *array = [NSMutableArray array];
for (UIView *view in views) {
for (UIView *subView in view.subviews) {
for (UIView *subView in [view.subviews reverseObjectEnumerator]) {
[array addObject:subView];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/dsl/UIDescendants.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ -(NSArray *)collect:(NSArray *)views {

-(void)collectDescendantsOnView:(UIView *)view inToArray:(NSMutableArray *)array {
NSArray *subViews = ([view isKindOfClass:[UIApplication class]]) ? [view windows] : [view subviews];
for (UIView * v in subViews) {
for (UIView * v in [subViews reverseObjectEnumerator]) {
[array addObject:v];
}
for (UIView * v in subViews) {
for (UIView * v in [subViews reverseObjectEnumerator]) {
[self collectDescendantsOnView:v inToArray:array];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dsl/UIQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@class UIFilter, UIExpectation, UIRedoer;

UIQuery * $(NSString *script, ...);
UIQuery * $(NSMutableString *script, ...);

@interface UIQuery : ViewFilterSwizzler {
UIQuery *first, *last, *all, *redo;
Expand Down
117 changes: 45 additions & 72 deletions src/dsl/UIQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,17 @@ - (BOOL)respondsToSelector:(SEL)aSelector {
-(UIQuery *)flash {
[self.should exist:@"before you can flash it"];
for (UIView *view in [self targetViews]) {
UIColor *tempColor = view.backgroundColor;
UIColor *tempColor = [view.backgroundColor retain];
for (int i=0; i<5; i++) {
view.backgroundColor = [UIColor yellowColor];
CFRunLoopRunInMode(kCFRunLoopDefaultMode, .05, false);
view.backgroundColor = [UIColor blueColor];
CFRunLoopRunInMode(kCFRunLoopDefaultMode, .05, false);
}
view.backgroundColor = tempColor;
[tempColor release];
}
return self;
return [UIQuery withViews:views className:className];
}

-(UIQuery *)show {
Expand All @@ -224,15 +225,15 @@ -(UIQuery *)show {

-(UIQuery *)path {
[self.should exist:@"before you can show its path"];
NSMutableString *path = [NSMutableString stringWithString:@"\n"];
for (UIView *view in [self targetViews]) {
NSMutableString *path = [NSMutableString stringWithString:@"\n"];
NSArray *parentViews = [[UIParents withTraversal] collect:[NSArray arrayWithObject:view]];
for (int i = parentViews.count-1; i>=0; i--) {
[path appendFormat:@"%@ -> ", [[parentViews objectAtIndex:i] class]];
}
[path appendFormat:@"%@", [view class]];
NSLog(path);
}
NSLog(path);
return [UIQuery withViews:views className:className];
}

Expand Down Expand Up @@ -456,85 +457,57 @@ - (void)setLocationInWindow:(CGPoint)location

@end

UIQuery * $(NSString *script, ...) {
UIQuery * $(NSMutableString *script, ...) {
va_list args;
va_start(args, script);
script = [[[NSString alloc] initWithFormat:script arguments:args] autorelease];
script = [[[NSMutableString alloc] initWithFormat:script arguments:args] autorelease];
va_end(args);

//float test;
// [[NSScanner scannerWithString:@"45.73"] scanFloat:(float *)&test];
// NSLog(@"((((((( test = %f", test);

//NSLog(@"script = %@, length = %d", script, script.length);
UIQuery *result = [UIQuery withApplicaton];
NSRange nextSearchRange = NSMakeRange(0, script.length);
NSRange nextSpaceRange = [script rangeOfString:@" " options:NSLiteralSearch range:nextSearchRange];
//NSLog(@"script = %@, length = %d", script, script.length);

NSRange checkForSet = [script rangeOfString:@":" options:NSLiteralSearch range:nextSearchRange];
if (checkForSet.length != 0 && checkForSet.location < nextSpaceRange.location) {
NSRange openQuote = [script rangeOfString:@"'" options:NSLiteralSearch range:nextSearchRange];
nextSearchRange = NSMakeRange(openQuote.location + openQuote.length, script.length - openQuote.location - openQuote.length);
NSRange closeQuote = [script rangeOfString:@"'" options:NSLiteralSearch range:nextSearchRange];
nextSearchRange = NSMakeRange(closeQuote.location + closeQuote.length, script.length - closeQuote.location - closeQuote.length);
nextSpaceRange = [script rangeOfString:@" " options:NSLiteralSearch range:nextSearchRange];
NSMutableArray *strings = [NSMutableArray array];
NSArray *stringParams = [script componentsSeparatedByString:@"'"];
//NSLog(@"%@", stringParams);
if (stringParams.count > 1) {
for (int i=1; i<stringParams.count; i=i+2) {
[strings addObject:[stringParams objectAtIndex:i]];
[script replaceOccurrencesOfString:[NSString stringWithFormat:@"'%@'", [stringParams objectAtIndex:i]] withString:@"BIGFATGUYWITHPIGFEET" options:NSLiteralSearch range:NSMakeRange(0, [script length])];
}
}
//NSLog(@"script = %@", script);
//NSLog(@"strings = %@", strings);

if (nextSpaceRange.length == 0) {
nextSpaceRange = NSMakeRange(script.length, 0);
}
NSRange nextCommandRange = NSMakeRange(nextSearchRange.location, nextSpaceRange.location);
while (YES) {
NSString *command = [script substringWithRange:nextCommandRange];

//NSLog(@"command = %@", command);
if (![command isEqualToString:@""]) {
NSRange whereIsSet = [command rangeOfString:@":"];
if (whereIsSet.length != 0) {
NSArray *selectors = [command componentsSeparatedByString:@":"];
NSString *selector = [NSString stringWithFormat:@"%@:", [selectors objectAtIndex:0]];
NSString *arg = [selectors objectAtIndex:1];
BOOL isString = [arg rangeOfString:@"'"].length != 0;
arg = [arg stringByReplacingOccurrencesOfString:@"'" withString:@""];
id argValue = nil;
if (isString) {
argValue = arg;
} else if ([arg isEqualToString:@"YES"] || [arg isEqualToString:@"NO"]) {
argValue = [arg isEqualToString:@"YES"];
} else {
argValue = [arg intValue];
}
result = [result performSelector:NSSelectorFromString(selector) withObject:argValue];
NSArray *commands = [script componentsSeparatedByString:@" "];
//NSLog(@"commands = %@", commands);

int stringCount = 0;
for (NSString *command in commands) {
NSArray *commandAndParam = [command componentsSeparatedByString:@":"];
NSString *commandValue = [commandAndParam objectAtIndex:0];
//NSLog(@"commandValue = %@", commandValue);
NSString *param = nil;
if (commandAndParam.count > 1) {
param = [commandAndParam objectAtIndex:1];
}
if (param != nil) {
id paramValue = nil;
if ([param isEqualToString:@"BIGFATGUYWITHPIGFEET"]) {
paramValue = [strings objectAtIndex:stringCount];
stringCount++;
//NSLog(@"paramValue = %@", paramValue);
} else if ([param isEqualToString:@"YES"] || [param isEqualToString:@"NO"]) {
paramValue = [param isEqualToString:@"YES"];
//NSLog(@"paramValue = %d", paramValue);
} else {
result = [result performSelector:NSSelectorFromString(command)];
paramValue = [param intValue];
//NSLog(@"paramValue = %d", paramValue);
}
result = [result performSelector:NSSelectorFromString([NSString stringWithFormat:@"%@:", commandValue]) withObject:paramValue];
} else {
result = [result performSelector:NSSelectorFromString(commandValue)];
}
//NSLog(@"result = %@", [result target]);
if (nextSpaceRange.location == script.length) {
break;
}
nextSearchRange = NSMakeRange(nextSpaceRange.location + nextSpaceRange.length, script.length - nextSpaceRange.location - nextSpaceRange.length);
nextSpaceRange = [script rangeOfString:@" " options:NSLiteralSearch range:nextSearchRange];

NSRange checkForSet = [script rangeOfString:@":" options:NSLiteralSearch range:nextSearchRange];
if (checkForSet.length != 0 && checkForSet.location < nextSpaceRange.location) {
NSRange openQuote = [script rangeOfString:@"'" options:NSLiteralSearch range:nextSearchRange];
//[self logRange:@"openQuote" range:openQuote];
nextSearchRange = NSMakeRange(openQuote.location + openQuote.length, script.length - openQuote.location - openQuote.length);
//[self logRange:@"nextSearchRange" range:nextSearchRange];
NSRange closeQuote = [script rangeOfString:@"'" options:NSLiteralSearch range:nextSearchRange];
//[self logRange:@"closeQuote" range:closeQuote];
nextSearchRange = NSMakeRange(closeQuote.location + closeQuote.length, script.length - closeQuote.location - closeQuote.length);
//[self logRange:@"nextSearchRange" range:nextSearchRange];
nextSpaceRange = [script rangeOfString:@" " options:NSLiteralSearch range:nextSearchRange];
//[self logRange:@"nextSpaceRange" range:nextSpaceRange];
}

if (nextSpaceRange.length == 0) {
nextSpaceRange = NSMakeRange(script.length, 0);
}
nextCommandRange = NSMakeRange(nextCommandRange.location + nextCommandRange.length + 1, nextSpaceRange.location - nextCommandRange.location - nextCommandRange.length - 1);
//[self logRange:@"nextCommandRange" range:nextCommandRange];
//NSLog(@"result = %@", result);
}
return result;
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/UIBug.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

}

+(id)bugAtPoint:(CGPoint)point;

@end
Loading

0 comments on commit fbf874e

Please sign in to comment.