From d6e293c06e1bbda8bb5b78cb7b6440384f74283d Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Sun, 14 Nov 2021 02:28:15 +0700 Subject: [PATCH] Add test for deallocating keys in AssociativeArray --- .../Tests/TEST_AssociativeArray.uc | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/sources/Data/Collections/Tests/TEST_AssociativeArray.uc b/sources/Data/Collections/Tests/TEST_AssociativeArray.uc index 2c30c59..bbc9ec0 100644 --- a/sources/Data/Collections/Tests/TEST_AssociativeArray.uc +++ b/sources/Data/Collections/Tests/TEST_AssociativeArray.uc @@ -160,12 +160,18 @@ protected static function Test_CopyTextKeys() } protected static function Test_Remove() +{ + Context("Testing removing elements from `AssociativeArray`."); + SubTest_RemoveWithoutKeys(); + SubTest_RemoveWithKeys(); +} + +protected static function SubTest_RemoveWithoutKeys() { local AcediaObject key1, key2, key3; local array keys; local AssociativeArray array; array = AssociativeArray(__().memory.Allocate(class'AssociativeArray')); - Context("Testing removing elements from `AssociativeArray`."); key1 = __().text.FromString("some key"); key2 = __().box.int(25); key3 = __().box.float(0.07); @@ -180,6 +186,38 @@ protected static function Test_Remove() TEST_ExpectTrue(array.GetLength() == 1); TEST_ExpectTrue(keys.length == 1); TEST_ExpectTrue(keys[0] == key3); + + Issue("Keys are deallocated upon removing elements from `AssociativeArray`" + @ "when they should not."); + TEST_ExpectTrue(key1.IsAllocated()); + TEST_ExpectTrue(key2.IsAllocated()); +} + +protected static function SubTest_RemoveWithKeys() +{ + local AcediaObject key1, key2, key3; + local array keys; + local AssociativeArray array; + array = AssociativeArray(__().memory.Allocate(class'AssociativeArray')); + key1 = __().text.FromString("some key"); + key2 = __().box.int(25); + key3 = __().box.float(0.07); + array.SetItem(key1, __().text.FromString("value")); + array.SetItem(key2, __().text.FromString("value #2")); + array.SetItem(key3, __().box.bool(true)); + Issue("Elements are not properly removed from `AssociativeArray`."); + array.RemoveItem(key1, true) + .RemoveItem(__().box.int(25), true) + .RemoveItem(__().box.float(0.06), true); + keys = array.GetKeys(); + TEST_ExpectTrue(array.GetLength() == 1); + TEST_ExpectTrue(keys.length == 1); + TEST_ExpectTrue(keys[0] == key3); + + Issue("Keys are not deallocated upon removing elements from" + @ "`AssociativeArray` when they should."); + TEST_ExpectFalse(key1.IsAllocated()); + TEST_ExpectFalse(key2.IsAllocated()); } protected static function Test_CreateItem()