/GHUnitIOS.framework/Versions/A/Headers/GHTest.h

http://github.com/zwaldowski/BlocksKit · C++ Header · 187 lines · 72 code · 34 blank · 81 comment · 0 complexity · d13b9de678c73ebecd9dbf6e11f64264 MD5 · raw file

  1. //
  2. // GHTest.h
  3. // GHUnit
  4. //
  5. // Created by Gabriel Handford on 1/18/09.
  6. // Copyright 2009. All rights reserved.
  7. //
  8. // Permission is hereby granted, free of charge, to any person
  9. // obtaining a copy of this software and associated documentation
  10. // files (the "Software"), to deal in the Software without
  11. // restriction, including without limitation the rights to use,
  12. // copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the
  14. // Software is furnished to do so, subject to the following
  15. // conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  22. // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  24. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  25. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27. // OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. //! @cond DEV
  30. #import <Foundation/Foundation.h>
  31. /*!
  32. Test status.
  33. */
  34. typedef enum {
  35. GHTestStatusNone = 0,
  36. GHTestStatusRunning, // Test is running
  37. GHTestStatusCancelling, // Test is being cancelled
  38. GHTestStatusCancelled, // Test was cancelled
  39. GHTestStatusSucceeded, // Test finished and succeeded
  40. GHTestStatusErrored, // Test finished and errored
  41. } GHTestStatus;
  42. enum {
  43. GHTestOptionReraiseExceptions = 1 << 0, // Allows exceptions to be raised (so you can trigger the debugger)
  44. GHTestOptionForceSetUpTearDownClass = 1 << 1, // Runs setUpClass/tearDownClass for this (each) test; Used when re-running a single test in a group
  45. };
  46. typedef NSInteger GHTestOptions;
  47. /*!
  48. Generate string from GHTestStatus
  49. @param status
  50. */
  51. extern NSString* NSStringFromGHTestStatus(GHTestStatus status);
  52. /*!
  53. Check if test is running (or trying to cancel).
  54. */
  55. extern BOOL GHTestStatusIsRunning(GHTestStatus status);
  56. /*!
  57. Check if test has succeeded, errored or cancelled.
  58. */
  59. extern BOOL GHTestStatusEnded(GHTestStatus status);
  60. /*!
  61. Test stats.
  62. */
  63. typedef struct {
  64. NSInteger succeedCount; // Number of succeeded tests
  65. NSInteger failureCount; // Number of failed tests
  66. NSInteger cancelCount; // Number of aborted tests
  67. NSInteger testCount; // Total number of tests
  68. } GHTestStats;
  69. /*!
  70. Create GHTestStats.
  71. */
  72. extern GHTestStats GHTestStatsMake(NSInteger succeedCount, NSInteger failureCount, NSInteger cancelCount, NSInteger testCount);
  73. extern const GHTestStats GHTestStatsEmpty;
  74. extern NSString *NSStringFromGHTestStats(GHTestStats stats);
  75. @protocol GHTestDelegate;
  76. /*!
  77. The base interface for a runnable test.
  78. A runnable with a unique identifier, display name, stats, timer, delegate, log and error handling.
  79. */
  80. @protocol GHTest <NSObject, NSCoding, NSCopying>
  81. - (void)run:(GHTestOptions)options;
  82. @property (readonly, nonatomic) NSString *identifier; // Unique identifier for test
  83. @property (readonly, nonatomic) NSString *name;
  84. @property (assign, nonatomic) NSTimeInterval interval;
  85. @property (assign, nonatomic) GHTestStatus status;
  86. @property (readonly, nonatomic) GHTestStats stats;
  87. @property (retain, nonatomic) NSException *exception;
  88. @property (assign, nonatomic, getter=isDisabled) BOOL disabled;
  89. @property (assign, nonatomic, getter=isHidden) BOOL hidden;
  90. @property (assign, nonatomic) id<GHTestDelegate> delegate; // weak
  91. - (NSArray *)log;
  92. - (void)reset;
  93. - (void)cancel;
  94. - (NSInteger)disabledCount;
  95. @end
  96. /*!
  97. Test delegate for notification when a test starts and ends.
  98. */
  99. @protocol GHTestDelegate <NSObject>
  100. - (void)testDidStart:(id<GHTest>)test source:(id<GHTest>)source;
  101. - (void)testDidUpdate:(id<GHTest>)test source:(id<GHTest>)source;
  102. - (void)testDidEnd:(id<GHTest>)test source:(id<GHTest>)source;
  103. - (void)test:(id<GHTest>)test didLog:(NSString *)message source:(id<GHTest>)source;
  104. @end
  105. /*!
  106. Delegate which is notified of log messages from inside GHTestCase.
  107. */
  108. @protocol GHTestCaseLogWriter <NSObject>
  109. - (void)log:(NSString *)message testCase:(id)testCase;
  110. @end
  111. /*!
  112. Default test implementation with a target/selector pair.
  113. - Tests a target and selector
  114. - Notifies a test delegate
  115. - Keeps track of status, running time and failures
  116. - Stores any test specific logging
  117. */
  118. @interface GHTest : NSObject <GHTest, GHTestCaseLogWriter> {
  119. NSObject<GHTestDelegate> *delegate_; // weak
  120. id target_;
  121. SEL selector_;
  122. NSString *identifier_;
  123. NSString *name_;
  124. GHTestStatus status_;
  125. NSTimeInterval interval_;
  126. BOOL disabled_;
  127. BOOL hidden_;
  128. NSException *exception_; // If failed
  129. NSMutableArray *log_;
  130. }
  131. @property (readonly, nonatomic) id target;
  132. @property (readonly, nonatomic) SEL selector;
  133. @property (readonly, nonatomic) NSArray *log;
  134. /*!
  135. Create test with identifier, name.
  136. @param identifier Unique identifier
  137. @param name Name
  138. */
  139. - (id)initWithIdentifier:(NSString *)identifier name:(NSString *)name;
  140. /*!
  141. Create test with target/selector.
  142. @param target Target (usually a test case)
  143. @param selector Selector (usually a test method)
  144. */
  145. - (id)initWithTarget:(id)target selector:(SEL)selector;
  146. /*!
  147. Create autoreleased test with target/selector.
  148. @param target Target (usually a test case)
  149. @param selector Selector (usually a test method)
  150. */
  151. + (id)testWithTarget:(id)target selector:(SEL)selector;
  152. @end
  153. //! @endcond