test(datamodel): destruction
This commit is contained in:
parent
fc52e2625c
commit
b61362cc07
2 changed files with 31 additions and 0 deletions
|
|
@ -15,12 +15,15 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
int _dbgDataModelDestroyCount = 0;
|
||||||
|
|
||||||
DataModel::DataModel()
|
DataModel::DataModel()
|
||||||
: Instance(&TYPE) {
|
: Instance(&TYPE) {
|
||||||
this->name = "Place";
|
this->name = "Place";
|
||||||
}
|
}
|
||||||
|
|
||||||
DataModel::~DataModel() {
|
DataModel::~DataModel() {
|
||||||
|
_dbgDataModelDestroyCount++;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
printf("Datamodel successfully destroyed\n");
|
printf("Datamodel successfully destroyed\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
28
tests/src/objectmodel/datamodel.cpp
Normal file
28
tests/src/objectmodel/datamodel.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#include "objects/datamodel.h"
|
||||||
|
#include "objects/script.h"
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
|
extern int _dbgDataModelDestroyCount;
|
||||||
|
|
||||||
|
TEST_CASE("Datamodel destruction") {
|
||||||
|
// Ensure no cyclic-dependency causing datamodel to not be destructed
|
||||||
|
|
||||||
|
auto root = DataModel::New();
|
||||||
|
root->Init(true);
|
||||||
|
|
||||||
|
SECTION("Empty model") {
|
||||||
|
int prevCount = _dbgDataModelDestroyCount;
|
||||||
|
root = nullptr;
|
||||||
|
REQUIRE(_dbgDataModelDestroyCount == prevCount + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Model with script") {
|
||||||
|
auto s = Script::New();
|
||||||
|
root->AddChild(s);
|
||||||
|
s->source = "local x = game; wait(0)";
|
||||||
|
s->Run();
|
||||||
|
int prevCount = _dbgDataModelDestroyCount;
|
||||||
|
root = nullptr;
|
||||||
|
REQUIRE(_dbgDataModelDestroyCount == prevCount + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue