irrList.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "testUtils.h"
  2. #include <irrlicht.h>
  3. using namespace irr;
  4. using namespace core;
  5. // list has no operator== currently so we have to check manually
  6. // TODO: Add an operator== to core::list and the kick this function out
  7. template <typename T>
  8. static bool compareLists(const core::list<T> & a, const core::list<T> & 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::list<T>::ConstIterator iterA = a.begin();
  14. typename core::list<T>::ConstIterator iterB = b.begin();
  15. for ( ; iterA != a.end(); ++iterA, ++iterB )
  16. {
  17. if ( (*iterA) != (*iterB) )
  18. return false;
  19. }
  20. return true;
  21. }
  22. // Make sure that we can get a const iterator from a non-const list
  23. template <typename T>
  24. static void constIteratorCompileTest(core::list<T> & a)
  25. {
  26. typename core::list<T>::ConstIterator iterA = a.begin();
  27. while (iterA != a.end() )
  28. {
  29. ++iterA;
  30. }
  31. }
  32. static bool testSwap()
  33. {
  34. bool result = true;
  35. core::list<int> list1, list2, copy1, copy2;
  36. for ( int i=0; i<99; ++i )
  37. {
  38. list1.push_back(i);
  39. if ( i < 10 ) // we want also different container sizes i < 50 )
  40. list2.push_back(99-i);
  41. }
  42. copy1 = list1;
  43. copy2 = list2;
  44. list1.swap(list2);
  45. result &= compareLists<int>(list1, copy2);
  46. result &= compareLists<int>(list2, copy1);
  47. assert_log( result );
  48. return result;
  49. }
  50. // Test the functionality of core::list
  51. bool testIrrList(void)
  52. {
  53. bool success = true;
  54. core::list<int> compileThisList;
  55. constIteratorCompileTest(compileThisList);
  56. success &= testSwap();
  57. if(success)
  58. logTestString("\nAll tests passed\n");
  59. else
  60. logTestString("\nFAIL!\n");
  61. return success;
  62. }