FileReaderTests.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include <AzCore/IO/FileReader.h>
  9. #include <FileIOBaseTestTypes.h>
  10. #include <AzCore/UnitTest/TestTypes.h>
  11. namespace UnitTest
  12. {
  13. template <typename FileIOType>
  14. class FileReaderTestFixture
  15. : public LeakDetectionFixture
  16. {
  17. public:
  18. void SetUp() override
  19. {
  20. if constexpr (AZStd::is_same_v<FileIOType, TestFileIOBase>)
  21. {
  22. m_fileIo = AZStd::make_unique<TestFileIOBase>();
  23. }
  24. }
  25. void TearDown() override
  26. {
  27. m_fileIo.reset();
  28. }
  29. protected:
  30. AZStd::unique_ptr<AZ::IO::FileIOBase> m_fileIo{};
  31. };
  32. using FileIOTypes = ::testing::Types<void, TestFileIOBase>;
  33. TYPED_TEST_SUITE(FileReaderTestFixture, FileIOTypes);
  34. TYPED_TEST(FileReaderTestFixture, ConstructorWithFilePath_OpensFileSuccessfully)
  35. {
  36. AZ::IO::FileReader fileReader(this->m_fileIo.get(), AZ::IO::SystemFile::GetNullFilename());
  37. EXPECT_TRUE(fileReader.IsOpen());
  38. }
  39. TYPED_TEST(FileReaderTestFixture, Open_OpensFileSucessfully)
  40. {
  41. AZ::IO::FileReader fileReader;
  42. fileReader.Open(this->m_fileIo.get(), AZ::IO::SystemFile::GetNullFilename());
  43. EXPECT_TRUE(fileReader.IsOpen());
  44. }
  45. TYPED_TEST(FileReaderTestFixture, Eof_OnNULDeviceFile_Succeeds)
  46. {
  47. AZ::IO::FileReader fileReader(this->m_fileIo.get(), AZ::IO::SystemFile::GetNullFilename());
  48. EXPECT_TRUE(fileReader.Eof());
  49. }
  50. TYPED_TEST(FileReaderTestFixture, GetFilePath_ReturnsNULDeviceFilename_Succeeds)
  51. {
  52. AZ::IO::FileReader fileReader(this->m_fileIo.get(), AZ::IO::SystemFile::GetNullFilename());
  53. AZ::IO::FixedMaxPath filePath;
  54. EXPECT_TRUE(fileReader.GetFilePath(filePath));
  55. AZ::IO::FixedMaxPath nulFilename{ AZ::IO::SystemFile::GetNullFilename() };
  56. if (this->m_fileIo)
  57. {
  58. EXPECT_TRUE(this->m_fileIo->ResolvePath(nulFilename, nulFilename));
  59. }
  60. EXPECT_EQ(nulFilename, filePath);
  61. }
  62. } // namespace UnitTest