Advanced Strategic Command
objectconstructiontest.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 "../loaders.h"
12 #include "objectconstructiontest.h"
13 #include "unittestutil.h"
14 #include "spfst.h"
15 #include "../actions/spawnobject.h"
16 #include "../actions/putobjectcommand.h"
17 #include "itemrepository.h"
18 
19 
21 {
22  auto_ptr<GameMap> game ( startMap("unittest-objectconstruction.map"));
23 
24  ObjectType* crystals = objectTypeRepository.getObject_byID( 2105 );
25  assertOrThrow( crystals != NULL );
26 
27  ObjectType* road = objectTypeRepository.getObject_byID( 1 );
28  assertOrThrow( road != NULL );
29 
30  MapCoordinate pos ( 4,8);
31  MapField* fld = game->getField( pos );
32  assertOrThrow( fld != NULL );
33 
34  assertOrThrow( fld->checkForObject( crystals ) != NULL );
35 
36  SpawnObject so ( game.get(), pos, 1 );
37  ActionResult res = so.execute( createTestingContext( game.get() ));
38  assertOrThrow( res.successful() );
39 
40  assertOrThrow( fld->checkForObject( crystals ) == NULL );
41  assertOrThrow( fld->checkForObject( road ) != NULL );
42 
43  res = so.undo( createTestingContext( game.get() ) );
44  assertOrThrow( res.successful() );
45 
46  assertOrThrow( fld->checkForObject( crystals ) != NULL );
47  assertOrThrow( fld->checkForObject( road ) == NULL );
48 }
49 
51 {
52  auto_ptr<GameMap> game ( startMap("unittest-objectremoval.map"));
53 
54  ObjectType* wood = objectTypeRepository.getObject_byID( 181 );
55  assertOrThrow( wood != NULL );
56 
57  MapCoordinate pos ( 7, 9 );
58  MapField* fld = game->getField( pos );
59  assertOrThrow( fld != NULL );
60 
61  assertOrThrow( fld->checkForObject( wood ) != NULL );
62 
63  MapCoordinate unit ( 7, 10 );
64  Vehicle* v = game->getField( unit )->vehicle;
65  assertOrThrow( v != NULL );
66 
67  MapField* view = game->getField( MapCoordinate( 8,7 ) );
68 
70 
71  PutObjectCommand* po = new PutObjectCommand( v );
72  ActionResult res = po->searchFields();
73  assertOrThrow( res.successful() );
74 
75  po->setTarget( pos, wood->id );
76  res = po->execute( createTestingContext( game.get() ));
77  assertOrThrow( res.successful() );
78 
80  assertOrThrow( fld->checkForObject( wood ) == NULL );
81 
82 
83  res = po->undo( createTestingContext( game.get() ) );
84  assertOrThrow( res.successful() );
85 
87  assertOrThrow( fld->checkForObject( wood ) != NULL );
88 }
89 
91 {
94 }
ItemRepositoryLoader< ObjectType > objectTypeRepository("objecttype")
int id
the id of the object, used when referencing objects in files
Definition: objecttype.h:35
map accessing and usage routines used by ASC and the mapeditor
#define assertOrThrow(expr)
Definition: errors.h:69
Context createTestingContext(GameMap *gamemap)
a single field of the map
Definition: mapfield.h:26
ActionResult undo(const Context &context)
Definition: action.cpp:77
void setTarget(const MapCoordinate &target, int objectID)
ActionResult execute(const Context &context)
Definition: action.cpp:41
void testObjectRemoval()
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
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 testObjectConstruction1()
Object * checkForObject(const ObjectType *o)
checks if there are objects from the given type on the field and returns them
Definition: mapfield.cpp:648
void testObjectConstruction()
ActionResult searchFields()