Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: third_party/ocmock/OCMock/OCMConstraintTests.m

Issue 9240023: Roll OCMock r77:7f521db0628086185123666b0979e48d6ecaeac1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 //------------------------------------------------------------------------------ ---------
2 // $Id: OCMConstraintTests.m 57 2010-07-19 06:14:27Z erik $
3 // Copyright (c) 2004-2010 by Mulle Kybernetik. See License file for details.
4 //------------------------------------------------------------------------------ ---------
5
6 #import "OCMConstraintTests.h"
7 #import <OCMock/OCMConstraint.h>
8
9
10 @implementation OCMConstraintTests
11
12 - (void)setUp
13 {
14 didCallCustomConstraint = NO;
15 }
16
17 - (void)testAnyAcceptsAnything
18 {
19 OCMConstraint *constraint = [OCMAnyConstraint constraint];
20
21 STAssertTrue([constraint evaluate:@"foo"], @"Should have accepted a valu e.");
22 STAssertTrue([constraint evaluate:@"foo"], @"Should have accepted anothe r value.");
23 STAssertTrue([constraint evaluate:@"foo"], @"Should have accepted nil.") ;
24 }
25
26 - (void)testIsNilAcceptsOnlyNil
27 {
28 OCMConstraint *constraint = [OCMIsNilConstraint constraint];
29
30 STAssertFalse([constraint evaluate:@"foo"], @"Should not have accepted a value.");
31 STAssertTrue([constraint evaluate:nil], @"Should have accepted nil.");
32 }
33
34 - (void)testIsNotNilAcceptsAnythingButNil
35 {
36 OCMConstraint *constraint = [OCMIsNotNilConstraint constraint];
37
38 STAssertTrue([constraint evaluate:@"foo"], @"Should have accepted a valu e.");
39 STAssertFalse([constraint evaluate:nil], @"Should not have accepted nil. ");
40 }
41
42 - (void)testNotEqualAcceptsAnythingButValue
43 {
44 OCMIsNotEqualConstraint *constraint = [OCMIsNotEqualConstraint constrain t];
45 constraint->testValue = @"foo";
46
47 STAssertFalse([constraint evaluate:@"foo"], @"Should not have accepted v alue.");
48 STAssertTrue([constraint evaluate:@"bar"], @"Should have accepted other value.");
49 STAssertTrue([constraint evaluate:nil], @"Should have accepted nil.");
50 }
51
52
53 - (BOOL)checkArg:(id)theArg
54 {
55 didCallCustomConstraint = YES;
56 return [theArg isEqualToString:@"foo"];
57 }
58
59 - (void)testUsesPlainMethod
60 {
61 OCMConstraint *constraint = CONSTRAINT(@selector(checkArg:));
62
63 STAssertTrue([constraint evaluate:@"foo"], @"Should have accepted foo.") ;
64 STAssertTrue(didCallCustomConstraint, @"Should have used custom method." );
65 STAssertFalse([constraint evaluate:@"bar"], @"Should not have accepted b ar.");
66 }
67
68
69 - (BOOL)checkArg:(id)theArg withValue:(id)value
70 {
71 didCallCustomConstraint = YES;
72 return [theArg isEqual:value];
73 }
74
75 - (void)testUsesMethodWithValue
76 {
77 OCMConstraint *constraint = CONSTRAINTV(@selector(checkArg:withValue:), @"foo");
78
79 STAssertTrue([constraint evaluate:@"foo"], @"Should have accepted foo.") ;
80 STAssertTrue(didCallCustomConstraint, @"Should have used custom method." );
81 STAssertFalse([constraint evaluate:@"bar"], @"Should not have accepted b ar.");
82 }
83
84
85 - (void)testRaisesExceptionWhenConstraintMethodDoesNotTakeArgument
86 {
87 STAssertThrows(CONSTRAINTV(@selector(checkArg:), @"bar"), @"Should have thrown for invalid constraint method.");
88 }
89
90
91 - (void)testRaisesExceptionOnUnknownSelector
92 {
93 STAssertThrows(CONSTRAINTV(@selector(checkArgXXX:), @"bar"), @"Should ha ve thrown for unknown constraint method.");
94 }
95
96
97 #if NS_BLOCKS_AVAILABLE
98
99 -(void)testUsesBlock
100 {
101 BOOL (^checkForFooBlock)(id) = ^(id value)
102 {
103 return [value isEqualToString:@"foo"];
104 };
105
106 OCMBlockConstraint *constraint = [[[OCMBlockConstraint alloc] initWithCo nstraintBlock:checkForFooBlock] autorelease];
107
108 STAssertTrue([constraint evaluate:@"foo"], @"Should have accepted foo.") ;
109 STAssertFalse([constraint evaluate:@"bar"], @"Should not have accepted b ar.");
110 }
111
112 -(void)testBlockConstraintCanCaptureArgument
113 {
114 __block NSString *captured;
115 BOOL (^captureArgBlock)(id) = ^(id value)
116 {
117 captured = value;
118 return YES;
119 };
120
121 OCMBlockConstraint *constraint = [[[OCMBlockConstraint alloc] initWithCo nstraintBlock:captureArgBlock] autorelease];
122
123 [constraint evaluate:@"foo"];
124 STAssertEqualObjects(@"foo", captured, @"Should have captured value from last invocation.");
125 [constraint evaluate:@"bar"];
126 STAssertEqualObjects(@"bar", captured, @"Should have captured value from last invocation.");
127 }
128
129 #endif
130
131 @end
OLDNEW
« no previous file with comments | « third_party/ocmock/OCMock/OCMConstraintTests.h ('k') | third_party/ocmock/OCMock/OCMExceptionReturnValueProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698