DummyResource.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Resource/ResourceObject.h>
  7. namespace anki {
  8. /// @addtogroup resource_private
  9. /// @{
  10. /// A dummy resource for the unit tests of the ResourceManager
  11. class DummyResource : public ResourceObject
  12. {
  13. public:
  14. DummyResource(ResourceManager* manager)
  15. : ResourceObject(manager)
  16. {
  17. }
  18. ~DummyResource()
  19. {
  20. if(m_memory)
  21. {
  22. getAllocator().deallocate(m_memory, 128);
  23. }
  24. }
  25. Error load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
  26. {
  27. Error err = Error::NONE;
  28. if(filename.find("error") == ResourceFilename::NPOS)
  29. {
  30. m_memory = getAllocator().allocate(128);
  31. void* tempMem = getTempAllocator().allocate(128);
  32. getTempAllocator().deallocate(tempMem, 128);
  33. }
  34. else
  35. {
  36. ANKI_RESOURCE_LOGE("Dummy error");
  37. err = Error::USER_DATA;
  38. }
  39. return err;
  40. }
  41. private:
  42. void* m_memory = nullptr;
  43. };
  44. /// @}
  45. } // end namespace anki