Test runner #7

Merged
Mergul merged 6 commits from TestRunner into master 2020-04-25 10:19:17 +02:00
2 changed files with 288 additions and 3 deletions
Showing only changes of commit d0b7138f9f - Show all commits

View file

@ -2085,6 +2085,7 @@ export struct EntityManager
{ {
num--; num--;
new_ids[i] = new_ids[num]; new_ids[i] = new_ids[num];
data_pointers[i] = data_pointers[num];
} }
} }
@ -2558,6 +2559,7 @@ export struct EntityManager
pointers[i] = &thread.change_entities_list[index]; pointers[i] = &thread.change_entities_list[index];
index += components[ids[i]].size; index += components[ids[i]].size;
} }
__addComponents(id, ids, pointers[0 .. num]); __addComponents(id, ids, pointers[0 .. num]);
} }
} }

View file

@ -101,7 +101,7 @@ struct EmptySystem
void beforeEveryTest() void beforeEveryTest()
{ {
gEM.initialize(1); gEM.initialize(0);
gEM.beginRegister(); gEM.beginRegister();
@ -493,11 +493,10 @@ unittest
gEM.end(); gEM.end();
} }
@("SystemEntityCallbacks") @("SystemEntityCallbacks")
unittest unittest
{ {
//TODO: this test is WIP by now
struct TestSystem struct TestSystem
{ {
mixin ECS.System!16; mixin ECS.System!16;
@ -569,4 +568,288 @@ unittest
assert(system.add == 2); assert(system.add == 2);
gEM.commit(); gEM.commit();
}
@("TemplateCoverage")
unittest
{
struct TestSystem
{
mixin ECS.System;
struct EntitiesData
{
int length;
Entity[] entity;
@readonly CLong[] long_;
@optional CInt[] int_;
@readonly CFloat[] float_;
}
mixin ECS.ExcludedComponents!(CUnregistered);
void onUpdate(EntitiesData data)
{
}
}
gEM.beginRegister();
gEM.registerComponent!CUnregistered;
gEM.registerSystem!TestSystem(0);
gEM.endRegister();
}
@("UnregisteredSystem")
unittest
{
struct TestSystem
{
mixin ECS.System;
struct EntitiesData
{
int length;
Entity[] entity;
@readonly CLong[] long_;
@optional CInt[] int_;
@readonly CFloat[] float_;
}
void onUpdate(EntitiesData data)
{
}
}
assert(gEM.getSystem!TestSystem is null);
assert(gEM.getSystem(TestSystem.system_id) is null);
}
@("MultithreadedUpdate")
unittest
{
struct TestSystem
{
mixin ECS.System;
struct EntitiesData
{
int length;
Entity[] entity;
@readonly CLong[] long_;
@optional CInt[] int_;
@readonly CFloat[] float_;
}
void onUpdate(EntitiesData data)
{
update++;
entities += data.length;
}
int update = 0;
int entities = 0;
}
struct TestEmptySystem
{
mixin ECS.System;
struct EntitiesData
{
int length;
}
void onUpdate(EntitiesData data)
{
update++;
}
int update = 0;
}
void dispatch(EntityManager.JobGroup grp)
{
foreach(job; grp.jobs)
{
job.execute();
}
}
uint getID()
{
return 0;
}
gEM.setMultithreadingCallbacks(&dispatch, &getID);
gEM.beginRegister();
gEM.registerPass("custom");
gEM.registerSystem!TestSystem(-1,"custom");
gEM.registerSystem!TestEmptySystem(1,"custom");
gEM.endRegister();
TestSystem* system = gEM.getSystem!TestSystem;
TestEmptySystem* empty_system = gEM.getSystem!TestEmptySystem;
gEM.begin();
gEM.updateMT("custom");
gEM.end();
assert(system.update == 0);
assert(system.entities == 0);
assert(empty_system.update == 1);
ushort[2] ids = [CLong.component_id,CFloat.component_id];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
scope (exit) gEM.freeTemplate(tmpl);
gEM.addEntity(tmpl);
gEM.begin();
gEM.updateMT("custom");
gEM.end();
assert(system.update == 1);
assert(system.entities == 1);
assert(empty_system.update == 2);
system.entities = 0;
foreach(i;0..2000)gEM.addEntity(tmpl);
gEM.begin();
gEM.updateMT("custom");
gEM.end();
assert(system.update > 2);
assert(system.entities == 2001);
assert(empty_system.update == 3);
system.entities = 0;
foreach(i;0..10000)gEM.addEntity(tmpl);
gEM.begin();
gEM.updateMT("custom");
gEM.end();
assert(system.entities == 12001);
}
unittest
{
assert(gEM.pageSize == 32768);
assert(gEM.pagesInBlock == 128);
}
@("AddRemoveEntities")
unittest
{
ushort[3] ids = [CLong.component_id,CFloat.component_id,CShort.component_id];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
scope (exit) gEM.freeTemplate(tmpl);
EntityID[5000] entities;
foreach(i;0..4)
{
foreach(j;0..5000)
{
entities[j] = gEM.addEntity(tmpl).id;
}
gEM.commit();
foreach(j;0..5000)
{
gEM.removeEntity(entities[j]);
}
gEM.commit();
}
}
@("ChangeEntityComponents")
unittest
{
gEM.beginRegister();
gEM.registerComponent!CUnregistered;
gEM.endRegister();
ushort[1] ids = [CLong.component_id];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
scope (exit) gEM.freeTemplate(tmpl);
EntityID id = gEM.addEntity(tmpl).id;
gEM.commit();
Entity* entity = gEM.getEntity(id);
assert(entity.id == id);
assert(entity.getComponent!CLong !is null);
assert(entity.getComponent!CFloat is null);
assert(entity.getComponent!CUnregistered is null);
assert(entity.getComponent!CShort is null);
assert(entity.getComponent!CInt is null);
assert(*entity.getComponent!CLong == 10);
gEM.addComponents(id, CShort(15), CFloat(13));
gEM.commit();
entity = gEM.getEntity(id);
assert(entity.id == id);
assert(entity.getComponent!CLong !is null);
assert(entity.getComponent!CFloat !is null);
assert(entity.getComponent!CUnregistered is null);
assert(entity.getComponent!CShort !is null);
assert(entity.getComponent!CInt is null);
assert(*entity.getComponent!CLong == 10);
assert(*entity.getComponent!CShort == 15);
assert(*entity.getComponent!CFloat == 13);
ushort[3] ids2 = [CFloat.component_id, CLong.component_id, CUnregistered.component_id];
gEM.removeComponents(id, ids2);
gEM.commit();
entity = gEM.getEntity(id);
assert(entity.id == id);
assert(entity.getComponent!CLong is null);
assert(entity.getComponent!CFloat is null);
assert(entity.getComponent!CUnregistered is null);
assert(entity.getComponent!CShort !is null);
assert(entity.getComponent!CInt is null);
assert(*entity.getComponent!CShort == 15);
gEM.removeComponents(id, ids2);
gEM.addComponents(id, CShort(11), CLong(2)); //wrong order of components
gEM.commit();
entity = gEM.getEntity(id);
assert(entity.id == id);
assert(entity.getComponent!CLong !is null);
assert(entity.getComponent!CFloat is null);
assert(entity.getComponent!CUnregistered is null);
assert(entity.getComponent!CShort !is null);
assert(entity.getComponent!CInt is null);
assert(*entity.getComponent!CLong == 2);
assert(*entity.getComponent!CShort == 15);
gEM.removeEntity(id);
entity = gEM.getEntity(id);
assert(entity !is null);
assert(entity.id == id);
gEM.commit();
entity = gEM.getEntity(id);
assert(entity is null);
} }