/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "StdAfx.h" #include #include #include #include #include #include "CrySizerImpl.h" using SystemAllocatorScope = AZ::AllocatorScope; namespace UnitTest { class CrySizerTest : public ::testing::Test , public SystemAllocatorScope { public: CrySizerTest() { } void SetUp() override { SystemAllocatorScope::ActivateAllocators(); m_sizer = new CrySizerImpl(); } ~CrySizerTest() { } void TearDown() override { delete m_sizer; SystemAllocatorScope::DeactivateAllocators(); } protected: CrySizerImpl* m_sizer; }; //class StatisticsTest /** * The key data structures fed to ICrySizer in CTerrain::GetMemoryUsage(class ICrySizer* pSizer): * 1. structs and classes. * 2. PodArray< of structs / classes> * 3. PodArray< of pointers> */ TEST_F(CrySizerTest, CrySizerTest_AddSomeObjectsUsedInCTerrain_GetExpectedSize) { struct TmpStruct { AZ::u32 a; AZ::u32 b; }; TmpStruct tmpStructObj; //Tracking a simple struct. m_sizer->AddObjectSize(&tmpStructObj); //The AddObject method is only available when using the ICrySizer base class. ICrySizer* sizer = static_cast(m_sizer); const int numItemsPerArray = 1024; //PodArray of structs PodArray podArrayOfTmpStruct; podArrayOfTmpStruct.resize(numItemsPerArray); sizer->AddObject(podArrayOfTmpStruct); //PodArray of pointers PodArray podArrayOfTmpStructPointers; podArrayOfTmpStructPointers.resize(numItemsPerArray); sizer->AddObject(podArrayOfTmpStructPointers); //PodArray of Array2d of pointers. const int array2dAxisSize = 64; PodArray> podArrayOfArray2d; podArrayOfArray2d.resize(numItemsPerArray); for (int i = 0; i < numItemsPerArray; ++i) { //Array2d will allocate array2dAxisSize * array2dAxisSize elements. podArrayOfArray2d[i].Allocate(array2dAxisSize); } sizer->AddObject(podArrayOfArray2d); //Calculate the total expected size const size_t expectedSizeOfArray2d = sizeof(Array2d) + (array2dAxisSize * array2dAxisSize) * sizeof(TmpStruct*); const size_t expectedTotalSize = sizeof(TmpStruct) + numItemsPerArray * sizeof(TmpStruct) + numItemsPerArray * sizeof(TmpStruct*) + numItemsPerArray * expectedSizeOfArray2d; EXPECT_EQ( m_sizer->GetTotalSize(), expectedTotalSize); } }//namespace UnitTest