/* * 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 #include namespace UnitTest { using namespace AZ; using namespace AZ::Data; TEST_F(AllocatorsFixture, AssetId_PrintDecimalSubId_SubIdIsDecimal) { // Arbitrary GUID, sub ID picked that will be different in decimal and hexadecimal. AssetId id("{A9F596D7-9913-4BA4-AD4E-7E477FB9B542}", 20); AZStd::string asString = id.ToString(AZ::Data::AssetId::SubIdDisplayType::Decimal); ASSERT_EQ(asString.size(), 41); ASSERT_EQ(asString[39], '2'); ASSERT_EQ(asString[40], '0'); } TEST_F(AllocatorsFixture, AssetId_PrintHexadecimalSubId_SubIdIsHex) { // Arbitrary GUID, sub ID picked that will be different in decimal and hexadecimal. AssetId id("{A9F596D7-9913-4BA4-AD4E-7E477FB9B542}", 20); AZStd::string asString = id.ToString(AZ::Data::AssetId::SubIdDisplayType::Hex); ASSERT_EQ(asString.size(), 41); ASSERT_EQ(asString[39], '1'); ASSERT_EQ(asString[40], '4'); } TEST_F(AllocatorsFixture, AssetPreserveHintTest_Const_Copy) { // test to make sure that when we copy assets around using copy operations // that the asset Hint is preserved in the case of assets being copied from things missing asset hints. AssetId id("{52C79B55-B5AA-4841-AFC8-683D77716287}", 1); AssetId idWithDifferentAssetId("{EA554205-D887-4A01-9E39-A318DDE4C0FC}", 1); AssetType typeOfExample("{A99E8722-1F1D-4CA9-B89B-921EB3D907A9}"); Asset assetWithHint(id, typeOfExample, "an asset hint"); Asset differentAssetEntirely(idWithDifferentAssetId, typeOfExample, ""); Asset sameAssetWithoutHint(id, typeOfExample, ""); Asset sameAssetWithDifferentHint(id, typeOfExample, "a different hint"); // if we copy an asset from one with the same id, but no hint, preserve the sources hint. assetWithHint = sameAssetWithoutHint; ASSERT_STREQ(assetWithHint.GetHint().c_str(), "an asset hint"); // if we copy from an asset with same id, but with a different hint, we do not preserve the hint. assetWithHint = sameAssetWithDifferentHint; ASSERT_STREQ(assetWithHint.GetHint().c_str(), "a different hint"); // if we copy different assets (different id or sub) the hint must be copied. // even if its empty. assetWithHint = Asset(id, typeOfExample, "an asset hint"); assetWithHint = differentAssetEntirely; ASSERT_STREQ(assetWithHint.GetHint().c_str(), ""); // ensure copy construction copies the hint. Asset copied(sameAssetWithDifferentHint); ASSERT_STREQ(copied.GetHint().c_str(), "a different hint"); } TEST_F(AllocatorsFixture, AssetPreserveHintTest_Rvalue_Ref_Move) { // test to make sure that when we move assets around using move operators // that the asset Hint is preserved in the case of assets being moved from things missing asset hints. AssetId id("{52C79B55-B5AA-4841-AFC8-683D77716287}", 1); AssetId idWithDifferentAssetId("{EA554205-D887-4A01-9E39-A318DDE4C0FC}", 1); AssetType typeOfExample("{A99E8722-1F1D-4CA9-B89B-921EB3D907A9}"); Asset assetWithHint(id, typeOfExample, "an asset hint"); Asset differentAssetEntirely(idWithDifferentAssetId, typeOfExample, ""); Asset sameAssetWithoutHint(id, typeOfExample, ""); Asset sameAssetWithDifferentHint(id, typeOfExample, "a different hint"); // if we move an asset from one with the same id, but no hint, preserve the sources hint. assetWithHint = AZStd::move(sameAssetWithoutHint); ASSERT_STREQ(assetWithHint.GetHint().c_str(), "an asset hint"); // if we move from an asset with same id, but with a different hint, we do not preserve the hint. assetWithHint = AZStd::move(sameAssetWithDifferentHint); ASSERT_STREQ(assetWithHint.GetHint().c_str(), "a different hint"); // if we move different assets (different id or sub) the hint must be copied. // even if its empty. assetWithHint = Asset(id, typeOfExample, "an asset hint"); assetWithHint = AZStd::move(differentAssetEntirely); ASSERT_STREQ(assetWithHint.GetHint().c_str(), ""); // ensure move construction copies the hint. Asset copied(Asset(id, typeOfExample, "a different hint")); ASSERT_STREQ(copied.GetHint().c_str(), "a different hint"); } TEST_F(AllocatorsFixture, AssetIdLessThanOperator_LHSEqualsRHS_ReturnsFalse) { AssetId left("{88888888-4444-4444-4444-CCCCCCCCCCCC}", 1); AssetId right("{88888888-4444-4444-4444-CCCCCCCCCCCC}", 1); ASSERT_FALSE(left < right); } TEST_F(AllocatorsFixture, AssetIdLessThanOperator_GuidsEqualLHSSubIdLessThanRHS_ReturnsTrue) { AssetId left("{EEEEEEEE-EEEE-BBBB-BBBB-CCCCCCCCCCCC}", 0); AssetId right("{EEEEEEEE-EEEE-BBBB-BBBB-CCCCCCCCCCCC}", 1); ASSERT_TRUE(left < right); } TEST_F(AllocatorsFixture, AssetIdLessThanOperator_GuidsEqualLHSSubIdGreaterThanRHS_ReturnsFalse) { AssetId left("{66666666-2222-4444-3333-CCCCCCCCCCCC}", 4); AssetId right("{66666666-2222-4444-3333-CCCCCCCCCCCC}", 2); ASSERT_FALSE(left < right); } TEST_F(AllocatorsFixture, AssetIdLessThanOperator_LHSGuidLessThanRHS_ReturnsTrue) { AssetId left("{00000000-4444-4444-4444-CCCCCCCCCCCC}", 1); AssetId right("{10000000-4444-4444-4444-CCCCCCCCCCCC}", 1); ASSERT_TRUE(left < right); } TEST_F(AllocatorsFixture, AssetIdLessThanOperator_LHSGuidGreaterThanRHS_ReturnsFalse) { AssetId left("{10200000-4444-4444-4444-CCCCCCCCCCCC}", 1); AssetId right("{10000000-4444-4444-4444-CCCCCCCCCCCC}", 1); ASSERT_FALSE(left < right); } TEST_F(AllocatorsFixture, AssetReleaseRetainsAssetState_Id_Type_Hint) { const AssetId id("{52C79B55-B5AA-4841-AFC8-683D77716287}", 1); const AssetType type("{A99E8722-1F1D-4CA9-B89B-921EB3D907A9}"); const AZStd::string hint("an asset hint"); Asset assetWithHint(id, type, hint); assetWithHint.Release(); EXPECT_EQ(assetWithHint.GetId(), id); EXPECT_EQ(assetWithHint.GetType(), type); EXPECT_EQ(assetWithHint.GetHint(), hint); } TEST_F(AllocatorsFixture, AssetResetDefaultsAssetState_Id_Type_Hint) { const AssetId id("{52C79B55-B5AA-4841-AFC8-683D77716287}", 1); const AssetType type("{A99E8722-1F1D-4CA9-B89B-921EB3D907A9}"); const AZStd::string hint("an asset hint"); Asset assetWithHint(id, type, hint); assetWithHint.Reset(); EXPECT_EQ(assetWithHint.GetId(), AssetId()); EXPECT_EQ(assetWithHint.GetType(), AssetType::CreateNull()); EXPECT_EQ(assetWithHint.GetHint(), AZStd::string{}); } }