1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MEDMEMTest.hxx"
23 #include <cppunit/Message.h>
24 #include <cppunit/TestAssert.h>
26 #include "MEDMEM_Group.hxx"
27 #include "MEDMEM_define.hxx"
28 #include "MEDMEM_Mesh.hxx"
29 #include "MEDMEM_MedMeshDriver.hxx"
35 using namespace MEDMEM;
36 using namespace MED_EN;
39 * Check methods (10), defined in MEDMEM_Group.hxx:
40 * class GROUP : virtual public SUPPORT {
42 * (+) GROUP(const string & name, const list<FAMILY*> & family) throw (MEDEXCEPTION);
43 * (+) GROUP(const GROUP & m);
44 * (+) virtual ~GROUP();
45 * (+) GROUP & operator=(const GROUP &group);
46 * (+) friend ostream & operator<<(ostream &os, GROUP &my);
47 * (+) inline void setNumberOfFamilies(int numberOfFamilies);
48 * (+) inline void setFamilies(vector<FAMILY*> Family);
49 * (+) inline int getNumberOfFamilies() const;
50 * (+) inline vector<FAMILY*> getFamilies() const;
51 * (+) inline FAMILY * getFamily(int i) const;
54 void MEDMEMTest::testGroup()
56 string datadir = getenv("MED_ROOT_DIR");
57 string filename = datadir + "/share/salome/resources/med/pointe.med" ;
58 string meshname = "maa1";
60 MESH * myMesh= new MESH() ;
61 myMesh->setName(meshname);
62 MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh);
63 myMeshDriver.setMeshName(meshname);
68 const GROUP * myGroup = myMesh->getGroup(MED_NODE,1);
69 CPPUNIT_ASSERT(myGroup != NULL);
71 int NumberOfFamillies = myGroup->getNumberOfFamilies();
72 CPPUNIT_ASSERT(NumberOfFamillies != 0);
74 vector<FAMILY*> aFamilies = myGroup->getFamilies();
75 CPPUNIT_ASSERT(NumberOfFamillies == aFamilies.size());
78 for (int j=1;j<=NumberOfFamillies;j++)
81 aList.push_back(myGroup->getFamily(j));
83 catch (const std::exception &e)
85 CPPUNIT_FAIL(e.what());
89 CPPUNIT_FAIL("Unknown exception");
91 CPPUNIT_ASSERT_EQUAL(myGroup->getFamily(j)->getName(), aFamilies[j-1]->getName());
94 GROUP* myGroup2 = new GROUP(*myGroup);
96 cout<<*myGroup2<<endl;
99 CPPUNIT_ASSERT(os.str() != "");
103 myGroup3 = *myGroup2;
105 catch (const std::exception &e)
107 CPPUNIT_FAIL(e.what());
111 CPPUNIT_FAIL("Unknown exception");
114 CPPUNIT_ASSERT_EQUAL(myGroup3, *myGroup2);
117 const GROUP * Group = myMesh->getGroup(MED_NODE,2);
118 CPPUNIT_ASSERT(Group != NULL);
120 int NumberOfFamillies1 = Group->getNumberOfFamilies();
121 CPPUNIT_ASSERT(NumberOfFamillies1 != 0);
122 if(NumberOfFamillies1)
124 myGroup4.setNumberOfFamilies(NumberOfFamillies1);
125 myGroup4.setFamilies(Group->getFamilies());
126 for(int i = 1; i <= myGroup4.getNumberOfFamilies(); i++ )
128 CPPUNIT_ASSERT_EQUAL(myGroup4.getFamily(i), Group->getFamily(i));
135 GROUP myGroup5("newFamily", aList);
136 cout<< myGroup5 <<endl;
138 catch (const std::exception &e)
140 CPPUNIT_FAIL(e.what());
144 CPPUNIT_FAIL("Unknown exception");