/core/externals/google-toolbox-for-mac/UnitTesting/GTMSenTestCaseTest.m
Objective C | 72 lines | 36 code | 15 blank | 21 comment | 2 complexity | d481c8c09d476465f4186f29ba70ac6d MD5 | raw file
1// 2// GTMSenTestCaseTest.m 3// 4// Copyright 2010 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 21// These make use of the fact that methods are run in alphebetical order 22// to have one test check that a previous one was run. If that order ever 23// changes, there is a good chance things will break. 24 25static int gAbstractCalls_ = 0; 26static int gZzCheckCalls_ = 0; 27 28@interface GTMTestingAbstractTest : GTMTestCase 29@end 30 31@interface GTMTestingTestOne : GTMTestingAbstractTest { 32 BOOL zzCheckCalled_; 33} 34@end 35 36@interface GTMTestingTestTwo : GTMTestingTestOne 37@end 38 39@implementation GTMTestingAbstractTest 40 41- (void)testAbstractUnitTest { 42 STAssertFalse([self isMemberOfClass:[GTMTestingAbstractTest class]], 43 @"test should not run on the abstract class"); 44 ++gAbstractCalls_; 45} 46 47@end 48 49@implementation GTMTestingTestOne 50 51- (void)testZZCheck { 52 ++gZzCheckCalls_; 53 if ([self isMemberOfClass:[GTMTestingTestOne class]]) { 54 STAssertEquals(gAbstractCalls_, 1, 55 @"wrong number of abstract calls at this point"); 56 } else { 57 STAssertTrue([self isMemberOfClass:[GTMTestingTestTwo class]], nil); 58 STAssertEquals(gAbstractCalls_, 2, 59 @"wrong number of abstract calls at this point"); 60 } 61} 62 63@end 64 65@implementation GTMTestingTestTwo 66 67- (void)testZZZCheck { 68 // Test defined at this leaf, it should always run, check on the other methods. 69 STAssertEquals(gZzCheckCalls_, 2, @"the parent class method wasn't called"); 70} 71 72@end