2020-09-29 13:47:50 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <mm/engine.hpp>
|
|
|
|
#include <mm/services/simple_scene.hpp>
|
|
|
|
#include <entt/entity/registry.hpp>
|
|
|
|
|
|
|
|
TEST(simple_scene, add_en_dis) {
|
2020-12-26 19:29:39 +01:00
|
|
|
MM::Engine engine;
|
2020-09-29 13:47:50 +02:00
|
|
|
|
2020-12-26 19:29:39 +01:00
|
|
|
engine.addService<MM::Services::SimpleSceneService>();
|
2020-09-29 13:47:50 +02:00
|
|
|
|
2020-12-26 19:29:39 +01:00
|
|
|
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
|
2020-09-29 13:47:50 +02:00
|
|
|
|
|
|
|
{
|
2020-12-26 19:29:39 +01:00
|
|
|
auto* sss = engine.tryService<MM::Services::SimpleSceneService>();
|
2020-09-29 13:47:50 +02:00
|
|
|
ASSERT_NE(sss, nullptr);
|
|
|
|
|
|
|
|
auto& s = sss->getScene();
|
|
|
|
auto e = s.create();
|
|
|
|
ASSERT_TRUE(s.valid(e));
|
|
|
|
}
|
|
|
|
|
2020-12-26 19:29:39 +01:00
|
|
|
engine.disableService<MM::Services::SimpleSceneService>();
|
2020-09-29 13:47:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(simple_scene, add_en_dis_provide) {
|
2020-12-26 19:29:39 +01:00
|
|
|
MM::Engine engine;
|
2020-09-29 13:47:50 +02:00
|
|
|
|
2020-12-26 19:29:39 +01:00
|
|
|
engine.addService<MM::Services::SimpleSceneService>();
|
|
|
|
engine.provide<MM::Services::SceneServiceInterface, MM::Services::SimpleSceneService>();
|
2020-09-29 13:47:50 +02:00
|
|
|
|
2020-12-26 19:29:39 +01:00
|
|
|
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
|
2020-09-29 13:47:50 +02:00
|
|
|
|
|
|
|
{
|
2020-12-26 19:29:39 +01:00
|
|
|
auto* ssi = engine.tryService<MM::Services::SceneServiceInterface>();
|
2020-09-29 13:47:50 +02:00
|
|
|
ASSERT_NE(ssi, nullptr);
|
|
|
|
|
|
|
|
auto& s = ssi->getScene();
|
|
|
|
auto e = s.create();
|
|
|
|
ASSERT_TRUE(s.valid(e));
|
|
|
|
}
|
|
|
|
|
2020-12-26 19:29:39 +01:00
|
|
|
engine.disableService<MM::Services::SimpleSceneService>();
|
2020-09-29 13:47:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(simple_scene, change_scene) {
|
|
|
|
MM::Engine engine;
|
|
|
|
|
|
|
|
engine.addService<MM::Services::SimpleSceneService>();
|
|
|
|
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
|
|
|
|
|
|
|
|
{
|
|
|
|
auto* sss = engine.tryService<MM::Services::SimpleSceneService>();
|
|
|
|
ASSERT_NE(sss, nullptr);
|
|
|
|
|
|
|
|
auto e = sss->getScene().create();
|
|
|
|
ASSERT_TRUE(sss->getScene().valid(e));
|
|
|
|
|
|
|
|
sss->changeScene(std::make_unique<MM::Scene>());
|
|
|
|
|
|
|
|
ASSERT_TRUE(sss->getScene().valid(e));
|
|
|
|
|
2020-12-26 19:29:39 +01:00
|
|
|
//engine.fixedUpdate();
|
2021-04-24 02:03:11 +02:00
|
|
|
engine.getUpdateStrategy().addDeferred([](MM::Engine& eng) {eng.stop();});
|
2020-12-26 19:29:39 +01:00
|
|
|
engine.run();
|
2020-09-29 13:47:50 +02:00
|
|
|
|
|
|
|
ASSERT_FALSE(sss->getScene().valid(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
engine.disableService<MM::Services::SimpleSceneService>();
|
|
|
|
}
|
|
|
|
|