tests/test_image_modifications.cpp

Go to the documentation of this file.
00001 /* $Id: test_image_modifications.cpp 53553 2012-03-18 14:15:04Z mordante $ */
00002 /*
00003    Copyright (C) 2011 - 2012 by Karol Kozub <karol.alt@gmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #define GETTEXT_DOMAIN "wesnoth-test"
00017 
00018 #include <boost/test/unit_test.hpp>
00019 #include <sstream>
00020 
00021 #include "game_config.hpp"
00022 #include "config_cache.hpp"
00023 #include "config.hpp"
00024 #include "color_range.hpp"
00025 #include "image.hpp"
00026 #include "image_modifications.hpp"
00027 #include "log.hpp"
00028 #include "filesystem.hpp"
00029 
00030 using namespace image;
00031 
00032 namespace {
00033 /// Sets up the environment for every test
00034 class environment_setup
00035 {
00036 public:
00037     environment_setup()
00038         // redirects the output to an ignored stream
00039         : ignored_stream_()
00040         , output_redirect_(ignored_stream_)
00041         , paths_manager_()
00042     {
00043         set_up_color_info();
00044         set_up_team_colors();
00045         set_up_image_paths();
00046     }
00047 
00048 private:
00049     /** Sets up color_info configuration
00050      *
00051      * This is required by the RC modifications
00052      */
00053     void set_up_color_info()
00054     {
00055         config cfg;
00056         cfg.add_child("color_range",
00057                    create_color_range("red",
00058                           "FF0000,FFFFFF,000000,FF0000",
00059                           "Red"));
00060         cfg.add_child("color_range",
00061                    create_color_range("blue",
00062                           "2E419B,FFFFFF,0F0F0F,0000FF",
00063                           "Blue"));
00064 
00065         game_config::add_color_info(cfg);
00066     }
00067 
00068     /** Sets up team color mapping
00069      *
00070      * This is required by TC modification
00071      */
00072     void set_up_team_colors()
00073     {
00074         std::vector<std::string> tc;
00075 
00076         tc.push_back("red");
00077         tc.push_back("blue");
00078 
00079         image::set_team_colors(&tc);
00080     }
00081 
00082     /** Sets up the paths later used to load images
00083      *
00084      * This is required by all the modifications that use image::get_image
00085      * to load images from disk
00086      */
00087     void set_up_image_paths()
00088     {
00089         config cfg;
00090 
00091         cfg.add_child("binary_path",
00092                   create_path_config("data/core"));
00093 
00094         paths_manager_.set_paths(cfg);
00095     }
00096 
00097     config create_color_range(const std::string& id,
00098                   const std::string& rgb,
00099                   const std::string& name)
00100     {
00101         config cfg;
00102 
00103         cfg["id"] = id;
00104         cfg["rgb"] = rgb;
00105         cfg["name"] = name;
00106 
00107         return cfg;
00108     }
00109 
00110     config create_path_config(const std::string& path)
00111     {
00112         config cfg;
00113 
00114         cfg["path"] = path;
00115 
00116         return cfg;
00117     }
00118 
00119     std::stringstream ignored_stream_;
00120     lg::tredirect_output_setter output_redirect_;
00121     binary_paths_manager paths_manager_;
00122 };
00123 } // anonymous namespace
00124 
00125 BOOST_AUTO_TEST_SUITE(image_modification_parsing)
00126 
00127 /** Tests if modifications with a higher priority are placed before the others
00128  *
00129  * The RC modification has a higher priority than other modifications and has
00130  * to be applied before all the others. This test checks if that order is taken
00131  * care of by the queue.
00132  */
00133 BOOST_AUTO_TEST_CASE(test_modificaiton_queue_order)
00134 {
00135     environment_setup env_setup;
00136 
00137     modification_queue queue;
00138     modification* low_priority_mod = new fl_modification();
00139     modification* high_priority_mod = new rc_modification();
00140 
00141     queue.push(low_priority_mod);
00142     queue.push(high_priority_mod);
00143 
00144     BOOST_REQUIRE_EQUAL(queue.size(), 2);
00145 
00146     BOOST_CHECK_EQUAL(queue.top(), high_priority_mod);
00147     queue.pop();
00148     BOOST_CHECK_EQUAL(queue.top(), low_priority_mod);
00149     queue.pop();
00150 
00151     // reverse insertion order now
00152     queue.push(high_priority_mod);
00153     queue.push(low_priority_mod);
00154 
00155     BOOST_REQUIRE_EQUAL(queue.size(), 2);
00156 
00157     BOOST_CHECK_EQUAL(queue.top(), high_priority_mod);
00158     queue.pop();
00159     BOOST_CHECK_EQUAL(queue.top(), low_priority_mod);
00160     queue.pop();
00161 
00162     delete low_priority_mod;
00163     delete high_priority_mod;
00164 }
00165 
00166 /// Tests if the TC modification is correctly decoded
00167 BOOST_AUTO_TEST_CASE(test_tc_modification_decoding)
00168 {
00169     environment_setup env_setup;
00170 
00171     modification_queue queue = modification::decode("~TC(1,blue)");
00172 
00173     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00174 
00175     rc_modification* mod = dynamic_cast<rc_modification*>(queue.top());
00176 
00177     // The dynamic_cast returns NULL if the argument doesn't match the type
00178     BOOST_REQUIRE(mod != NULL);
00179 
00180     const std::vector<Uint32>& old_color = game_config::tc_info("blue");
00181     // The first team color is red
00182     const color_range& new_color = game_config::color_info("red");
00183     std::map<Uint32, Uint32> expected = recolor_range(new_color, old_color);
00184 
00185     BOOST_CHECK(expected == mod->map());
00186 
00187     delete mod;
00188 }
00189 
00190 /// Tests if the TC modification with invalid arguments is ignored
00191 BOOST_AUTO_TEST_CASE(test_tc_modification_decoding_invalid_args)
00192 {
00193     environment_setup env_setup;
00194 
00195     modification_queue queue = modification::decode("~TC()~TC(1)~TC(0,blue)");
00196 
00197     BOOST_REQUIRE_EQUAL(queue.size(), 0);
00198 }
00199 
00200 /// Tests if the RC modification is correctly decoded
00201 BOOST_AUTO_TEST_CASE(test_rc_modification_decoding)
00202 {
00203     environment_setup env_setup;
00204 
00205     modification_queue queue = modification::decode("~RC(red>blue)");
00206 
00207     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00208 
00209     rc_modification* mod = dynamic_cast<rc_modification*>(queue.top());
00210 
00211     // The dynamic_cast returns NULL if the argument doesn't match the type
00212     BOOST_REQUIRE(mod != NULL);
00213 
00214     const std::vector<Uint32>& old_color = game_config::tc_info("red");
00215     const color_range& new_color = game_config::color_info("blue");
00216     std::map<Uint32, Uint32> expected = recolor_range(new_color, old_color);
00217 
00218     BOOST_CHECK(expected == mod->map());
00219 
00220     delete mod;
00221 }
00222 
00223 /// Tests if the RC modification with invalid arguments is ignored
00224 BOOST_AUTO_TEST_CASE(test_rc_modification_decoding_invalid_args)
00225 {
00226     environment_setup env_setup;
00227 
00228     modification_queue queue = modification::decode("~RC()~RC(blue)~RC(>)");
00229 
00230     BOOST_REQUIRE_EQUAL(queue.size(), 0);
00231 }
00232 
00233 /// Tests if the PAL modification is correctly decoded
00234 BOOST_AUTO_TEST_CASE(test_pal_modification_decoding)
00235 {
00236     environment_setup env_setup;
00237 
00238     modification_queue queue =
00239         modification::decode("~PAL(000000,005000 > FFFFFF,FF00FF)");
00240 
00241     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00242 
00243     rc_modification* mod = dynamic_cast<rc_modification*>(queue.top());
00244 
00245     // The dynamic_cast returns NULL if the argument doesn't match the type
00246     BOOST_REQUIRE(mod != NULL);
00247 
00248     std::vector<Uint32> const& old_palette = game_config::tc_info("000000,005000");
00249     std::vector<Uint32> const& new_palette = game_config::tc_info("FFFFFF,FF00FF");
00250     std::map<Uint32, Uint32> expected;
00251 
00252     for(size_t i = 0; i < old_palette.size() && i < new_palette.size(); ++i) {
00253     environment_setup env_setup;
00254 
00255         expected[old_palette[i]] = new_palette[i];
00256     }
00257 
00258     BOOST_CHECK(expected == mod->map());
00259 
00260     delete mod;
00261 }
00262 
00263 /// Tests if the PAL modification with invalid arguments is ignored
00264 BOOST_AUTO_TEST_CASE(test_pal_modification_decoding_invalid_args)
00265 {
00266     environment_setup env_setup;
00267 
00268     modification_queue queue =
00269         modification::decode("~PAL()~PAL(>)");
00270 
00271     BOOST_REQUIRE_EQUAL(queue.size(), 0);
00272 }
00273 
00274 /// Tests if the FL modification is correctly decoded without arguments
00275 BOOST_AUTO_TEST_CASE(test_fl_modification_decoding_default)
00276 {
00277     environment_setup env_setup;
00278 
00279     modification_queue queue = modification::decode("~FL()");
00280 
00281     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00282 
00283     fl_modification* mod = dynamic_cast<fl_modification*>(queue.top());
00284 
00285     // The dynamic_cast returns NULL if the argument doesn't match the type
00286     BOOST_REQUIRE(mod != NULL);
00287 
00288     BOOST_CHECK(mod->get_horiz());
00289     BOOST_CHECK(!mod->get_vert());
00290 
00291     delete mod;
00292 }
00293 
00294 /// Tests if the FL modification is correctly decoded with the horiz argument
00295 BOOST_AUTO_TEST_CASE(test_fl_modification_decoding_horiz)
00296 {
00297     environment_setup env_setup;
00298 
00299     modification_queue queue = modification::decode("~FL(horiz)");
00300 
00301     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00302 
00303     fl_modification* mod = dynamic_cast<fl_modification*>(queue.top());
00304 
00305     // The dynamic_cast returns NULL if the argument doesn't match the type
00306     BOOST_REQUIRE(mod != NULL);
00307 
00308     BOOST_CHECK(mod->get_horiz());
00309     BOOST_CHECK(!mod->get_vert());
00310 
00311     delete mod;
00312 }
00313 
00314 /// Tests if the FL modification is correctly decoded with the vert argument
00315 BOOST_AUTO_TEST_CASE(test_fl_modification_decoding_vert)
00316 {
00317     environment_setup env_setup;
00318 
00319     modification_queue queue = modification::decode("~FL(vert)");
00320 
00321     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00322 
00323     fl_modification* mod = dynamic_cast<fl_modification*>(queue.top());
00324 
00325     // The dynamic_cast returns NULL if the argument doesn't match the type
00326     BOOST_REQUIRE(mod != NULL);
00327 
00328     BOOST_CHECK(!mod->get_horiz());
00329     BOOST_CHECK(mod->get_vert());
00330 
00331     delete mod;
00332 }
00333 
00334 /// Tests if the FL modification is correctly decoded with both horiz and vert
00335 BOOST_AUTO_TEST_CASE(test_fl_modification_decoding_horiz_and_vert)
00336 {
00337     environment_setup env_setup;
00338 
00339     modification_queue queue = modification::decode("~FL(horiz,vert)");
00340 
00341     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00342 
00343     fl_modification* mod = dynamic_cast<fl_modification*>(queue.top());
00344 
00345     // The dynamic_cast returns NULL if the argument doesn't match the type
00346     BOOST_REQUIRE(mod != NULL);
00347 
00348     BOOST_CHECK(mod->get_horiz());
00349     BOOST_CHECK(mod->get_vert());
00350 
00351     delete mod;
00352 }
00353 
00354 /// Tests if the GS modification is correctly decoded
00355 BOOST_AUTO_TEST_CASE(test_gs_modification_decoding)
00356 {
00357     environment_setup env_setup;
00358 
00359     modification_queue queue = modification::decode("~GS()");
00360 
00361     BOOST_REQUIRE(queue.size() == 1);
00362 
00363     gs_modification* mod = dynamic_cast<gs_modification*>(queue.top());
00364 
00365     // The dynamic_cast returns NULL if the argument doesn't match the type
00366     BOOST_CHECK(mod != NULL);
00367 
00368     delete mod;
00369 }
00370 
00371 /// Tests if the CROP modification without arguments is ignored
00372 BOOST_AUTO_TEST_CASE(test_crop_modification_decoding_no_args)
00373 {
00374     environment_setup env_setup;
00375 
00376     modification_queue queue = modification::decode("~CROP()");
00377 
00378     BOOST_REQUIRE_EQUAL(queue.size(), 0);
00379 }
00380 
00381 /// Tests if the CROP modification is correctly decoded when given one argument
00382 BOOST_AUTO_TEST_CASE(test_crop_modification_decoding_1_arg)
00383 {
00384     environment_setup env_setup;
00385 
00386     modification_queue queue = modification::decode("~CROP(1)");
00387 
00388     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00389 
00390     crop_modification* mod = dynamic_cast<crop_modification*>(queue.top());
00391 
00392     // The dynamic_cast returns NULL if the argument doesn't match the type
00393     BOOST_REQUIRE(mod != NULL);
00394 
00395     const SDL_Rect& slice = mod->get_slice();
00396 
00397     BOOST_CHECK_EQUAL(slice.x, 1);
00398     BOOST_CHECK_EQUAL(slice.y, 0);
00399     BOOST_CHECK_EQUAL(slice.w, 0);
00400     BOOST_CHECK_EQUAL(slice.h, 0);
00401 
00402     delete mod;
00403 }
00404 
00405 /// Tests if the CROP modification is correctly decoded when given two args
00406 BOOST_AUTO_TEST_CASE(test_crop_modification_decoding_2_args)
00407 {
00408     environment_setup env_setup;
00409 
00410     modification_queue queue = modification::decode("~CROP(1,2)");
00411 
00412     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00413 
00414     crop_modification* mod = dynamic_cast<crop_modification*>(queue.top());
00415 
00416     // The dynamic_cast returns NULL if the argument doesn't match the type
00417     BOOST_REQUIRE(mod != NULL);
00418 
00419     const SDL_Rect& slice = mod->get_slice();
00420 
00421     BOOST_CHECK_EQUAL(slice.x, 1);
00422     BOOST_CHECK_EQUAL(slice.y, 2);
00423     BOOST_CHECK_EQUAL(slice.w, 0);
00424     BOOST_CHECK_EQUAL(slice.h, 0);
00425 
00426     delete mod;
00427 }
00428 
00429 /// Tests if the CROP modification is correctly decoded when given three args
00430 BOOST_AUTO_TEST_CASE(test_crop_modification_decoding_3_args)
00431 {
00432     environment_setup env_setup;
00433 
00434     modification_queue queue = modification::decode("~CROP(1,2,3)");
00435 
00436     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00437 
00438     crop_modification* mod = dynamic_cast<crop_modification*>(queue.top());
00439 
00440     // The dynamic_cast returns NULL if the argument doesn't match the type
00441     BOOST_REQUIRE(mod != NULL);
00442 
00443     const SDL_Rect& slice = mod->get_slice();
00444 
00445     BOOST_CHECK_EQUAL(slice.x, 1);
00446     BOOST_CHECK_EQUAL(slice.y, 2);
00447     BOOST_CHECK_EQUAL(slice.w, 3);
00448     BOOST_CHECK_EQUAL(slice.h, 0);
00449 
00450     delete mod;
00451 }
00452 
00453 /// Tests if the CROP modification is correctly decoded when given four args
00454 BOOST_AUTO_TEST_CASE(test_crop_modification_decoding_4_args)
00455 {
00456     environment_setup env_setup;
00457 
00458     modification_queue queue = modification::decode("~CROP(1,2,3,4)");
00459 
00460     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00461 
00462     crop_modification* mod = dynamic_cast<crop_modification*>(queue.top());
00463 
00464     // The dynamic_cast returns NULL if the argument doesn't match the type
00465     BOOST_REQUIRE(mod != NULL);
00466 
00467     const SDL_Rect& slice = mod->get_slice();
00468 
00469     BOOST_CHECK_EQUAL(slice.x, 1);
00470     BOOST_CHECK_EQUAL(slice.y, 2);
00471     BOOST_CHECK_EQUAL(slice.w, 3);
00472     BOOST_CHECK_EQUAL(slice.h, 4);
00473 
00474     delete mod;
00475 }
00476 
00477 /** Tests if the BLIT modification with one argument is correctly decoded
00478  *
00479  * @todo check if the surface is correct
00480  */
00481 BOOST_AUTO_TEST_CASE(test_blit_modification_decoding_1_arg)
00482 {
00483     environment_setup env_setup;
00484 
00485     modification_queue queue = modification::decode("~BLIT(wesnoth-icon.png)");
00486 
00487     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00488 
00489     blit_modification* mod = dynamic_cast<blit_modification*>(queue.top());
00490 
00491     // The dynamic_cast returns NULL if the argument doesn't match the type
00492     BOOST_REQUIRE(mod != NULL);
00493 
00494     BOOST_CHECK(!mod->get_surface().null());
00495     BOOST_CHECK_EQUAL(mod->get_x(), 0);
00496     BOOST_CHECK_EQUAL(mod->get_y(), 0);
00497 
00498     delete mod;
00499 }
00500 
00501 /** Tests if the BLIT modification with three arguments is correctly decoded
00502  *
00503  * @todo check if the surface is correct
00504  */
00505 BOOST_AUTO_TEST_CASE(test_blit_modification_decoding_3_args)
00506 {
00507     environment_setup env_setup;
00508 
00509     modification_queue queue = modification::decode("~BLIT(wesnoth-icon.png,1,2)");
00510 
00511     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00512 
00513     blit_modification* mod = dynamic_cast<blit_modification*>(queue.top());
00514 
00515     BOOST_REQUIRE(mod != NULL);
00516     // The dynamic_cast returns NULL if the argument doesn't match the type
00517 
00518     BOOST_CHECK(!mod->get_surface().null());
00519     BOOST_CHECK_EQUAL(mod->get_x(), 1);
00520     BOOST_CHECK_EQUAL(mod->get_y(), 2);
00521 
00522     delete mod;
00523 }
00524 
00525 /// Tests if the BLIT modification with invalid arguments is ignored
00526 BOOST_AUTO_TEST_CASE(test_blit_modification_decoding_invalid_args)
00527 {
00528     environment_setup env_setup;
00529 
00530     modification_queue queue =
00531         modification::decode("~BLIT()"
00532                      "~BLIT(wesnoth-icon.png,1,-2)"
00533                      "~BLIT(wesnoth-icon.png,-1,2)"
00534                      "~BLIT(wesnoth-icon.png,-1,-2)");
00535 
00536     BOOST_CHECK_EQUAL(queue.size(), 0);
00537 }
00538 
00539 /** Tests if the MASK modification with one argument is correctly decoded
00540  *
00541  * @todo check if the surface is correct
00542  */
00543 BOOST_AUTO_TEST_CASE(test_mask_modification_decoding_1_arg)
00544 {
00545     environment_setup env_setup;
00546 
00547     modification_queue queue = modification::decode("~MASK(wesnoth-icon.png)");
00548 
00549     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00550 
00551     mask_modification* mod = dynamic_cast<mask_modification*>(queue.top());
00552 
00553     // The dynamic_cast returns NULL if the argument doesn't match the type
00554     BOOST_REQUIRE(mod != NULL);
00555 
00556     BOOST_CHECK(!mod->get_mask().null());
00557     BOOST_CHECK_EQUAL(mod->get_x(), 0);
00558     BOOST_CHECK_EQUAL(mod->get_y(), 0);
00559 
00560     delete mod;
00561 }
00562 
00563 /** Tests if the MASK modification with three arguments is correctly decoded
00564  *
00565  * @todo check if the surface is correct
00566  */
00567 BOOST_AUTO_TEST_CASE(test_mask_modification_decoding_3_args)
00568 {
00569     environment_setup env_setup;
00570 
00571     modification_queue queue = modification::decode("~MASK(wesnoth-icon.png,3,4)");
00572 
00573     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00574 
00575     mask_modification* mod = dynamic_cast<mask_modification*>(queue.top());
00576 
00577     // The dynamic_cast returns NULL if the argument doesn't match the type
00578     BOOST_REQUIRE(mod != NULL);
00579 
00580     BOOST_CHECK(!mod->get_mask().null());
00581     BOOST_CHECK_EQUAL(mod->get_x(), 3);
00582     BOOST_CHECK_EQUAL(mod->get_y(), 4);
00583 
00584     delete mod;
00585 }
00586 
00587 /// Tests if the MASK modification with invalid arguments is ignored
00588 BOOST_AUTO_TEST_CASE(test_mask_modification_decoding_invalid_args)
00589 {
00590     environment_setup env_setup;
00591 
00592     modification_queue queue =
00593         modification::decode("~MASK()"
00594                      "~MASK(wesnoth-icon.png,3,-4)"
00595                      "~MASK(wesnoth-icon.png,-3,4)"
00596                      "~MASK(wesnoth-icon.png,-3,-4)");
00597 
00598     BOOST_CHECK_EQUAL(queue.size(), 0);
00599 }
00600 
00601 /// Tests if the L modification without arguments is ignored
00602 BOOST_AUTO_TEST_CASE(test_l_modification_decoding_no_args)
00603 {
00604     environment_setup env_setup;
00605 
00606     modification_queue queue = modification::decode("~L()");
00607 
00608     BOOST_CHECK_EQUAL(queue.size(), 0);
00609 }
00610 
00611 /** Tests if the L modification with one argument is correctly decoded
00612  *
00613  * @todo check if the surface is correct
00614  */
00615 BOOST_AUTO_TEST_CASE(test_l_modification_decoding_1_arg)
00616 {
00617     environment_setup env_setup;
00618 
00619     modification_queue queue = modification::decode("~L(wesnoth-icon.png)");
00620 
00621     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00622 
00623     light_modification* mod = dynamic_cast<light_modification*>(queue.top());
00624 
00625     // The dynamic_cast returns NULL if the argument doesn't match the type
00626     BOOST_REQUIRE(mod != NULL);
00627 
00628     BOOST_CHECK(!mod->get_surface().null());
00629 
00630     delete mod;
00631 }
00632 
00633 /// Tests if the SCALE modification without arguments is ignored
00634 BOOST_AUTO_TEST_CASE(test_scale_modification_decoding_no_args)
00635 {
00636     environment_setup env_setup;
00637 
00638     modification_queue queue = modification::decode("~SCALE()");
00639 
00640     BOOST_CHECK_EQUAL(queue.size(), 0);
00641 }
00642 
00643 /// Tests if the SCALE modification with one argument is correctly decoded
00644 BOOST_AUTO_TEST_CASE(test_scale_modification_decoding_1_arg)
00645 {
00646     environment_setup env_setup;
00647 
00648     modification_queue queue = modification::decode("~SCALE(3)");
00649 
00650     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00651 
00652     scale_modification* mod = dynamic_cast<scale_modification*>(queue.top());
00653 
00654     // The dynamic_cast returns NULL if the argument doesn't match the type
00655     BOOST_REQUIRE(mod != NULL);
00656 
00657     BOOST_CHECK_EQUAL(mod->get_w(), 3);
00658     BOOST_CHECK_EQUAL(mod->get_h(), 0);
00659 
00660     delete mod;
00661 }
00662 
00663 /// Tests if the SCALE modification with two arguments is correctly decoded
00664 BOOST_AUTO_TEST_CASE(test_scale_modification_decoding_2_args)
00665 {
00666     environment_setup env_setup;
00667 
00668     modification_queue queue = modification::decode("~SCALE(4,5)");
00669 
00670     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00671 
00672     scale_modification* mod = dynamic_cast<scale_modification*>(queue.top());
00673 
00674     // The dynamic_cast returns NULL if the argument doesn't match the type
00675     BOOST_REQUIRE(mod != NULL);
00676 
00677     BOOST_CHECK_EQUAL(mod->get_w(), 4);
00678     BOOST_CHECK_EQUAL(mod->get_h(), 5);
00679 
00680     delete mod;
00681 }
00682 
00683 /// Tests if the O modification with a percent argument is correctly decoded
00684 BOOST_AUTO_TEST_CASE(test_o_modification_decoding_percent_args)
00685 {
00686     environment_setup env_setup;
00687 
00688     modification_queue queue = modification::decode("~O(45%)");
00689 
00690     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00691 
00692     o_modification* mod = dynamic_cast<o_modification*>(queue.top());
00693 
00694     // The dynamic_cast returns NULL if the argument doesn't match the type
00695     BOOST_REQUIRE(mod != NULL);
00696 
00697     BOOST_CHECK(mod->get_opacity() > 0.44f);
00698     BOOST_CHECK(mod->get_opacity() < 0.46f);
00699 
00700     delete mod;
00701 }
00702 
00703 /// Tests if the O modification with a fraction argument is correctly decoded
00704 BOOST_AUTO_TEST_CASE(test_o_modification_decoding_fraction_args)
00705 {
00706     environment_setup env_setup;
00707 
00708     modification_queue queue = modification::decode("~O(0.34)");
00709 
00710     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00711 
00712     o_modification* mod = dynamic_cast<o_modification*>(queue.top());
00713 
00714     // The dynamic_cast returns NULL if the argument doesn't match the type
00715     BOOST_REQUIRE(mod != NULL);
00716 
00717     BOOST_CHECK(mod->get_opacity() > 0.33f);
00718     BOOST_CHECK(mod->get_opacity() < 0.35f);
00719 
00720     delete mod;
00721 }
00722 
00723 /// Tests if the BL modification without arguments is correctly decoded
00724 BOOST_AUTO_TEST_CASE(test_bl_modification_decoding_no_args)
00725 {
00726     environment_setup env_setup;
00727 
00728     modification_queue queue = modification::decode("~BL()");
00729 
00730     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00731 
00732     bl_modification* mod = dynamic_cast<bl_modification*>(queue.top());
00733 
00734     // The dynamic_cast returns NULL if the argument doesn't match the type
00735     BOOST_REQUIRE(mod != NULL);
00736 
00737     BOOST_CHECK_EQUAL(mod->get_depth(), 0);
00738 
00739     delete mod;
00740 }
00741 
00742 /// Tests if the BL modification with one argument is correctly decoded
00743 BOOST_AUTO_TEST_CASE(test_bl_modification_decoding)
00744 {
00745     environment_setup env_setup;
00746 
00747     modification_queue queue = modification::decode("~BL(2)");
00748 
00749     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00750 
00751     bl_modification* mod = dynamic_cast<bl_modification*>(queue.top());
00752 
00753     // The dynamic_cast returns NULL if the argument doesn't match the type
00754     BOOST_REQUIRE(mod != NULL);
00755 
00756     BOOST_CHECK_EQUAL(mod->get_depth(), 2);
00757 
00758     delete mod;
00759 }
00760 
00761 /// Tests if the R, G and B modifications without args are correctly decoded
00762 BOOST_AUTO_TEST_CASE(test_rgb_modification_decoding_no_args)
00763 {
00764     environment_setup env_setup;
00765 
00766     modification_queue queue = modification::decode("~R()~G()~B()");
00767 
00768     BOOST_REQUIRE_EQUAL(queue.size(), 3);
00769 
00770     for(int i = 0; i < 3; i++) {
00771     environment_setup env_setup;
00772 
00773         cs_modification* mod = dynamic_cast<cs_modification*>(queue.top());
00774 
00775         // The dynamic_cast returns NULL if the argument doesn't match the type
00776         BOOST_REQUIRE(mod != NULL);
00777 
00778         BOOST_CHECK_EQUAL(mod->get_r(), 0);
00779         BOOST_CHECK_EQUAL(mod->get_g(), 0);
00780         BOOST_CHECK_EQUAL(mod->get_b(), 0);
00781 
00782         queue.pop();
00783 
00784         delete mod;
00785     }
00786 }
00787 
00788 /// Tests if the R modification with one argument is correctly decoded
00789 BOOST_AUTO_TEST_CASE(test_r_modification_decoding)
00790 {
00791     environment_setup env_setup;
00792 
00793     modification_queue queue = modification::decode("~R(123)");
00794 
00795     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00796 
00797     cs_modification* mod = dynamic_cast<cs_modification*>(queue.top());
00798 
00799     // The dynamic_cast returns NULL if the argument doesn't match the type
00800     BOOST_REQUIRE(mod != NULL);
00801 
00802     BOOST_CHECK_EQUAL(mod->get_r(), 123);
00803     BOOST_CHECK_EQUAL(mod->get_g(), 0);
00804     BOOST_CHECK_EQUAL(mod->get_b(), 0);
00805 
00806     delete mod;
00807 }
00808 
00809 /// Tests if the G modification with one argument is correctly decoded
00810 BOOST_AUTO_TEST_CASE(test_g_modification_decoding)
00811 {
00812     environment_setup env_setup;
00813 
00814     modification_queue queue = modification::decode("~G(132)");
00815 
00816     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00817 
00818     cs_modification* mod = dynamic_cast<cs_modification*>(queue.top());
00819 
00820     // The dynamic_cast returns NULL if the argument doesn't match the type
00821     BOOST_REQUIRE(mod != NULL);
00822 
00823     BOOST_CHECK_EQUAL(mod->get_r(), 0);
00824     BOOST_CHECK_EQUAL(mod->get_g(), 132);
00825     BOOST_CHECK_EQUAL(mod->get_b(), 0);
00826 
00827     delete mod;
00828 }
00829 
00830 /// Tests if the B modification with one argument is correctly decoded
00831 BOOST_AUTO_TEST_CASE(test_b_modification_decoding)
00832 {
00833     environment_setup env_setup;
00834 
00835     modification_queue queue = modification::decode("~B(312)");
00836 
00837     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00838 
00839     cs_modification* mod = dynamic_cast<cs_modification*>(queue.top());
00840 
00841     // The dynamic_cast returns NULL if the argument doesn't match the type
00842     BOOST_REQUIRE(mod != NULL);
00843 
00844     BOOST_CHECK_EQUAL(mod->get_r(), 0);
00845     BOOST_CHECK_EQUAL(mod->get_g(), 0);
00846     BOOST_CHECK_EQUAL(mod->get_b(), 312);
00847 
00848     delete mod;
00849 }
00850 
00851 /// Tests if the BRIGHTEN modification is correctly decoded
00852 BOOST_AUTO_TEST_CASE(test_brighten_modification_decoding)
00853 {
00854     environment_setup env_setup;
00855 
00856     modification_queue queue = modification::decode("~BRIGHTEN()");
00857 
00858     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00859 
00860     brighten_modification* mod = dynamic_cast<brighten_modification*>(queue.top());
00861 
00862     // The dynamic_cast returns NULL if the argument doesn't match the type
00863     BOOST_CHECK(mod != NULL);
00864 
00865     delete mod;
00866 }
00867 
00868 /// Tests if the DARKEN modification is correctly decoded
00869 BOOST_AUTO_TEST_CASE(test_draken_modification_decoding)
00870 {
00871     environment_setup env_setup;
00872 
00873     modification_queue queue = modification::decode("~DARKEN()");
00874 
00875     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00876 
00877     darken_modification* mod = dynamic_cast<darken_modification*>(queue.top());
00878 
00879     // The dynamic_cast returns NULL if the argument doesn't match the type
00880     BOOST_CHECK(mod != NULL);
00881 
00882     delete mod;
00883 }
00884 
00885 /// Tests if the BG modification without arguments is correctly decoded
00886 BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_no_args)
00887 {
00888     environment_setup env_setup;
00889 
00890     modification_queue queue = modification::decode("~BG()");
00891 
00892     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00893 
00894     background_modification* mod = dynamic_cast<background_modification*>(queue.top());
00895 
00896     // The dynamic_cast returns NULL if the argument doesn't match the type
00897     BOOST_REQUIRE(mod != NULL);
00898 
00899     BOOST_CHECK_EQUAL(mod->get_color().r, 0);
00900     BOOST_CHECK_EQUAL(mod->get_color().g, 0);
00901     BOOST_CHECK_EQUAL(mod->get_color().b, 0);
00902     BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
00903 
00904     delete mod;
00905 }
00906 
00907 /// Tests if the BG modification with one argument is correctly decoded
00908 BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_1_arg)
00909 {
00910     environment_setup env_setup;
00911 
00912     modification_queue queue = modification::decode("~BG(1)");
00913 
00914     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00915 
00916     background_modification* mod = dynamic_cast<background_modification*>(queue.top());
00917 
00918     // The dynamic_cast returns NULL if the argument doesn't match the type
00919     BOOST_REQUIRE(mod != NULL);
00920 
00921     BOOST_CHECK_EQUAL(mod->get_color().r, 1);
00922     BOOST_CHECK_EQUAL(mod->get_color().g, 0);
00923     BOOST_CHECK_EQUAL(mod->get_color().b, 0);
00924     BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
00925 
00926     delete mod;
00927 }
00928 
00929 /// Tests if the BG modification with two arguments is correctly decoded
00930 BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_2_args)
00931 {
00932     environment_setup env_setup;
00933 
00934     modification_queue queue = modification::decode("~BG(1,2)");
00935 
00936     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00937 
00938     background_modification* mod = dynamic_cast<background_modification*>(queue.top());
00939 
00940     // The dynamic_cast returns NULL if the argument doesn't match the type
00941     BOOST_REQUIRE(mod != NULL);
00942 
00943     BOOST_CHECK_EQUAL(mod->get_color().r, 1);
00944     BOOST_CHECK_EQUAL(mod->get_color().g, 2);
00945     BOOST_CHECK_EQUAL(mod->get_color().b, 0);
00946     BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
00947 
00948     delete mod;
00949 }
00950 
00951 /// Tests if the BG modification with three arguments is correctly decoded
00952 BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_3_args)
00953 {
00954     environment_setup env_setup;
00955 
00956     modification_queue queue = modification::decode("~BG(1,2,3)");
00957 
00958     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00959 
00960     background_modification* mod = dynamic_cast<background_modification*>(queue.top());
00961 
00962     // The dynamic_cast returns NULL if the argument doesn't match the type
00963     BOOST_REQUIRE(mod != NULL);
00964 
00965     BOOST_CHECK_EQUAL(mod->get_color().r, 1);
00966     BOOST_CHECK_EQUAL(mod->get_color().g, 2);
00967     BOOST_CHECK_EQUAL(mod->get_color().b, 3);
00968     BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
00969 
00970     delete mod;
00971 }
00972 
00973 /// Tests if the BG modification with four arguments is correctly decoded
00974 BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_4_args)
00975 {
00976     environment_setup env_setup;
00977 
00978     modification_queue queue = modification::decode("~BG(1,2,3,4)");
00979 
00980     BOOST_REQUIRE_EQUAL(queue.size(), 1);
00981 
00982     background_modification* mod = dynamic_cast<background_modification*>(queue.top());
00983 
00984     // The dynamic_cast returns NULL if the argument doesn't match the type
00985     BOOST_REQUIRE(mod != NULL);
00986 
00987     BOOST_CHECK_EQUAL(mod->get_color().r, 1);
00988     BOOST_CHECK_EQUAL(mod->get_color().g, 2);
00989     BOOST_CHECK_EQUAL(mod->get_color().b, 3);
00990     BOOST_CHECK_EQUAL(mod->get_color().unused, 4);
00991 
00992     delete mod;
00993 }
00994 
00995 BOOST_AUTO_TEST_SUITE_END()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:12 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs