Advanced Strategic Command
transfercontroltest.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 #include "../gamemap.h"
11 #include "../actions/transfercontrolcommand.h"
12 #include "../loaders.h"
13 #include "transfercontroltest.h"
14 #include "unittestutil.h"
15 #include "spfst.h"
16 
17 
18 
20 {
21  auto_ptr<GameMap> game ( startMap("unittest-transfercontrol.map"));
22 
23  Vehicle* veh = game->getField(4,8)->vehicle;
24  assertOrThrow( veh != NULL );
25  assertOrThrow( veh->getOwner() == 0 );
26 
27  MapField* fld = game->getField(4,0);
29  assertOrThrow( !fieldvisiblenow(fld,3) );
30 
31  auto_ptr<TransferControlCommand> tcc ( new TransferControlCommand( veh ));
32  tcc->setReceiver( &game->player[3] );
33  ActionResult res = tcc->execute( createTestingContext( game.get() ));
34  assertOrThrow( res.successful() );
35  tcc.release();
36 
37  assertOrThrow( veh->getOwner() == 3 );
38  assertOrThrow( !fieldvisiblenow(fld,0) );
40 
41  res = game->actions.undo( createTestingContext( game.get() ) );
42  assertOrThrow( res.successful() );
43 
44  assertOrThrow( veh->getOwner() == 0 );
47 
48 
49  Building* bld = game->getField(14,7)->building;
50  assertOrThrow( bld != NULL );
51  assertOrThrow( bld->getOwner() == 0 );
52 
53 
54  auto_ptr<TransferControlCommand> tcc2 ( new TransferControlCommand( bld));
55  tcc2->setReceiver( &game->player[1] );
56  ActionResult res2 = tcc2->execute( createTestingContext( game.get() ));
57  assertOrThrow( res2.successful() );
58  tcc2.release();
59 
60  assertOrThrow( bld->getOwner() == 1 );
62  assertOrThrow( getFirstCargo(bld)->getOwner() == 1 );
63 
64 }
map accessing and usage routines used by ASC and the mapeditor
#define assertOrThrow(expr)
Definition: errors.h:69
Vehicle * getFirstCargo(ContainerBase *carrier)
int getOwner() const
returns the number of the player this vehicle/building belongs to
Context createTestingContext(GameMap *gamemap)
a single field of the map
Definition: mapfield.h:26
bool fieldvisiblenow(const MapField *pe, Vehicle *veh, int player)
{@
Definition: spfst.cpp:399
MapField * getField(const BuildingType::LocalCoordinate &localCoordinates) const
returns the pointer to the field which the given part of the building is standing on ...
Definition: buildings.cpp:399
GameMap * startMap(const ASCString &filename)
void testTransferControl()
bool successful() const
VisibilityStates fieldVisibility(const MapField *pe)
}@
Definition: spfst.cpp:440
Building * building
Definition: mapfield.h:102
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38