viewtest.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 
00011 #include "../actions/moveunitcommand.h"
00012 #include "../actions/attackcommand.h"
00013 #include "../loaders.h"
00014 #include "../viewcalculation.h"
00015 #include "../spfst.h"
00016 #include "unittestutil.h"
00017 
00018 
00019 void testView3() 
00020 {
00021    auto_ptr<GameMap> game ( startMap("unittest-jammingdestroyview.map"));
00022    
00023    Vehicle* ari = game->getField(5,2)->vehicle;
00024    
00025    MapField* field = game->getField(0,12);
00026    MapField* field2 = game->getField(3,10);
00027    
00028    
00029    assertOrThrow( fieldVisibility(field) == visible_not );
00030    assertOrThrow( fieldVisibility(field2) == visible_not );
00031    
00032    attack( ari, MapCoordinate(3,8));
00033   
00034    assertOrThrow( fieldVisibility(field) == visible_not );
00035    assertOrThrow( fieldVisibility(field2) == visible_now );
00036 
00037    ActionResult res = game->actions.undo( createTestingContext( game.get() ) );  
00038    assertOrThrow( res.successful() );
00039    
00040    assertOrThrow( fieldVisibility(field) == visible_not );
00041    assertOrThrow( fieldVisibility(field2) == visible_not );
00042    
00043 }
00044 
00045 void testView1() 
00046 {
00047    auto_ptr<GameMap> game ( startMap("unittest-view1.map"));
00048    
00049    Vehicle* radar = game->getField(0,4)->vehicle;
00050    
00051    assertOrThrow( fieldvisiblenow(game->getField(3,5)) == false );
00052    
00053    move( radar, MapCoordinate(1,4));
00054   
00055    assertOrThrow( fieldvisiblenow(game->getField(3,5)) == true );
00056    
00057    assertOrThrow( fieldvisiblenow(game->getField(4,3)) == false );
00058    
00059    attack( game->getField(1,6)->vehicle, MapCoordinate( 3,5 ) );
00060    
00061    assertOrThrow( fieldvisiblenow(game->getField(4,3)) == true );
00062    
00063    ActionResult res = game->actions.undo( createTestingContext( game.get() ) );  
00064    assertOrThrow( res.successful() );
00065    
00066    assertOrThrow( fieldvisiblenow(game->getField(4,3)) == false );
00067    assertOrThrow( fieldvisiblenow(game->getField(3,5)) == true );
00068    
00069    res = game->actions.undo( createTestingContext( game.get() ) );  
00070    assertOrThrow( res.successful() );
00071    
00072    assertOrThrow( fieldvisiblenow(game->getField(3,5)) == false );
00073    
00074    
00075    // now we are testing the view of the BLUE player
00076    
00077    assertOrThrow( fieldvisiblenow(game->getField(0,15), 1) == true );
00078    attack( game->getField(2,16)->vehicle, MapCoordinate( 0,13 ) );
00079    
00080    assertOrThrow( fieldvisiblenow(game->getField(0,15), 1) == false );
00081    
00082    res = game->actions.undo( createTestingContext( game.get() ) );  
00083    assertOrThrow( res.successful() );
00084    
00085    assertOrThrow( fieldvisiblenow(game->getField(0,15), 1) == true );
00086 }
00087 
00088 
00089 void testView2() 
00090 {
00091    auto_ptr<GameMap> game ( startMap("unittest-view2.map"));
00092    
00093    Vehicle* spyplane = game->getField(5,2)->vehicle;
00094    
00095    assertOrThrow( spyplane != NULL );
00096    assertOrThrow( spyplane->damage == 0 );
00097    
00098    assertOrThrow( fieldvisiblenow(game->getField(5,2),1 ) == false );
00099    
00100    move( spyplane, MapCoordinate(5,18));
00101   
00102    spyplane = game->getField(5,18)->vehicle;
00103    assertOrThrow( spyplane != NULL );
00104    assertOrThrow( spyplane->damage == 0 );
00105 }
00106 
00107 
00108 void testView()
00109 {
00110    testView1();
00111    testView2();
00112    testView3();
00113 } 

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