MockPrefabFileIOActionValidator.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/std/functional.h>
  10. #include <AzCore/UnitTest/Mocks/MockFileIOBase.h>
  11. #include <AzToolsFramework/Prefab/PrefabDomTypes.h>
  12. #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
  13. namespace UnitTest
  14. {
  15. class MockPrefabFileIOActionValidator
  16. {
  17. public:
  18. MockPrefabFileIOActionValidator();
  19. ~MockPrefabFileIOActionValidator();
  20. void ReadPrefabDom(
  21. AZ::IO::PathView prefabFilePath,
  22. const AzToolsFramework::Prefab::PrefabDom& prefabFileContentDom,
  23. AZ::IO::ResultCode expectedReadResultCode = AZ::IO::ResultCode::Success,
  24. AZ::IO::ResultCode expectedOpenResultCode = AZ::IO::ResultCode::Success,
  25. AZ::IO::ResultCode expectedSizeResultCode = AZ::IO::ResultCode::Success,
  26. AZ::IO::ResultCode expectedCloseResultCode = AZ::IO::ResultCode::Success);
  27. void ReadPrefabDom(
  28. AZ::IO::PathView prefabFilePath,
  29. const AZStd::string& prefabFileContent,
  30. AZ::IO::ResultCode expectedReadResultCode = AZ::IO::ResultCode::Success,
  31. AZ::IO::ResultCode expectedOpenResultCode = AZ::IO::ResultCode::Success,
  32. AZ::IO::ResultCode expectedSizeResultCode = AZ::IO::ResultCode::Success,
  33. AZ::IO::ResultCode expectedCloseResultCode = AZ::IO::ResultCode::Success);
  34. private:
  35. // A counter for creating new file handles.
  36. AZStd::atomic<AZ::IO::HandleType> m_fileHandleCounter = 1u;
  37. // A mock file io for testing.
  38. AZStd::unique_ptr<testing::NiceMock<AZ::IO::MockFileIOBase>> m_fileIOMock;
  39. // A cache for the existing file io.
  40. AZ::IO::FileIOBase* m_priorFileIO = nullptr;
  41. };
  42. }