Back to index

salome-med  6.5.0
MEDMEMTest_Unit.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDMEMTest.hxx"
00021 #include <cppunit/Message.h>
00022 #include <cppunit/TestAssert.h>
00023 
00024 #include <cstdlib>
00025 #include <exception>
00026 
00027 #include <MEDMEM_Unit.hxx>
00028 
00029 using namespace std;
00030 using namespace MEDMEM;
00031 
00032 
00064 void MEDMEMTest::testUnit()
00065 {
00066   string myName        = "NameForTesting";
00067   string myDescription = "all values are setted 10";
00068   int    myMasse           = 10;
00069   int    myLength          = 10;
00070   int    myTime            = 10;
00071   int    myTemperature     = 10;
00072   int    myMatterQuantity  = 10;
00073   int    myCurrentStrength = 10;
00074   int    myLightIntensity  = 10;
00075 
00076   //Default constructor
00077   UNIT   myUNIT;
00078 
00079   //Normal constructor
00080   UNIT *myUNIT1 = new UNIT(myName,myDescription);
00081   CPPUNIT_ASSERT(myUNIT1);
00082   delete myUNIT1;
00083 
00084   //--------------------------------------------------------------------//
00085   //                        Tests des methodes                          //
00086   //                                                                    //
00087   // - setName                                                          //
00088   // - setDescription                                                   //
00089   // - setMasse                                                         //
00090   // - setLength                                                        //
00091   // - setTime                                                          //
00092   // - setTemperature                                                   //
00093   // - setMatterQuantity                                                //
00094   // - setCurrentStrength                                               //
00095   // - setLightIntensity                                                //
00096   //--------------------------------------------------------------------//
00097 
00098   try
00099   {
00100     myUNIT.setName(myName);
00101   }
00102   catch(const std::exception &e)
00103   {
00104     CPPUNIT_FAIL(e.what());
00105   }
00106   catch(...)
00107   {
00108     CPPUNIT_FAIL("Unknown exception");
00109   }
00110 
00111   try
00112   {
00113     myUNIT.setDescription(myDescription);
00114   }
00115   catch(const std::exception &e)
00116   {
00117     CPPUNIT_FAIL(e.what());
00118   }
00119   catch(...)
00120   {
00121     CPPUNIT_FAIL("MEDMEM_UNIT::setDescription(): Unknown exception");
00122   }
00123 
00124   try
00125   {
00126     myUNIT.setMasse(myMasse);
00127   }
00128   catch(const std::exception &e)
00129   {
00130     CPPUNIT_FAIL(e.what());
00131   }
00132   catch(...)
00133   {
00134     CPPUNIT_FAIL("Unknown exception");
00135   }
00136 
00137   try
00138   {
00139     myUNIT.setLength(myLength);
00140   }
00141   catch(const std::exception &e)
00142   {
00143     CPPUNIT_FAIL(e.what());
00144   }
00145   catch(...)
00146   {
00147     CPPUNIT_FAIL("Unknown exception");
00148   }
00149 
00150   try
00151   {
00152     myUNIT.setTime(myTime);
00153   }
00154   catch(const std::exception &e)
00155   {
00156     CPPUNIT_FAIL(e.what());
00157   }
00158   catch(...)
00159   {
00160     CPPUNIT_FAIL("Unknown exception");
00161   }
00162 
00163   try
00164   {
00165     myUNIT.setTemperature(myTemperature);
00166   }
00167   catch(const std::exception &e)
00168   {
00169     CPPUNIT_FAIL(e.what());
00170   }
00171   catch(...)
00172   {
00173     CPPUNIT_FAIL("Unknown exception");
00174   }
00175 
00176   try
00177   {
00178     myUNIT.setMatterQuantity(myMatterQuantity);
00179   }
00180   catch(const std::exception &e)
00181   {
00182     CPPUNIT_FAIL(e.what());
00183   }
00184   catch(...)
00185   {
00186     CPPUNIT_FAIL("Unknown exception");
00187   }
00188 
00189   try
00190   {
00191     myUNIT.setCurrentStrength(myCurrentStrength);
00192   }
00193   catch(const std::exception &e)
00194   {
00195     CPPUNIT_FAIL(e.what());
00196   }
00197   catch(...)
00198   {
00199     CPPUNIT_FAIL("Unknown exception");
00200   }
00201 
00202   try
00203   {
00204     myUNIT.setLightIntensity(myLightIntensity);
00205   }
00206   catch(const std::exception &e)
00207   {
00208     CPPUNIT_FAIL(e.what());
00209   }
00210   catch(...)
00211   {
00212     CPPUNIT_FAIL("Unknown exception");
00213   }
00214 
00215   //--------------------------------------------------------------------//
00216   //                        Tests des methodes                          //
00217   //                                                                    //
00218   // - getName                                                          //
00219   // - getDescription                                                   //
00220   // - getMasse                                                         //
00221   // - getLength                                                        //
00222   // - getTime                                                          //
00223   // - getTemperature                                                   //
00224   // - getMatterQuantity                                                //
00225   // - getCurrentStrength                                               //
00226   // - getLightIntensity                                                //
00227   //--------------------------------------------------------------------//
00228 
00229   try
00230   {
00231     CPPUNIT_ASSERT( myUNIT.getName() == myName );
00232   }
00233   catch( const std::exception &e )
00234   {
00235     CPPUNIT_FAIL(e.what());
00236   }
00237   catch ( ... )
00238   {
00239     CPPUNIT_FAIL("Unknown exception");
00240   }
00241 
00242   try
00243   {
00244     CPPUNIT_ASSERT( myUNIT.getDescription() == myDescription );
00245   }
00246   catch( const std::exception &e )
00247   {
00248     CPPUNIT_FAIL(e.what());
00249   }
00250   catch ( ... )
00251   {
00252     CPPUNIT_FAIL("Unknown exception");
00253   }
00254 
00255   try
00256   {
00257     CPPUNIT_ASSERT( myUNIT.getMasse() == myMasse );
00258   }
00259   catch( const std::exception &e )
00260   {
00261     CPPUNIT_FAIL(e.what());
00262   }
00263   catch ( ... )
00264   {
00265     CPPUNIT_FAIL("Unknown exception");
00266   }
00267 
00268   try
00269   {
00270     CPPUNIT_ASSERT( myUNIT.getLength() == myLength );
00271   }
00272   catch( const std::exception &e )
00273   {
00274     CPPUNIT_FAIL(e.what());
00275   }
00276   catch ( ... )
00277   {
00278     CPPUNIT_FAIL("Unknown exception");
00279   }
00280 
00281     try
00282   {
00283     CPPUNIT_ASSERT( myUNIT.getTime() == myTime );
00284   }
00285   catch( const std::exception &e )
00286   {
00287     CPPUNIT_FAIL(e.what());
00288   }
00289   catch ( ... )
00290   {
00291     CPPUNIT_FAIL("Unknown exception");
00292   }
00293 
00294   try
00295   {
00296     CPPUNIT_ASSERT( myUNIT.getTemperature() == myTemperature );
00297   }
00298   catch( const std::exception &e )
00299   {
00300     CPPUNIT_FAIL(e.what());
00301   }
00302   catch ( ... )
00303   {
00304     CPPUNIT_FAIL("Unknown exception");
00305   }
00306 
00307   try
00308   {
00309     CPPUNIT_ASSERT( myUNIT.getMatterQuantity() == myMatterQuantity );
00310   }
00311   catch( const std::exception &e )
00312   {
00313     CPPUNIT_FAIL(e.what());
00314   }
00315   catch ( ... )
00316   {
00317     CPPUNIT_FAIL("Unknown exception");
00318   }
00319 
00320   try
00321   {
00322     CPPUNIT_ASSERT( myUNIT.getCurrentStrength() == myCurrentStrength );
00323   }
00324   catch( const std::exception &e )
00325   {
00326     CPPUNIT_FAIL(e.what());
00327   }
00328   catch ( ... )
00329   {
00330     CPPUNIT_FAIL("Unknown exception");
00331   }
00332 
00333   try
00334   {
00335     CPPUNIT_ASSERT( myUNIT.getLightIntensity() == myLightIntensity );
00336   }
00337   catch( const std::exception &e )
00338   {
00339     CPPUNIT_FAIL(e.what());
00340   }
00341   catch ( ... )
00342   {
00343     CPPUNIT_FAIL("Unknown exception");
00344   }
00345 
00346   //--------------------------------------------------------------------//
00347   //                        Tests des method                            //
00348   // - operator=                                                        //
00349   //--------------------------------------------------------------------//
00350 
00351   UNIT myUNITCpy;
00352   myUNITCpy = myUNIT;
00353   CPPUNIT_ASSERT_EQUAL( myUNITCpy.getTemperature(), myUNITCpy.getTemperature());
00354 }