[lua] Test Image:flip() with sprite and without sprite (#3854)

This commit is contained in:
David Capello 2023-05-18 13:20:41 -03:00
parent ccc57800a8
commit 637d71a276
2 changed files with 22 additions and 8 deletions

View File

@ -26,6 +26,7 @@
#include "app/util/autocrop.h"
#include "app/util/resize_image.h"
#include "base/fs.h"
#include "doc/algorithm/flip_image.h"
#include "doc/algorithm/flip_type.h"
#include "doc/algorithm/shrink_bounds.h"
#include "doc/cel.h"
@ -585,12 +586,17 @@ int Image_flip(lua_State* L)
auto obj = get_obj<ImageObj>(L, 1);
doc::Image* img = obj->image(L);
doc::algorithm::FlipType flipType = doc::algorithm::FlipType::FlipHorizontal;
if (lua_isinteger(L, 2) && lua_tointeger(L, 2) > 0)
flipType = doc::algorithm::FlipType::FlipVertical;
if (lua_isinteger(L, 2))
flipType = (doc::algorithm::FlipType)lua_tointeger(L, 2);
if (obj->cel(L) == nullptr) {
doc::algorithm::flip_image(img, img->bounds(), flipType);
}
else {
Tx tx;
tx(new cmd::FlipImage(img, img->bounds(), flipType));
tx.commit();
}
return 0;
}

View File

@ -405,8 +405,7 @@ do
end
-- Tests for Image:flip()
do
local img = Image(3, 3)
function test_image_flip(img)
local r = Color(255, 0, 0).rgbaPixel
local g = Color(0, 255, 0).rgbaPixel
img:clear(0)
@ -420,6 +419,10 @@ do
expect_img(img, { 0, 0, g,
0, r, 0,
r, 0, 0 })
-- Without sprite, don't test undo
if not app.sprite then return end
app.undo()
expect_img(img, { g, 0, 0,
0, r, 0,
@ -443,3 +446,8 @@ do
0, r, 0,
0, 0, r })
end
local spr = Sprite(3, 3) -- Test with sprite (with transactions & undo/redo)
test_image_flip(app.image)
app.sprite = nil -- Test without sprite (without transactions)
test_image_flip(Image(3, 3))