Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
+307
View File
@@ -0,0 +1,307 @@
/*
* 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 <AtomCore/std/containers/array_view.h>
#include <AzCore/std/containers/array.h>
#include <AzCore/UnitTest/TestTypes.h>
namespace UnitTest
{
using namespace AZStd;
class ArrayView : public AllocatorsTestFixture
{
protected:
template<typename T>
void ExpectEqual(initializer_list<T> expectedValues, array_view<T> arrayView)
{
EXPECT_EQ(false, arrayView.empty());
EXPECT_EQ(expectedValues.size(), arrayView.size());
typename AZStd::vector<T>::const_iterator iterator = arrayView.begin();
for (int i = 0; i < expectedValues.size(); ++i, ++iterator)
{
EXPECT_EQ(expectedValues.begin()[i], arrayView[i]);
EXPECT_EQ(expectedValues.begin()[i], *iterator);
}
EXPECT_EQ(iterator, arrayView.end());
}
};
TEST_F(ArrayView, DefaultConstructor)
{
array_view<bool> defaultView;
EXPECT_EQ(nullptr, defaultView.begin());
EXPECT_EQ(nullptr, defaultView.end());
EXPECT_EQ(0, defaultView.size());
EXPECT_EQ(true, defaultView.empty());
}
TEST_F(ArrayView, PointerConstructor1)
{
int originalValues[4] = { 2,3,4,5 };
array_view<int> view(originalValues, AZ_ARRAY_SIZE(originalValues));
ExpectEqual({ 2,3,4,5 }, view);
EXPECT_EQ(originalValues, view.begin());
EXPECT_EQ(&originalValues[4], view.end());
}
TEST_F(ArrayView, PointerConstructor2)
{
int originalValues[3] = { 6,7,8 };
array_view<int> view(originalValues, &originalValues[3]);
ExpectEqual({ 6,7,8 }, view);
EXPECT_EQ(originalValues, view.begin());
EXPECT_EQ(&originalValues[3], view.end());
}
TEST_F(ArrayView, ArrayConstructor)
{
array<int, 4> originalValues = { 9,10,11,12 };
array_view<int> view(originalValues);
ExpectEqual({ 9,10,11,12 }, view);
EXPECT_EQ(originalValues.begin(), view.begin());
EXPECT_EQ(originalValues.end(), view.end());
}
TEST_F(ArrayView, VectorConstructor)
{
vector<int> originalValues = { 13,14,15,16,17,18 };
array_view<int> view(originalValues);
ExpectEqual({ 13,14,15,16,17,18 }, view);
EXPECT_EQ(originalValues.begin(), view.begin());
EXPECT_EQ(originalValues.end(), view.end());
}
TEST_F(ArrayView, FixedVectorConstructor)
{
fixed_vector<int, 10> originalValues = { 17,18,19 }; // Note that even though the fixed_vector capacity is 10, it's size is 3, so the view size will be 3 as well
array_view<int> view(originalValues);
ExpectEqual({ 17,18,19 }, view);
EXPECT_EQ(originalValues.begin(), view.begin());
EXPECT_EQ(originalValues.end(), view.end());
}
TEST_F(ArrayView, CopyConstructor)
{
fixed_vector<int, 2> originalValues = { 27,28 };
array_view<int> view1(originalValues);
array_view<int> view2(view1);
ExpectEqual({ 27,28 }, view2);
EXPECT_EQ(view1.begin(), view2.begin());
EXPECT_EQ(view1.end(), view2.end());
}
TEST_F(ArrayView, MoveConstructor)
{
int originalValues[] = { 29,30,31 };
array_view<int> view1(originalValues, AZ_ARRAY_SIZE(originalValues));
array_view<int> view2(AZStd::move(view1));
ExpectEqual({ 29,30,31 }, view2);
EXPECT_EQ(originalValues, view2.begin());
EXPECT_EQ(&originalValues[3], view2.end());
// This isn't strictly necessary but is a good way to make sure the move
// constructor actually exists and it itn't just calling the copy constructor
#if AZ_DEBUG_BUILD // The pointers are only cleared in debug
EXPECT_EQ(nullptr, view1.begin());
EXPECT_EQ(nullptr, view1.end());
#endif
}
TEST_F(ArrayView, AssignmentOperator)
{
fixed_vector<int, 4> originalValues = { 32,33,34,35 };
array_view<int> view1(originalValues);
array_view<int> view2;
view2 = view1;
ExpectEqual({ 32,33,34,35 }, view2);
EXPECT_EQ(view1.begin(), view2.begin());
EXPECT_EQ(view1.end(), view2.end());
}
TEST_F(ArrayView, MoveAssignmentOperator)
{
int originalValues[] = { 36,37,38,39,40 };
array_view<int> view1(originalValues, AZ_ARRAY_SIZE(originalValues));
array_view<int> view2;
view2 = AZStd::move(view1);
ExpectEqual({ 36,37,38,39,40 }, view2);
EXPECT_EQ(originalValues, view2.begin());
EXPECT_EQ(&originalValues[5], view2.end());
// This isn't strictly necessary but is a good way to make sure the move
// assignment operator actually exists and it itn't just calling the norm
// assignment operator
#if AZ_DEBUG_BUILD // The pointers are only cleared in debug
EXPECT_EQ(nullptr, view1.begin());
EXPECT_EQ(nullptr, view1.end());
#endif
}
TEST_F(ArrayView, Erase)
{
fixed_vector<int, 4> originalValues = { 1,2,3,4 };
array_view<int> view(originalValues);
view.erase();
EXPECT_EQ(nullptr, view.begin());
EXPECT_EQ(nullptr, view.end());
EXPECT_EQ(0, view.size());
EXPECT_EQ(true, view.empty());
}
TEST_F(ArrayView, BeginAndEnd)
{
fixed_vector<int, 4> originalValues = { 1,2,3,4 };
array_view<int> view(originalValues);
EXPECT_EQ(1, view.begin()[0]);
EXPECT_EQ(4, view.end()[-1]);
EXPECT_EQ(1, view.cbegin()[0]);
EXPECT_EQ(4, view.cend()[-1]);
EXPECT_EQ(4, view.rbegin()[0]);
EXPECT_EQ(1, view.rend()[-1]);
EXPECT_EQ(4, view.crbegin()[0]);
EXPECT_EQ(1, view.crend()[-1]);
}
TEST_F(ArrayView, ImplicitConstruction)
{
// This test verifies that we can pass in various non-array_view types
// into functions that take an array_view
// The compile cannot detect the correct template type so that has to be specified explicitly
ExpectEqual<int>({ 1,2,3 }, vector<int>({ 1,2,3 }));
ExpectEqual<int>({ 1,2,3 }, fixed_vector<int, 3>({ 1,2,3 }));
ExpectEqual<int>({ 1,2,3 }, array<int, 3>({ 1,2,3 }));
}
void CheckComparisonOperators(bool areEqual, array_view<int> a, array_view<int> b)
{
EXPECT_EQ(areEqual, a == b);
// For less/greater operators, the exact order doesn't really matter;
// We just check for internal consistency
if (areEqual)
{
EXPECT_EQ(false, a != b);
EXPECT_EQ(false, a < b);
EXPECT_EQ(false, a > b);
EXPECT_EQ(true, a <= b);
EXPECT_EQ(true, a >= b);
}
else
{
EXPECT_EQ(true, a != b);
EXPECT_EQ(a > b, a >= b);
EXPECT_EQ(a < b, a <= b);
EXPECT_NE(a > b, a < b);
EXPECT_NE(a >= b, a <= b);
EXPECT_NE(a >= b, a < b);
EXPECT_NE(a > b, a <= b);
EXPECT_NE(a <= b, a > b);
EXPECT_NE(a < b, a >= b);
}
}
TEST_F(ArrayView, ComparisonOperators)
{
int arrayA[] = { 1,2,3 };
int arrayB[] = { 1,2,3 };
array_view<int> arrayA_view(arrayA, 3);
array_view<int> arrayB_view(arrayB, 3);
array_view<int> arrayA_otherView(arrayA, 3);
// view of a sub-array aligned to the beginning of the array
array_view<int> arrayA_headView(arrayA, 2);
array_view<int> arrayB_headView(arrayB, 2);
// view of a sub-array aligned to the end of the array
array_view<int> arrayA_tailView(&arrayA[1], 2);
array_view<int> arrayB_tailView(&arrayB[1], 2);
// view of a sub-array in the middle of the array
array_view<int> arrayA_centerView(&arrayA[1], 1);
array_view<int> arrayB_centerView(&arrayB[1], 1);
// Same view
CheckComparisonOperators(true, arrayA_view, arrayA_view);
// Different view, same array
CheckComparisonOperators(true, arrayA_view, arrayA_otherView);
CheckComparisonOperators(true, arrayA_otherView, arrayA_view);
// Different arrays
CheckComparisonOperators(false, arrayA_view, arrayB_view);
CheckComparisonOperators(false, arrayB_view, arrayA_view);
// Same arrays, but one is a just a subset of the array
CheckComparisonOperators(false, arrayA_view, arrayA_headView);
CheckComparisonOperators(false, arrayA_view, arrayA_tailView);
CheckComparisonOperators(false, arrayA_view, arrayA_centerView);
CheckComparisonOperators(false, arrayA_headView, arrayA_view);
CheckComparisonOperators(false, arrayA_tailView, arrayA_view);
CheckComparisonOperators(false, arrayA_centerView, arrayA_view);
// Different arrays, different lengths
CheckComparisonOperators(false, arrayA_view, arrayB_headView);
CheckComparisonOperators(false, arrayB_view, arrayA_headView);
CheckComparisonOperators(false, arrayB_headView, arrayA_view);
CheckComparisonOperators(false, arrayA_headView, arrayB_view);
}
TEST_F(ArrayView, AssertOutOfBounds)
{
array_view<int> view({ 1,2,3,4 });
UnitTest::TestRunner::Instance().StartAssertTests();
EXPECT_EQ(0, UnitTest::TestRunner::Instance().m_numAssertsFailed);
view[4];
EXPECT_EQ(1, UnitTest::TestRunner::Instance().m_numAssertsFailed);
view[5];
EXPECT_EQ(2, UnitTest::TestRunner::Instance().m_numAssertsFailed);
UnitTest::TestRunner::Instance().StopAssertTests();
}
}
@@ -0,0 +1,627 @@
/*
* 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 <AtomCore/Instance/InstanceDatabase.h>
#include <AzCore/Asset/AssetManager.h>
#include <AzCore/Memory/PoolAllocator.h>
#include <AzCore/std/parallel/conditional_variable.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Debug/Timer.h>
using namespace AZ;
using namespace AZ::Data;
namespace UnitTest
{
static const InstanceId s_instanceId0{ Uuid("{5B29FE2B-6B41-48C9-826A-C723951B0560}") };
static const InstanceId s_instanceId1{ Uuid("{BD354AE5-B5D5-402A-A12E-BE3C96F6522B}") };
static const InstanceId s_instanceId2{ Uuid("{EE99215B-7AB4-4757-B8AF-F78BD4903AC4}") };
static const InstanceId s_instanceId3{ Uuid("{D9CDAB04-D206-431E-BDC0-1DD615D56197}") };
static const AssetId s_assetId0{ Uuid("{5B29FE2B-6B41-48C9-826A-C723951B0560}") };
static const AssetId s_assetId1{ Uuid("{BD354AE5-B5D5-402A-A12E-BE3C96F6522B}") };
static const AssetId s_assetId2{ Uuid("{EE99215B-7AB4-4757-B8AF-F78BD4903AC4}") };
static const AssetId s_assetId3{ Uuid("{D9CDAB04-D206-431E-BDC0-1DD615D56197}") };
// test asset type
class TestAssetType
: public AssetData
{
public:
AZ_CLASS_ALLOCATOR(TestAssetType, AZ::SystemAllocator, 0);
AZ_RTTI(TestAssetType, "{73D60606-BDE5-44F9-9420-5649FE7BA5B8}", AssetData);
TestAssetType()
{
m_status = AssetStatus::Ready;
}
};
class TestInstanceA
: public InstanceData
{
public:
AZ_INSTANCE_DATA(TestInstanceA, "{65CBF1C8-F65F-4A84-8A11-B510BC435DB0}");
AZ_CLASS_ALLOCATOR(TestInstanceA, AZ::SystemAllocator, 0);
TestInstanceA(TestAssetType* asset)
: m_asset{asset, AZ::Data::AssetLoadBehavior::Default}
{}
Asset<TestAssetType> m_asset;
};
class TestInstanceB
: public InstanceData
{
public:
AZ_INSTANCE_DATA(TestInstanceB, "{4ED0A8BF-7800-44B2-AC73-2CB759C61C37}");
AZ_CLASS_ALLOCATOR(TestInstanceB, AZ::SystemAllocator, 0);
TestInstanceB(TestAssetType* asset)
: m_asset{asset, AZ::Data::AssetLoadBehavior::Default }
{}
~TestInstanceB()
{
if (m_onDeleteCallback)
{
m_onDeleteCallback();
}
}
Asset<TestAssetType> m_asset;
AZStd::function<void()> m_onDeleteCallback;
};
// test asset handler
template<typename AssetDataT>
class MyAssetHandler
: public AssetHandler
{
public:
AZ_CLASS_ALLOCATOR(MyAssetHandler, AZ::SystemAllocator, 0);
AssetPtr CreateAsset(const AssetId& id, const AssetType& type) override
{
(void)id;
EXPECT_TRUE(type == AzTypeInfo<AssetDataT>::Uuid());
if (type == AzTypeInfo<AssetDataT>::Uuid())
{
return aznew AssetDataT();
}
return nullptr;
}
LoadResult LoadAssetData(const Asset<AssetData>&, AZStd::shared_ptr<AssetDataStream>, const AZ::Data::AssetFilterCB&) override
{
return LoadResult::Error;
}
void DestroyAsset(AssetPtr ptr) override
{
EXPECT_TRUE(ptr->GetType() == AzTypeInfo<AssetDataT>::Uuid());
delete ptr;
}
void GetHandledAssetTypes(AZStd::vector<AssetType>& assetTypes) override
{
assetTypes.push_back(AzTypeInfo<AssetDataT>::Uuid());
}
};
class InstanceDatabaseTest
: public AllocatorsFixture
{
protected:
MyAssetHandler<TestAssetType>* m_assetHandler;
public:
void SetUp() override
{
AllocatorsFixture::SetUp();
AllocatorInstance<PoolAllocator>::Create();
AllocatorInstance<ThreadPoolAllocator>::Create();
// create the asset database
{
AssetManager::Descriptor desc;
AssetManager::Create(desc);
}
// create the instance database
{
InstanceHandler<TestInstanceA> instanceHandler;
instanceHandler.m_createFunction = [](AssetData* assetData)
{
EXPECT_TRUE(azrtti_istypeof<TestAssetType>(assetData));
return aznew TestInstanceA(static_cast<TestAssetType*>(assetData));
};
InstanceDatabase<TestInstanceA>::Create(azrtti_typeid<TestAssetType>(), instanceHandler);
}
// create and register an asset handler
m_assetHandler = aznew MyAssetHandler<TestAssetType>;
AssetManager::Instance().RegisterHandler(m_assetHandler, AzTypeInfo<TestAssetType>::Uuid());
}
void TearDown() override
{
// destroy the database
AssetManager::Destroy();
InstanceDatabase<TestInstanceA>::Destroy();
AllocatorInstance<ThreadPoolAllocator>::Destroy();
AllocatorInstance<PoolAllocator>::Destroy();
AllocatorsFixture::TearDown();
}
};
TEST_F(InstanceDatabaseTest, InstanceCreate)
{
auto& assetManager = AssetManager::Instance();
auto& instanceDatabase = InstanceDatabase<TestInstanceA>::Instance();
Asset<TestAssetType> someAsset = assetManager.CreateAsset<TestAssetType>(s_assetId0, AZ::Data::AssetLoadBehavior::Default);
Instance<TestInstanceA> instance = instanceDatabase.Find(s_instanceId0);
EXPECT_EQ(instance, nullptr);
instance = instanceDatabase.FindOrCreate(s_instanceId0, someAsset);
EXPECT_NE(instance, nullptr);
Instance<TestInstanceA> instance2 = instanceDatabase.FindOrCreate(s_instanceId0, someAsset);
EXPECT_EQ(instance, instance2);
Instance<TestInstanceA> instance3 = instanceDatabase.Find(s_instanceId0);
EXPECT_EQ(instance, instance3);
}
void ParallelInstanceCreateHelper(size_t threadCountMax, size_t assetIdCount, size_t durationSeconds)
{
printf("Testing threads=%zu assetIds=%zu ... ", threadCountMax, assetIdCount);
AZ::Debug::Timer timer;
timer.Stamp();
auto& assetManager = AssetManager::Instance();
auto& instanceManager = InstanceDatabase<TestInstanceA>::Instance();
AZStd::vector<Uuid> guids;
AZStd::vector<Asset<TestAssetType>> assets;
for (size_t i = 0; i < assetIdCount; ++i)
{
Uuid guid = Uuid::CreateRandom();
guids.emplace_back(guid);
// Pre-create asset so we don't attempt to load it from the catalog.
assets.emplace_back(assetManager.CreateAsset<TestAssetType>(guid, AZ::Data::AssetLoadBehavior::Default));
}
AZStd::vector<AZStd::thread> threads;
AZStd::mutex mutex;
AZStd::atomic<int> threadCount((int)threadCountMax);
AZStd::condition_variable cv;
AZStd::atomic_bool keepDispatching(true);
auto dispatch = [&keepDispatching]()
{
while (keepDispatching)
{
AssetManager::Instance().DispatchEvents();
}
};
srand(0);
AZStd::thread dispatchThread(dispatch);
for (size_t i = 0; i < threadCountMax; ++i)
{
threads.emplace_back([&instanceManager, &threadCount, &cv, &guids, &assets, &durationSeconds]()
{
AZ::Debug::Timer timer;
timer.Stamp();
while(timer.GetDeltaTimeInSeconds() < durationSeconds)
{
const size_t index = rand() % guids.size();
const Uuid uuid = guids[index];
const InstanceId instanceId{uuid};
const AssetId assetId{uuid};
Instance<TestInstanceA> instance = instanceManager.FindOrCreate(instanceId, Asset<TestAssetType>(assetId, azrtti_typeid<TestAssetType>()));
EXPECT_NE(instance, nullptr);
EXPECT_EQ(instance->GetId(), instanceId);
EXPECT_EQ(instance->m_asset, assets[index]);
}
threadCount--;
cv.notify_one();
});
}
bool timedOut = false;
// Used to detect a deadlock. If we wait for more than 10 seconds, it's likely a deadlock has occurred
while (threadCount > 0 && !timedOut)
{
AZStd::unique_lock<AZStd::mutex> lock(mutex);
timedOut = (AZStd::cv_status::timeout == cv.wait_until(lock, AZStd::chrono::system_clock::now() + AZStd::chrono::seconds(durationSeconds * 2)));
}
EXPECT_TRUE(threadCount == 0) << "One or more threads appear to be deadlocked at " << timer.GetDeltaTimeInSeconds() << " seconds";
for (auto& thread : threads)
{
thread.join();
}
keepDispatching = false;
dispatchThread.join();
printf("Took %f seconds\n", timer.GetDeltaTimeInSeconds());
}
TEST_F(InstanceDatabaseTest, ParallelInstanceCreate)
{
// This is the original test scenario from when InstanceDatabase was first implemented
// threads, AssetIds, seconds
ParallelInstanceCreateHelper( 8, 100, 5 );
// This value is checked in as 1 so this test doesn't take too much time, but can be increased locally to soak the test.
const size_t attempts = 1;
for (size_t i = 0; i < attempts; ++i)
{
printf("Attempt %zu of %zu... \n", i, attempts);
// The idea behind this series of tests is that there are two threads sharing one Instance, and both threads try to
// create or release that instance at the same time.
// At the time, this set of scenarios has something like a 10% failure rate.
const size_t duration = 2;
// threads, AssetIds, seconds
ParallelInstanceCreateHelper(2, 1, duration);
ParallelInstanceCreateHelper(4, 1, duration);
ParallelInstanceCreateHelper(8, 1, duration);
}
for (size_t i = 0; i < attempts; ++i)
{
printf("Attempt %zu of %zu... \n", i, attempts);
// Here we try a bunch of different threadCount:assetCount ratios to be thorough
const size_t duration = 2;
// threads, AssetIds, seconds
ParallelInstanceCreateHelper(2, 1, duration);
ParallelInstanceCreateHelper(4, 1, duration);
ParallelInstanceCreateHelper(4, 2, duration);
ParallelInstanceCreateHelper(4, 4, duration);
ParallelInstanceCreateHelper(8, 1, duration);
ParallelInstanceCreateHelper(8, 2, duration);
ParallelInstanceCreateHelper(8, 3, duration);
ParallelInstanceCreateHelper(8, 4, duration);
}
}
TEST_F(InstanceDatabaseTest, InstanceCreateNoDatabase)
{
bool m_deleted = false;
{
Instance<TestInstanceB> instance = aznew TestInstanceB(nullptr);
EXPECT_FALSE(instance->GetId().IsValid());
// Tests whether the deleter actually calls delete properly without
// a parent database.
instance->m_onDeleteCallback = [this, &m_deleted] () { m_deleted = true; };
}
EXPECT_TRUE(m_deleted);
}
TEST_F(InstanceDatabaseTest, InstanceCreateMultipleDatabases)
{
// create a second instance database.
{
InstanceHandler<TestInstanceB> instanceHandler;
instanceHandler.m_createFunction = [](AssetData* assetData)
{
EXPECT_TRUE(azrtti_istypeof<TestAssetType>(assetData));
return aznew TestInstanceB(static_cast<TestAssetType*>(assetData));
};
InstanceDatabase<TestInstanceB>::Create(azrtti_typeid<TestAssetType>(), instanceHandler);
}
auto& assetManager = AssetManager::Instance();
auto& instanceDatabaseA = InstanceDatabase<TestInstanceA>::Instance();
auto& instanceDatabaseB = InstanceDatabase<TestInstanceB>::Instance();
{
Asset<TestAssetType> someAsset = assetManager.CreateAsset<TestAssetType>(s_assetId0, AZ::Data::AssetLoadBehavior::Default);
// Run the creation tests on 'A' first.
Instance<TestInstanceA> instanceA = instanceDatabaseA.Find(s_instanceId0);
EXPECT_EQ(instanceA, nullptr);
instanceA = instanceDatabaseA.FindOrCreate(s_instanceId0, someAsset);
EXPECT_NE(instanceA, nullptr);
Instance<TestInstanceA> instanceA2 = instanceDatabaseA.FindOrCreate(s_instanceId0, someAsset);
EXPECT_EQ(instanceA, instanceA2);
Instance<TestInstanceA> instanceA3 = instanceDatabaseA.Find(s_instanceId0);
EXPECT_EQ(instanceA, instanceA3);
// Run the same test on 'B' to make sure it works independently.
Instance<TestInstanceB> instanceB = instanceDatabaseB.Find(s_instanceId0);
EXPECT_EQ(instanceB, nullptr);
instanceB = instanceDatabaseB.FindOrCreate(s_instanceId0, someAsset);
EXPECT_NE(instanceB, nullptr);
Instance<TestInstanceB> instanceB2 = instanceDatabaseB.FindOrCreate(s_instanceId0, someAsset);
EXPECT_EQ(instanceB, instanceB2);
Instance<TestInstanceB> instanceB3 = instanceDatabaseB.Find(s_instanceId0);
EXPECT_EQ(instanceB, instanceB3);
}
InstanceDatabase<TestInstanceB>::Destroy();
}
class InstanceDatabaseTestWithMultipleSubclasses
: public AllocatorsFixture
{
protected:
// We have "BaseAsset" with subclasses "FooAsset" and "BarAsset",
// and corresponding "BaseInstance" with subclasses "FooInstance" and "BarInstance".
// There is one "InstanceDatabse<BaseInstance>" that can create instances of both subtypes.
class BaseAsset
: public AssetData
{
public:
AZ_CLASS_ALLOCATOR(BaseAsset, AZ::SystemAllocator, 0);
AZ_RTTI(FooAsset, "{35B443A6-D8ED-4C3C-A3F0-D642251F0AA5}", AssetData);
BaseAsset()
{
m_status = AssetStatus::Ready;
}
};
class BaseInstance
: public InstanceData
{
public:
AZ_INSTANCE_DATA(BaseInstance, "{EFEC3406-2CB7-462E-A676-C22177E143E6}");
AZ_CLASS_ALLOCATOR(BaseInstance, AZ::SystemAllocator, 0);
BaseInstance(BaseAsset* asset)
: m_asset{ asset, AZ::Data::AssetLoadBehavior::Default }
{}
Asset<BaseAsset> m_asset;
};
class FooAsset
: public BaseAsset
{
public:
AZ_CLASS_ALLOCATOR(FooAsset, AZ::SystemAllocator, 0);
AZ_RTTI(FooAsset, "{74BAE278-3DCA-4ADD-807E-2A6873F9EA3C}", BaseAsset);
};
class BarAsset
: public BaseAsset
{
public:
AZ_CLASS_ALLOCATOR(BarAsset, AZ::SystemAllocator, 0);
AZ_RTTI(FooAsset, "{2BCD66F5-768B-4569-9FC2-DE92ABC9C0BF}", BaseAsset);
};
class FooInstance
: public BaseInstance
{
public:
AZ_RTTI(FooInstance, "{B5487509-5518-4591-AC96-03E623A584B7}", BaseInstance);
AZ_CLASS_ALLOCATOR(FooInstance, AZ::SystemAllocator, 0);
FooInstance(BaseAsset* asset)
: BaseInstance(asset)
{
EXPECT_TRUE(azrtti_typeid<FooAsset>() == asset->GetType());
}
};
class BarInstance
: public BaseInstance
{
public:
AZ_RTTI(BarInstance, "{CE9C844A-625D-4899-B7DB-8127D4618D25}", BaseInstance);
AZ_CLASS_ALLOCATOR(BarInstance, AZ::SystemAllocator, 0);
BarInstance(BaseAsset* asset)
: BaseInstance(asset)
{
EXPECT_TRUE(azrtti_typeid<BarAsset>() == asset->GetType());
}
};
MyAssetHandler<FooAsset> m_fooAssetHandler;
MyAssetHandler<BarAsset> m_barAssetHandler;
public:
void SetUp() override
{
AllocatorsFixture::SetUp();
AllocatorInstance<PoolAllocator>::Create();
AllocatorInstance<ThreadPoolAllocator>::Create();
// create the asset database
{
AssetManager::Descriptor desc;
AssetManager::Create(desc);
}
// create the instance database
{
InstanceDatabase<BaseInstance>::Create(azrtti_typeid<BaseAsset>());
InstanceHandler<BaseInstance> fooHandler;
fooHandler.m_createFunction = [](AssetData* assetData)
{
EXPECT_TRUE(azrtti_istypeof<FooAsset>(assetData));
return aznew FooInstance(static_cast<FooAsset*>(assetData));
};
InstanceDatabase<BaseInstance>::Instance().AddHandler(azrtti_typeid<FooAsset>(), fooHandler);
// Using a different overload of AddHandler()
InstanceDatabase<BaseInstance>::Instance().AddHandler(azrtti_typeid<BarAsset>(), [](AssetData* assetData)
{
EXPECT_TRUE(azrtti_istypeof<BarAsset>(assetData));
return aznew BarInstance(static_cast<BarAsset*>(assetData));
});
}
AssetManager::Instance().RegisterHandler(&m_fooAssetHandler, AzTypeInfo<FooAsset>::Uuid());
AssetManager::Instance().RegisterHandler(&m_barAssetHandler, AzTypeInfo<BarAsset>::Uuid());
}
void TearDown() override
{
AssetManager::Instance().UnregisterHandler(&m_fooAssetHandler);
AssetManager::Instance().UnregisterHandler(&m_barAssetHandler);
AssetManager::Destroy();
InstanceDatabase<BaseInstance>::Destroy();
AllocatorInstance<ThreadPoolAllocator>::Destroy();
AllocatorInstance<PoolAllocator>::Destroy();
AllocatorsFixture::TearDown();
}
};
TEST_F(InstanceDatabaseTestWithMultipleSubclasses, InstanceCreate)
{
auto& assetManager = AssetManager::Instance();
auto& instanceDatabase = InstanceDatabase<BaseInstance>::Instance();
Asset<FooAsset> fooAsset = assetManager.CreateAsset<FooAsset>(s_assetId0, AZ::Data::AssetLoadBehavior::Default);
Asset<BarAsset> barAsset = assetManager.CreateAsset<BarAsset>(s_assetId1, AZ::Data::AssetLoadBehavior::Default);
// Run the creation tests on 'A' first.
Instance<BaseInstance> fooInstanceA = instanceDatabase.Find(s_instanceId0);
EXPECT_EQ(fooInstanceA, nullptr);
Instance<BaseInstance> barInstanceA = instanceDatabase.Find(s_instanceId1);
EXPECT_EQ(barInstanceA, nullptr);
fooInstanceA = instanceDatabase.FindOrCreate(s_instanceId0, fooAsset);
EXPECT_NE(fooInstanceA, nullptr);
EXPECT_EQ(fooInstanceA->m_asset, fooAsset);
EXPECT_TRUE(azrtti_typeid<FooInstance>() == fooInstanceA->RTTI_GetType());
EXPECT_EQ(fooInstanceA, instanceDatabase.Find(s_instanceId0));
barInstanceA = instanceDatabase.FindOrCreate(s_instanceId1, barAsset);
EXPECT_NE(barInstanceA, nullptr);
EXPECT_EQ(barInstanceA->m_asset, barAsset);
EXPECT_TRUE(azrtti_typeid<BarInstance>() == barInstanceA->RTTI_GetType());
EXPECT_EQ(barInstanceA, instanceDatabase.Find(s_instanceId1));
// Run the same test on 'B' to make sure it works independently.
Instance<BaseInstance> fooInstanceB = instanceDatabase.Find(s_instanceId2);
EXPECT_EQ(fooInstanceB, nullptr);
Instance<BaseInstance> barInstanceB = instanceDatabase.Find(s_instanceId3);
EXPECT_EQ(barInstanceB, nullptr);
fooInstanceB = instanceDatabase.FindOrCreate(s_instanceId2, fooAsset);
EXPECT_NE(fooInstanceB, nullptr);
EXPECT_EQ(fooInstanceB->m_asset, fooAsset);
EXPECT_TRUE(azrtti_typeid<FooInstance>() == fooInstanceB->RTTI_GetType());
EXPECT_EQ(fooInstanceB, instanceDatabase.Find(s_instanceId2));
barInstanceB = instanceDatabase.FindOrCreate(s_instanceId3, barAsset);
EXPECT_NE(barInstanceB, nullptr);
EXPECT_EQ(barInstanceB->m_asset, barAsset);
EXPECT_TRUE(azrtti_typeid<BarInstance>() == barInstanceB->RTTI_GetType());
EXPECT_EQ(barInstanceB, instanceDatabase.Find(s_instanceId3));
// Make sure the instances are unique
EXPECT_NE(fooInstanceA, fooInstanceB);
EXPECT_NE(barInstanceA, barInstanceB);
}
TEST_F(InstanceDatabaseTestWithMultipleSubclasses, TestError_AddHandler_AssetTypeIsNotSubclass)
{
MyAssetHandler<TestAssetType> testAssetHandler;
AssetManager::Instance().RegisterHandler(&testAssetHandler, azrtti_typeid<TestAssetType>());
// Register an instance handler with an unrelated asset type. This can't actually
// check the AssetType yet because all it has are AssetType GUIDs, no actual data.
{
InstanceHandler<BaseInstance> instanceHandler;
instanceHandler.m_createFunction = [](AssetData* assetData)
{
return aznew BaseInstance(static_cast<BaseAsset*>(assetData));
};
AssetType unrelatedAssetType = azrtti_typeid<TestAssetType>();
InstanceDatabase<BaseInstance>::Instance().AddHandler(unrelatedAssetType, instanceHandler);
}
// Try to use the unrelated handler. This is where we'll actually get an error.
{
AZ_TEST_START_ASSERTTEST;
Asset<TestAssetType> testAsset = AssetManager::Instance().CreateAsset<TestAssetType>(s_assetId0, AZ::Data::AssetLoadBehavior::Default);
EXPECT_EQ(nullptr, InstanceDatabase<BaseInstance>::Instance().FindOrCreate(s_instanceId0, testAsset));
AZ_TEST_STOP_ASSERTTEST(1);
}
AssetManager::Instance().UnregisterHandler(&testAssetHandler);
}
TEST_F(InstanceDatabaseTestWithMultipleSubclasses, TestError_AddHandler_AlreadyExists)
{
InstanceHandler<BaseInstance> instanceHandler;
instanceHandler.m_createFunction = [](AssetData*)
{
return nullptr; // Doesn't matter
};
AZ_TEST_START_ASSERTTEST;
// The SetUp() function already registered a handler for FooAsset so this should fail
InstanceDatabase<BaseInstance>::Instance().AddHandler(azrtti_typeid<FooAsset>(), instanceHandler);
InstanceDatabase<BaseInstance>::Instance().AddHandler(azrtti_typeid<FooAsset>(), [](AssetData*) { return nullptr; });
AZ_TEST_STOP_ASSERTTEST(2);
}
}
@@ -0,0 +1,496 @@
/*
* 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 <AzCore/Serialization/Json/JsonSerialization.h>
#include <AzCore/Serialization/Json/JsonSystemComponent.h>
#include <AzCore/Serialization/Json/RegistrationContext.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzTest/AzTest.h>
#include <AtomCore/Serialization/Json/JsonUtils.h>
namespace UnitTest
{
using namespace AZ;
namespace Test1
{
class TestClass
{
public:
AZ_TYPE_INFO(TestClass, "{731F8B22-086E-4CDE-9645-23078C6277C1}");
static void Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<TestClass>()
->Version(1)
->Field("int", &TestClass::m_int)
->Field("float", &TestClass::m_float)
->Field("string", &TestClass::m_string)
->Field("unordered_map", &TestClass::m_unorderedMap)
->Field("array", &TestClass::m_array)
->Field("vector", &TestClass::m_vector)
;
}
}
int m_int = 0;
float m_float = 0;
AZStd::string m_string = "TestClass";
AZStd::unordered_map<int, AZStd::string> m_unorderedMap;
AZStd::array<AZStd::string, 2> m_array;
AZStd::vector<AZStd::string> m_vector;
void Init()
{
m_unorderedMap.emplace(1, "one");
m_unorderedMap.emplace(5, "five");
m_array[1] = "ONE";
m_vector.push_back("anything");
m_vector.push_back("something");
}
bool operator == (const TestClass& other) const
{
return m_int == other.m_int
&& m_float == other.m_float
&& m_string == other.m_string
&& m_unorderedMap == other.m_unorderedMap
&& m_array == other.m_array
&& m_vector == other.m_vector
;
}
};
}
namespace Test2
{
// Test class which has same class name with TestClass but difference class id reflected in SerializeContext
class TestClass
{
public:
AZ_TYPE_INFO(TestClass, "{DAC825C5-AB14-4D9D-AAC2-124E56E1F8FD}");
static void Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<TestClass>()
->Version(1)
->Field("SomeData", &TestClass::m_someData)
;
}
}
int m_someData = 0;
};
}
class JsonSerializationUtilsTests
: public AllocatorsTestFixture
{
protected:
void SetUp() override
{
AllocatorsTestFixture::SetUp();
m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
m_jsonRegistrationContext = AZStd::make_unique<AZ::JsonRegistrationContext>();
m_jsonSystemComponent = AZStd::make_unique<AZ::JsonSystemComponent>();
m_serializationSettings.m_serializeContext = m_serializeContext.get();
m_serializationSettings.m_registrationContext = m_jsonRegistrationContext.get();
m_deserializationSettings.m_serializeContext = m_serializeContext.get();
m_deserializationSettings.m_registrationContext = m_jsonRegistrationContext.get();
m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get());
Test1::TestClass::Reflect(m_serializeContext.get());
Test2::TestClass::Reflect(m_serializeContext.get());
}
void TearDown() override
{
m_jsonRegistrationContext->EnableRemoveReflection();
m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get());
m_jsonRegistrationContext->DisableRemoveReflection();
m_serializeContext->EnableRemoveReflection();
Test1::TestClass::Reflect(m_serializeContext.get());
Test2::TestClass::Reflect(m_serializeContext.get());
m_serializeContext->DisableRemoveReflection();
m_jsonRegistrationContext.reset();
m_serializeContext.reset();
m_jsonSystemComponent.reset();
AllocatorsTestFixture::TearDown();
}
AZStd::unique_ptr<SerializeContext> m_serializeContext;
AZStd::unique_ptr<JsonRegistrationContext> m_jsonRegistrationContext;
AZStd::unique_ptr<JsonSystemComponent> m_jsonSystemComponent;
JsonSerializerSettings m_serializationSettings;
JsonDeserializerSettings m_deserializationSettings;
};
TEST_F(JsonSerializationUtilsTests, SaveLoadObjectToStream_Success)
{
char buffer[1024];
IO::MemoryStream stream(buffer, 1024, 0);
m_serializationSettings.m_keepDefaults = true;
Test1::TestClass dataToSave;
dataToSave.Init();
dataToSave.m_float = 10;
dataToSave.m_string = "SaveObjectToStreamSuccess";
Outcome<void, AZStd::string> saveResult = JsonSerializationUtils::SaveObjectToStream(&dataToSave, stream, (Test1::TestClass*)nullptr, &m_serializationSettings);
EXPECT_TRUE(saveResult.IsSuccess());
Test1::TestClass loadedData;
stream.Seek(0, IO::GenericStream::ST_SEEK_BEGIN);
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(loadedData, stream, &m_deserializationSettings);
EXPECT_TRUE(loadResult.IsSuccess());
EXPECT_TRUE(dataToSave == loadedData);
}
TEST_F(JsonSerializationUtilsTests, SaveObjectToStream_Failed_NoSerializationContext)
{
char buffer[1024];
IO::MemoryStream stream(buffer, 1024, 0);
m_serializationSettings.m_keepDefaults = true;
Test1::TestClass dataToSave;
dataToSave.m_float = 10;
Outcome<void, AZStd::string> saveResult = JsonSerializationUtils::SaveObjectToStream(&dataToSave, stream);
EXPECT_TRUE(!saveResult.IsSuccess());
}
TEST_F(JsonSerializationUtilsTests, WriteJson)
{
rapidjson::Document document;
document.SetObject();
document.AddMember("a", 1, document.GetAllocator());
document.AddMember("b", 2, document.GetAllocator());
document.AddMember("c", 3, document.GetAllocator());
const char* expectedJsonText =
"{\n"
" \"a\": 1,\n"
" \"b\": 2,\n"
" \"c\": 3\n"
"}";
AZStd::string outString;
AZ::Outcome<void, AZStd::string> result1 = JsonSerializationUtils::WriteJsonString(document, outString);
EXPECT_TRUE(result1.IsSuccess());
EXPECT_STREQ(expectedJsonText, outString.c_str());
AZStd::vector<char> outBuffer;
AZ::IO::ByteContainerStream<AZStd::vector<char>> outStream{&outBuffer};
AZ::Outcome<void, AZStd::string> result2 = JsonSerializationUtils::WriteJsonStream(document, outStream);
EXPECT_TRUE(result2.IsSuccess());
outBuffer.push_back(0);
EXPECT_STREQ(expectedJsonText, outBuffer.data());
// Unfortunately we can't unit test WriteJsonFile because core unit tests don't have access to the local file IO system.
}
TEST_F(JsonSerializationUtilsTests, ReadJsonString)
{
const char* jsonText =
R"(
{
"a": 1,
"b": 2,
"c": 3
})";
AZ::Outcome<rapidjson::Document, AZStd::string> result = JsonSerializationUtils::ReadJsonString(jsonText);
EXPECT_TRUE(result.IsSuccess());
EXPECT_TRUE(result.GetValue().IsObject());
EXPECT_TRUE(result.GetValue().HasMember("a"));
EXPECT_TRUE(result.GetValue().HasMember("b"));
EXPECT_TRUE(result.GetValue().HasMember("c"));
EXPECT_EQ(result.GetValue()["a"].GetInt(), 1);
EXPECT_EQ(result.GetValue()["b"].GetInt(), 2);
EXPECT_EQ(result.GetValue()["c"].GetInt(), 3);
}
TEST_F(JsonSerializationUtilsTests, ReadJsonString_ErrorReportsLineNumber)
{
const char* jsonText =
R"(
{
"a": "This line is missing a comma"
"b": 2,
"c": 3
}
)";
AZ::Outcome<rapidjson::Document, AZStd::string> result = JsonSerializationUtils::ReadJsonString(jsonText);
EXPECT_FALSE(result.IsSuccess());
EXPECT_TRUE(result.GetError().find("JSON parse error at line 4:") == 0);
}
TEST_F(JsonSerializationUtilsTests, LoadJsonStream)
{
const char* jsonText =
R"(
{
"a": 1,
"b": 2,
"c": 3
})";
IO::MemoryStream stream(jsonText, strlen(jsonText));
AZ::Outcome<rapidjson::Document, AZStd::string> result = JsonSerializationUtils::ReadJsonStream(stream);
EXPECT_TRUE(result.IsSuccess());
EXPECT_TRUE(result.GetValue().IsObject());
EXPECT_TRUE(result.GetValue().HasMember("a"));
EXPECT_TRUE(result.GetValue().HasMember("b"));
EXPECT_TRUE(result.GetValue().HasMember("c"));
EXPECT_EQ(result.GetValue()["a"].GetInt(), 1);
EXPECT_EQ(result.GetValue()["b"].GetInt(), 2);
EXPECT_EQ(result.GetValue()["c"].GetInt(), 3);
}
TEST_F(JsonSerializationUtilsTests, LoadJsonStream_ErrorReportsLineNumber)
{
const char* jsonText =
R"(
{
"a": 1,
"b": "This line is missing a comma"
"c": 3
}
)";
IO::MemoryStream stream(jsonText, strlen(jsonText));
AZ::Outcome<rapidjson::Document, AZStd::string> result = JsonSerializationUtils::ReadJsonStream(stream);
EXPECT_FALSE(result.IsSuccess());
EXPECT_TRUE(result.GetError().find("JSON parse error at line 5:") == 0);
}
TEST_F(JsonSerializationUtilsTests, LoadObjectFromStream_Failed_ParseError)
{
char buffer[1024] = "Not a Json";
IO::MemoryStream stream(buffer, 1024);
Test1::TestClass dataToLoad;
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(dataToLoad, stream, &m_deserializationSettings);
EXPECT_TRUE(!loadResult.IsSuccess());
}
TEST_F(JsonSerializationUtilsTests, LoadObjectFromStream_Failed_NotJsonSerialization)
{
char buffer[1024] = "{}";
IO::MemoryStream stream(buffer, 1024);
Test1::TestClass dataToLoad;
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(dataToLoad, stream, &m_deserializationSettings);
EXPECT_TRUE(!loadResult.IsSuccess());
}
TEST_F(JsonSerializationUtilsTests, LoadObjectFromStream_Failed_NoClassInfo)
{
char buffer[1024] =
"{ "
" \"Type\": \"JsonSerialization\" "
"} ";
IO::MemoryStream stream(buffer, 1024);
Test1::TestClass dataToLoad;
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(dataToLoad, stream, &m_deserializationSettings);
EXPECT_TRUE(!loadResult.IsSuccess());
}
TEST_F(JsonSerializationUtilsTests, LoadObjectFromStream_Failed_MismatchClassName)
{
char buffer[1024] =
"{ "
" \"Type\": \"JsonSerialization\", "
" \"ClassName\": \"NotTestClass\", "
" \"ClassData\" : {} "
"} ";
IO::MemoryStream stream(buffer, 1024);
Test1::TestClass dataToLoad;
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(dataToLoad, stream, &m_deserializationSettings);
EXPECT_TRUE(!loadResult.IsSuccess());
}
TEST_F(JsonSerializationUtilsTests, LoadObjectFromStream_Failed_NoSerializeContext)
{
char buffer[1024] =
"{ "
" \"Type\": \"JsonSerialization\", "
" \"ClassName\": \"TestClass\", "
" \"ClassData\" : {} "
"} ";
IO::MemoryStream stream(buffer, 1024);
Test1::TestClass dataToLoad;
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(dataToLoad, stream);
EXPECT_TRUE(!loadResult.IsSuccess());
}
TEST_F(JsonSerializationUtilsTests, LoadObjectFromStream_Failed_HaltMismatchClassMember)
{
char buffer[1024] =
"{ "
" \"Type\": \"JsonSerialization\", "
" \"ClassName\": \"TestClass\", "
" \"ClassData\" : { \"uint\":\"10\", "
" \"bad name2\":\"blabla\"} "
"} ";
IO::MemoryStream stream(buffer, 1024);
Test1::TestClass dataToLoad;
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(dataToLoad, stream, &m_deserializationSettings);
EXPECT_TRUE(!loadResult.IsSuccess());
}
TEST_F(JsonSerializationUtilsTests, LoadObjectFromStream_Failed_WrongValueType)
{
char buffer[1024] =
"{ "
" \"Type\": \"JsonSerialization\", "
" \"ClassName\": \"TestClass\", "
" \"ClassData\" : { \"int\":\"Ten\"} "
"} ";
IO::MemoryStream stream(buffer, 1024);
Test1::TestClass dataToLoad;
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(dataToLoad, stream, &m_deserializationSettings);
EXPECT_TRUE(!loadResult.IsSuccess());
}
TEST_F(JsonSerializationUtilsTests, LoadObjectFromStream_Success_LessField)
{
char buffer[1024] =
"{ "
" \"Type\": \"JsonSerialization\", "
" \"ClassName\": \"TestClass\", "
" \"ClassData\" : { \"int\":\"10\"} "
"} ";
IO::MemoryStream stream(buffer, 1024);
Test1::TestClass dataToLoad;
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(dataToLoad, stream, &m_deserializationSettings);
EXPECT_TRUE(loadResult.IsSuccess());
EXPECT_TRUE(dataToLoad.m_int == 10);
}
TEST_F(JsonSerializationUtilsTests, LoadObjectFromStream_Success_CustomizeCallback)
{
char buffer[1024] =
"{ "
" \"Type\": \"JsonSerialization\", "
" \"ClassName\": \"TestClass\", "
" \"ClassData\" : { \"int\":\"10\"} "
"} ";
IO::MemoryStream stream(buffer, 1024);
Test1::TestClass dataToLoad;
AZStd::string callbackString;
auto issueReportingCallback = [&callbackString](AZStd::string_view message, JsonSerializationResult::ResultCode result, AZStd::string_view target) -> JsonSerializationResult::ResultCode
{
using namespace JsonSerializationResult;
AZ_UNUSED(message);
AZ_UNUSED(target);
callbackString = "issueReportingCallback";
return result;
};
auto settings = m_deserializationSettings;
settings.m_reporting = issueReportingCallback;
Outcome<void, AZStd::string> loadResult = JsonSerializationUtils::LoadObjectFromStream(dataToLoad, stream, &settings);
EXPECT_TRUE(loadResult.IsSuccess());
EXPECT_TRUE(dataToLoad.m_int == 10);
EXPECT_TRUE(!callbackString.empty());
}
TEST_F(JsonSerializationUtilsTests, LoadAnyObjectFromStream_Success)
{
char buffer[1024] =
"{ "
" \"Type\": \"JsonSerialization\", "
" \"ClassName\": \"TestClass\", "
" \"ClassData\" : { \"int\":\"10\"} "
"} ";
IO::MemoryStream stream(buffer, 1024);
Outcome<AZStd::any, AZStd::string> loadResult = JsonSerializationUtils::LoadAnyObjectFromStream(stream, &m_deserializationSettings);
EXPECT_TRUE(loadResult.IsSuccess());
EXPECT_TRUE(loadResult.GetValue().type() == Test1::TestClass::TYPEINFO_Uuid());
Test1::TestClass test = AZStd::any_cast<Test1::TestClass>(loadResult.GetValue());
EXPECT_TRUE(test.m_int == 10);
}
TEST_F(JsonSerializationUtilsTests, LoadAnyObjectFromStream_Failed_WrongValueType)
{
char buffer[1024] =
"{ "
" \"Type\": \"JsonSerialization\", "
" \"ClassName\": \"TestClass\", "
" \"ClassData\" : { \"int\":\"Ten\"} "
"} ";
IO::MemoryStream stream(buffer, 1024);
Outcome<AZStd::any, AZStd::string> loadResult = JsonSerializationUtils::LoadAnyObjectFromStream(stream, &m_deserializationSettings);
EXPECT_TRUE(!loadResult.IsSuccess());
}
} // namespace UnitTest
+66
View File
@@ -0,0 +1,66 @@
/*
* 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 <AzCore/Debug/Timer.h>
#include <AzCore/Debug/TraceMessageBus.h>
#include <AzCore/std/typetraits/typetraits.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzTest/AzTest.h>
#include <AzCore/Memory/OSAllocator.h>
DECLARE_AZ_UNIT_TEST_MAIN()
namespace AZ
{
inline void* AZMemAlloc(AZStd::size_t byteSize, AZStd::size_t alignment, const char* name = "No name allocation")
{
(void)name;
return AZ_OS_MALLOC(byteSize, alignment);
}
inline void AZFree(void* ptr, AZStd::size_t byteSize = 0, AZStd::size_t alignment = 0)
{
(void)byteSize;
(void)alignment;
AZ_OS_FREE(ptr);
}
}
// END OF TEMP MEMORY ALLOCATIONS
using namespace AZ;
// Handle asserts
class TraceDrillerHook
: public AZ::Test::ITestEnvironment
, public UnitTest::TraceBusRedirector
{
public:
void SetupEnvironment() override
{
AllocatorInstance<OSAllocator>::Create(); // used by the bus
BusConnect();
}
void TeardownEnvironment() override
{
BusDisconnect();
AllocatorInstance<OSAllocator>::Destroy(); // used by the bus
}
};
AZ_UNIT_TEST_HOOK(new TraceDrillerHook());
@@ -0,0 +1,142 @@
/*
* 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 "RHITestFixture.h"
#include <AzFramework/IO/LocalFileIO.h>
#include <Atom/RHI.Edit/Utils.h>
#include <Atom/RHI.Reflect/NameIdReflectionMap.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/ObjectStream.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/IO/ByteContainerStream.h>
#include <AzCore/Serialization/Utils.h>
namespace UnitTest
{
class NamedReflectionTests
: public RHITestFixture
{
protected:
void SetUp() override
{
RHITestFixture::SetUp();
AZ::IO::FileIOBase::SetInstance(aznew AZ::IO::LocalFileIO());
}
void TearDown() override
{
delete AZ::IO::FileIOBase::GetInstance();
AZ::IO::FileIOBase::SetInstance(nullptr);
RHITestFixture::TearDown();
}
};
TEST_F(NamedReflectionTests, NameIdReflectionMap_Empty)
{
AZ::RHI::NameIdReflectionMap<AZ::RHI::Handle<>> map;
EXPECT_EQ(map.Size(), 0);
}
TEST_F(NamedReflectionTests, NameIdReflectionMap_Insert)
{
AZ::RHI::NameIdReflectionMap<AZ::RHI::Handle<>> map;
// insert() also sorts the vector
map.Insert(AZ::Name("name1"), AZ::RHI::Handle<>(3));
map.Insert(AZ::Name("name2"), AZ::RHI::Handle<>(2));
map.Insert(AZ::Name("name3"), AZ::RHI::Handle<>(1));
EXPECT_EQ(map.Size(), 3);
}
TEST_F(NamedReflectionTests, NameIdReflectionMap_Serialize)
{
AZ::SerializeContext serializeContext;
AZ::Name::Reflect(&serializeContext);
AZ::RHI::Handle<>::Reflect(&serializeContext);
AZ::RHI::NameIdReflectionMap<AZ::RHI::Handle<>>::Reflect(&serializeContext);
AZ::RHI::NameIdReflectionMap<AZ::RHI::Handle<>> map;
map.Insert(AZ::Name("name1"), AZ::RHI::Handle<>(3));
map.Insert(AZ::Name("name2"), AZ::RHI::Handle<>(2));
map.Insert(AZ::Name("name3"), AZ::RHI::Handle<>(1));
// XML
AZStd::vector<char> xmlBuffer;
AZ::IO::ByteContainerStream<AZStd::vector<char> > xmlStream(&xmlBuffer);
AZ::ObjectStream* xmlObjStream = AZ::ObjectStream::Create(&xmlStream, serializeContext, AZ::ObjectStream::ST_XML);
xmlObjStream->WriteClass(&map);
xmlObjStream->Finalize();
const AZStd::string output(xmlBuffer.data(), xmlBuffer.size());
EXPECT_NE(output.size(), 0);
}
TEST_F(NamedReflectionTests, NameIdReflectionMap_Deserialize)
{
const char* serializeDataFormat = R"(<ObjectStream version="3">
<Class name = "AZ::RHI::NameIdReflectionMap&lt;AZ::RHI::Handle&lt;unsigned int, DefaultNamespaceType&gt;&gt;" type = "{4EAD7B2D-6190-5CB1-898D-5B96EB36EB46}" >
<Class name = "AZStd::vector" field = "ReflectionMap" type = "{74463005-1C3D-5949-A2FB-90E795144DD6}">
<Class name = "AZ::RHI::ReflectionNamePair&lt;AZ::RHI::Handle&lt;unsigned int, DefaultNamespaceType&gt;&gt;" field = "element" version = "2" type = "{A9301E84-7228-5301-9B2A-8A096DE3C712}">
<Class name = "Name" field = "Name" value = "%s" type = "{3D2B920C-9EFD-40D5-AAE0-DF131C3D4931}" />
<Class name = "AZ::RHI::Handle&lt;unsigned int, DefaultNamespaceType&gt;" field = "Index" version = "1" type = "{1811456D-0C3D-58C8-ACE8-FD47F4E80E25}">
<Class name = "unsigned int" field = "m_index" value = "%s" type = "{43DA906B-7DEF-4CA8-9790-854106D3F983}" />
</Class>
</Class>
<Class name = "AZ::RHI::ReflectionNamePair&lt;AZ::RHI::Handle&lt;unsigned int, DefaultNamespaceType&gt;&gt;" field = "element" version = "2" type = "{A9301E84-7228-5301-9B2A-8A096DE3C712}">
<Class name = "Name" field = "Name" value = "%s" type = "{3D2B920C-9EFD-40D5-AAE0-DF131C3D4931}" />
<Class name = "AZ::RHI::Handle&lt;unsigned int, DefaultNamespaceType&gt;" field = "Index" version = "1" type = "{1811456D-0C3D-58C8-ACE8-FD47F4E80E25}">
<Class name = "unsigned int" field = "m_index" value = "%s" type = "{43DA906B-7DEF-4CA8-9790-854106D3F983}" />
</Class>
</Class>
<Class name = "AZ::RHI::ReflectionNamePair&lt;AZ::RHI::Handle&lt;unsigned int, DefaultNamespaceType&gt;&gt;" field = "element" version = "2" type = "{A9301E84-7228-5301-9B2A-8A096DE3C712}">
<Class name = "Name" field = "Name" value = "%s" type = "{3D2B920C-9EFD-40D5-AAE0-DF131C3D4931}" />
<Class name = "AZ::RHI::Handle&lt;unsigned int, DefaultNamespaceType&gt;" field = "Index" version = "1" type = "{1811456D-0C3D-58C8-ACE8-FD47F4E80E25}">
<Class name = "unsigned int" field = "m_index" value = "%s" type = "{43DA906B-7DEF-4CA8-9790-854106D3F983}" />
</Class>
</Class>
</Class>
</Class>
</ObjectStream>)";
// The internal storage sorts by the hash value of strings, so name2 comes before name3, which comes before name1.
// So the inpuit is specifically putting them out order with how it appears sorted when inserted.
AZStd::string inputData = AZStd::string::format(serializeDataFormat, "name3", "3", "name2", "2", "name1", "1");
AZ::SerializeContext serializeContext;
AZ::Name::Reflect(&serializeContext);
AZ::RHI::Handle<>::Reflect(&serializeContext);
AZ::RHI::NameIdReflectionMap<AZ::RHI::Handle<>>::Reflect(&serializeContext);
AZStd::vector<AZ::u8> binaryData(inputData.begin(), inputData.end());
AZ::IO::ByteContainerStream<const AZStd::vector<AZ::u8> > binaryStream(&binaryData);
binaryStream.Seek(0, AZ::IO::GenericStream::ST_SEEK_BEGIN);
{
AZ::RHI::NameIdReflectionMap<AZ::RHI::Handle<>> map;
EXPECT_TRUE(AZ::Utils::LoadObjectFromStreamInPlace(binaryStream, map, &serializeContext));
EXPECT_EQ(map.Size(), 3);
EXPECT_EQ(map.Find(AZ::Name("name1")).m_index, 1);
EXPECT_EQ(map.Find(AZ::Name("name2")).m_index, 2);
EXPECT_EQ(map.Find(AZ::Name("name3")).m_index, 3);
}
}
}
@@ -0,0 +1,19 @@
#
# 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.
#
set(FILES
ArrayView.cpp
InstanceDatabase.cpp
JsonSerializationUtilsTests.cpp
lru_cache.cpp
Main.cpp
vector_set.cpp
)
+172
View File
@@ -0,0 +1,172 @@
/*
* 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 <AtomCore/std/containers/lru_cache.h>
#include <AzCore/std/smart_ptr/intrusive_base.h>
#include <AzCore/std/smart_ptr/unique_ptr.h>
#include <AzCore/UnitTest/TestTypes.h>
using namespace AZStd;
namespace UnitTest
{
using HashedContainers = AllocatorsFixture;
TEST_F(HashedContainers, LRUCacheBasic)
{
lru_cache<int, int> intint_cache;
EXPECT_EQ(intint_cache.capacity(), 0);
EXPECT_EQ(intint_cache.empty(), true);
EXPECT_EQ(intint_cache.size(), 0);
EXPECT_EQ(intint_cache.begin(), intint_cache.end());
EXPECT_EQ(intint_cache.rbegin(), intint_cache.rend());
// should assert since capacity is 0.
AZ_TEST_START_ASSERTTEST;
intint_cache.insert(0, 0);
AZ_TEST_STOP_ASSERTTEST(1);
intint_cache.set_capacity(10);
EXPECT_EQ(intint_cache.capacity(), 10);
int i = 0;
for (; i < 10; ++i)
{
intint_cache.insert(i, 2 * i);
}
EXPECT_EQ(intint_cache.size(), 10);
// We should now have [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], with 9 as the most recent (i.e. at begin()).
i = 0;
for (auto it = intint_cache.rbegin(); it != intint_cache.rend(); ++it, ++i)
{
EXPECT_EQ(it->first, i);
EXPECT_EQ(it->second, 2 * i);
}
EXPECT_EQ(intint_cache.get(9)->first, 9);
EXPECT_EQ(intint_cache.get(9)->second, 9 * 2);
// Bump 2 to most recent.
EXPECT_EQ(intint_cache.get(2)->first, 2);
EXPECT_EQ(intint_cache.get(2)->second, 2 * 2);
// Make sure it's most recent.
EXPECT_EQ(intint_cache.begin()->first, 2);
for (i = 10; i < 20; ++i)
{
intint_cache.insert(i, 2 * i);
}
EXPECT_EQ(intint_cache.size(), 10);
// We should now have [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], with 19 as the most recent (i.e. at begin()).
i = 10;
for (auto it = intint_cache.rbegin(); it != intint_cache.rend(); ++it, ++i)
{
EXPECT_EQ(it->first, i);
EXPECT_EQ(it->second, 2 * i);
}
intint_cache.set_capacity(1);
EXPECT_EQ(intint_cache.size(), 1);
EXPECT_EQ(intint_cache.capacity(), 1);
EXPECT_EQ(intint_cache.begin()->first, 19);
intint_cache.set_capacity(8);
for (i = 0; i < 8; ++i)
{
intint_cache.insert(i, 2 * i);
}
{
auto it = intint_cache.get(5);
EXPECT_EQ(it, intint_cache.begin());
EXPECT_EQ(it->first, 5);
EXPECT_EQ(it->second, 10);
}
// Test adding the same key 10 times.
for (i = 0; i < 10; ++i)
{
intint_cache.insert(0, 0);
}
// the first element should be 0, the rest should be shifted.
EXPECT_EQ(intint_cache.begin()->first, 0);
EXPECT_EQ(intint_cache.begin()->second, 0);
// Asset the second element is (5, 10) the previously added element.
{
auto it = intint_cache.begin();
it++;
EXPECT_EQ(it->first, 5);
EXPECT_EQ(it->second, 10);
}
}
TEST_F(HashedContainers, LRUCacheMoveConstruct)
{
using PtrType = AZStd::unique_ptr<int>;
lru_cache<int, PtrType> intintptr_cache(10);
int i = 0;
for (; i < 10; ++i)
{
intintptr_cache.emplace(i, new int(2 * i));
}
EXPECT_EQ(intintptr_cache.size(), 10);
i = 0;
for (auto it = intintptr_cache.rbegin(); it != intintptr_cache.rend(); ++it, ++i)
{
EXPECT_EQ(it->first, i);
EXPECT_EQ(*(it->second), i * 2);
}
}
TEST_F(HashedContainers, LRUCacheRefCount)
{
class X : public AZStd::intrusive_base
{
public:
X(uint32_t value) : m_value{value} {}
uint32_t m_value;
};
const int TestValue = 123;
using PtrType = AZStd::intrusive_ptr<X>;
lru_cache<int, PtrType> intintptr_cache(10);
PtrType p(new X(TestValue));
intintptr_cache.emplace(0, p);
auto beginIt = intintptr_cache.begin();
EXPECT_EQ(beginIt->second->m_value, TestValue);
EXPECT_EQ(p->use_count(), 2);
int i = 0;
for (; i < 10; ++i)
{
intintptr_cache.emplace(i, p);
}
// Should have all 10 references + the one we hold.
EXPECT_EQ(p->use_count(), 11);
intintptr_cache.clear();
EXPECT_EQ(p->use_count(), 1);
}
}
@@ -0,0 +1,285 @@
/*
* 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 <AtomCore/std/containers/vector_set.h>
#include <AtomCore/std/containers/fixed_vector_set.h>
#include <AzCore/UnitTest/TestTypes.h>
using namespace AZStd;
namespace UnitTest
{
class VectorSets
: public AllocatorsFixture
{
void SetUp() override
{
AllocatorsFixture::SetUp();
}
};
class FixedVectorSets
: public AllocatorsFixture
{
void SetUp() override
{
AllocatorsFixture::SetUp();
}
};
template <typename SetType>
struct VectorSetTester
{
using this_type = VectorSetTester<SetType>;
const AZStd::vector<int32_t> m_expected = { 0, 1, 4, 9, 11, 14, 21, 23, 25, 27, 31 };
const AZStd::vector<int32_t> m_unexpected = { 5, -2 };
const SetType m_vectorSet = { 25, 0, 9, 21, 27, 1, 9, 23, 4, 14, 31, 0, 11 };
void TestFindConst() const
{
for (int32_t value : m_expected)
{
auto it = m_vectorSet.find(value);
EXPECT_EQ(*it, value);
}
for (int32_t value : m_unexpected)
{
auto it = m_vectorSet.find(value);
EXPECT_EQ(it, m_vectorSet.end());
}
EXPECT_EQ(m_vectorSet.size(), m_expected.size());
for (size_t i = 0; i < m_vectorSet.size(); ++i)
{
EXPECT_EQ(m_vectorSet[i], m_expected[i]);
}
}
void TestFind()
{
for (int32_t value : m_expected)
{
auto it = m_vectorSet.find(value);
EXPECT_EQ(*it, value);
}
for (int32_t value : m_unexpected)
{
auto it = m_vectorSet.find(value);
EXPECT_EQ(it, m_vectorSet.end());
}
EXPECT_EQ(m_vectorSet.size(), m_expected.size());
for (size_t i = 0; i < m_vectorSet.size(); ++i)
{
EXPECT_EQ(m_vectorSet[i], m_expected[i]);
}
}
void TestInsertion()
{
auto vectorSet = m_vectorSet;
EXPECT_EQ(vectorSet.erase(9), 1);
EXPECT_EQ(vectorSet.erase(8), 0);
EXPECT_EQ(vectorSet.find(9), vectorSet.end());
EXPECT_EQ(vectorSet.insert(9).second, true);
EXPECT_EQ(*vectorSet.find(9), 9);
EXPECT_EQ(vectorSet.erase(25), 1);
EXPECT_EQ(vectorSet.find(25), vectorSet.end());
EXPECT_EQ(*vectorSet.lower_bound(25), 27);
EXPECT_EQ(*vectorSet.upper_bound(25), 27);
auto iterBoolPair = vectorSet.emplace(25);
EXPECT_EQ(*iterBoolPair.first, 25);
EXPECT_TRUE(iterBoolPair.second);
iterBoolPair = vectorSet.insert(25);
EXPECT_EQ(*iterBoolPair.first, 25);
EXPECT_FALSE(iterBoolPair.second);
}
void TestCompare()
{
auto vectorSet = m_vectorSet;
EXPECT_FALSE(vectorSet.empty());
SetType intSet2 = vectorSet;
EXPECT_EQ(vectorSet, intSet2);
intSet2.erase(9);
EXPECT_NE(vectorSet, intSet2);
intSet2.clear();
EXPECT_EQ(intSet2.size(), 0);
EXPECT_TRUE(intSet2.empty());
}
void TestAssignment()
{
auto vectorSet = m_vectorSet;
vectorSet.assign(m_expected.begin(), m_expected.end());
vectorSet.insert(m_expected.begin(), m_expected.end());
for (size_t i = 0; i < vectorSet.size(); ++i)
{
EXPECT_EQ(vectorSet[i], m_expected[i]);
}
}
void TestIterators()
{
EXPECT_EQ(m_expected.size(), m_vectorSet.size());
{
auto it1 = m_expected.begin();
auto it2 = m_vectorSet.begin();
for (; it1 != m_expected.end(); ++it1, ++it2)
{
EXPECT_NE(it2, m_vectorSet.end());
EXPECT_EQ(*it1, *it2);
}
}
{
auto it1 = m_expected.rbegin();
auto it2 = m_vectorSet.rbegin();
for (; it1 != m_expected.rend(); ++it1, ++it2)
{
EXPECT_NE(it2, m_vectorSet.rend());
EXPECT_EQ(*it1, *it2);
}
}
}
void TestIteratorsConst() const
{
EXPECT_EQ(m_expected.size(), m_vectorSet.size());
{
auto it1 = m_expected.begin();
auto it2 = m_vectorSet.begin();
for (; it1 != m_expected.end(); ++it1, ++it2)
{
EXPECT_NE(it2, m_vectorSet.end());
EXPECT_EQ(*it1, *it2);
}
}
{
auto it1 = m_expected.rbegin();
auto it2 = m_vectorSet.rbegin();
for (; it1 != m_expected.rend(); ++it1, ++it2)
{
EXPECT_NE(it2, m_vectorSet.rend());
EXPECT_EQ(*it1, *it2);
}
}
}
};
TEST_F(VectorSets, Find)
{
VectorSetTester<AZStd::vector_set<int32_t>> tester;
tester.TestFind();
}
TEST_F(VectorSets, FindConst)
{
VectorSetTester<AZStd::vector_set<int32_t>> tester;
tester.TestFindConst();
}
TEST_F(VectorSets, Insertion)
{
VectorSetTester<AZStd::vector_set<int32_t>> tester;
tester.TestInsertion();
}
TEST_F(VectorSets, Compare)
{
VectorSetTester<AZStd::vector_set<int32_t>> tester;
tester.TestCompare();
}
TEST_F(VectorSets, Assignment)
{
VectorSetTester<AZStd::vector_set<int32_t>> tester;
tester.TestAssignment();
}
TEST_F(VectorSets, Iterators)
{
VectorSetTester<AZStd::vector_set<int32_t>> tester;
tester.TestIterators();
}
TEST_F(VectorSets, IteratorsConst)
{
VectorSetTester<AZStd::vector_set<int32_t>> tester;
tester.TestIteratorsConst();
}
TEST_F(FixedVectorSets, Find)
{
VectorSetTester<AZStd::fixed_vector_set<int32_t, 64>> tester;
tester.TestFind();
}
TEST_F(FixedVectorSets, FindConst)
{
VectorSetTester<AZStd::fixed_vector_set<int32_t, 64>> tester;
tester.TestFindConst();
}
TEST_F(FixedVectorSets, Insertion)
{
VectorSetTester<AZStd::fixed_vector_set<int32_t, 64>> tester;
tester.TestInsertion();
}
TEST_F(FixedVectorSets, Compare)
{
VectorSetTester<AZStd::fixed_vector_set<int32_t, 64>> tester;
tester.TestCompare();
}
TEST_F(FixedVectorSets, Assignment)
{
VectorSetTester<AZStd::fixed_vector_set<int32_t, 64>> tester;
tester.TestAssignment();
}
TEST_F(FixedVectorSets, Iterators)
{
VectorSetTester<AZStd::fixed_vector_set<int32_t, 64>> tester;
tester.TestIterators();
}
TEST_F(FixedVectorSets, IteratorsConst)
{
VectorSetTester<AZStd::fixed_vector_set<int32_t, 64>> tester;
tester.TestIteratorsConst();
}
}