PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/UnitTesting/GTMTestTimerTest.m

http://macfuse.googlecode.com/
Objective C | 56 lines | 29 code | 6 blank | 21 comment | 0 complexity | 47fbd7322bec0d1bc3f6cfcffdfe0829 MD5 | raw file
 1//
 2//  GTMTestTimerTest.m
 3//
 4//  Copyright 2008 Google Inc.
 5//
 6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 7//  use this file except in compliance with the License.  You may obtain a copy
 8//  of the License at
 9// 
10//  http://www.apache.org/licenses/LICENSE-2.0
11// 
12//  Unless required by applicable law or agreed to in writing, software
13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15//  License for the specific language governing permissions and limitations under
16//  the License.
17//
18
19#import "GTMSenTestCase.h"
20#import "GTMTestTimer.h"
21
22@interface GTMTestTimerTest : GTMTestCase
23@end
24
25@implementation GTMTestTimerTest
26- (void)testTimer {
27  GTMTestTimer *timer = GTMTestTimerCreate();
28  STAssertNotNULL(timer, nil);
29  GTMTestTimerRetain(timer);
30  GTMTestTimerRelease(timer);
31  STAssertEqualsWithAccuracy(GTMTestTimerGetSeconds(timer), 0.0, 0.0, nil);
32  GTMTestTimerStart(timer);
33  STAssertTrue(GTMTestTimerIsRunning(timer), nil);
34  NSRunLoop *loop = [NSRunLoop currentRunLoop];
35  [loop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
36  GTMTestTimerStop(timer);
37  
38  // We use greater than (and an almost absurd less than) because 
39  // these tests are very dependant on machine load, and we don't want
40  // automated tests reporting false negatives.
41  STAssertGreaterThan(GTMTestTimerGetSeconds(timer), 0.1, nil);
42  STAssertGreaterThan(GTMTestTimerGetMilliseconds(timer), 100.0,nil);
43  STAssertGreaterThan(GTMTestTimerGetMicroseconds(timer), 100000.0, nil);
44  
45  // Check to make sure we're not WAY off the mark (by a factor of 10)
46  STAssertLessThan(GTMTestTimerGetMicroseconds(timer), 1000000.0, nil);
47  
48  [loop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
49  GTMTestTimerStart(timer);
50  [loop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
51  STAssertGreaterThan(GTMTestTimerGetSeconds(timer), 0.2, nil);
52  GTMTestTimerStop(timer);
53  STAssertEquals(GTMTestTimerGetIterations(timer), (NSUInteger)2, nil);
54  GTMTestTimerRelease(timer);
55}
56@end