Fix for a leaky test
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,11 @@
|
||||
|
||||
#include <AzCore/Name/Internal/NameData.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
class NameTest;
|
||||
}
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class NameDictionary;
|
||||
@@ -29,6 +34,7 @@ namespace AZ
|
||||
class Name
|
||||
{
|
||||
friend NameDictionary;
|
||||
friend UnitTest::NameTest;
|
||||
public:
|
||||
using Hash = Internal::NameData::Hash;
|
||||
|
||||
|
||||
@@ -171,7 +171,17 @@ namespace UnitTest
|
||||
azsnprintf(buffer, RandomStringBufferSize, "%d", m_random.GetRandom());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
AZ::Internal::NameData* GetNameData(AZ::Name& name)
|
||||
{
|
||||
return name.m_data.get();
|
||||
}
|
||||
|
||||
void FreeMemoryFromNameData(AZ::Internal::NameData* nameData)
|
||||
{
|
||||
delete nameData;
|
||||
}
|
||||
|
||||
AZ::SimpleLcgRandom m_random;
|
||||
};
|
||||
|
||||
@@ -488,13 +498,20 @@ namespace UnitTest
|
||||
|
||||
TEST_F(NameTest, ReportLeakedNames)
|
||||
{
|
||||
AZ::Name leakedName{"hello"};
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
AZ::NameDictionary::Destroy();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
||||
AZ::Internal::NameData* leakedNameData = nullptr;
|
||||
{
|
||||
AZ::Name leakedName{ "hello" };
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
AZ::NameDictionary::Destroy();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
||||
|
||||
// Create the dictionary again to avoid error in TearDown()
|
||||
AZ::NameDictionary::Create();
|
||||
leakedNameData = GetNameData(leakedName);
|
||||
|
||||
// Create the dictionary again to avoid crash when the intrusive_ptr in Name tries to access NameDictionary to free it
|
||||
AZ::NameDictionary::Create();
|
||||
}
|
||||
|
||||
FreeMemoryFromNameData(leakedNameData); // free it to avoid memory system reporting the leak
|
||||
}
|
||||
|
||||
TEST_F(NameTest, NullTerminatedTest)
|
||||
|
||||
Reference in New Issue
Block a user