mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-16 10:20:50 +00:00
Fix memory leaks in some tests found with LeakSanitizer
This commit is contained in:
parent
b212a24479
commit
d16c34b247
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -13,6 +14,8 @@ using namespace app;
|
||||
|
||||
TEST(IniFile, Basic)
|
||||
{
|
||||
ConfigModule cm;
|
||||
|
||||
if (base::is_file("_test.ini"))
|
||||
base::delete_file("_test.ini");
|
||||
|
||||
@ -36,6 +39,8 @@ TEST(IniFile, Basic)
|
||||
|
||||
TEST(IniFile, PushPop)
|
||||
{
|
||||
ConfigModule cm;
|
||||
|
||||
if (base::is_file("_a.ini")) base::delete_file("_a.ini");
|
||||
if (base::is_file("_b.ini")) base::delete_file("_b.ini");
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2022 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -13,6 +14,7 @@
|
||||
#include "doc/algorithm/resize_image.h"
|
||||
#include "doc/color.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/image_ref.h"
|
||||
#include "doc/primitives.h"
|
||||
|
||||
using namespace std;
|
||||
@ -56,41 +58,46 @@ color_t test_image_scaled_9x9_bilinear[81] =
|
||||
0x000000, 0x000000, 0x565656, 0xa9a9a9, 0xffffff, 0xa9a9a9, 0x565656, 0x000000, 0x000000
|
||||
};
|
||||
|
||||
Image* create_image_from_data(PixelFormat format, color_t* data, int width, int height)
|
||||
ImageRef create_image_from_data(PixelFormat format, color_t* data, int width, int height)
|
||||
{
|
||||
Image* new_image = Image::create(format, width, height);
|
||||
ImageRef new_image(Image::create(format, width, height));
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
new_image->putPixel(i % width, i / width, data[i]);
|
||||
}
|
||||
|
||||
return new_image;
|
||||
}
|
||||
|
||||
TEST(ResizeImage, NearestNeighborInterp)
|
||||
{
|
||||
Image* src = create_image_from_data(IMAGE_RGB, test_image_base_3x3, 3, 3);
|
||||
Image* dst_expected = create_image_from_data(IMAGE_RGB, test_image_scaled_9x9_nearest, 9, 9);
|
||||
ImageRef src(create_image_from_data(IMAGE_RGB, test_image_base_3x3, 3, 3));
|
||||
ImageRef dst_expected(create_image_from_data(IMAGE_RGB, test_image_scaled_9x9_nearest, 9, 9));
|
||||
|
||||
Image* dst = Image::create(IMAGE_RGB, 9, 9);
|
||||
algorithm::resize_image(src, dst, algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR, NULL, NULL, -1);
|
||||
ImageRef dst(Image::create(IMAGE_RGB, 9, 9));
|
||||
algorithm::resize_image(src.get(), dst.get(),
|
||||
algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR,
|
||||
nullptr, nullptr, -1);
|
||||
|
||||
ASSERT_EQ(0, count_diff_between_images(dst, dst_expected));
|
||||
ASSERT_EQ(0, count_diff_between_images(dst.get(), dst_expected.get()));
|
||||
|
||||
Image* dst2 = Image::create(IMAGE_RGB, 3, 3);
|
||||
algorithm::resize_image(dst, dst2, algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR, NULL, NULL, -1);
|
||||
ASSERT_EQ(0, count_diff_between_images(src, dst2));
|
||||
ImageRef dst2(Image::create(IMAGE_RGB, 3, 3));
|
||||
algorithm::resize_image(dst.get(), dst2.get(),
|
||||
algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR,
|
||||
nullptr, nullptr, -1);
|
||||
ASSERT_EQ(0, count_diff_between_images(src.get(), dst2.get()));
|
||||
}
|
||||
|
||||
#if 0 // TODO complete this test
|
||||
TEST(ResizeImage, BilinearInterpRGBType)
|
||||
{
|
||||
Image* src = create_image_from_data(IMAGE_RGB, test_image_base_3x3, 3, 3);
|
||||
Image* dst_expected = create_image_from_data(IMAGE_RGB, test_image_scaled_9x9_bilinear, 9, 9);
|
||||
ImageRef src(create_image_from_data(IMAGE_RGB, test_image_base_3x3, 3, 3));
|
||||
ImageRef dst_expected(create_image_from_data(IMAGE_RGB, test_image_scaled_9x9_bilinear, 9, 9));
|
||||
|
||||
Image* dst = Image::create(IMAGE_RGB, 9, 9);
|
||||
algorithm::resize_image(src, dst, algorithm::RESIZE_METHOD_BILINEAR, NULL, NULL);
|
||||
ImageRef dst(Image::create(IMAGE_RGB, 9, 9));
|
||||
algorithm::resize_image(src.get(), dst.get(),
|
||||
algorithm::RESIZE_METHOD_BILINEAR,
|
||||
nullptr, nullptr, -1);
|
||||
|
||||
ASSERT_EQ(0, count_diff_between_images(dst, dst_expected));
|
||||
ASSERT_EQ(0, count_diff_between_images(dst.get(), dst_expected.get()));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2018-2019 Igara Studio S.A.
|
||||
// Copyright (c) 2018-2022 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -17,11 +17,15 @@
|
||||
#include "doc/pixel_format.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace doc;
|
||||
|
||||
TEST(Sprite, Layers)
|
||||
{
|
||||
Sprite* spr = new Sprite(ImageSpec(ColorMode::RGB, 32, 32), 256);
|
||||
std::shared_ptr<Sprite> sprPtr(std::make_shared<Sprite>(
|
||||
ImageSpec(ColorMode::RGB, 32, 32), 256));
|
||||
Sprite* spr = sprPtr.get();
|
||||
|
||||
LayerImage* lay1 = new LayerImage(spr);
|
||||
LayerImage* lay2 = new LayerImage(spr);
|
||||
@ -90,7 +94,9 @@ TEST(Sprite, Layers)
|
||||
// - lay3: F G~H
|
||||
TEST(Sprite, CelsRange)
|
||||
{
|
||||
Sprite* spr = new Sprite(ImageSpec(ColorMode::RGB, 32, 32), 256);
|
||||
std::shared_ptr<Sprite> sprPtr(std::make_shared<Sprite>(
|
||||
ImageSpec(ColorMode::RGB, 32, 32), 256));
|
||||
Sprite* spr = sprPtr.get();
|
||||
spr->setTotalFrames(3);
|
||||
|
||||
LayerImage* lay1 = new LayerImage(spr);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2019 Igara Studio S.A.
|
||||
// Copyright (c) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -66,7 +66,7 @@ TYPED_TEST_CASE(RenderAllModes, ImageAllTraits);
|
||||
|
||||
TEST(Render, Basic)
|
||||
{
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::INDEXED, 2, 2)));
|
||||
|
||||
Image* src = doc->sprite()->root()->firstLayer()->cel(0)->image();
|
||||
@ -85,7 +85,7 @@ TYPED_TEST(RenderAllModes, CheckDefaultBackgroundMode)
|
||||
{
|
||||
typedef TypeParam ImageTraits;
|
||||
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ImageTraits::color_mode, 2, 2)));
|
||||
|
||||
EXPECT_TRUE(!doc->sprite()->root()->firstLayer()->isBackground());
|
||||
@ -105,7 +105,7 @@ TYPED_TEST(RenderAllModes, CheckDefaultBackgroundMode)
|
||||
|
||||
TEST(Render, DefaultBackgroundModeWithNonzeroTransparentIndex)
|
||||
{
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::INDEXED, 2, 2)));
|
||||
doc->sprite()->setTransparentColor(2); // Transparent color is index 2
|
||||
|
||||
@ -133,7 +133,7 @@ TEST(Render, DefaultBackgroundModeWithNonzeroTransparentIndex)
|
||||
|
||||
TEST(Render, CheckedBackground)
|
||||
{
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::INDEXED, 4, 4)));
|
||||
|
||||
std::unique_ptr<Image> dst(Image::create(IMAGE_INDEXED, 4, 4));
|
||||
@ -185,7 +185,7 @@ TEST(Render, ZoomAndDstBounds)
|
||||
// 0 0 0
|
||||
// 0 4 4
|
||||
// 0 4 4
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::INDEXED, 3, 3)));
|
||||
Image* src = doc->sprite()->root()->firstLayer()->cel(0)->image();
|
||||
clear_image(src, 0);
|
||||
@ -213,7 +213,7 @@ TEST(Render, ZoomAndDstBounds)
|
||||
|
||||
TEST(Render, BugWithMultiplesOf3ZoomFactors)
|
||||
{
|
||||
Document* doc = new Document;
|
||||
std::shared_ptr<Document> doc = std::make_shared<Document>();
|
||||
doc->sprites().add(Sprite::MakeStdSprite(ImageSpec(ColorMode::RGB, 4, 4)));
|
||||
Image* src = doc->sprite()->root()->firstLayer()->cel(0)->image();
|
||||
clear_image(src, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user