Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEMCppTest / MEDMEMTest_Group.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEMTest.hxx"
23 #include <cppunit/Message.h>
24 #include <cppunit/TestAssert.h>
25
26 #include "MEDMEM_Group.hxx"
27 #include "MEDMEM_define.hxx"
28 #include "MEDMEM_Mesh.hxx"
29 #include "MEDMEM_MedMeshDriver.hxx"
30
31 #include <sstream>
32 #include <cmath>
33
34 using namespace std;
35 using namespace MEDMEM;
36 using namespace MED_EN;
37
38 /*!
39  *  Check methods (10), defined in MEDMEM_Group.hxx:
40  *  class GROUP : virtual public SUPPORT {
41  *   (+) GROUP();
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;
52  *  }
53  */
54 void MEDMEMTest::testGroup()
55 {
56   string datadir  = getenv("MED_ROOT_DIR");
57   string filename = datadir + "/share/salome/resources/med/pointe.med" ;
58   string meshname = "maa1";
59
60   MESH * myMesh= new MESH() ;
61   myMesh->setName(meshname);
62   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh);
63   myMeshDriver.setMeshName(meshname);
64   myMeshDriver.open();
65   myMeshDriver.read();
66   myMeshDriver.close();
67
68   const GROUP * myGroup = myMesh->getGroup(MED_NODE,1);
69   CPPUNIT_ASSERT(myGroup != NULL);
70
71   int NumberOfFamillies = myGroup->getNumberOfFamilies();
72   CPPUNIT_ASSERT(NumberOfFamillies != 0);
73
74   vector<FAMILY*> aFamilies = myGroup->getFamilies();
75   CPPUNIT_ASSERT(NumberOfFamillies == aFamilies.size());
76   list<FAMILY*> aList;
77
78   for (int j=1;j<=NumberOfFamillies;j++)
79   {
80     try{
81       aList.push_back(myGroup->getFamily(j));
82     }
83     catch (const std::exception &e)
84     {
85       CPPUNIT_FAIL(e.what());
86     }
87     catch (...)
88     {
89       CPPUNIT_FAIL("Unknown exception");
90     }
91     CPPUNIT_ASSERT_EQUAL(myGroup->getFamily(j)->getName(), aFamilies[j-1]->getName());
92   }
93
94   GROUP* myGroup2 = new GROUP(*myGroup);
95
96   cout<<*myGroup2<<endl;
97   ostringstream os;
98   os << *myGroup2;
99   CPPUNIT_ASSERT(os.str() != "");
100
101   GROUP myGroup3;
102   try{
103     myGroup3 = *myGroup2;
104   }
105   catch (const std::exception &e)
106   {
107     CPPUNIT_FAIL(e.what());
108   }
109   catch (...)
110   {
111     CPPUNIT_FAIL("Unknown exception");
112   }
113
114   CPPUNIT_ASSERT_EQUAL(myGroup3, *myGroup2);
115
116   GROUP myGroup4;
117   const GROUP * Group = myMesh->getGroup(MED_NODE,2);
118   CPPUNIT_ASSERT(Group != NULL);
119
120   int NumberOfFamillies1 = Group->getNumberOfFamilies();
121   CPPUNIT_ASSERT(NumberOfFamillies1 != 0);
122   if(NumberOfFamillies1)
123   {
124     myGroup4.setNumberOfFamilies(NumberOfFamillies1);
125     myGroup4.setFamilies(Group->getFamilies());
126     for(int i = 1; i <= myGroup4.getNumberOfFamilies(); i++ )
127     {
128       CPPUNIT_ASSERT_EQUAL(myGroup4.getFamily(i), Group->getFamily(i));
129     }
130   }
131
132   if(aList.size())
133   {
134     try{
135       GROUP myGroup5("newFamily", aList);
136       cout<< myGroup5 <<endl;
137     }
138     catch (const std::exception &e)
139     {
140       CPPUNIT_FAIL(e.what());
141     }
142     catch (...)
143     {
144       CPPUNIT_FAIL("Unknown exception");
145     }
146   }
147
148   delete myGroup2;
149   delete myMesh ;
150 }