Browse Source

Rename UuidEntry to MetaUuidEntry.

Switch to using MockComponentApplication.
Minor cleanup

Signed-off-by: amzn-mike <[email protected]>
amzn-mike 2 years ago
parent
commit
afef868c2e

+ 7 - 7
Code/Framework/AzToolsFramework/AzToolsFramework/Metadata/MetaUuidEntry.cpp

@@ -6,20 +6,20 @@
  *
  */
 
-#include <AzToolsFramework/Metadata/UuidEntry.h>
+#include <AzToolsFramework/Metadata/MetaUuidEntry.h>
 
 namespace AzToolsFramework
 {
-    void AzToolsFramework::UuidEntry::Reflect(AZ::ReflectContext* context)
+    void AzToolsFramework::MetaUuidEntry::Reflect(AZ::ReflectContext* context)
     {
         if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
         {
-            serializeContext->Class<UuidEntry>()
+            serializeContext->Class<MetaUuidEntry>()
                 ->Version(0)
-                ->Field("uuid", &UuidEntry::m_uuid)
-                ->Field("legacyUuids", &UuidEntry::m_legacyUuids)
-                ->Field("originalPath", &UuidEntry::m_originalPath)
-                ->Field("creationUnixEpochMS", &UuidEntry::m_millisecondsSinceUnixEpoch);
+                ->Field("uuid", &MetaUuidEntry::m_uuid)
+                ->Field("legacyUuids", &MetaUuidEntry::m_legacyUuids)
+                ->Field("originalPath", &MetaUuidEntry::m_originalPath)
+                ->Field("creationUnixEpochMS", &MetaUuidEntry::m_millisecondsSinceUnixEpoch);
         }
     }
 } // namespace AzToolsFramework

+ 3 - 3
Code/Framework/AzToolsFramework/AzToolsFramework/Metadata/UuidUtils.cpp

@@ -8,7 +8,7 @@
 
 #include <AzToolsFramework/Metadata/UuidUtils.h>
 #include <AzToolsFramework/Metadata/MetadataManager.h>
-#include <AzToolsFramework/Metadata/UuidEntry.h>
+#include <AzToolsFramework/Metadata/MetaUuidEntry.h>
 
 namespace AzToolsFramework
 {
@@ -19,7 +19,7 @@ namespace AzToolsFramework
             serializeContext->Class<UuidUtilComponent, AZ::Component>();
         }
 
-        UuidEntry::Reflect(context);
+        MetaUuidEntry::Reflect(context);
     }
 
     bool UuidUtilComponent::CreateSourceUuid(AZ::IO::PathView absoluteFilePath, AZ::Uuid uuid)
@@ -32,7 +32,7 @@ namespace AzToolsFramework
             return false;
         }
 
