attacktest.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 "../actions/attackcommand.h"
00012 #include "../loaders.h"
00013 #include "unittestutil.h"
00014 #include "../itemrepository.h"
00015 #include "../spfst.h"
00016 
00017 
00018 void testAttack1() 
00019 {
00020    auto_ptr<GameMap> game ( startMap("unittest-attack.map"));
00021    
00022    Vehicle* veh = game->getField(3,6)->vehicle;
00023    assertOrThrow( veh != NULL );
00024    assertOrThrow( veh->getMovement() == 100 );
00025    
00026    attack( veh, MapCoordinate( 3,5) );
00027    
00028    assertOrThrow( veh->getMovement() == 0 );
00029    
00030    testCargoMovement( veh, 50 );
00031    
00032    ActionResult res = game->actions.undo( createTestingContext( game.get() ) );  
00033    assertOrThrow( res.successful() );
00034    
00035    assertOrThrow( veh->getMovement() == 100 );
00036    testCargoMovement( veh, 100 );
00037    
00038    
00039    Vehicle* mam = game->getField(4,4)->vehicle;
00040    assertOrThrow( mam != NULL );
00041    assertOrThrow( mam->getMovement() == 100 );
00042    
00043    attack( mam, MapCoordinate( 3,5) );
00044    
00045    assertOrThrow( mam->getMovement() == 100 );
00046    testCargoMovement( mam, 100 );
00047    
00048    Vehicle* v2 = game->getField(9,14)->vehicle;
00049    assertOrThrow( v2 != NULL );
00050    
00051    Vehicle* a2 = game->getField(9,17)->vehicle;
00052    assertOrThrow( a2 != NULL );
00053    
00054    attack( a2, MapCoordinate( 9, 14 ) );
00055     
00056    assertOrThrow( game->getField(9,14)->vehicle == NULL );
00057    res = game->actions.undo( createTestingContext( game.get() ) );  
00058    assertOrThrow( res.successful() );
00059    assertOrThrow( game->getField(9,14)->vehicle != NULL );
00060 }
00061 
00062 void testAttack2()
00063 {
00064    auto_ptr<GameMap> game ( startMap("unittest-objectattack.map"));
00065    
00066    Vehicle* buggy = game->getField(0,3)->vehicle;
00067    assertOrThrow( buggy != NULL );
00068    
00069    Vehicle* assault = game->getField(1,2)->vehicle;
00070    assertOrThrow( assault != NULL );
00071    
00072    MapCoordinate h ( 3, 8 );
00073    MapCoordinate cry( 3,9);
00074    
00075    move( buggy, h);
00076    attack( buggy, cry );
00077    move( buggy, MapCoordinate( 0,3 ));
00078    
00079    move( assault, h );
00080    
00081    ObjectType* cryst = objectTypeRepository.getObject_byID( 2105 );
00082    assertOrThrow( cryst != NULL );
00083    
00084    MapField* fld = game->getField( cry );   
00085    assertOrThrow( fld->checkForObject( cryst ) != NULL );
00086    
00087    MapField* view = game->getField( MapCoordinate( 4,11 ));
00088    assertOrThrow( fieldvisiblenow(view) == false ); 
00089    
00090    attack( assault, cry );
00091    
00092    assertOrThrow( fld->checkForObject( cryst ) == NULL );
00093    
00094    assertOrThrow( fieldvisiblenow(view) == true ); 
00095    
00096    ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
00097    assertOrThrow( res.successful() );
00098    
00099    assertOrThrow( fld->checkForObject( cryst ) != NULL );
00100    assertOrThrow( fieldvisiblenow(view) == false ); 
00101    
00102    assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
00103    assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
00104    assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
00105    assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
00106    
00107 } 
00108 
00109       
00110 void testAttack3()
00111 {
00112    auto_ptr<GameMap> game ( startMap("unittest-attack-view.map"));
00113    
00114    Vehicle* assault = game->getField(4,9)->vehicle;
00115    assertOrThrow( assault != NULL );
00116    
00117    Vehicle* ari = game->getField(4,11)->vehicle;
00118    assertOrThrow( ari != NULL );
00119    
00120    MapCoordinate r( 5, 8);
00121    MapCoordinate j( 5,11);
00122    
00123    MapField* fld = game->getField( MapCoordinate(0,0)); 
00124    assertOrThrow( fieldvisiblenow(fld) == true ); 
00125    
00126    attack( assault, r );
00127    
00128    assertOrThrow( fieldvisiblenow(fld) == true ); 
00129    
00130    
00131    MapField* fld2 = game->getField( MapCoordinate(6,8));  
00132    assertOrThrow( fieldvisiblenow(fld2) == false ); 
00133    
00134    attack( ari, j );
00135    
00136    assertOrThrow( fieldvisiblenow(fld2) == true ); 
00137    
00138    ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
00139    assertOrThrow( res.successful() );
00140    
00141    assertOrThrow( fieldvisiblenow(fld2) == false ); 
00142    
00143 } 
00144       
00145       
00146 void testAttack() {
00147    testAttack3();
00148    testAttack2();
00149    testAttack1();
00150 }

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