main
 1//
 2// Licensed under the terms in License.txt
 3//
 4// Copyright 2010 Allen Ding. All rights reserved.
 5//
 6
 7#import "KiwiConfiguration.h"
 8
 9// This category is solely meant to coax Xcode into exposing the method names below during autocompletion.
10// There is no implementation and this class definition must come before the macro definitions below.
11@interface NSObject (KiwiVerifierMacroNames)
12
13- (void)should;
14- (void)shouldNot;
15- (void)shouldBeNil;
16- (void)shouldNotBeNil;
17- (void)shouldEventually;
18- (void)shouldEventuallyBeforeTimingOutAfter;
19
20@end
21
22#pragma mark -
23#pragma mark Support Macros
24
25#define KW_THIS_CALLSITE [KWCallSite callSiteWithFilename:@__FILE__ lineNumber:__LINE__]
26#define KW_ADD_EXIST_VERIFIER(expectationType) [self addExistVerifierWithExpectationType:expectationType callSite:KW_THIS_CALLSITE]
27#define KW_ADD_MATCH_VERIFIER(expectationType) [self addMatchVerifierWithExpectationType:expectationType callSite:KW_THIS_CALLSITE]
28#define KW_ADD_ASYNC_VERIFIER(expectationType, timeOut) [self addAsyncVerifierWithExpectationType:expectationType callSite:KW_THIS_CALLSITE timeout:timeOut]
29
30#pragma mark -
31#pragma mark Keywords
32
33// Kiwi macros used in specs for verifying expectations.
34#define should attachToVerifier:KW_ADD_MATCH_VERIFIER(KWExpectationTypeShould) verifier:KW_ADD_EXIST_VERIFIER(KWExpectationTypeShould)
35#define shouldNot attachToVerifier:KW_ADD_MATCH_VERIFIER(KWExpectationTypeShouldNot) verifier:KW_ADD_EXIST_VERIFIER(KWExpectationTypeShould)
36#define shouldBeNil attachToVerifier:KW_ADD_EXIST_VERIFIER(KWExpectationTypeShouldNot)
37#define shouldNotBeNil attachToVerifier:KW_ADD_EXIST_VERIFIER(KWExpectationTypeShould)
38#define shouldEventually attachToVerifier:KW_ADD_ASYNC_VERIFIER(KWExpectationTypeShould, kKW_DEFAULT_PROBE_TIMEOUT)
39#define shouldEventuallyBeforeTimingOutAfter(timeout) attachToVerifier:KW_ADD_ASYNC_VERIFIER(KWExpectationTypeShould, timeout)
40
41// waitFor is like a shouldEventually but will not fail if it's never satisfied
42#define waitFor attachToVerifier:KW_ADD_ASYNC_VERIFIER(KWExpectationTypeMaybe, kKW_DEFAULT_PROBE_TIMEOUT)
43
44// used to wrap a pointer to an object that will change in the future (used with shouldEventually)
45#define theObject(objectPtr) [KWFutureObject objectWithObjectPointer:objectPtr] // DEPRECATED
46#define theReturnValueOfBlock(block) [KWFutureObject futureObjectWithBlock:block] // DEPRECATED
47#define expectFutureValue(futureValue) [KWFutureObject futureObjectWithBlock:^{ return futureValue; }]
48
49// used for message patterns to allow matching any value
50#define any() [KWAny any]
51
52// If a gcc compatible compiler is available, use the statement and
53// declarations in expression extension to provide a convenient catch-all macro
54// to create KWValues.
55#if defined(__GNUC__)
56    #define theValue(expr) \
57        ({ \
58            __typeof__(expr) kiwiReservedPrefix_lVar = expr; \
59            [KWValue valueWithBytes:&kiwiReservedPrefix_lVar objCType:@encode(__typeof__(expr))]; \
60        })
61#endif // #if defined(__GNUC__)
62
63// Allows for comparision of pointer values in expectations
64#define thePointerValue(expr) [NSValue valueWithPointer:(expr)]
65
66// Example group declarations.
67#define SPEC_BEGIN(name) \
68    \
69    @interface name : KWSpec \
70    \
71    @end \
72    \
73    @implementation name \
74    \
75    + (void)buildExampleGroups { \
76
77#define SPEC_END \
78    } \
79    \
80    @end