-        AzToolsFramework::UuidEntry entry;
+        AzToolsFramework::MetaUuidEntry entry;
 
         if (metadataInterface->GetValue(absoluteFilePath, UuidKey, entry) && !entry.m_uuid.IsNull())
         {

+ 30 - 51
Code/Framework/AzToolsFramework/Tests/Metadata/UuidUtilTests.cpp

@@ -15,37 +15,13 @@
 #include <AzCore/Component/ComponentApplication.h>
 #include <AzCore/Utils/Utils.h>
 #include <AzToolsFramework/Metadata/UuidUtils.h>
+#include <AzCore/UnitTest/MockComponentApplication.h>
 
 namespace UnitTest
 {
     struct UuidUtilTests
         : LeakDetectionFixture
-        , AZ::ComponentApplicationBus::Handler
     {
-        //////////////////////////////////////////////////////////////////////////
-        // ComponentApplicationMessages
-        AZ::ComponentApplication* GetApplication() override { return nullptr; }
-        void RegisterComponentDescriptor(const AZ::ComponentDescriptor*) override { }
-        void UnregisterComponentDescriptor(const AZ::ComponentDescriptor*) override { }
-        void RegisterEntityAddedEventHandler(AZ::EntityAddedEvent::Handler&) override { }
-        void RegisterEntityRemovedEventHandler(AZ::EntityRemovedEvent::Handler&) override { }
-        void RegisterEntityActivatedEventHandler(AZ::EntityActivatedEvent::Handler&) override { }
-        void RegisterEntityDeactivatedEventHandler(AZ::EntityDeactivatedEvent::Handler&) override { }
-        void SignalEntityActivated(AZ::Entity*) override { }
-        void SignalEntityDeactivated(AZ::Entity*) override { }
-        bool AddEntity(AZ::Entity*) override { return false; }
-        bool RemoveEntity(AZ::Entity*) override { return false; }
-        bool DeleteEntity(const AZ::EntityId&) override { return false; }
-        AZ::Entity* FindEntity(const AZ::EntityId&) override { return nullptr; }
-        AZ::SerializeContext* GetSerializeContext() override { return m_serializeContext.get(); }
-        AZ::BehaviorContext*  GetBehaviorContext() override { return nullptr; }
-        AZ::JsonRegistrationContext* GetJsonRegistrationContext() override { return m_jsonRegistrationContext.get(); }
-        const char* GetEngineRoot() const override { return nullptr; }
-        const char* GetExecutableFolder() const override { return nullptr; }
-        void EnumerateEntities(const EntityCallback& /*callback*/) override {}
-        void QueryApplicationType(AZ::ApplicationTypeQuery& /*appType*/) const override {}
-        //////////////////////////////////////////////////////////////////////////
-
         void SetUp() override
         {
             UnitTest::TestRunner::Instance().m_suppressPrintf = false;
@@ -57,7 +33,21 @@ namespace UnitTest
             m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
             m_jsonRegistrationContext = AZStd::make_unique<AZ::JsonRegistrationContext>();
 
-            AZ::ComponentApplicationBus::Handler::BusConnect();
+            m_applicationMock = AZStd::make_unique<testing::NiceMock<UnitTest::MockComponentApplication>>();
+
+            ON_CALL(*m_applicationMock, GetSerializeContext())
+                .WillByDefault(
+                    [this]()
+                    {
+                        return m_serializeContext.get();
+                    });
+
+            ON_CALL(*m_applicationMock, GetJsonRegistrationContext())
+                .WillByDefault(
+                    [this]()
+                    {
+                        return m_jsonRegistrationContext.get();
+                    });
 
             AZ::JsonSystemComponent::Reflect(m_jsonRegistrationContext.get());
 
@@ -139,12 +129,14 @@ namespace UnitTest
                         *bytesWritten = size;
                         return AZ::IO::ResultCode::Success;
                     }));
+
+            m_utilInterface = AZ::Interface<AzToolsFramework::IUuidUtil>::Get();
+
+            ASSERT_TRUE(m_utilInterface);
         }
 
         void TearDown() override
         {
-            AZ::ComponentApplicationBus::Handler::BusDisconnect();
-
             m_jsonRegistrationContext->EnableRemoveReflection();
             AZ::JsonSystemComponent::Reflect(m_jsonRegistrationContext.get());
             m_jsonRegistrationContext->DisableRemoveReflection();
@@ -158,6 +150,7 @@ namespace UnitTest
             UnitTest::TestRunner::Instance().ResetSuppressionSettingsToDefault();
         }
 
+        AZStd::unique_ptr<testing::NiceMock<UnitTest::MockComponentApplication>> m_applicationMock;
         AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
         AZStd::unique_ptr<AZ::JsonRegistrationContext> m_jsonRegistrationContext;
         AZStd::unique_ptr<testing::NiceMock<AZ::IO::MockFileIOBase>> m_fileIOMock;
@@ -165,51 +158,37 @@ namespace UnitTest
         AZStd::unordered_map<AZ::IO::HandleType, AZStd::string> m_mockFiles;
         AzToolsFramework::MetadataManager m_manager;
         AzToolsFramework::UuidUtilComponent m_uuidUtil;
