From 13767cdea0e4b29ad33b0b98e997d3174e22c57d Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sat, 9 Feb 2019 18:10:44 +0700 Subject: [PATCH] little more code coverage --- untests/sources/untests_high/actor.cpp | 33 +++++++++++++++++++++++++- untests/sources/untests_high/node.cpp | 27 +++++++++++++++++++++ untests/sources/untests_high/scene.cpp | 10 ++++++++ untests/sources/untests_high/world.cpp | 16 +++++++++++-- untests/sources/untests_math/rect.cpp | 4 ++++ 5 files changed, 87 insertions(+), 3 deletions(-) diff --git a/untests/sources/untests_high/actor.cpp b/untests/sources/untests_high/actor.cpp index 7f0918c6..d4e0cf56 100644 --- a/untests/sources/untests_high/actor.cpp +++ b/untests/sources/untests_high/actor.cpp @@ -7,5 +7,36 @@ #include "_high.hpp" using namespace e2d; -TEST_CASE("actor") { +namespace +{ + class safe_starter_initializer final : private noncopyable { + public: + safe_starter_initializer() { + modules::initialize(0, nullptr, + starter::parameters( + engine::parameters("world_untests", "enduro2d") + .without_graphics(true))); + } + + ~safe_starter_initializer() noexcept { + modules::shutdown(); + } + }; +} + +TEST_CASE("actor") { + safe_starter_initializer initializer; + world& w = the(); + SECTION("ctor") { + auto a = actor::create(w.registry().create_entity()); + REQUIRE(w.registry().alive_entity(a->entity())); + { + const_actor_iptr ca = a; + REQUIRE(w.registry().alive_entity(ca->entity())); + } + } + SECTION("as_node") { + auto a = actor::create(w.registry().create_entity()); + w.scene()->root()->add_child(a); + } } diff --git a/untests/sources/untests_high/node.cpp b/untests/sources/untests_high/node.cpp index b752cda1..b57d6c68 100644 --- a/untests/sources/untests_high/node.cpp +++ b/untests/sources/untests_high/node.cpp @@ -391,6 +391,16 @@ TEST_CASE("node") { } SECTION("last_child/first_child") { auto p = node::create(); + + REQUIRE_FALSE(p->last_child()); + REQUIRE_FALSE(p->first_child()); + + { + const_node_iptr cp = p; + REQUIRE_FALSE(cp->last_child()); + REQUIRE_FALSE(cp->first_child()); + } + auto n1 = node::create(p); auto n2 = node::create(p); auto n3 = node::create(p); @@ -817,6 +827,23 @@ TEST_CASE("node") { REQUIRE(fake_node::s_parent_changes == 6); REQUIRE(fake_node::s_children_changes == 4); } + SECTION("transform") { + auto p = node::create(); + + REQUIRE(p->transform() == t3f::identity()); + REQUIRE(p->translation() == v3f::zero()); + REQUIRE(p->rotation() == q4f::identity()); + REQUIRE(p->scale() == v3f::unit()); + + p->translation(v3f(1,2,3)); + REQUIRE(p->translation() == v3f(1,2,3)); + + p->rotation(q4f(1,2,3,4)); + REQUIRE(p->rotation() == q4f(1,2,3,4)); + + p->scale(v3f(1,2,3)); + REQUIRE(p->scale() == v3f(1,2,3)); + } SECTION("local_matrix") { { auto p = node::create(); diff --git a/untests/sources/untests_high/scene.cpp b/untests/sources/untests_high/scene.cpp index b8ca6bfb..ec3b52e2 100644 --- a/untests/sources/untests_high/scene.cpp +++ b/untests/sources/untests_high/scene.cpp @@ -8,4 +8,14 @@ using namespace e2d; TEST_CASE("scene") { + SECTION("ctor") { + auto s = scene::create(); + REQUIRE(s); + REQUIRE(s->root()); + + { + const_scene_iptr cs = s; + REQUIRE(cs->root()); + } + } } diff --git a/untests/sources/untests_high/world.cpp b/untests/sources/untests_high/world.cpp index 7f3fd385..907843cc 100644 --- a/untests/sources/untests_high/world.cpp +++ b/untests/sources/untests_high/world.cpp @@ -24,8 +24,20 @@ namespace }; } -TEST_CASE("world"){ +TEST_CASE("world") { safe_starter_initializer initializer; world& w = the(); - REQUIRE(w.scene()); + const world& cw = w; + + SECTION("scene") { + REQUIRE(w.scene()); + REQUIRE(cw.scene()); + } + + SECTION("registry") { + auto e = w.registry().create_entity(); + REQUIRE(cw.registry().alive_entity(e)); + REQUIRE(w.registry().destroy_entity(e)); + REQUIRE_FALSE(cw.registry().alive_entity(e)); + } } diff --git a/untests/sources/untests_math/rect.cpp b/untests/sources/untests_math/rect.cpp index 6f3b9a43..3e566ed9 100644 --- a/untests/sources/untests_math/rect.cpp +++ b/untests/sources/untests_math/rect.cpp @@ -8,6 +8,10 @@ using namespace e2d; TEST_CASE("rect") { + { + REQUIRE(b2i::zero() == b2i(0,0,0,0)); + REQUIRE(b2i::unit() == b2i(0,0,1,1)); + } { REQUIRE(b2i().position == v2i(0,0)); REQUIRE(b2i().size == v2i(0,0));