//----------------------------------------------------------------------------- // Copyright (c) 2023-2024 tgemit contributors. // See AUTHORS file and git repository for contributor information. // // SPDX-License-Identifier: MIT //----------------------------------------------------------------------------- #ifdef TORQUE_TESTS_ENABLED #include "testing/unitTesting.h" #include "core/frameAllocator.h" struct TestAlignmentStruct { U64 values[4]; }; TEST(AlignedBufferAllocatorTest, AlignedBufferAllocator_Should_Function_Correctly) { AlignedBufferAllocator ba4; AlignedBufferAllocator ba8; AlignedBufferAllocator bas; const U32 bufSize32 = (sizeof(TestAlignmentStruct) / 4) * 20; U32 testAlignmentBuffer[bufSize32]; for (U32 i=0; i fooTemp(20); EXPECT_TRUE(FrameAllocator::getWaterMarkBytes() == sizeof(TestAlignmentStruct)*20); EXPECT_TRUE(&fooTemp[0] == fooTemp.address()); EXPECT_TRUE((&fooTemp[1] - &fooTemp[0]) == 1); EXPECT_TRUE(fooTemp.getObjectCount() == 20); EXPECT_TRUE(fooTemp.size() == 20); const FrameTemp& fooC = fooTemp; EXPECT_TRUE(&fooC[0] == fooC.address()); EXPECT_TRUE((&fooC[1] - &fooC[0]) == 1); EXPECT_TRUE(fooC.getObjectCount() == 20); EXPECT_TRUE(fooC.size() == 20); // Accessors should work // Call the overloaded operators by name TestAlignmentStruct& value = fooTemp.operator*(); TestAlignmentStruct** ptr = fooTemp.operator&(); const TestAlignmentStruct* constPtr = fooTemp.operator const TestAlignmentStruct * (); TestAlignmentStruct& ref = fooTemp.operator TestAlignmentStruct & (); const TestAlignmentStruct& constRef = fooTemp.operator const TestAlignmentStruct & (); TestAlignmentStruct copy = fooTemp.operator TestAlignmentStruct(); EXPECT_TRUE(*ptr == fooTemp.address()); EXPECT_TRUE(&value == fooTemp.address()); EXPECT_TRUE(constPtr == fooTemp.address()); EXPECT_TRUE(&ref == fooTemp.address()); EXPECT_TRUE(&constRef == fooTemp.address()); EXPECT_TRUE(© != fooTemp.address()); // Same for fooC const TestAlignmentStruct& Cvalue = fooC.operator*(); TestAlignmentStruct* const* Cptr = fooC.operator&(); const TestAlignmentStruct* CconstPtr = fooC.operator const TestAlignmentStruct * (); const TestAlignmentStruct& CconstRef = fooC.operator const TestAlignmentStruct & (); EXPECT_TRUE(*Cptr == fooC.address()); EXPECT_TRUE(&Cvalue == fooC.address()); EXPECT_TRUE(CconstPtr == fooC.address()); EXPECT_TRUE(&CconstRef == fooC.address()); EXPECT_TRUE(&ref == fooC.address()); EXPECT_TRUE(&constRef == fooC.address()); } // Exiting scope sets watermark EXPECT_TRUE(FrameAllocator::getWaterMarkBytes() == 0); // Test the destructor actually gets called struct FTDestructTest { ~FTDestructTest() { gFTDestructTest++; } }; { gFTDestructTest = 0; FrameTemp foo2Temp(10); } EXPECT_TRUE(gFTDestructTest == 10); } #endif