aboutsummaryrefslogtreecommitdiff
path: root/UnitTesting/GTMFoundationUnitTestingUtilities.m
diff options
context:
space:
mode:
Diffstat (limited to 'UnitTesting/GTMFoundationUnitTestingUtilities.m')
-rw-r--r--UnitTesting/GTMFoundationUnitTestingUtilities.m26
1 files changed, 22 insertions, 4 deletions
diff --git a/UnitTesting/GTMFoundationUnitTestingUtilities.m b/UnitTesting/GTMFoundationUnitTestingUtilities.m
index ab1f29b..5304990 100644
--- a/UnitTesting/GTMFoundationUnitTestingUtilities.m
+++ b/UnitTesting/GTMFoundationUnitTestingUtilities.m
@@ -6,9 +6,9 @@
// 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
@@ -16,6 +16,8 @@
// the License.
//
+#import <unistd.h>
+
#import "GTMFoundationUnitTestingUtilities.h"
@implementation GTMFoundationUnitTestingUtilities
@@ -23,7 +25,7 @@
// Returns YES if we are currently being unittested.
+ (BOOL)areWeBeingUnitTested {
BOOL answer = NO;
-
+
// Check to see if the SenTestProbe class is linked in before we call it.
Class SenTestProbeClass = NSClassFromString(@"SenTestProbe");
if (SenTestProbeClass != Nil) {
@@ -39,6 +41,22 @@
return answer;
}
++ (void)maxRuntimeTimer:(NSTimer*)timer {
+ // Directly use fprintf so the message always shows up.
+ fprintf(stderr, "%s:%d: error: %s : Hit app testing timeout!\n",
+ __FILE__, __LINE__, __func__);
+ fflush(stderr);
+ exit(1);
+}
+
++ (void)installTestingTimeout:(NSTimeInterval)maxRunInterval {
+ [NSTimer scheduledTimerWithTimeInterval:maxRunInterval
+ target:self
+ selector:@selector(maxRuntimeTimer:)
+ userInfo:nil
+ repeats:NO];
+}
+
@end
@implementation GTMUnitTestingBooleanRunLoopContext
@@ -64,7 +82,7 @@
context:context];
}
-- (BOOL)gtm_runUntilDate:(NSDate *)date
+- (BOOL)gtm_runUntilDate:(NSDate *)date
context:(id<GTMUnitTestingRunLoopContext>)context {
return [self gtm_runUntilDate:date mode:NSDefaultRunLoopMode context:context];
}