-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestBase.m
103 lines (70 loc) · 2.66 KB
/
TestBase.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// TestBase.m
// MathWars
//
// Created by Inf on 01.03.10.
// Copyright 2010 Soulteam. All rights reserved.
//
#import <OCMock/OCMock.h>
#import "Puzzle.h"
#import "Factory.h"
#import "TestBase.h"
#define typeof __typeof__
@implementation TestBase
-(void)setUp {
[super setUp];
mockPuzzle = [OCMockObject mockForClass:[Puzzle class]];
((Factory*)mapObject).owner = mockPlayer;
}
-(void)createMapObject {
mapObject = [[Factory alloc] init];
}
-(void)testOwnerChange {
id mockDelegate = [OCMockObject mockForProtocol:@protocol(BaseDelegate)];
((Factory*)mapObject).delegate = mockDelegate;
[[mockDelegate expect] ownerChangedTo:mockEnemy];
[[mockPlayer expect] unassignFactory:(Factory*)mapObject];
[[mockEnemy expect] assignFactory:(Factory*)mapObject];
[((Factory*)mapObject) onOwnerChange:mockEnemy];
[mockPlayer verify];
[mockEnemy verify];
[mockDelegate verify];
}
-(void)testBuildUnit {
int buildCount=1;
[[[mockPlayer stub] andReturnValue:OCMOCK_VALUE(buildCount)] buildCount];
//[[mockPlayer expect] createPuzzleOfDifficulty:1 withDelegate:[OCMArg any]];
[[mockPlayer expect] setBuildCount:0];
[((Factory*)mapObject) buildUnitOfType:(uint8_t)MWUnitTank];
[mockPlayer verify];
}
-(void)testSuccesfulBuild {
int buildCount=1;
id mockDelegate = [OCMockObject mockForProtocol:@protocol(BaseDelegate)];
[[mockDelegate expect] buildedUnit:[OCMArg any]];
[[[mockPlayer stub] andReturn:mockPuzzle] createPuzzleOfDifficulty:1 withDelegate:(Factory*)mapObject];
[[[mockPlayer stub] andReturnValue:OCMOCK_VALUE(buildCount)] buildCount];
[[mockPlayer expect] assignUnit:(Unit*)[OCMArg any]];
[[mockPlayer stub] setBuildCount:0];
((Factory*)mapObject).delegate = mockDelegate;
[(Factory*)mapObject buildUnitOfType:MWUnitTank];
[(Factory*)mapObject puzzleWasSolved:mockPuzzle];
STAssertNotNil(mapObject.guardian, @"Должен появится стражник");
STAssertEquals(mapObject.guardian.type, (uint8_t)MWUnitTank, @"Стражник должен быть танком");
[mockDelegate verify];
}
-(void)testCombatLose {
[[mockPlayer stub] unassignFactory:(Factory*)mapObject];
[[mockEnemy stub] assignFactory:(Factory*)mapObject];
[super testCombatLose];
}
-(void)testUnsuccessfulBuild {
int buildCount=1;
[[[mockPlayer stub] andReturn:mockPuzzle] createPuzzleOfDifficulty:1 withDelegate:(Factory*)mapObject];
[[[mockPlayer stub] andReturnValue:OCMOCK_VALUE(buildCount)] buildCount];
[[mockPlayer stub] setBuildCount:0];
[(Factory*)mapObject buildUnitOfType:MWUnitTank];
[(Factory*)mapObject puzzleWasFailed:mockPuzzle];
STAssertNil(mapObject.guardian, @"Стражник не должен появиться");
}
@end