• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

test/TTestList.cpp

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #include <spl/Debug.h>
00018 #include <spl/collection/List.h>
00019 #include <spl/Log.h>
00020 #include <spl/String.h>
00021 
00022 #ifdef DEBUG
00023 
00024 static void _TestList1()
00025 {
00026         List<int> *list = new List<int>();
00027         DEBUG_CLEAR_MEM_CHECK_POINTS();
00028         DEBUG_NOTE_MEM( list );
00029         list->CheckMem();
00030         DEBUG_DUMP_MEM_LEAKS();
00031         UNIT_ASSERT_MEM_NOTED("List test 1.1");
00032 
00033         list->Add( 1 );
00034         UNIT_ASSERT("list count", list->Count() == 1);
00035         DEBUG_CLEAR_MEM_CHECK_POINTS();
00036         DEBUG_NOTE_MEM( list );
00037         list->CheckMem();
00038         DEBUG_DUMP_MEM_LEAKS();
00039         UNIT_ASSERT_MEM_NOTED("List test 1.2");
00040 
00041         list->Remove( 1 );
00042         UNIT_ASSERT("list count", list->Count() == 0);
00043         DEBUG_CLEAR_MEM_CHECK_POINTS();
00044         DEBUG_NOTE_MEM( list );
00045         list->CheckMem();
00046         DEBUG_DUMP_MEM_LEAKS();
00047         UNIT_ASSERT_MEM_NOTED("List test 1.3");
00048 
00049         list->Add( 2 );
00050         List<int>::Iterator iter = list->Begin();
00051         UNIT_ASSERT("list next", iter.Next());
00052         list->RemoveCurrent(iter);
00053         UNIT_ASSERT("list count", list->Count() == 0);
00054         DEBUG_CLEAR_MEM_CHECK_POINTS();
00055         DEBUG_NOTE_MEM( list );
00056         list->CheckMem();
00057         DEBUG_DUMP_MEM_LEAKS();
00058         UNIT_ASSERT_MEM_NOTED("List test 1.4");
00059 
00060         delete list;
00061         DEBUG_CLEAR_MEM_CHECK_POINTS();
00062         UNIT_ASSERT_MEM_NOTED("List test 1.5");
00063 
00064         Log::SWriteOkFail( "TestList test 1" );
00065 }
00066 
00067 static void _TestList2()
00068 {
00069         List<int> list;
00070         DEBUG_CLEAR_MEM_CHECK_POINTS();
00071         list.CheckMem();
00072         DEBUG_DUMP_MEM_LEAKS();
00073         UNIT_ASSERT_MEM_NOTED("List test 2.1");
00074 
00075         list.Add( 1 );
00076         UNIT_ASSERT("list count", list.Count() == 1);
00077         DEBUG_CLEAR_MEM_CHECK_POINTS();
00078         list.CheckMem();
00079         DEBUG_DUMP_MEM_LEAKS();
00080         UNIT_ASSERT_MEM_NOTED("List test 2.2");
00081 
00082         list.Remove( 1 );
00083         UNIT_ASSERT("list count", list.Count() == 0);
00084         DEBUG_CLEAR_MEM_CHECK_POINTS();
00085         list.CheckMem();
00086         DEBUG_DUMP_MEM_LEAKS();
00087         UNIT_ASSERT_MEM_NOTED("List test 2.3");
00088 
00089         list.Add( 2 );
00090         List<int>::Iterator iter = list.Begin();
00091         UNIT_ASSERT("list next", iter.Next());
00092         list.RemoveCurrent(iter);
00093         UNIT_ASSERT("list count", list.Count() == 0);
00094         DEBUG_CLEAR_MEM_CHECK_POINTS();
00095         list.CheckMem();
00096         DEBUG_DUMP_MEM_LEAKS();
00097         UNIT_ASSERT_MEM_NOTED("List test 2.4");
00098 
00099         Log::SWriteOkFail( "TestList test 2" );
00100 }
00101 
00102 static void _TestList3()
00103 {
00104         List<String> list;
00105         DEBUG_CLEAR_MEM_CHECK_POINTS();
00106         list.CheckMem();
00107         DEBUG_DUMP_MEM_LEAKS();
00108         UNIT_ASSERT_MEM_NOTED("List test 3.1");
00109 
00110         String data1("1");
00111         list.Add( data1 );
00112         
00113         UNIT_ASSERT("list count", list.Count() == 1);
00114         DEBUG_CLEAR_MEM_CHECK_POINTS();
00115         list.CheckMem();
00116         data1.CheckMem();
00117         DEBUG_DUMP_MEM_LEAKS();
00118         UNIT_ASSERT_MEM_NOTED("List test 3.2");
00119 
00120         list.Remove( data1 );
00121         UNIT_ASSERT("list count", list.Count() == 0);
00122         DEBUG_CLEAR_MEM_CHECK_POINTS();
00123         data1.CheckMem();
00124         list.CheckMem();
00125         DEBUG_DUMP_MEM_LEAKS();
00126         UNIT_ASSERT_MEM_NOTED("List test 3.3");
00127 
00128         list.Add( data1 );
00129         List<String>::Iterator iter = list.Begin();
00130         UNIT_ASSERT("list next", iter.Next());
00131         list.RemoveCurrent(iter);
00132         UNIT_ASSERT("list count", list.Count() == 0);
00133         DEBUG_CLEAR_MEM_CHECK_POINTS();
00134         list.CheckMem();
00135         data1.CheckMem();
00136         DEBUG_DUMP_MEM_LEAKS();
00137         UNIT_ASSERT_MEM_NOTED("List test 3.4");
00138 
00139         Log::SWriteOkFail( "TestList test 3" );
00140 }
00141 
00142 void _TestList()
00143 {
00144         _TestList1();
00145         DEBUG_CLEAR_MEM_CHECK_POINTS();
00146         DEBUG_DUMP_MEM_LEAKS();
00147 
00148         _TestList2();
00149         DEBUG_CLEAR_MEM_CHECK_POINTS();
00150         DEBUG_DUMP_MEM_LEAKS();
00151 
00152         _TestList3();
00153         DEBUG_CLEAR_MEM_CHECK_POINTS();
00154         DEBUG_DUMP_MEM_LEAKS();
00155 }
00156 
00157 #endif