Advanced Strategic Command
viewtest.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 
11 #include "../actions/moveunitcommand.h"
12 #include "../actions/attackcommand.h"
13 #include "../loaders.h"
14 #include "../viewcalculation.h"
15 #include "../spfst.h"
16 #include "unittestutil.h"
17 
18 
19 void testView3()
20 {
21  auto_ptr<GameMap> game ( startMap("unittest-jammingdestroyview.map"));
22 
23  Vehicle* ari = game->getField(5,2)->vehicle;
24 
25  MapField* field = game->getField(0,12);
26  MapField* field2 = game->getField(3,10);
27 
28 
31 
32  attack( ari, MapCoordinate(3,8));
33 
36 
37  ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
38  assertOrThrow( res.successful() );
39 
42 
43 }
44 
45 void testView1()
46 {
47  auto_ptr<GameMap> game ( startMap("unittest-view1.map"));
48 
49  Vehicle* radar = game->getField(0,4)->vehicle;
50 
51  assertOrThrow( fieldvisiblenow(game->getField(3,5)) == false );
52 
53  move( radar, MapCoordinate(1,4));
54 
55  assertOrThrow( fieldvisiblenow(game->getField(3,5)) == true );
56 
57  assertOrThrow( fieldvisiblenow(game->getField(4,3)) == false );
58 
59  attack( game->getField(1,6)->vehicle, MapCoordinate( 3,5 ) );
60 
61  assertOrThrow( game->getField(3,5)->vehicle == NULL );
62  assertOrThrow( fieldvisiblenow(game->getField(4,3)) == true );
63 
64  ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
65  assertOrThrow( res.successful() );
66 
67  assertOrThrow( fieldvisiblenow(game->getField(4,3)) == false );
68  assertOrThrow( fieldvisiblenow(game->getField(3,5)) == true );
69 
70  res = game->actions.undo( createTestingContext( game.get() ) );
71  assertOrThrow( res.successful() );
72 
73  assertOrThrow( fieldvisiblenow(game->getField(3,5)) == false );
74 
75 
76  // now we are testing the view of the BLUE player
77 
78  assertOrThrow( fieldvisiblenow(game->getField(0,15), 1) == true );
79  attack( game->getField(2,16)->vehicle, MapCoordinate( 0,13 ) );
80 
81  assertOrThrow( fieldvisiblenow(game->getField(0,15), 1) == false );
82 
83  res = game->actions.undo( createTestingContext( game.get() ) );
84  assertOrThrow( res.successful() );
85 
86  assertOrThrow( fieldvisiblenow(game->getField(0,15), 1) == true );
87 }
88 
89 
90 void testView2()
91 {
92  auto_ptr<GameMap> game ( startMap("unittest-view2.map"));
93 
94  Vehicle* spyplane = game->getField(5,2)->vehicle;
95 
96  assertOrThrow( spyplane != NULL );
97  assertOrThrow( spyplane->damage == 0 );
98 
99  assertOrThrow( fieldvisiblenow(game->getField(5,2),1 ) == false );
100 
101  move( spyplane, MapCoordinate(5,18));
102 
103  spyplane = game->getField(5,18)->vehicle;
104  assertOrThrow( spyplane != NULL );
105  assertOrThrow( spyplane->damage == 0 );
106 }
107 
108 
109 void testView()
110 {
111  testView1();
112  testView2();
113  testView3();
114 }
void testView2()
Definition: viewtest.cpp:90
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
void move(Vehicle *veh, const MapCoordinate &dest)
#define assertOrThrow(expr)
Definition: errors.h:69
void testView()
Definition: viewtest.cpp:109
Context createTestingContext(GameMap *gamemap)
a single field of the map
Definition: mapfield.h:26
void testView1()
Definition: viewtest.cpp:45
bool fieldvisiblenow(const MapField *pe, Vehicle *veh, int player)
{@
Definition: spfst.cpp:399
Coordinate on the twodimensional map.
Definition: typen.h:202
GameMap * startMap(const ASCString &filename)
bool successful() const
VisibilityStates fieldVisibility(const MapField *pe)
}@
Definition: spfst.cpp:440
void attack(Vehicle *veh, const MapCoordinate &target)
void testView3()
Definition: viewtest.cpp:19