Salome HOME
d911a43557c4b318f5bdc99966cb3501066214f3
[modules/med.git] / src / MEDMEMCppTest / MEDMEMTest_Family_fault.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MEDMEM_define.hxx"
21 #include "MEDMEM_Family.hxx"
22 #include "MEDMEM_MedMeshDriver.hxx"
23 #include "MEDMEM_Mesh.hxx"
24 #include "MEDMEMTest_Utils.hxx"
25
26 using namespace std;
27 using namespace MEDMEM;
28
29 int main (int argc, char** argv)
30 {
31   string filename = getResourceFile("pointe.med");
32   string meshname = "maa1";
33
34   MESH * aMesh = new MESH;
35   aMesh->setName(meshname);
36   MED_MESH_RDONLY_DRIVER aMeshDriver (filename, aMesh);
37   aMeshDriver.setMeshName(meshname);
38   aMeshDriver.open();
39   aMeshDriver.read();
40   aMeshDriver.close();
41
42   const FAMILY * aFamily1 = aMesh->getFamily(MED_EN::MED_NODE, 1);
43
44   // check default constructor and operator=
45   FAMILY *aFamily4=new FAMILY;
46
47   // (BUG) Wrong implementation or usage of PointerOf<string>.
48   //       Do not use memcpy() with array of std::string!
49   //       Impossible to use FAMILY::operator=!
50   *aFamily4 = *aFamily1;
51   aFamily4->removeReference();
52
53   /*{
54     int nb = 3;
55     string * str = new string[nb];
56
57     char tmp_str [32];
58     for (int i = 0; i < nb; i++) {
59       sprintf(tmp_str, "My String N° %d", i+1);
60       str[i] = tmp;
61     }
62
63     // bad
64     string* _pointer;
65     _pointer = new string[3];
66     // This is wrong, because class string is not simple type
67     // and can have pointers to some data, deallocated in it's destructor,
68     // which (data) will not be copied by this operation.
69     memcpy(_pointer, str, 3*sizeof(string));
70     delete [] _pointer;
71
72     // good
73     //PointerOf<int> p1 (1);
74     //PointerOf<int> p2 (20);
75     //p2 = newAttributeValue;
76     //p1.set(3, p2);
77
78     // bad
79     //PointerOf<string> p1 (1);
80     //PointerOf<string> p2 (20);
81     //p2 = str;
82     //p1.set(3, p2);
83
84     delete [] str;
85   }
86   */
87
88   aMesh->removeReference();
89 }