disambiguateTextures.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (C) 2008-2012 Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace core;
  6. using namespace scene;
  7. using namespace video;
  8. using namespace io;
  9. using namespace gui;
  10. /** This tests verifies that textures opened from different places in the filesystem
  11. can be distinguished, even if they have the same filename. */
  12. bool disambiguateTextures(void)
  13. {
  14. IrrlichtDevice *device =
  15. createDevice( video::EDT_NULL, dimension2d<u32>(640, 480));
  16. if (!device)
  17. {
  18. logTestString("Unable to create EDT_NULL device\n");
  19. return false;
  20. }
  21. // Expects an empty tmp/tmp directory under this app's wd and
  22. // a media directory under this apps' directory with tools.png in it.
  23. stringc wd = device->getFileSystem()->getWorkingDirectory();
  24. if(-1 == wd.find("/tests") && -1 == wd.find("\\tests"))
  25. {
  26. logTestString("The tests must be run from the /tests directory, regardless of where\n"\
  27. "the test executable was built.\n");
  28. device->drop();
  29. return false;
  30. }
  31. IVideoDriver * driver = device->getVideoDriver();
  32. ITexture * tex1 = driver->getTexture("../media/tools.png");
  33. assert_log(tex1);
  34. if(!tex1)
  35. logTestString("Unable to open ../media/tools.png\n");
  36. ITexture * tex2 = driver->getTexture("../media/tools.png");
  37. assert_log(tex2);
  38. if(!tex2)
  39. logTestString("Unable to open ../media/tools.png\n");
  40. IReadFile * readFile = device->getFileSystem()->createAndOpenFile("../media/tools.png");
  41. assert_log(readFile);
  42. if(!readFile)
  43. logTestString("Unable to open ../media/tools.png\n");
  44. ITexture * tex3 = driver->getTexture(readFile);
  45. assert_log(tex3);
  46. if(!readFile)
  47. logTestString("Unable to create texture from ../media/tools.png\n");
  48. readFile->drop();
  49. // All 3 of the above textures should be identical.
  50. assert_log(tex1 == tex2);
  51. assert_log(tex1 == tex3);
  52. stringc newWd = wd + "/empty/empty";
  53. bool changed = device->getFileSystem()->changeWorkingDirectoryTo(newWd.c_str());
  54. assert_log(changed);
  55. ITexture * tex4 = driver->getTexture("../../media/tools.png");
  56. assert_log(tex4);
  57. if(!tex4)
  58. logTestString("Unable to open ../../media/tools.png\n");
  59. assert_log(tex1 != tex4);
  60. // The working directory must be restored for the other tests to work.
  61. changed &= device->getFileSystem()->changeWorkingDirectoryTo(wd.c_str());
  62. device->closeDevice();
  63. device->run();
  64. device->drop();
  65. return (changed && tex1 == tex2 && tex1 == tex3 && tex1 != tex4) ? true : false;
  66. }