Back to index

salome-med  6.5.0
MEDMEMTest_Group.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 "MEDMEM_Group.hxx"
00025 #include "MEDMEM_define.hxx"
00026 #include "MEDMEM_Mesh.hxx"
00027 #include "MEDMEM_MedMeshDriver.hxx"
00028 
00029 #include <sstream>
00030 #include <cmath>
00031 
00032 using namespace std;
00033 using namespace MEDMEM;
00034 using namespace MED_EN;
00035 
00052 void MEDMEMTest::testGroup()
00053 {
00054   string filename = getResourceFile("pointe.med") ;
00055   string meshname = "maa1";
00056 
00057   MESH * myMesh=new MESH;
00058   myMesh->setName(meshname);
00059   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh);
00060   myMeshDriver.setMeshName(meshname);
00061   myMeshDriver.open();
00062   myMeshDriver.read();
00063   myMeshDriver.close();
00064 
00065   const GROUP * myGroup = myMesh->getGroup(MED_NODE,1);
00066   CPPUNIT_ASSERT(myGroup != NULL);
00067 
00068   int NumberOfFamillies = myGroup->getNumberOfFamilies();
00069   CPPUNIT_ASSERT(NumberOfFamillies != 0);
00070 
00071   vector<FAMILY*> aFamilies = myGroup->getFamilies();
00072   CPPUNIT_ASSERT(NumberOfFamillies == (int)aFamilies.size());
00073   list<FAMILY*> aList;
00074 
00075   for (int j=1;j<=NumberOfFamillies;j++)
00076   {
00077     try{
00078       aList.push_back(myGroup->getFamily(j));
00079     }
00080     catch (const std::exception &e)
00081     {
00082       CPPUNIT_FAIL(e.what());
00083     }
00084     catch (...)
00085     {
00086       CPPUNIT_FAIL("Unknown exception");
00087     }
00088     CPPUNIT_ASSERT_EQUAL(myGroup->getFamily(j)->getName(), aFamilies[j-1]->getName());
00089   }
00090 
00091   GROUP* myGroup2 = new GROUP(*myGroup);
00092 
00093   ostringstream os;
00094   os << *myGroup2;
00095   CPPUNIT_ASSERT(os.str() != "");
00096 
00097   GROUP *myGroup3=new GROUP;
00098   try{
00099     *myGroup3 = *myGroup2;
00100   }
00101   catch (const std::exception &e)
00102   {
00103     CPPUNIT_FAIL(e.what());
00104   }
00105   catch (...)
00106   {
00107     CPPUNIT_FAIL("Unknown exception");
00108   }
00109 
00110   CPPUNIT_ASSERT_EQUAL(*myGroup3, *myGroup2);
00111   myGroup3->removeReference();
00112 
00113   GROUP *myGroup4=new GROUP;
00114   const GROUP * Group = myMesh->getGroup(MED_NODE,2);
00115   CPPUNIT_ASSERT(Group != NULL);
00116 
00117   int NumberOfFamillies1 = Group->getNumberOfFamilies();
00118   CPPUNIT_ASSERT(NumberOfFamillies1 != 0);
00119   if(NumberOfFamillies1)
00120   {
00121     myGroup4->setNumberOfFamilies(NumberOfFamillies1);
00122     myGroup4->setFamilies(Group->getFamilies());
00123     for(int i = 1; i <= myGroup4->getNumberOfFamilies(); i++ )
00124     {
00125       CPPUNIT_ASSERT_EQUAL(myGroup4->getFamily(i), Group->getFamily(i));
00126     }
00127   }
00128   myGroup4->removeReference();
00129   if(aList.size())
00130   {
00131     try{
00132       GROUP *myGroup5=new GROUP("newFamily", aList);
00133       myGroup5->removeReference();
00134     }
00135     catch (const std::exception &e)
00136     {
00137       CPPUNIT_FAIL(e.what());
00138     }
00139     catch (...)
00140     {
00141       CPPUNIT_FAIL("Unknown exception");
00142     }
00143   }
00144   myGroup2->removeReference();
00145   myMesh->removeReference() ;
00146 }