From 98ba22e7064db57316dfff1ae127feb3dceeb73e Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 31 Jul 2014 13:58:22 +0200 Subject: Initial commit --- docs/html/presentation_tests_8cpp_source.html | 303 ++++++++++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 docs/html/presentation_tests_8cpp_source.html (limited to 'docs/html/presentation_tests_8cpp_source.html') diff --git a/docs/html/presentation_tests_8cpp_source.html b/docs/html/presentation_tests_8cpp_source.html new file mode 100644 index 0000000..2a1d52d --- /dev/null +++ b/docs/html/presentation_tests_8cpp_source.html @@ -0,0 +1,303 @@ + + + + +Rally X: tests/presentationTests.cpp Source File + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + +
+
Rally X + +
+
ELEN3009 Project by Justin Wernick and David Schneider
+
+
+ + + + + +
+
+
tests/presentationTests.cpp
+
+
+Go to the documentation of this file.
00001 
+00033 #include <utility>
+00034 #include <list>
+00035 using namespace std;
+00036 
+00037 #include <gtest/gtest.h>
+00038 
+00039 #include "../source/presentation/BitmapStore.h"
+00040 #include "../source/presentation/ColourStore.h"
+00041 #include "../source/presentation/GamePanel.h"
+00042 #include "../source/presentation/Screen.h"
+00043 
+00044 #include "../source/logic/PlayerCar.h"
+00045 #include "../source/logic/EnemyCar.h"
+00046 #include "../source/logic/Checkpoint.h"
+00047 #include "../source/logic/Rock.h"
+00048 #include "../source/logic/Smokescreen.h"
+00049 #include "../source/logic/Maze.h"
+00050 #include "../source/logic/DestroyedObjectPopup.h"
+00051 
+00055 TEST(BitmapStore, returnsBitmapForAllImages)
+00056 {
+00057     BitmapStore testStore(50);
+00058 
+00059     ALLEGRO_BITMAP* testBitmap = NULL;
+00060 
+00061     EXPECT_NO_FATAL_FAILURE(testBitmap = testStore.getBitmap(BitmapStore::PLAYER));
+00062     EXPECT_NO_FATAL_FAILURE(testBitmap = testStore.getBitmap(BitmapStore::ENEMY));
+00063     EXPECT_NO_FATAL_FAILURE(testBitmap = testStore.getBitmap(BitmapStore::CHECKPOINT));
+00064     EXPECT_NO_FATAL_FAILURE(testBitmap = testStore.getBitmap(BitmapStore::ROCK));
+00065     EXPECT_NO_FATAL_FAILURE(testBitmap = testStore.getBitmap(BitmapStore::MAZE_WALL));
+00066     EXPECT_NO_FATAL_FAILURE(testBitmap = testStore.getBitmap(BitmapStore::MAZE_FLOOR));
+00067     EXPECT_NO_FATAL_FAILURE(testBitmap = testStore.getBitmap(BitmapStore::SMOKE));
+00068     EXPECT_NO_FATAL_FAILURE(testBitmap = testStore.getBitmap(BitmapStore::CRASHED_CAR));
+00069     EXPECT_NO_FATAL_FAILURE(testBitmap = testStore.getBitmap(BitmapStore::CLAIMED_CHECKPOINT));
+00070 }
+00071 
+00075 TEST(ColourStore, returnsColourForAllImages)
+00076 {
+00077     ColourStore testStore;
+00078 
+00079     ALLEGRO_COLOR testColour;
+00080 
+00081     EXPECT_NO_FATAL_FAILURE(testColour = testStore.getColour(BitmapStore::PLAYER));
+00082     EXPECT_NO_FATAL_FAILURE(testColour = testStore.getColour(BitmapStore::ENEMY));
+00083     EXPECT_NO_FATAL_FAILURE(testColour = testStore.getColour(BitmapStore::CHECKPOINT));
+00084     EXPECT_NO_FATAL_FAILURE(testColour = testStore.getColour(BitmapStore::ROCK));
+00085     EXPECT_NO_FATAL_FAILURE(testColour = testStore.getColour(BitmapStore::MAZE_WALL));
+00086     EXPECT_NO_FATAL_FAILURE(testColour = testStore.getColour(BitmapStore::MAZE_FLOOR));
+00087     EXPECT_NO_FATAL_FAILURE(testColour = testStore.getColour(BitmapStore::SMOKE));
+00088     EXPECT_NO_FATAL_FAILURE(testColour = testStore.getColour(BitmapStore::CRASHED_CAR));
+00089     EXPECT_NO_FATAL_FAILURE(testColour = testStore.getColour(BitmapStore::CLAIMED_CHECKPOINT));
+00090 }
+00091 
+00095 TEST(Screen, exceptionOnBadResolution)
+00096 {
+00097     //resolution should be unsupported on most displays
+00098     int badWidth = 1000;
+00099     int badHeight = 5;
+00100 
+00101     EXPECT_ANY_THROW(Screen(badWidth, badHeight, true));
+00102 }
+00106 TEST(Screen, noExceptionOnWindowed)
+00107 {
+00108     int badWidth = 1000;
+00109     int badHeight = 5;
+00110 
+00111     EXPECT_NO_THROW(Screen(badWidth, badHeight, false));
+00112 
+00113 }
+00117 TEST(Screen, noExceptionOnGoodResolution)
+00118 {
+00119     //resolution should be supported on most monitors
+00120     int goodWidth = 800;
+00121     int goodHeight = 600;
+00122 
+00123     EXPECT_NO_THROW(Screen(goodWidth, goodHeight, true));
+00124 }
+00125 
+00129 TEST(ScreenPanel, drawingToCurrentBackBuffer)
+00130 {
+00131     al_init();
+00132 
+00133     ALLEGRO_BITMAP* testBitmapBack = al_create_bitmap(500,500);
+00134     ALLEGRO_BITMAP* testBitmapFront = al_create_bitmap(500,500);
+00135 
+00136     ALLEGRO_COLOR blankColour = al_map_rgb(0,0,0);
+00137     al_set_target_bitmap(testBitmapBack);
+00138     al_clear_to_color(blankColour);
+00139     al_set_target_bitmap(testBitmapFront);
+00140     al_clear_to_color(blankColour);
+00141 
+00142     GamePanel testPanel(testBitmapBack, testBitmapFront, 0, 0, 500, 500);
+00143     Maze testMaze;
+00144 
+00145     vector<pair<int,int> > wallsFull;
+00146 
+00147     for (int x=0; x<20; ++x)
+00148     {
+00149         for (int y=0; y<20; ++y)
+00150         {
+00151             wallsFull.push_back(make_pair(x,y));
+00152         }
+00153     }
+00154     testMaze.generateMaze(wallsFull,20,20);
+00155 
+00156     list<PlayerCar> players;
+00157     list<EnemyCar> enemies;
+00158     list<Checkpoint> checkpoints;
+00159     list<Rock> rocks;
+00160     list<Smokescreen> smokescreens;
+00161     list<DestroyedObjectPopup> popups;
+00162 
+00163     testPanel.draw(testMaze, players, enemies, checkpoints, rocks, smokescreens, popups);
+00164 
+00165     BitmapStore bitmapStore(50);
+00166     ALLEGRO_BITMAP* wall = bitmapStore.getBitmap(BitmapStore::MAZE_WALL);
+00167     ALLEGRO_COLOR mazeColour = al_get_pixel(wall, 25, 25);
+00168 
+00169     ALLEGRO_COLOR backSample = al_get_pixel(testBitmapBack, 250, 250);
+00170     ALLEGRO_COLOR frontSample = al_get_pixel(testBitmapFront, 250, 250);
+00171 
+00172     EXPECT_FLOAT_EQ(mazeColour.r, backSample.r);
+00173     EXPECT_FLOAT_EQ(mazeColour.g, backSample.g);
+00174     EXPECT_FLOAT_EQ(mazeColour.b, backSample.b);
+00175     EXPECT_FLOAT_EQ(mazeColour.a, backSample.a);
+00176 
+00177     EXPECT_FLOAT_EQ(blankColour.r, frontSample.r);
+00178     EXPECT_FLOAT_EQ(blankColour.g, frontSample.g);
+00179     EXPECT_FLOAT_EQ(blankColour.b, frontSample.b);
+00180     EXPECT_FLOAT_EQ(blankColour.a, frontSample.a);
+00181 
+00182     al_destroy_bitmap(testBitmapBack);
+00183     al_destroy_bitmap(testBitmapFront);
+00184 }
+00185 
+00189 TEST(ScreenPanel, drawingToCurrentBackBufferAfterFlip)
+00190 {
+00191     al_init();
+00192 
+00193     al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); //removes dependency on display existing
+00194 
+00195     ALLEGRO_BITMAP* testBitmapBack = al_create_bitmap(500,500);
+00196     ALLEGRO_BITMAP* testBitmapFront = al_create_bitmap(500,500);
+00197 
+00198     ALLEGRO_COLOR blankColour = al_map_rgb(0,0,0);
+00199     al_set_target_bitmap(testBitmapBack);
+00200     al_clear_to_color(blankColour);
+00201     al_set_target_bitmap(testBitmapFront);
+00202     al_clear_to_color(blankColour);
+00203 
+00204     GamePanel testPanel(testBitmapBack, testBitmapFront, 0, 0, 500, 500);
+00205     Maze testMaze;
+00206 
+00207     vector<pair<int,int> > wallsFull;
+00208 
+00209     for (int x=0; x<20; ++x)
+00210     {
+00211         for (int y=0; y<20; ++y)
+00212         {
+00213             wallsFull.push_back(make_pair(x,y));
+00214         }
+00215     }
+00216     testMaze.generateMaze(wallsFull,20,20);
+00217 
+00218     list<PlayerCar> players;
+00219     list<EnemyCar> enemies;
+00220     list<Checkpoint> checkpoints;
+00221     list<Rock> rocks;
+00222     list<Smokescreen> smokescreens;
+00223     list<DestroyedObjectPopup> popups;
+00224 
+00225     testPanel.flip();
+00226 
+00227     testPanel.draw(testMaze, players, enemies, checkpoints, rocks, smokescreens, popups);
+00228 
+00229     BitmapStore bitmapStore(50);
+00230     ALLEGRO_BITMAP* wall = bitmapStore.getBitmap(BitmapStore::MAZE_WALL);
+00231     ALLEGRO_COLOR mazeColour = al_get_pixel(wall, 25, 25);
+00232 
+00233     ALLEGRO_COLOR backSample = al_get_pixel(testBitmapBack, 250, 250);
+00234     ALLEGRO_COLOR frontSample = al_get_pixel(testBitmapFront, 250, 250);
+00235 
+00236     EXPECT_FLOAT_EQ(mazeColour.r, frontSample.r);
+00237     EXPECT_FLOAT_EQ(mazeColour.g, frontSample.g);
+00238     EXPECT_FLOAT_EQ(mazeColour.b, frontSample.b);
+00239     EXPECT_FLOAT_EQ(mazeColour.a, frontSample.a);
+00240 
+00241     EXPECT_FLOAT_EQ(blankColour.r, backSample.r);
+00242     EXPECT_FLOAT_EQ(blankColour.g, backSample.g);
+00243     EXPECT_FLOAT_EQ(blankColour.b, backSample.b);
+00244     EXPECT_FLOAT_EQ(blankColour.a, backSample.a);
+00245 
+00246     al_destroy_bitmap(testBitmapBack);
+00247     al_destroy_bitmap(testBitmapFront);
+00248 }
+
+
+ +
+ All Classes Files Functions Variables Typedefs Enumerations Enumerator
+ + +
+ +
+ + + + + + + -- cgit v1.2.3