]> git.lizzy.rs Git - irrlicht.git/blob - tests/irrList.cpp
Fix bug introduced in last merge from svn trunk
[irrlicht.git] / tests / irrList.cpp
1 #include "testUtils.h"\r
2 #include <irrlicht.h>\r
3 \r
4 using namespace irr;\r
5 using namespace core;\r
6 \r
7 // list has no operator== currently so we have to check manually\r
8 // TODO: Add an operator== to core::list and the kick this function out\r
9 template <typename T>\r
10 static bool compareLists(const core::list<T> & a, const core::list<T> & b)\r
11 {\r
12         if ( a.size() != b.size() )\r
13                 return false;\r
14         // can't test allocator because we have no access to it here\r
15         typename core::list<T>::ConstIterator iterA = a.begin();\r
16         typename core::list<T>::ConstIterator iterB = b.begin();\r
17         for ( ; iterA != a.end(); ++iterA, ++iterB )\r
18         {\r
19                 if ( (*iterA) != (*iterB) )\r
20                         return false;\r
21         }\r
22         return true;\r
23 }\r
24 \r
25 // Make sure that we can get a const iterator from a non-const list\r
26 template <typename T>\r
27 static void constIteratorCompileTest(core::list<T> & a)\r
28 {\r
29         typename core::list<T>::ConstIterator iterA = a.begin();\r
30         while (iterA != a.end() )\r
31         {\r
32                 ++iterA;\r
33         }\r
34 }\r
35 \r
36 static bool testSwap()\r
37 {\r
38         bool result = true;\r
39 \r
40         core::list<int> list1, list2, copy1, copy2;\r
41         for ( int i=0; i<99; ++i )\r
42         {\r
43                 list1.push_back(i);\r
44                 if ( i < 10 )   // we want also different container sizes i < 50 )\r
45                         list2.push_back(99-i);\r
46         }\r
47         copy1 = list1;\r
48         copy2 = list2;\r
49         list1.swap(list2);\r
50 \r
51 \r
52         result &= compareLists<int>(list1, copy2);\r
53         result &= compareLists<int>(list2, copy1);\r
54 \r
55         assert_log( result );\r
56 \r
57         return result;\r
58 }\r
59 \r
60 // Test the functionality of core::list\r
61 bool testIrrList(void)\r
62 {\r
63         bool success = true;\r
64 \r
65         core::list<int> compileThisList;\r
66         constIteratorCompileTest(compileThisList);\r
67 \r
68         success &= testSwap();\r
69 \r
70         if(success)\r
71                 logTestString("\nAll tests passed\n");\r
72         else\r
73                 logTestString("\nFAIL!\n");\r
74 \r
75         return success;\r
76 }\r