irrMap.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "testUtils.h"
  2. #include <irrlicht.h>
  3. using namespace irr;
  4. using namespace core;
  5. // map has no operator== currently so we have to check manually
  6. // TODO: Add an operator== to core::map and the kick this function out
  7. template <class KeyType, class ValueType>
  8. static bool compareMaps(core::map<KeyType,ValueType> & a, core::map<KeyType,ValueType> & b)
  9. {
  10. if ( a.size() != b.size() )
  11. return false;
  12. // can't test allocator because we have no access to it here
  13. typename core::map<KeyType, ValueType>::Iterator iterA = a.getIterator();
  14. typename core::map<KeyType, ValueType>::Iterator iterB = b.getIterator();
  15. for ( ; !iterA.atEnd(); iterA++, iterB++ ) // TODO: only iter++, no ++iter in irr::map
  16. {
  17. if ( iterA->getValue() != iterB->getValue() )
  18. return false;
  19. }
  20. return true;
  21. }
  22. static bool testSwap()
  23. {
  24. bool result = true;
  25. core::map<int, int> map1, map2, copy1, copy2;
  26. for ( int i=0; i<99; ++i )
  27. {
  28. map1[i] = i;
  29. copy1[i] = i; // TODO: whatever the reason - irr::map does not want operator= so we have to assign to identical values
  30. if ( i < 10 ) // we want also different container sizes
  31. {
  32. map2[i] = 99-i;
  33. copy2[i] = 99-i; // TODO: whatever the reason - irr::map does not want operator= so we have to assign to identical values
  34. }
  35. }
  36. map1.swap(map2);
  37. result &= compareMaps(map1, copy2);
  38. result &= compareMaps(map2, copy1);
  39. assert_log( result );
  40. return result;
  41. }
  42. // Test the functionality of core::list
  43. bool testIrrMap(void)
  44. {
  45. bool success = true;
  46. success &= testSwap();
  47. if(success)
  48. logTestString("\nAll tests passed\n");
  49. else
  50. logTestString("\nFAIL!\n");
  51. return success;
  52. }