Back to index

salome-med  6.5.0
MEDMEMTest_Coordinate_fault.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 "MEDMEM_Array.hxx"
00021 #include "MEDMEM_Coordinate.hxx"
00022 
00023 using namespace std;
00024 using namespace MEDMEM;
00025 
00026 int main (int argc, char** argv)
00027 {
00028   COORDINATE anEmptyC (2, 10, MED_EN::MED_FULL_INTERLACE);
00029 
00030   // (BUG) Incoherence between setCoordinateName() and getCoordinateName()
00031   //       C++ index notation is used in "set" methods, while in "get" methods indices start from 1.
00032   anEmptyC.setCoordinateName("alpha", 1);
00033   anEmptyC.setCoordinateName("betta", 2);
00034   // (BUG) Incoherence between setCoordinateUnit() and getCoordinateUnit()
00035   //       C++ index notation is used in "set" methods, while in "get" methods indices start from 1.
00036   anEmptyC.setCoordinateUnit("ttt", 1);
00037   anEmptyC.setCoordinateUnit("sss", 2);
00038 
00039   //CPPUNIT_ASSERT(anEmptyC.getCoordinateName(1) == "alpha");
00040   //CPPUNIT_ASSERT(anEmptyC.getCoordinateName(2) == "betta");
00041   //CPPUNIT_ASSERT(anEmptyC.getCoordinateUnit(1) == "ttt");
00042   //CPPUNIT_ASSERT(anEmptyC.getCoordinateUnit(2) == "sss");
00043 
00044   int len = 10 * 2;
00045   double * cc = new double[len];
00046   for (int i = 0; i < len; i++) {
00047     cc[i] = (double)(i + 1);
00048   }
00049 
00050   MEDARRAY<double> mcc (cc, 2, 10, MED_EN::MED_FULL_INTERLACE, false, false);
00051   delete [] cc;
00052 
00053   // (BUG) Bug in COORDINATE::setCoordinates() in shallow copy mode:
00054   // Segmentation Fault or Hang up after anEmptyC and mcc destruction,
00055   // because array will be owned by two pointers (in mcc and in anEmptyC) after this call
00056   anEmptyC.setCoordinates(&mcc, true);
00057   // In other case (if we dynamically allocate mcc and do not free it) we will have memory leak.
00058 }