15 #define GETTEXT_DOMAIN "wesnoth-test"
17 #include <boost/test/unit_test.hpp>
29 using namespace image;
33 class environment_setup
39 , output_redirect_(ignored_stream_)
52 void set_up_color_info()
56 create_color_range(
"red",
57 "FF0000,FFFFFF,000000,FF0000",
60 create_color_range(
"blue",
61 "2E419B,FFFFFF,0F0F0F,0000FF",
71 void set_up_team_colors()
73 std::vector<std::string>
tc;
86 void set_up_image_paths()
91 create_path_config(
"data/core"));
93 paths_manager_.set_paths(cfg);
118 std::stringstream ignored_stream_;
134 environment_setup env_setup;
140 queue.
push(low_priority_mod);
141 queue.
push(high_priority_mod);
143 BOOST_REQUIRE_EQUAL(queue.
size(), 2);
145 BOOST_CHECK_EQUAL(queue.
top(), high_priority_mod);
147 BOOST_CHECK_EQUAL(queue.
top(), low_priority_mod);
151 queue.
push(high_priority_mod);
152 queue.
push(low_priority_mod);
154 BOOST_REQUIRE_EQUAL(queue.
size(), 2);
156 BOOST_CHECK_EQUAL(queue.
top(), high_priority_mod);
158 BOOST_CHECK_EQUAL(queue.
top(), low_priority_mod);
161 delete low_priority_mod;
162 delete high_priority_mod;
168 environment_setup env_setup;
172 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
177 BOOST_REQUIRE(mod !=
nullptr);
182 std::map<Uint32, Uint32> expected =
recolor_range(new_color, old_color);
184 BOOST_CHECK(expected == mod->map());
192 environment_setup env_setup;
196 BOOST_REQUIRE_EQUAL(queue.
size(), 0);
202 environment_setup env_setup;
206 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
211 BOOST_REQUIRE(mod !=
nullptr);
215 std::map<Uint32, Uint32> expected =
recolor_range(new_color, old_color);
217 BOOST_CHECK(expected == mod->map());
225 environment_setup env_setup;
229 BOOST_REQUIRE_EQUAL(queue.
size(), 0);
235 environment_setup env_setup;
240 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
245 BOOST_REQUIRE(mod !=
nullptr);
249 std::map<Uint32, Uint32> expected;
251 for(
size_t i = 0;
i < old_palette.size() &&
i < new_palette.size(); ++
i) {
252 environment_setup env_setup;
254 expected[old_palette[
i]] = new_palette[
i];
257 BOOST_CHECK(expected == mod->map());
265 environment_setup env_setup;
270 BOOST_REQUIRE_EQUAL(queue.
size(), 0);
276 environment_setup env_setup;
280 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
285 BOOST_REQUIRE(mod !=
nullptr);
287 BOOST_CHECK(mod->get_horiz());
288 BOOST_CHECK(!mod->get_vert());
296 environment_setup env_setup;
300 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
305 BOOST_REQUIRE(mod !=
nullptr);
307 BOOST_CHECK(mod->get_horiz());
308 BOOST_CHECK(!mod->get_vert());
316 environment_setup env_setup;
320 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
325 BOOST_REQUIRE(mod !=
nullptr);
327 BOOST_CHECK(!mod->get_horiz());
328 BOOST_CHECK(mod->get_vert());
336 environment_setup env_setup;
340 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
345 BOOST_REQUIRE(mod !=
nullptr);
347 BOOST_CHECK(mod->get_horiz());
348 BOOST_CHECK(mod->get_vert());
356 environment_setup env_setup;
360 BOOST_REQUIRE(queue.
size() == 1);
365 BOOST_CHECK(mod !=
nullptr);
373 environment_setup env_setup;
377 BOOST_REQUIRE_EQUAL(queue.
size(), 0);
383 environment_setup env_setup;
387 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
392 BOOST_REQUIRE(mod !=
nullptr);
394 const SDL_Rect& slice = mod->get_slice();
396 BOOST_CHECK_EQUAL(slice.x, 1);
397 BOOST_CHECK_EQUAL(slice.y, 0);
398 BOOST_CHECK_EQUAL(slice.w, 0);
399 BOOST_CHECK_EQUAL(slice.h, 0);
407 environment_setup env_setup;
411 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
416 BOOST_REQUIRE(mod !=
nullptr);
418 const SDL_Rect& slice = mod->get_slice();
420 BOOST_CHECK_EQUAL(slice.x, 1);
421 BOOST_CHECK_EQUAL(slice.y, 2);
422 BOOST_CHECK_EQUAL(slice.w, 0);
423 BOOST_CHECK_EQUAL(slice.h, 0);
431 environment_setup env_setup;
435 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
440 BOOST_REQUIRE(mod !=
nullptr);
442 const SDL_Rect& slice = mod->get_slice();
444 BOOST_CHECK_EQUAL(slice.x, 1);
445 BOOST_CHECK_EQUAL(slice.y, 2);
446 BOOST_CHECK_EQUAL(slice.w, 3);
447 BOOST_CHECK_EQUAL(slice.h, 0);
455 environment_setup env_setup;
459 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
464 BOOST_REQUIRE(mod !=
nullptr);
466 const SDL_Rect& slice = mod->get_slice();
468 BOOST_CHECK_EQUAL(slice.x, 1);
469 BOOST_CHECK_EQUAL(slice.y, 2);
470 BOOST_CHECK_EQUAL(slice.w, 3);
471 BOOST_CHECK_EQUAL(slice.h, 4);
482 environment_setup env_setup;
486 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
491 BOOST_REQUIRE(mod !=
nullptr);
493 BOOST_CHECK(!mod->get_surface().null());
494 BOOST_CHECK_EQUAL(mod->get_x(), 0);
495 BOOST_CHECK_EQUAL(mod->get_y(), 0);
506 environment_setup env_setup;
510 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
514 BOOST_REQUIRE(mod !=
nullptr);
517 BOOST_CHECK(!mod->get_surface().null());
518 BOOST_CHECK_EQUAL(mod->get_x(), 1);
519 BOOST_CHECK_EQUAL(mod->get_y(), 2);
527 environment_setup env_setup;
531 "~BLIT(wesnoth-icon.png,1,-2)"
532 "~BLIT(wesnoth-icon.png,-1,2)"
533 "~BLIT(wesnoth-icon.png,-1,-2)");
535 BOOST_CHECK_EQUAL(queue.
size(), 0);
544 environment_setup env_setup;
548 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
553 BOOST_REQUIRE(mod !=
nullptr);
555 BOOST_CHECK(!mod->get_mask().null());
556 BOOST_CHECK_EQUAL(mod->get_x(), 0);
557 BOOST_CHECK_EQUAL(mod->get_y(), 0);
568 environment_setup env_setup;
572 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
577 BOOST_REQUIRE(mod !=
nullptr);
579 BOOST_CHECK(!mod->get_mask().null());
580 BOOST_CHECK_EQUAL(mod->get_x(), 3);
581 BOOST_CHECK_EQUAL(mod->get_y(), 4);
589 environment_setup env_setup;
593 "~MASK(wesnoth-icon.png,3,-4)"
594 "~MASK(wesnoth-icon.png,-3,4)"
595 "~MASK(wesnoth-icon.png,-3,-4)");
597 BOOST_CHECK_EQUAL(queue.
size(), 0);
603 environment_setup env_setup;
607 BOOST_CHECK_EQUAL(queue.
size(), 0);
616 environment_setup env_setup;
620 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
625 BOOST_REQUIRE(mod !=
nullptr);
627 BOOST_CHECK(!mod->get_surface().null());
635 environment_setup env_setup;
639 BOOST_CHECK_EQUAL(queue.
size(), 0);
645 environment_setup env_setup;
649 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
654 BOOST_REQUIRE(mod !=
nullptr);
656 BOOST_CHECK_EQUAL(mod->get_w(), 3);
657 BOOST_CHECK_EQUAL(mod->get_h(), 0);
665 environment_setup env_setup;
669 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
674 BOOST_REQUIRE(mod !=
nullptr);
676 BOOST_CHECK_EQUAL(mod->get_w(), 4);
677 BOOST_CHECK_EQUAL(mod->get_h(), 5);
685 environment_setup env_setup;
689 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
694 BOOST_REQUIRE(mod !=
nullptr);
696 BOOST_CHECK(mod->get_opacity() > 0.44f);
697 BOOST_CHECK(mod->get_opacity() < 0.46f);
705 environment_setup env_setup;
709 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
714 BOOST_REQUIRE(mod !=
nullptr);
716 BOOST_CHECK(mod->get_opacity() > 0.33f);
717 BOOST_CHECK(mod->get_opacity() < 0.35f);
725 environment_setup env_setup;
729 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
734 BOOST_REQUIRE(mod !=
nullptr);
736 BOOST_CHECK_EQUAL(mod->get_depth(), 0);
744 environment_setup env_setup;
748 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
753 BOOST_REQUIRE(mod !=
nullptr);
755 BOOST_CHECK_EQUAL(mod->get_depth(), 2);
763 environment_setup env_setup;
767 BOOST_REQUIRE_EQUAL(queue.
size(), 3);
769 for(
int i = 0;
i < 3;
i++) {
770 environment_setup env_setup;
775 BOOST_REQUIRE(mod !=
nullptr);
777 BOOST_CHECK_EQUAL(mod->
get_r(), 0);
778 BOOST_CHECK_EQUAL(mod->
get_g(), 0);
779 BOOST_CHECK_EQUAL(mod->
get_b(), 0);
790 environment_setup env_setup;
794 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
799 BOOST_REQUIRE(mod !=
nullptr);
801 BOOST_CHECK_EQUAL(mod->get_r(), 123);
802 BOOST_CHECK_EQUAL(mod->get_g(), 0);
803 BOOST_CHECK_EQUAL(mod->get_b(), 0);
811 environment_setup env_setup;
815 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
820 BOOST_REQUIRE(mod !=
nullptr);
822 BOOST_CHECK_EQUAL(mod->get_r(), 0);
823 BOOST_CHECK_EQUAL(mod->get_g(), 132);
824 BOOST_CHECK_EQUAL(mod->get_b(), 0);
832 environment_setup env_setup;
836 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
841 BOOST_REQUIRE(mod !=
nullptr);
843 BOOST_CHECK_EQUAL(mod->get_r(), 0);
844 BOOST_CHECK_EQUAL(mod->get_g(), 0);
845 BOOST_CHECK_EQUAL(mod->get_b(), 312);
853 environment_setup env_setup;
857 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
862 BOOST_CHECK(mod !=
nullptr);
870 environment_setup env_setup;
874 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
879 BOOST_CHECK(mod !=
nullptr);
887 environment_setup env_setup;
891 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
896 BOOST_REQUIRE(mod !=
nullptr);
898 BOOST_CHECK_EQUAL(mod->get_color().r, 0);
899 BOOST_CHECK_EQUAL(mod->get_color().g, 0);
900 BOOST_CHECK_EQUAL(mod->get_color().b, 0);
901 BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
909 environment_setup env_setup;
913 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
918 BOOST_REQUIRE(mod !=
nullptr);
920 BOOST_CHECK_EQUAL(mod->get_color().r, 1);
921 BOOST_CHECK_EQUAL(mod->get_color().g, 0);
922 BOOST_CHECK_EQUAL(mod->get_color().b, 0);
923 BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
931 environment_setup env_setup;
935 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
940 BOOST_REQUIRE(mod !=
nullptr);
942 BOOST_CHECK_EQUAL(mod->get_color().r, 1);
943 BOOST_CHECK_EQUAL(mod->get_color().g, 2);
944 BOOST_CHECK_EQUAL(mod->get_color().b, 0);
945 BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
953 environment_setup env_setup;
957 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
962 BOOST_REQUIRE(mod !=
nullptr);
964 BOOST_CHECK_EQUAL(mod->get_color().r, 1);
965 BOOST_CHECK_EQUAL(mod->get_color().g, 2);
966 BOOST_CHECK_EQUAL(mod->get_color().b, 3);
967 BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
975 environment_setup env_setup;
979 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
984 BOOST_REQUIRE(mod !=
nullptr);
986 BOOST_CHECK_EQUAL(mod->get_color().r, 1);
987 BOOST_CHECK_EQUAL(mod->get_color().g, 2);
988 BOOST_CHECK_EQUAL(mod->get_color().b, 3);
989 BOOST_CHECK_EQUAL(mod->get_color().a, 4);
994 BOOST_AUTO_TEST_SUITE_END()
Grayscale (GS) modification.
Scale (BLIT) modification.
Fill background with a color (BG).
BOOST_AUTO_TEST_CASE(test_modificaiton_queue_order)
Tests if modifications with a higher priority are placed before the others.
Gaussian-like blur (BL) modification.
Color-shift (CS, R, G, B) modification.
const std::vector< Uint32 > & tc_info(const std::string &name)
void set_team_colors(const std::vector< std::string > *colors)
set the team colors used by the TC image modification use a vector with one string for each team usin...
A modified priority queue used to order image modifications.
Overlay with ToD darkening (DARKEN).
The paths manager is responsible for recording the various paths that binary files may be located at...
BOOST_AUTO_TEST_SUITE(test_map_location)
Mask (MASK) modification.
Definitions for the interface to Wesnoth Markup Language (WML).
Recolor (RC/TC/PAL) modification.
void push(modification *mod)
Adds mod to the queue (unless mod is nullptr).
GLsizei const char ** path
Crop (CROP) modification.
void add_color_info(const config &v)
config & add_child(const std::string &key)
Overlay with ToD brightening (BRIGHTEN).
Base abstract class for an image-path modification.
static modification_queue decode(const std::string &)
Decodes modifications from a modification string.
modification * top() const
Returns the top element in the queue .
A color range definition is made of four reference RGB colors, used for calculating conversions from ...
Declarations for File-IO.
size_t size() const
Returns the number of elements in the queue.
Opacity (O) modification.
GLuint const GLchar * name
const color_range & color_info(const std::string &name)
this module manages the cache of images.
Standard logging facilities (interface).
std::map< Uint32, Uint32 > recolor_range(const color_range &new_range, const std::vector< Uint32 > &old_rgb)
Converts a source palette using the specified color_range object.
void pop()
Removes the top element from the queue.
A config object defines a single node in a WML file, with access to child nodes.
Helper class to redirect the output of the logger in a certain scope.
GLsizei const GLcharARB ** string
Mirror (FL) modification.
Scaling modifications base class.