TestContainer.cpp
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
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   
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         
00090   }
00091 
00092  
00093 
00094   
00095   
00096   
00097 
00098   void TestContainer::test_add_std__string_ElementPointer()
00099   {
00100 
00101         
00102 
00103 
00104 
00105 
00106 
00107         
00108         MyContainer::Pointer container(new MyContainer());
00109 
00110         
00111         MyClass::Pointer element(new MyClass);
00112 
00113         
00114         CPPUNIT_ASSERT(!container->has("element"));
00115         CPPUNIT_ASSERT_NO_THROW(container->add("element", element));
00116         CPPUNIT_ASSERT(container->has("element"));
00117 
00118         
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 
00130 
00131 
00132 
00133 
00134         
00135         MyContainer::Pointer container(new MyContainer());
00136         CPPUNIT_ASSERT_THROW(container->get("element"), ParCompMark::Exception);
00137 
00138         
00139         MyClass::Pointer element(new MyClass);
00140 
00141         
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 
00153 
00154 
00155 
00156 
00157         
00158   }
00159 
00160  
00161 
00162   void TestContainer::test_remove_cstd__string()
00163   {
00164 
00165         
00166 
00167 
00168 
00169 
00170 
00171         
00172         MyContainer::Pointer container(new MyContainer());
00173         CPPUNIT_ASSERT_THROW(container->remove("element"), ParCompMark::Exception);
00174 
00175         
00176         MyClass::Pointer element(new MyClass);
00177 
00178         
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 
00191 
00192 
00193 
00194 
00195         
00196         MyContainer::Pointer container(new MyContainer());
00197         CPPUNIT_ASSERT(container->getSize() == 0);
00198 
00199         
00200         MyClass::Pointer element1(new MyClass), element2(new MyClass);
00201 
00202         
00203         CPPUNIT_ASSERT_NO_THROW(container->add("element1", element1));
00204         CPPUNIT_ASSERT(container->getSize() == 1);
00205 
00206         
00207         CPPUNIT_ASSERT_NO_THROW(container->add("element2", element2));
00208         CPPUNIT_ASSERT(container->getSize() == 2);
00209 
00210         
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 
00224 
00225 
00226 
00227 
00228         
00229   }
00230 
00231  
00232 
00233   void TestContainer::test_begin()
00234   {
00235 
00236         
00237 
00238 
00239 
00240 
00241 
00242         CPPUNIT_FAIL("Implement this test!");
00243   }
00244 
00245  
00246 
00247   void TestContainer::test_end()
00248   {
00249 
00250         
00251 
00252 
00253 
00254 
00255 
00256         CPPUNIT_FAIL("Implement this test!");
00257   }
00258 
00259  
00260 
00261   
00263   CPPUNIT_TEST_SUITE_REGISTRATION(TestContainer);
00264 }