16 #define GETTEXT_DOMAIN "wesnoth-test"
18 #include <boost/test/unit_test.hpp>
31 using namespace image;
35 class environment_setup
41 , output_redirect_(ignored_stream_)
53 void set_up_color_info()
57 create_color_range(
"red",
58 "FF0000,FFFFFF,000000,FF0000",
61 create_color_range(
"blue",
62 "2E419B,FFFFFF,0F0F0F,0000FF",
73 void set_up_image_paths()
78 create_path_config(
"data/core"));
81 paths_manager_.set_paths(v);
84 static config create_color_range(
const std::string&
id,
85 const std::string& rgb,
86 const std::string& name)
97 static config create_path_config(
const std::string&
path)
106 std::stringstream ignored_stream_;
122 environment_setup env_setup;
126 auto low_priority_mod = std::make_unique<fl_modification>();
127 auto high_priority_mod = std::make_unique<rc_modification>();
132 queue.
push(std::move(low_priority_mod));
133 queue.
push(std::move(high_priority_mod));
135 BOOST_REQUIRE_EQUAL(queue.
size(), 2);
137 BOOST_CHECK_EQUAL(queue.
top(), hptr);
139 BOOST_CHECK_EQUAL(queue.
top(), lptr);
142 low_priority_mod = std::make_unique<fl_modification>();
143 high_priority_mod = std::make_unique<rc_modification>();
145 lptr = low_priority_mod.get();
146 hptr = high_priority_mod.get();
149 queue.
push(std::move(high_priority_mod));
150 queue.
push(std::move(low_priority_mod));
152 BOOST_REQUIRE_EQUAL(queue.
size(), 2);
154 BOOST_CHECK_EQUAL(queue.
top(), hptr);
156 BOOST_CHECK_EQUAL(queue.
top(), lptr);
163 environment_setup env_setup;
167 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
172 BOOST_REQUIRE(mod !=
nullptr);
179 BOOST_CHECK(expected == mod->
map());
185 environment_setup env_setup;
189 BOOST_REQUIRE_EQUAL(queue.
size(), 0);
195 environment_setup env_setup;
199 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
204 BOOST_REQUIRE(mod !=
nullptr);
210 BOOST_CHECK(expected == mod->
map());
216 environment_setup env_setup;
220 BOOST_REQUIRE_EQUAL(queue.
size(), 0);
226 environment_setup env_setup;
231 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
236 BOOST_REQUIRE(mod !=
nullptr);
242 for(std::size_t
i = 0;
i < old_palette.size() &&
i < new_palette.size(); ++
i) {
243 environment_setup env_setup;
245 expected[old_palette[
i]] = new_palette[
i];
248 BOOST_CHECK(expected == mod->
map());
254 environment_setup env_setup;
259 BOOST_REQUIRE_EQUAL(queue.
size(), 0);
265 environment_setup env_setup;
269 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
274 BOOST_REQUIRE(mod !=
nullptr);
283 environment_setup env_setup;
287 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
292 BOOST_REQUIRE(mod !=
nullptr);
301 environment_setup env_setup;
305 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
310 BOOST_REQUIRE(mod !=
nullptr);
319 environment_setup env_setup;
323 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
328 BOOST_REQUIRE(mod !=
nullptr);
337 environment_setup env_setup;
341 BOOST_REQUIRE(queue.
size() == 1);
346 BOOST_CHECK(mod !=
nullptr);
352 environment_setup env_setup;
356 BOOST_REQUIRE_EQUAL(queue.
size(), 0);
362 environment_setup env_setup;
366 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
371 BOOST_REQUIRE(mod !=
nullptr);
373 const SDL_Rect& slice = mod->
get_slice();
375 BOOST_CHECK_EQUAL(slice.x, 1);
376 BOOST_CHECK_EQUAL(slice.y, 0);
377 BOOST_CHECK_EQUAL(slice.w, 0);
378 BOOST_CHECK_EQUAL(slice.h, 0);
384 environment_setup env_setup;
388 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
393 BOOST_REQUIRE(mod !=
nullptr);
395 const SDL_Rect& slice = mod->
get_slice();
397 BOOST_CHECK_EQUAL(slice.x, 1);
398 BOOST_CHECK_EQUAL(slice.y, 2);
399 BOOST_CHECK_EQUAL(slice.w, 0);
400 BOOST_CHECK_EQUAL(slice.h, 0);
406 environment_setup env_setup;
410 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
415 BOOST_REQUIRE(mod !=
nullptr);
417 const SDL_Rect& slice = mod->
get_slice();
419 BOOST_CHECK_EQUAL(slice.x, 1);
420 BOOST_CHECK_EQUAL(slice.y, 2);
421 BOOST_CHECK_EQUAL(slice.w, 3);
422 BOOST_CHECK_EQUAL(slice.h, 0);
428 environment_setup env_setup;
432 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
437 BOOST_REQUIRE(mod !=
nullptr);
439 const SDL_Rect& slice = mod->
get_slice();
441 BOOST_CHECK_EQUAL(slice.x, 1);
442 BOOST_CHECK_EQUAL(slice.y, 2);
443 BOOST_CHECK_EQUAL(slice.w, 3);
444 BOOST_CHECK_EQUAL(slice.h, 4);
453 environment_setup env_setup;
457 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
462 BOOST_REQUIRE(mod !=
nullptr);
465 BOOST_CHECK_EQUAL(mod->
get_x(), 0);
466 BOOST_CHECK_EQUAL(mod->
get_y(), 0);
475 environment_setup env_setup;
479 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
483 BOOST_REQUIRE(mod !=
nullptr);
487 BOOST_CHECK_EQUAL(mod->
get_x(), 1);
488 BOOST_CHECK_EQUAL(mod->
get_y(), 2);
494 environment_setup env_setup;
498 "~BLIT(wesnoth-icon.png,1,-2)"
499 "~BLIT(wesnoth-icon.png,-1,2)"
500 "~BLIT(wesnoth-icon.png,-1,-2)"
501 "~BLIT(wesnoth-icon.png,1,2,3)");
503 BOOST_CHECK_EQUAL(queue.
size(), 3);
512 environment_setup env_setup;
516 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
521 BOOST_REQUIRE(mod !=
nullptr);
524 BOOST_CHECK_EQUAL(mod->
get_x(), 0);
525 BOOST_CHECK_EQUAL(mod->
get_y(), 0);
534 environment_setup env_setup;
538 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
543 BOOST_REQUIRE(mod !=
nullptr);
546 BOOST_CHECK_EQUAL(mod->
get_x(), 3);
547 BOOST_CHECK_EQUAL(mod->
get_y(), 4);
553 environment_setup env_setup;
557 "~MASK(wesnoth-icon.png,3,-4)"
558 "~MASK(wesnoth-icon.png,-3,4)"
559 "~MASK(wesnoth-icon.png,-3,-4)");
561 BOOST_CHECK_EQUAL(queue.
size(), 0);
567 environment_setup env_setup;
571 BOOST_CHECK_EQUAL(queue.
size(), 0);
580 environment_setup env_setup;
584 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
589 BOOST_REQUIRE(mod !=
nullptr);
597 environment_setup env_setup;
601 BOOST_CHECK_EQUAL(queue.
size(), 0);
607 environment_setup env_setup;
611 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
616 BOOST_REQUIRE(mod !=
nullptr);
618 BOOST_CHECK_EQUAL(mod->
get_w(), 3);
619 BOOST_CHECK_EQUAL(mod->
get_h(), 0);
625 environment_setup env_setup;
629 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
634 BOOST_REQUIRE(mod !=
nullptr);
636 BOOST_CHECK_EQUAL(mod->
get_w(), 4);
637 BOOST_CHECK_EQUAL(mod->
get_h(), 5);
643 environment_setup env_setup;
647 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
652 BOOST_REQUIRE(mod !=
nullptr);
661 environment_setup env_setup;
665 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
670 BOOST_REQUIRE(mod !=
nullptr);
679 environment_setup env_setup;
683 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
688 BOOST_REQUIRE(mod !=
nullptr);
696 environment_setup env_setup;
700 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
705 BOOST_REQUIRE(mod !=
nullptr);
713 environment_setup env_setup;
717 BOOST_REQUIRE_EQUAL(queue.
size(), 3);
719 for(
int i = 0;
i < 3;
i++) {
720 environment_setup env_setup;
725 BOOST_REQUIRE(mod !=
nullptr);
727 BOOST_CHECK_EQUAL(mod->
get_r(), 0);
728 BOOST_CHECK_EQUAL(mod->
get_g(), 0);
729 BOOST_CHECK_EQUAL(mod->
get_b(), 0);
738 environment_setup env_setup;
742 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
747 BOOST_REQUIRE(mod !=
nullptr);
749 BOOST_CHECK_EQUAL(mod->
get_r(), 123);
750 BOOST_CHECK_EQUAL(mod->
get_g(), 0);
751 BOOST_CHECK_EQUAL(mod->
get_b(), 0);
757 environment_setup env_setup;
761 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
766 BOOST_REQUIRE(mod !=
nullptr);
768 BOOST_CHECK_EQUAL(mod->
get_r(), 0);
769 BOOST_CHECK_EQUAL(mod->
get_g(), 132);
770 BOOST_CHECK_EQUAL(mod->
get_b(), 0);
776 environment_setup env_setup;
780 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
785 BOOST_REQUIRE(mod !=
nullptr);
787 BOOST_CHECK_EQUAL(mod->
get_r(), 0);
788 BOOST_CHECK_EQUAL(mod->
get_g(), 0);
789 BOOST_CHECK_EQUAL(mod->
get_b(), 312);
795 environment_setup env_setup;
799 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
804 BOOST_REQUIRE(mod !=
nullptr);
806 BOOST_CHECK_EQUAL(mod->
get_color().r, 0);
807 BOOST_CHECK_EQUAL(mod->
get_color().g, 0);
808 BOOST_CHECK_EQUAL(mod->
get_color().b, 0);
809 BOOST_CHECK_EQUAL(mod->
get_color().a, SDL_ALPHA_OPAQUE);
815 environment_setup env_setup;
819 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
824 BOOST_REQUIRE(mod !=
nullptr);
826 BOOST_CHECK_EQUAL(mod->
get_color().r, 1);
827 BOOST_CHECK_EQUAL(mod->
get_color().g, 0);
828 BOOST_CHECK_EQUAL(mod->
get_color().b, 0);
829 BOOST_CHECK_EQUAL(mod->
get_color().a, SDL_ALPHA_OPAQUE);
835 environment_setup env_setup;
839 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
844 BOOST_REQUIRE(mod !=
nullptr);
846 BOOST_CHECK_EQUAL(mod->
get_color().r, 1);
847 BOOST_CHECK_EQUAL(mod->
get_color().g, 2);
848 BOOST_CHECK_EQUAL(mod->
get_color().b, 0);
849 BOOST_CHECK_EQUAL(mod->
get_color().a, SDL_ALPHA_OPAQUE);
855 environment_setup env_setup;
859 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
864 BOOST_REQUIRE(mod !=
nullptr);
866 BOOST_CHECK_EQUAL(mod->
get_color().r, 1);
867 BOOST_CHECK_EQUAL(mod->
get_color().g, 2);
868 BOOST_CHECK_EQUAL(mod->
get_color().b, 3);
869 BOOST_CHECK_EQUAL(mod->
get_color().a, SDL_ALPHA_OPAQUE);
875 environment_setup env_setup;
879 BOOST_REQUIRE_EQUAL(queue.
size(), 1);
884 BOOST_REQUIRE(mod !=
nullptr);
886 BOOST_CHECK_EQUAL(mod->
get_color().r, 1);
887 BOOST_CHECK_EQUAL(mod->
get_color().g, 2);
888 BOOST_CHECK_EQUAL(mod->
get_color().b, 3);
889 BOOST_CHECK_EQUAL(mod->
get_color().a, 4);
892 BOOST_AUTO_TEST_SUITE_END()
A color range definition is made of four reference RGB colors, used for calculating conversions from ...
A config object defines a single node in a WML file, with access to child nodes.
config & add_child(config_key_type key)
A class grating read only view to a vector of config objects, viewed as one config with all children ...
static game_config_view wrap(const config &cfg)
Gaussian-like blur (BL) modification.
Scale (BLIT) modification.
const surface & get_surface() const
Crop (CROP) modification.
const SDL_Rect & get_slice() const
Color-shift (CS, R, G, B) modification.
Mirror (FL) modification.
Grayscale (GS) modification.
const surface & get_surface() const
Mask (MASK) modification.
const surface & get_mask() const
A modified priority queue used to order image modifications.
modification * top() const
Returns the top element in the queue .
void pop()
Removes the top element from the queue.
void push(std::unique_ptr< modification > mod)
Adds mod to the queue (unless mod is nullptr).
std::size_t size() const
Returns the number of elements in the queue.
Base abstract class for an image-path modification.
static modification_queue decode(const std::string &)
Decodes modifications from a modification string.
Opacity (O) modification.
float get_opacity() const
Recolor (RC/TC/PAL) modification.
const color_range_map & map() const
Scaling (SCALE[_INTO], SCALE[_INTO]_SHARP) modifications.
Helper class to redirect the output of the logger in a certain scope.
color_range_map recolor_range(const color_range &new_range, const std::vector< color_t > &old_rgb)
Converts a source palette using the specified color_range object.
std::unordered_map< color_t, color_t > color_range_map
Definitions for the interface to Wesnoth Markup Language (WML).
Declarations for File-IO.
std::string id
Text to match against addon_info.tags()
Standard logging facilities (interface).
const std::vector< color_t > & tc_info(std::string_view name)
const color_range & color_info(std::string_view name)
static void add_color_info(const game_config_view &v, bool build_defaults)
Functions to load and save images from/to disk.
The paths manager is responsible for recording the various paths that binary files may be located at.
Fill background with a color (BG).
const color_t & get_color() const
BOOST_AUTO_TEST_SUITE(filesystem)
BOOST_AUTO_TEST_CASE(test_modificaiton_queue_order)
Tests if modifications with a higher priority are placed before the others.