File: viewtest.cpp

package info (click to toggle)
asc 2.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 75,080 kB
  • ctags: 24,943
  • sloc: cpp: 155,023; sh: 8,829; ansic: 6,890; makefile: 650; perl: 138
file content (86 lines) | stat: -rw-r--r-- 2,766 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#include "../actions/moveunitcommand.h"
#include "../actions/attackcommand.h"
#include "../loaders.h"
#include "../viewcalculation.h"
#include "../spfst.h"
#include "unittestutil.h"


void testView1() 
{
   auto_ptr<GameMap> game ( startMap("unittest-view1.map"));
   
   Vehicle* radar = game->getField(0,4)->vehicle;
   
   assertOrThrow( fieldvisiblenow(game->getField(3,5)) == false );
   
   move( radar, MapCoordinate(1,4));
  
   assertOrThrow( fieldvisiblenow(game->getField(3,5)) == true );
   
   assertOrThrow( fieldvisiblenow(game->getField(4,3)) == false );
   
   attack( game->getField(1,6)->vehicle, MapCoordinate( 3,5 ) );
   
   assertOrThrow( fieldvisiblenow(game->getField(4,3)) == true );
   
   ActionResult res = game->actions.undo( createTestingContext( game.get() ) );  
   assertOrThrow( res.successful() );
   
   assertOrThrow( fieldvisiblenow(game->getField(4,3)) == false );
   assertOrThrow( fieldvisiblenow(game->getField(3,5)) == true );
   
   res = game->actions.undo( createTestingContext( game.get() ) );  
   assertOrThrow( res.successful() );
   
   assertOrThrow( fieldvisiblenow(game->getField(3,5)) == false );
   
   
   // now we are testing the view of the BLUE player
   
   assertOrThrow( fieldvisiblenow(game->getField(0,15), 1) == true );
   attack( game->getField(2,16)->vehicle, MapCoordinate( 0,13 ) );
   
   assertOrThrow( fieldvisiblenow(game->getField(0,15), 1) == false );
   
   res = game->actions.undo( createTestingContext( game.get() ) );  
   assertOrThrow( res.successful() );
   
   assertOrThrow( fieldvisiblenow(game->getField(0,15), 1) == true );
}


void testView2() 
{
   auto_ptr<GameMap> game ( startMap("unittest-view2.map"));
   
   Vehicle* spyplane = game->getField(5,2)->vehicle;
   
   assertOrThrow( spyplane != NULL );
   assertOrThrow( spyplane->damage == 0 );
   
   assertOrThrow( fieldvisiblenow(game->getField(5,2),1 ) == false );
   
   move( spyplane, MapCoordinate(5,18));
  
   spyplane = game->getField(5,18)->vehicle;
   assertOrThrow( spyplane != NULL );
   assertOrThrow( spyplane->damage == 0 );
}


void testView()
{
   testView1();
   testView2();
}