+
+        // Cached pointer, no need to clean up
+        AzToolsFramework::IUuidUtil* m_utilInterface{};
     };
 
     TEST_F(UuidUtilTests, CreateSourceUuid_Random_ReturnsRandomUuid)
     {
-        auto* utilInterface = AZ::Interface<AzToolsFramework::IUuidUtil>::Get();
-
-        ASSERT_TRUE(utilInterface);
-
-        auto uuid = utilInterface->CreateSourceUuid("mockfile");
+        auto uuid = m_utilInterface->CreateSourceUuid("mockfile");
 
         EXPECT_FALSE(uuid.IsNull());
     }
 
     TEST_F(UuidUtilTests, CreateSourceUuid_SpecifyUuid_ReturnsTrue)
     {
-        auto* utilInterface = AZ::Interface<AzToolsFramework::IUuidUtil>::Get();
-
-        ASSERT_TRUE(utilInterface);
-
         auto uuid = AZ::Uuid::CreateRandom();
-        EXPECT_TRUE(utilInterface->CreateSourceUuid("mockfile", uuid));
+        EXPECT_TRUE(m_utilInterface->CreateSourceUuid("mockfile", uuid));
     }
 
     TEST_F(UuidUtilTests, CreateSourceUuidRandom_AlreadyAssigned_Fails)
     {
-        auto* utilInterface = AZ::Interface<AzToolsFramework::IUuidUtil>::Get();
-
-        ASSERT_TRUE(utilInterface);
-
-        utilInterface->CreateSourceUuid("mockfile");
-
-        auto uuid = utilInterface->CreateSourceUuid("mockfile");
+        m_utilInterface->CreateSourceUuid("mockfile");
+        auto uuid = m_utilInterface->CreateSourceUuid("mockfile");
 
         EXPECT_TRUE(uuid.IsNull());
     }
 
     TEST_F(UuidUtilTests, CreateSourceUuid_AlreadyAssigned_Fails)
     {
-        auto* utilInterface = AZ::Interface<AzToolsFramework::IUuidUtil>::Get();
-
-        ASSERT_TRUE(utilInterface);
-
         auto uuid = AZ::Uuid::CreateRandom();
-        utilInterface->CreateSourceUuid("mockfile");
+        m_utilInterface->CreateSourceUuid("mockfile");
 
-        EXPECT_FALSE(utilInterface->CreateSourceUuid("mockfile", uuid));
+        EXPECT_FALSE(m_utilInterface->CreateSourceUuid("mockfile", uuid));
     }
 }

+ 6 - 6
Code/Tools/AssetProcessor/native/utilities/UuidManager.cpp

@@ -92,7 +92,7 @@ namespace AssetProcessor
         return file.LexicallyNormal().FixedMaxPathStringAsPosix().c_str();
     }
 
