File: attacktest.cpp

package info (click to toggle)
asc 2.6.1.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 81,740 kB
  • sloc: cpp: 158,704; sh: 11,544; ansic: 6,736; makefile: 604; perl: 138
file content (150 lines) | stat: -rw-r--r-- 4,602 bytes parent folder | download | duplicates (5)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "../gamemap.h"
#include "../actions/attackcommand.h"
#include "../loaders.h"
#include "unittestutil.h"
#include "../itemrepository.h"
#include "../spfst.h"


void testAttack1() 
{
   auto_ptr<GameMap> game ( startMap("unittest-attack.map"));
   
   Vehicle* veh = game->getField(3,6)->vehicle;
   assertOrThrow( veh != NULL );
   assertOrThrow( veh->getMovement() == 100 );
   
   attack( veh, MapCoordinate( 3,5) );
   
   assertOrThrow( veh->getMovement() == 0 );
   
   testCargoMovement( veh, 50 );
   
   ActionResult res = game->actions.undo( createTestingContext( game.get() ) );  
   assertOrThrow( res.successful() );
   
   assertOrThrow( veh->getMovement() == 100 );
   testCargoMovement( veh, 100 );
   
   
   Vehicle* mam = game->getField(4,4)->vehicle;
   assertOrThrow( mam != NULL );
   assertOrThrow( mam->getMovement() == 100 );
   
   attack( mam, MapCoordinate( 3,5) );
   
   assertOrThrow( mam->getMovement() == 100 );
   testCargoMovement( mam, 100 );
   
   Vehicle* v2 = game->getField(9,14)->vehicle;
   assertOrThrow( v2 != NULL );
   
   Vehicle* a2 = game->getField(9,17)->vehicle;
   assertOrThrow( a2 != NULL );
   
   attack( a2, MapCoordinate( 9, 14 ) );
    
   assertOrThrow( game->getField(9,14)->vehicle == NULL );
   res = game->actions.undo( createTestingContext( game.get() ) );  
   assertOrThrow( res.successful() );
   assertOrThrow( game->getField(9,14)->vehicle != NULL );
}

void testAttack2()
{
   auto_ptr<GameMap> game ( startMap("unittest-objectattack.map"));
   
   Vehicle* buggy = game->getField(0,3)->vehicle;
   assertOrThrow( buggy != NULL );
   
   Vehicle* assault = game->getField(1,2)->vehicle;
   assertOrThrow( assault != NULL );
   
   MapCoordinate h ( 3, 8 );
   MapCoordinate cry( 3,9);
   
   move( buggy, h);
   attack( buggy, cry );
   move( buggy, MapCoordinate( 0,3 ));
   
   move( assault, h );
   
   ObjectType* cryst = objectTypeRepository.getObject_byID( 2105 );
   assertOrThrow( cryst != NULL );
   
   MapField* fld = game->getField( cry );   
   assertOrThrow( fld->checkForObject( cryst ) != NULL );
   
   MapField* view = game->getField( MapCoordinate( 4,11 ));
   assertOrThrow( fieldvisiblenow(view) == false ); 
   
   attack( assault, cry );
   
   assertOrThrow( fld->checkForObject( cryst ) == NULL );
   
   assertOrThrow( fieldvisiblenow(view) == true ); 
   
   ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
   assertOrThrow( res.successful() );
   
   assertOrThrow( fld->checkForObject( cryst ) != NULL );
   assertOrThrow( fieldvisiblenow(view) == false ); 
   
   assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
   assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
   assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
   assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
   
} 

      
void testAttack3()
{
   auto_ptr<GameMap> game ( startMap("unittest-attack-view.map"));
   
   Vehicle* assault = game->getField(4,9)->vehicle;
   assertOrThrow( assault != NULL );
   
   Vehicle* ari = game->getField(4,11)->vehicle;
   assertOrThrow( ari != NULL );
   
   MapCoordinate r( 5, 8);
   MapCoordinate j( 5,11);
   
   MapField* fld = game->getField( MapCoordinate(0,0)); 
   assertOrThrow( fieldvisiblenow(fld) == true ); 
   
   attack( assault, r );
   
   assertOrThrow( fieldvisiblenow(fld) == true ); 
   
   
   MapField* fld2 = game->getField( MapCoordinate(6,8));  
   assertOrThrow( fieldvisiblenow(fld2) == false ); 
   
   attack( ari, j );
   
   assertOrThrow( fieldvisiblenow(fld2) == true ); 
   
   ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
   assertOrThrow( res.successful() );
   
   assertOrThrow( fieldvisiblenow(fld2) == false ); 
   
} 
      
      
void testAttack() {
   testAttack3();
   testAttack2();
   testAttack1();
}