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

http://macfuse.googlecode.com/ · 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. #import "GTMSenTestCase.h"
  19. // These make use of the fact that methods are run in alphebetical order
  20. // to have one test check that a previous one was run. If that order ever
  21. // changes, there is a good chance things will break.
  22. static int gAbstractCalls_ = 0;
  23. static int gZzCheckCalls_ = 0;
  24. @interface GTMTestingAbstractTest : GTMTestCase
  25. @end
  26. @interface GTMTestingTestOne : GTMTestingAbstractTest {
  27. BOOL zzCheckCalled_;
  28. }
  29. @end
  30. @interface GTMTestingTestTwo : GTMTestingTestOne
  31. @end
  32. @implementation GTMTestingAbstractTest
  33. - (void)testAbstractUnitTest {
  34. STAssertFalse([self isMemberOfClass:[GTMTestingAbstractTest class]],
  35. @"test should not run on the abstract class");
  36. ++gAbstractCalls_;
  37. }
  38. @end
  39. @implementation GTMTestingTestOne
  40. - (void)testZZCheck {
  41. ++gZzCheckCalls_;
  42. if ([self isMemberOfClass:[GTMTestingTestOne class]]) {
  43. STAssertEquals(gAbstractCalls_, 1,
  44. @"wrong number of abstract calls at this point");
  45. } else {
  46. STAssertTrue([self isMemberOfClass:[GTMTestingTestTwo class]], nil);
  47. STAssertEquals(gAbstractCalls_, 2,
  48. @"wrong number of abstract calls at this point");
  49. }
  50. }
  51. @end
  52. @implementation GTMTestingTestTwo
  53. - (void)testZZZCheck {
  54. // Test defined at this leaf, it should always run, check on the other methods.
  55. STAssertEquals(gZzCheckCalls_, 2, @"the parent class method wasn't called");
  56. }
  57. @end