objectconstructiontest.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  ***************************************************************************/
00009 
00010 #include "../gamemap.h"
00011 #include "../loaders.h"
00012 #include "objectconstructiontest.h"
00013 #include "unittestutil.h"
00014 #include "spfst.h"
00015 #include "../actions/spawnobject.h"
00016 #include "../actions/putobjectcommand.h"
00017 #include "itemrepository.h"
00018 
00019 
00020 void testObjectConstruction1() 
00021 {
00022    auto_ptr<GameMap> game ( startMap("unittest-objectconstruction.map"));
00023    
00024    ObjectType* crystals = objectTypeRepository.getObject_byID( 2105 );
00025    assertOrThrow( crystals != NULL );
00026    
00027    ObjectType* road = objectTypeRepository.getObject_byID( 1 );
00028    assertOrThrow( road != NULL );
00029    
00030    MapCoordinate pos ( 4,8);
00031    MapField* fld = game->getField( pos );
00032    assertOrThrow( fld != NULL );
00033    
00034    assertOrThrow( fld->checkForObject( crystals ) != NULL );
00035    
00036    SpawnObject so ( game.get(), pos, 1 );
00037    ActionResult res = so.execute( createTestingContext( game.get() ));
00038    assertOrThrow( res.successful() );
00039    
00040    assertOrThrow( fld->checkForObject( crystals ) == NULL );
00041    assertOrThrow( fld->checkForObject( road ) != NULL );
00042    
00043    res = so.undo( createTestingContext( game.get() ) );  
00044    assertOrThrow( res.successful() );
00045    
00046    assertOrThrow( fld->checkForObject( crystals ) != NULL );
00047    assertOrThrow( fld->checkForObject( road ) == NULL );
00048 }
00049 
00050 void testObjectRemoval() 
00051 {
00052    auto_ptr<GameMap> game ( startMap("unittest-objectremoval.map"));
00053    
00054    ObjectType* wood = objectTypeRepository.getObject_byID( 181 );
00055    assertOrThrow( wood != NULL );
00056    
00057    MapCoordinate pos ( 7, 10 );
00058    MapField* fld = game->getField( pos );
00059    assertOrThrow( fld != NULL );
00060    
00061    assertOrThrow( fld->checkForObject( wood ) != NULL );
00062    
00063    MapCoordinate unit ( 6, 11 );
00064    Vehicle* v = game->getField( unit )->vehicle;
00065    assertOrThrow( v != NULL );
00066    
00067    MapField* view = game->getField( MapCoordinate( 8,7 ) );
00068    
00069    assertOrThrow( fieldVisibility( view ) == visible_not );
00070                    
00071    PutObjectCommand* po = new PutObjectCommand( v );
00072    ActionResult res = po->searchFields();
00073    assertOrThrow( res.successful() );
00074    
00075    po->setTarget( pos, wood->id );
00076    res = po->execute( createTestingContext( game.get() ));
00077    assertOrThrow( res.successful() );
00078    
00079    assertOrThrow( fieldVisibility( view ) >= visible_now );
00080    assertOrThrow( fld->checkForObject( wood ) == NULL );
00081    
00082    
00083    res = po->undo( createTestingContext( game.get() ) );  
00084    assertOrThrow( res.successful() );
00085    
00086    assertOrThrow( fieldVisibility( view ) == visible_not );
00087    assertOrThrow( fld->checkForObject( wood ) != NULL );
00088 }
00089 
00090 void testObjectConstruction() 
00091 {
00092    testObjectConstruction1();
00093    testObjectRemoval();
00094 }

Generated on Mon May 21 01:26:35 2012 for Advanced Strategic Command by  doxygen 1.5.1