TestContainer.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00027 
00028 #include "../include/TestContainer.h"
00029 #include "../../include/PCMFileSystemManager.h"
00030 
00031 namespace ParCompMarkTest
00032 {
00033 
00035   struct MyClass
00036   {
00037         int i;
00038         typedef ParCompMark::Pointer < MyClass,
00039         Mutex > Pointer;
00040   };
00041 
00043   typedef Container < MyClass,
00044    Mutex > MyContainer;
00045 
00046   void TestContainer::setUp()
00047   {
00048         std::string currentLogFile = "logs/TestContainer.log";
00049 
00050         if(Logger::getInstance() && Logger::getInstance()->getLogFileName() != currentLogFile)
00051          Logger::destroyInstance();
00052 
00053         if(!FileSystemManager::getInstance())
00054         {
00055          FileSystemManager::createInstance();
00056          FileSystemManager::getInstance()->setAppDirectory("./");
00057          FileSystemManager::getInstance()->initialize();
00058         }
00059 
00060         if(!Logger::getInstance())
00061         {
00062          Logger::createInstance();
00063          Logger::getInstance()->setLogFileName(currentLogFile);
00064          Logger::getInstance()->initialize();
00065         }
00066   }
00067 
00068  /*----------------------------------------------------------------------*/
00069 
00070   void TestContainer::tearDown()
00071   {
00072   }
00073 
00074  /*----------------------------------------------------------------------*/
00075 
00076   //
00077   // Constructor & destructor tests
00078   //
00079 
00080   void TestContainer::test_constructor()
00081   {
00082         CPPUNIT_ASSERT_NO_THROW(MyContainer::Pointer container(new MyContainer()));
00083   }
00084 
00085  /*----------------------------------------------------------------------*/
00086 
00087   void TestContainer::test_destructor()
00088   {
00089         // Tested in contstructor
00090   }
00091 
00092  /*----------------------------------------------------------------------*/
00093 
00094   //
00095   // Method tests
00096   //
00097 
00098   void TestContainer::test_add_std__string_ElementPointer()
00099   {
00100 
00101         /*
00102          * You have to verify the following:
00103          * 
00104          * Add an element.
00105          */
00106 
00107         // Create container
00108         MyContainer::Pointer container(new MyContainer());
00109 
00110         // Create element
00111         MyClass::Pointer element(new MyClass);
00112 
00113         // Add element
00114         CPPUNIT_ASSERT(!container->has("element"));
00115         CPPUNIT_ASSERT_NO_THROW(container->add("element", element));
00116         CPPUNIT_ASSERT(container->has("element"));
00117 
00118         // Add again
00119         CPPUNIT_ASSERT_THROW(container->add("element", element), ParCompMark::Exception);
00120         CPPUNIT_ASSERT(container->has("element"));
00121   }
00122 
00123  /*----------------------------------------------------------------------*/
00124 
00125   void TestContainer::test_get_cstd__string()
00126   {
00127 
00128         /*
00129          * You have to verify the following:
00130          * 
00131          * Get an element by name.
00132          */
00133 
00134         // Create container
00135         MyContainer::Pointer container(new MyContainer());
00136         CPPUNIT_ASSERT_THROW(container->get("element"), ParCompMark::Exception);
00137 
00138         // Create element
00139         MyClass::Pointer element(new MyClass);
00140 
00141         // Add element
00142         CPPUNIT_ASSERT_NO_THROW(container->add("element", element));
00143         CPPUNIT_ASSERT(container->get("element") == element);
00144   }
00145 
00146  /*----------------------------------------------------------------------*/
00147 
00148   void TestContainer::test_has_cstd__string()
00149   {
00150 
00151         /*
00152          * You have to verify the following:
00153          * 
00154          * Search for an element by name.
00155          */
00156 
00157         // Tested in add and get test methods
00158   }
00159 
00160  /*----------------------------------------------------------------------*/
00161 
00162   void TestContainer::test_remove_cstd__string()
00163   {
00164 
00165         /*
00166          * You have to verify the following:
00167          * 
00168          * Remove an element by name.
00169          */
00170 
00171         // Create container
00172         MyContainer::Pointer container(new MyContainer());
00173         CPPUNIT_ASSERT_THROW(container->remove("element"), ParCompMark::Exception);
00174 
00175         // Create element
00176         MyClass::Pointer element(new MyClass);
00177 
00178         // Add element
00179         CPPUNIT_ASSERT_NO_THROW(container->add("element", element));
00180         CPPUNIT_ASSERT_NO_THROW(container->remove("element"));
00181         CPPUNIT_ASSERT(!container->has("element"));
00182   }
00183 
00184  /*----------------------------------------------------------------------*/
00185 
00186   void TestContainer::test_getSize()
00187   {
00188 
00189         /*
00190          * You have to verify the following:
00191          * 
00192          * Return the number of elements.
00193          */
00194 
00195         // Create container
00196         MyContainer::Pointer container(new MyContainer());
00197         CPPUNIT_ASSERT(container->getSize() == 0);
00198 
00199         // Create elements
00200         MyClass::Pointer element1(new MyClass), element2(new MyClass);
00201 
00202         // Add element
00203         CPPUNIT_ASSERT_NO_THROW(container->add("element1", element1));
00204         CPPUNIT_ASSERT(container->getSize() == 1);
00205 
00206         // Add another element
00207         CPPUNIT_ASSERT_NO_THROW(container->add("element2", element2));
00208         CPPUNIT_ASSERT(container->getSize() == 2);
00209 
00210         // Remove elements
00211         CPPUNIT_ASSERT_NO_THROW(container->remove("element1"));
00212         CPPUNIT_ASSERT(container->getSize() == 1);
00213         CPPUNIT_ASSERT_NO_THROW(container->remove("element2"));
00214         CPPUNIT_ASSERT(container->getSize() == 0);
00215   }
00216 
00217  /*----------------------------------------------------------------------*/
00218 
00219   void TestContainer::test_isEmpty()
00220   {
00221 
00222         /*
00223          * You have to verify the following:
00224          * 
00225          * Return true if the container is empty.
00226          */
00227 
00228         // Tested in getSize method
00229   }
00230 
00231  /*----------------------------------------------------------------------*/
00232 
00233   void TestContainer::test_begin()
00234   {
00235 
00236         /*
00237          * You have to verify the following:
00238          * 
00239          * Begin iterator on the container.
00240          */
00241 
00242         CPPUNIT_FAIL("Implement this test!");
00243   }
00244 
00245  /*----------------------------------------------------------------------*/
00246 
00247   void TestContainer::test_end()
00248   {
00249 
00250         /*
00251          * You have to verify the following:
00252          * 
00253          * End iterator on the container.
00254          */
00255 
00256         CPPUNIT_FAIL("Implement this test!");
00257   }
00258 
00259  /*----------------------------------------------------------------------*/
00260 
00261   // To register the suite we add:
00263   CPPUNIT_TEST_SUITE_REGISTRATION(TestContainer);
00264 }