-    AzToolsFramework::UuidEntry UuidManager::GetOrCreateUuidEntry(const SourceAssetReference& sourceAsset)
+    AzToolsFramework::MetaUuidEntry UuidManager::GetOrCreateUuidEntry(const SourceAssetReference& sourceAsset)
     {
         AZStd::scoped_lock scopeLock(m_uuidMutex);
 
@@ -119,7 +119,7 @@ namespace AssetProcessor
         // Metadata manager can't use the file state cache since it is in AzToolsFramework, so it's faster to do an Exists check up-front.
         if (fileExists)
         {
-            AzToolsFramework::UuidEntry uuidInfo;
+            AzToolsFramework::MetaUuidEntry uuidInfo;
 
             // Check if there's a metadata file that already contains a saved UUID
             if (GetMetadataManager()->GetValue(sourceAsset.AbsolutePath(), AzToolsFramework::UuidUtilComponent::UuidKey, uuidInfo))
@@ -134,7 +134,7 @@ namespace AssetProcessor
                 // Missing other entries is ok, just generate them now and update the metadata file
                 if (uuidInfo.m_legacyUuids.empty() || uuidInfo.m_originalPath.empty() || uuidInfo.m_millisecondsSinceUnixEpoch == 0)
                 {
-                    AzToolsFramework::UuidEntry regeneratedEntry = CreateUuidEntry(sourceAsset, isEnabledType);
+                    AzToolsFramework::MetaUuidEntry regeneratedEntry = CreateUuidEntry(sourceAsset, isEnabledType);
 
                     if (uuidInfo.m_legacyUuids.empty())
                     {
@@ -172,7 +172,7 @@ namespace AssetProcessor
         }
 
         // Last resort - generate a new UUID and save it to the metadata file
-        AzToolsFramework::UuidEntry newUuid = CreateUuidEntry(sourceAsset, isEnabledType);
+        AzToolsFramework::MetaUuidEntry newUuid = CreateUuidEntry(sourceAsset, isEnabledType);
 
         if (!isEnabledType ||
             GetMetadataManager()->SetValue(sourceAsset.AbsolutePath(), AzToolsFramework::UuidUtilComponent::UuidKey, newUuid))
@@ -195,9 +195,9 @@ namespace AssetProcessor
         return m_metadataManager;
     }
 
-    AzToolsFramework::UuidEntry UuidManager::CreateUuidEntry(const SourceAssetReference& sourceAsset, bool enabledType)
+    AzToolsFramework::MetaUuidEntry UuidManager::CreateUuidEntry(const SourceAssetReference& sourceAsset, bool enabledType)
     {
-        AzToolsFramework::UuidEntry newUuid;
+        AzToolsFramework::MetaUuidEntry newUuid;
 
         newUuid.m_uuid = enabledType ? CreateUuid() : AssetUtilities::CreateSafeSourceUUIDFromName(sourceAsset.RelativePath().c_str());
         newUuid.m_legacyUuids = CreateLegacyUuids(sourceAsset.RelativePath().c_str());

+ 4 - 4
Code/Tools/AssetProcessor/native/utilities/UuidManager.h

@@ -14,7 +14,7 @@
 #include <AzCore/std/string/string.h>
 #include <AzToolsFramework/Metadata/UuidUtils.h>
 #include <native/AssetManager/SourceAssetReference.h>
-#include <AzToolsFramework/Metadata/UuidEntry.h>
+#include <AzToolsFramework/Metadata/MetaUuidEntry.h>
 
 namespace AzToolsFramework
 {
@@ -76,16 +76,16 @@ namespace AssetProcessor
 
     private:
         AZStd::string GetCanonicalPath(AZ::IO::PathView file);
-        AzToolsFramework::UuidEntry GetOrCreateUuidEntry(const SourceAssetReference& sourceAsset);
+        AzToolsFramework::MetaUuidEntry GetOrCreateUuidEntry(const SourceAssetReference& sourceAsset);
         AzToolsFramework::IMetadataRequests* GetMetadataManager();
-        AzToolsFramework::UuidEntry CreateUuidEntry(const SourceAssetReference& sourceAsset, bool enabledType);
+        AzToolsFramework::MetaUuidEntry CreateUuidEntry(const SourceAssetReference& sourceAsset, bool enabledType);
         AZ::Uuid CreateUuid();
         AZStd::unordered_set<AZ::Uuid> CreateLegacyUuids(const AZStd::string& file);
         void InvalidateCacheEntry(AZ::IO::FixedMaxPath file);
 
         AZStd::recursive_mutex m_uuidMutex;
         // Cache of uuids.  AbsPath -> UUIDEntry
-        AZStd::unordered_map<AZStd::string, AzToolsFramework::UuidEntry> m_uuids;
+        AZStd::unordered_map<AZStd::string, AzToolsFramework::MetaUuidEntry> m_uuids;
         // Types which should use randomly generated UUIDs
         AZStd::unordered_set<AZStd::string> m_enabledTypes;
         AzToolsFramework::IMetadataRequests* m_metadataManager{};