mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
test: ++paint reference counting
This commit is contained in:
parent
16b985799a
commit
df8fc1949c
2 changed files with 92 additions and 0 deletions
|
@ -338,3 +338,50 @@ TEST_CASE("Paint LumaMask Composite Method", "[capiPaint]")
|
|||
|
||||
REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_CASE("Paint Reference Counter", "[capiPaint]")
|
||||
{
|
||||
Tvg_Paint* paint = tvg_shape_new();
|
||||
REQUIRE(tvg_paint_get_ref(paint) == 0);
|
||||
REQUIRE(tvg_paint_unref(paint, false) == 0);
|
||||
REQUIRE(tvg_paint_ref(paint) == 1);
|
||||
REQUIRE(tvg_paint_ref(paint) == 2);
|
||||
REQUIRE(tvg_paint_ref(paint) == 3);
|
||||
REQUIRE(tvg_paint_unref(paint, true) == 2);
|
||||
REQUIRE(tvg_paint_unref(paint, true) == 1);
|
||||
REQUIRE(tvg_paint_unref(paint, true) == 0);
|
||||
|
||||
tvg_engine_init(TVG_ENGINE_SW, 0);
|
||||
|
||||
Tvg_Canvas* canvas = tvg_swcanvas_create();
|
||||
|
||||
paint = tvg_shape_new();
|
||||
REQUIRE(tvg_paint_ref(paint) == 1);
|
||||
tvg_canvas_push(canvas, paint);
|
||||
REQUIRE(tvg_paint_get_ref(paint) == 2);
|
||||
tvg_canvas_clear(canvas, true, false);
|
||||
REQUIRE(tvg_paint_get_ref(paint) == 1);
|
||||
REQUIRE(tvg_paint_unref(paint, true) == 0);
|
||||
|
||||
paint = tvg_shape_new();
|
||||
REQUIRE(tvg_paint_ref(paint) == 1);
|
||||
Tvg_Paint* scene = tvg_scene_new();
|
||||
tvg_scene_push(scene, paint);
|
||||
tvg_canvas_push(canvas, scene);
|
||||
tvg_canvas_clear(canvas, true, false);
|
||||
REQUIRE(tvg_paint_get_ref(paint) == 1);
|
||||
REQUIRE(tvg_paint_unref(paint, true) == 0);
|
||||
|
||||
paint = tvg_shape_new();
|
||||
REQUIRE(tvg_paint_ref(paint) == 1);
|
||||
scene = tvg_scene_new();
|
||||
tvg_scene_push(scene, paint);
|
||||
tvg_scene_clear(scene, true);
|
||||
tvg_canvas_push(canvas, scene);
|
||||
tvg_canvas_clear(canvas, true, false);
|
||||
REQUIRE(tvg_paint_unref(paint, true) == 0);
|
||||
|
||||
tvg_canvas_destroy(canvas);
|
||||
|
||||
tvg_engine_term(TVG_ENGINE_SW);
|
||||
}
|
|
@ -286,4 +286,49 @@ TEST_CASE("Blending", "[tvgPaint]")
|
|||
|
||||
//SoftLight
|
||||
REQUIRE(shape->blend(BlendMethod::SoftLight) == Result::Success);
|
||||
}
|
||||
|
||||
TEST_CASE("Refernce Count", "[tvgPaint]")
|
||||
{
|
||||
auto shape = Shape::gen();
|
||||
REQUIRE(shape->refCnt() == 0);
|
||||
REQUIRE(shape->unref(false) == 0);
|
||||
REQUIRE(shape->ref() == 1);
|
||||
REQUIRE(shape->ref() == 2);
|
||||
REQUIRE(shape->ref() == 3);
|
||||
REQUIRE(shape->unref() == 2);
|
||||
REQUIRE(shape->unref() == 1);
|
||||
REQUIRE(shape->unref() == 0);
|
||||
|
||||
Initializer::init(0);
|
||||
|
||||
auto canvas = unique_ptr<SwCanvas>(SwCanvas::gen());
|
||||
|
||||
shape = Shape::gen();
|
||||
REQUIRE(shape->ref() == 1);
|
||||
canvas->push(shape);
|
||||
REQUIRE(shape->refCnt() == 2);
|
||||
canvas->clear();
|
||||
REQUIRE(shape->refCnt() == 1);
|
||||
REQUIRE(shape->unref() == 0);
|
||||
|
||||
shape = Shape::gen();
|
||||
REQUIRE(shape->ref() == 1);
|
||||
auto scene = Scene::gen();
|
||||
scene->push(shape);
|
||||
canvas->push(scene);
|
||||
canvas->clear();
|
||||
REQUIRE(shape->refCnt() == 1);
|
||||
REQUIRE(shape->unref() == 0);
|
||||
|
||||
shape = Shape::gen();
|
||||
REQUIRE(shape->ref() == 1);
|
||||
scene = Scene::gen();
|
||||
scene->push(shape);
|
||||
scene->clear();
|
||||
canvas->push(scene);
|
||||
canvas->clear();
|
||||
REQUIRE(shape->unref() == 0);
|
||||
|
||||
Initializer::term();
|
||||
}
|
Loading…
Add table
Reference in a new issue