From d10860cb3fc40afa3c734f4e12879cfb47af231b Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Sat, 11 Mar 2023 18:05:40 +0700 Subject: [PATCH] Fix style for `MemoryAPI` tests --- .../BaseRealm/API/Memory/Tests/MockActor.uc | 16 ++-- .../BaseRealm/API/Memory/Tests/MockObject.uc | 16 ++-- .../API/Memory/Tests/MockObjectNoPool.uc | 10 +- .../BaseRealm/API/Memory/Tests/TEST_Memory.uc | 94 ++++++++----------- 4 files changed, 60 insertions(+), 76 deletions(-) diff --git a/sources/BaseRealm/API/Memory/Tests/MockActor.uc b/sources/BaseRealm/API/Memory/Tests/MockActor.uc index fcdd541..f83ee79 100644 --- a/sources/BaseRealm/API/Memory/Tests/MockActor.uc +++ b/sources/BaseRealm/API/Memory/Tests/MockActor.uc @@ -1,7 +1,8 @@ /** - * Mock actor class for testing `MemoryAPI` and - * it's actor allocation/deallocation. - * Copyright 2020 Anton Tarasenko + * Author: dkanus + * Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore + * License: GPL + * Copyright 2020-2023 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -22,17 +23,14 @@ class MockActor extends AcediaActor; var public int actorCount; -protected function Constructor() -{ +protected function Constructor() { default.actorCount += 1; } -protected function Finalizer() -{ +protected function Finalizer() { default.actorCount -= 1; } -defaultproperties -{ +defaultproperties { actorCount = 0 } \ No newline at end of file diff --git a/sources/BaseRealm/API/Memory/Tests/MockObject.uc b/sources/BaseRealm/API/Memory/Tests/MockObject.uc index 1d22d72..db68666 100644 --- a/sources/BaseRealm/API/Memory/Tests/MockObject.uc +++ b/sources/BaseRealm/API/Memory/Tests/MockObject.uc @@ -1,7 +1,8 @@ /** - * Mock object class for testing `MemoryAPI` and - * it's object allocation/deallocation. - * Copyright 2020 Anton Tarasenko + * Author: dkanus + * Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore + * License: GPL + * Copyright 2020 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -22,17 +23,14 @@ class MockObject extends AcediaObject; var public int objectCount; -protected function Constructor() -{ +protected function Constructor() { default.objectCount += 1; } -protected function Finalizer() -{ +protected function Finalizer() { default.objectCount -= 1; } -defaultproperties -{ +defaultproperties { objectCount = 0 } \ No newline at end of file diff --git a/sources/BaseRealm/API/Memory/Tests/MockObjectNoPool.uc b/sources/BaseRealm/API/Memory/Tests/MockObjectNoPool.uc index 881c73e..4ac4b16 100644 --- a/sources/BaseRealm/API/Memory/Tests/MockObjectNoPool.uc +++ b/sources/BaseRealm/API/Memory/Tests/MockObjectNoPool.uc @@ -1,7 +1,8 @@ /** - * Mock object class for testing `MemoryAPI` and - * it's object allocation/deallocation. - * Copyright 2020 Anton Tarasenko + * Author: dkanus + * Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore + * License: GPL + * Copyright 2020 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -20,7 +21,6 @@ */ class MockObjectNoPool extends AcediaObject; -defaultproperties -{ +defaultproperties { usesObjectPool = false } \ No newline at end of file diff --git a/sources/BaseRealm/API/Memory/Tests/TEST_Memory.uc b/sources/BaseRealm/API/Memory/Tests/TEST_Memory.uc index 8a71b1d..e3a1fa8 100644 --- a/sources/BaseRealm/API/Memory/Tests/TEST_Memory.uc +++ b/sources/BaseRealm/API/Memory/Tests/TEST_Memory.uc @@ -1,7 +1,8 @@ /** - * Set of tests related to `MemoryAPI` class and the chain of events related to - * creating/destroying Acedia's objects / actors. - * Copyright 2020-2022 Anton Tarasenko + * Author: dkanus + * Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore + * License: GPL + * Copyright 2020-2023 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -21,8 +22,7 @@ class TEST_Memory extends TestCase abstract; -protected static function TESTS() -{ +protected static function TESTS() { Test_ObjectConstructorsFinalizers(); Test_ActorConstructorsFinalizers(); Test_ObjectPoolUsage(); @@ -30,24 +30,21 @@ protected static function TESTS() Test_RefCounting(); } -protected static function Test_LifeVersionIsUnique() -{ - local int i, j; - local int nextVersion; - local MockObject obj; - local array objectVersions; - local bool versionsRepeated; - // Deallocate and reallocate same object/actor a bunch of times and - // ensure that every single time a unique number is returned. - // Not a comprehensive test of uniqueness, but such is impossible. - for (i = 0; i < 1000 && !versionsRepeated; i += 1) - { +protected static function Test_LifeVersionIsUnique() { + local int i, j; + local int nextVersion; + local MockObject obj; + local array objectVersions; + local bool versionsRepeated; + + // Deallocate and reallocate same object/actor a bunch of times and + // ensure that every single time a unique number is returned. + // Not a comprehensive test of uniqueness, but such is impossible. + for (i = 0; i < 1000 && !versionsRepeated; i += 1) { obj = MockObject(__().memory.Allocate(class'MockObject')); nextVersion = obj.GetLifeVersion(); - for (j = 0; j < objectVersions.length; j += 1) - { - if (nextVersion == objectVersions[j]) - { + for (j = 0; j < objectVersions.length; j += 1) { + if (nextVersion == objectVersions[j]) { versionsRepeated = true; break; } @@ -61,11 +58,10 @@ protected static function Test_LifeVersionIsUnique() TEST_ExpectFalse(versionsRepeated); } -protected static function Test_ObjectConstructorsFinalizers() -{ +protected static function Test_ObjectConstructorsFinalizers() { local MockObject obj1, obj2; - Context("Testing that Acedia object's constructors and finalizers are" - @ "called properly."); + + Context("Testing that Acedia object's constructors and finalizers are called properly."); Issue("Object's constructor is not called."); class'MockObject'.default.objectCount = 0; obj1 = MockObject(__().memory.Allocate(class'MockObject')); @@ -92,11 +88,10 @@ protected static function Test_ObjectConstructorsFinalizers() TEST_ExpectTrue(class'MockObject'.default.objectCount == 0); } -protected static function Test_ActorConstructorsFinalizers() -{ +protected static function Test_ActorConstructorsFinalizers() { local MockActor act1, act2; - Context("Testing that Acedia actor's constructors and finalizers are" - @ "called properly."); + + Context("Testing that Acedia actor's constructors and finalizers are called properly."); Issue("Actor's constructor is not called."); act1 = MockActor(__core().GetLevelCore().Allocate(class'MockActor')); TEST_ExpectTrue(class'MockActor'.default.actorCount == 1); @@ -115,33 +110,29 @@ protected static function Test_ActorConstructorsFinalizers() TEST_ExpectTrue(class'MockActor'.default.actorCount == 0); } -protected static function Test_ObjectPoolUsage() -{ - local bool allocatedNewObject; - local int i, j; - local MockObject temp; +protected static function Test_ObjectPoolUsage() { + local bool allocatedNewObject; + local int i, j; + local MockObject temp; local array objects; - local MockObjectNoPool obj1, obj2; + local MockObjectNoPool obj1, obj2; + Context("Testing usage of object pools by `MockObject`s."); Issue("Object pool is not utilized enough."); - for (i = 0; i < 200; i += 1) - { + for (i = 0; i < 200; i += 1) { objects[objects.length] = MockObject(__().memory.Allocate(class'MockObject')); } for (i = 0; i < 200; i += 1) { __().memory.Free(objects[i]); } - for (i = 0; i < 200; i += 1) - { + for (i = 0; i < 200; i += 1) { temp = MockObject(__().memory.Allocate(class'MockObject')); // Have to find just allocated object among already free ones j = 0; allocatedNewObject = true; - while (j < objects.length) - { - if (objects[j] == temp) - { + while (j < objects.length) { + if (objects[j] == temp) { allocatedNewObject = false; objects.Remove(j, 1); break; @@ -161,18 +152,16 @@ protected static function Test_ObjectPoolUsage() TEST_ExpectTrue(obj1 != obj2); } -protected static function Test_RefCounting() -{ +protected static function Test_RefCounting() { Context("Testing usage of reference counting."); SubTest_RefCountingObjectFreeSelf(); SubTest_RefCountingObjectFree(); } -protected static function SubTest_RefCountingObjectFreeSelf() -{ +protected static function SubTest_RefCountingObjectFreeSelf() { local MockObject temp; - Issue("Reference counting for `AcediaObject`s does not work correctly" - @ "with `FreeSelf()`"); + + Issue("Reference counting for `AcediaObject`s does not work correctly with `FreeSelf()`"); temp = MockObject(__().memory.Allocate(class'MockObject')); temp.NewRef().NewRef().NewRef(); TEST_ExpectTrue(temp._getRefCount() == 4); @@ -191,9 +180,9 @@ protected static function SubTest_RefCountingObjectFreeSelf() TEST_ExpectFalse(temp.IsAllocated()); } -protected static function SubTest_RefCountingObjectFree() -{ +protected static function SubTest_RefCountingObjectFree() { local MockObject temp; + Issue("Reference counting for `AcediaObject`s does not work correctly" @ "with `__().memory.Free()`"); temp = MockObject(__().memory.Allocate(class'MockObject')); @@ -214,8 +203,7 @@ protected static function SubTest_RefCountingObjectFree() TEST_ExpectFalse(temp.IsAllocated()); } -defaultproperties -{ +defaultproperties { caseGroup = "Memory" caseName = "AllocationDeallocation" } \ No newline at end of file