loadTextures.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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
  11. filesystem don't create duplicated textures. */
  12. bool loadFromFileFolder(void)
  13. {
  14. IrrlichtDevice *device =
  15. createDevice( video::EDT_NULL, dimension2du(160, 120));
  16. if (!device)
  17. {
  18. logTestString("Unable to create EDT_NULL device\n");
  19. return false;
  20. }
  21. IVideoDriver * driver = device->getVideoDriver();
  22. u32 numTexs = driver->getTextureCount();
  23. ITexture * tex1 = driver->getTexture("../media/tools.png");
  24. assert_log(tex1);
  25. if(!tex1)
  26. logTestString("Unable to open ../media/tools.png\n");
  27. if (driver->getTextureCount()!=numTexs+1)
  28. {
  29. logTestString("No additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
  30. return false;
  31. }
  32. IReadFile * readFile = device->getFileSystem()->createAndOpenFile("../media/tools.png");
  33. assert_log(readFile);
  34. if(!readFile)
  35. logTestString("Unable to open ../media/tools.png\n");
  36. if (driver->getTextureCount()!=numTexs+1)
  37. {
  38. logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
  39. return false;
  40. }
  41. ITexture * tex2 = driver->getTexture(readFile);
  42. assert_log(tex2);
  43. if(!readFile)
  44. logTestString("Unable to create texture from ../media/tools.png\n");
  45. if (driver->getTextureCount()!=numTexs+1)
  46. {
  47. logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
  48. return false;
  49. }
  50. readFile->drop();
  51. // adding a folder archive
  52. device->getFileSystem()->addFileArchive( "../media/" );
  53. ITexture * tex3 = driver->getTexture("tools.png");
  54. assert_log(tex3);
  55. if(!tex3)
  56. logTestString("Unable to open tools.png\n");
  57. if (driver->getTextureCount()!=numTexs+1)
  58. {
  59. logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
  60. return false;
  61. }
  62. ITexture * tex4 = driver->getTexture("tools.png");
  63. assert_log(tex4);
  64. if(!tex4)
  65. logTestString("Unable to open tools.png\n");
  66. if (driver->getTextureCount()!=numTexs+1)
  67. {
  68. logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__);
  69. return false;
  70. }
  71. device->closeDevice();
  72. device->run();
  73. device->drop();
  74. return ((tex1 == tex2) && (tex1 == tex3) && (tex1 == tex4));
  75. }
  76. bool loadTextures()
  77. {
  78. bool result = true;
  79. result &= loadFromFileFolder();
  80. return result;
  81. }