From a0d7be6bf31bcec3e92341f3937f9b5956625de5 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 1 Jul 2010 09:40:23 +0000 Subject: [PATCH] MEDLoader test. --- src/MEDLoader/Makefile.am | 9 +- src/MEDLoader/Test/MEDLoaderTest.cxx | 235 +++++++++++++++++++++++++++ src/MEDLoader/Test/MEDLoaderTest.hxx | 53 ++++++ src/MEDLoader/Test/Makefile.am | 28 ++++ src/MEDLoader/Test/TestMEDLoader.cxx | 25 +++ 5 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 src/MEDLoader/Test/MEDLoaderTest.cxx create mode 100644 src/MEDLoader/Test/MEDLoaderTest.hxx create mode 100755 src/MEDLoader/Test/Makefile.am create mode 100644 src/MEDLoader/Test/TestMEDLoader.cxx diff --git a/src/MEDLoader/Makefile.am b/src/MEDLoader/Makefile.am index bc5acc7e0..0a2e54757 100755 --- a/src/MEDLoader/Makefile.am +++ b/src/MEDLoader/Makefile.am @@ -19,10 +19,17 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am +MEDLOADER_SUBDIRS = + if !MED_ENABLE_MICROMED - SUBDIRS = . Swig + MEDLOADER_SUBDIRS += . Swig +if CPPUNIT_IS_OK + MEDLOADER_SUBDIRS += Test +endif endif +SUBDIRS = $(MEDLOADER_SUBDIRS) + #DIST_SUBDIRS = Swig lib_LTLIBRARIES = libmedloader.la diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx new file mode 100644 index 000000000..27be8bb92 --- /dev/null +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -0,0 +1,235 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDLoaderTest.hxx" +#include "MEDLoader.hxx" +#include "MEDCouplingUMesh.hxx" +#include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingMemArray.hxx" + +using namespace ParaMEDMEM; + +void MEDLoaderTest::testMesh1DRW() +{ + MEDCouplingUMesh *mesh=build1DMesh_1(); + mesh->checkCoherency(); + MEDLoader::WriteUMesh("file1.med",mesh,true); + MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file1.med",mesh->getName(),0); + CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12)); + mesh_rw->decrRef(); + mesh->decrRef(); +} + +void MEDLoaderTest::testMesh2DCurveRW() +{ + MEDCouplingUMesh *mesh=build2DCurveMesh_1(); + mesh->checkCoherency(); + MEDLoader::WriteUMesh("file2.med",mesh,true); + MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file2.med",mesh->getName(),0); + CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12)); + mesh_rw->decrRef(); + mesh->decrRef(); +} + +void MEDLoaderTest::testMesh2DRW() +{ + MEDCouplingUMesh *mesh=build2DMesh_1(); + mesh->checkCoherency(); + MEDLoader::WriteUMesh("file3.med",mesh,true); + MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file3.med",mesh->getName(),0); + CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12)); + mesh_rw->decrRef(); + mesh->decrRef(); +} + +void MEDLoaderTest::testMesh3DSurfRW() +{ + MEDCouplingUMesh *mesh=build3DSurfMesh_1(); + mesh->checkCoherency(); + MEDLoader::WriteUMesh("file4.med",mesh,true); + MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file4.med",mesh->getName(),0); + CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12)); + mesh_rw->decrRef(); + mesh->decrRef(); +} + +void MEDLoaderTest::testMesh3DRW() +{ + MEDCouplingUMesh *mesh=build3DMesh_1(); + mesh->checkCoherency(); + MEDLoader::WriteUMesh("file5.med",mesh,true); + MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile("file5.med",mesh->getName(),0); + CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12)); + mesh_rw->decrRef(); + mesh->decrRef(); +} + +MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1() +{ + double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 }; + int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5}; + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setName("1DMesh_1"); + mesh->setMeshDimension(1); + mesh->allocateCells(4); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6); + mesh->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(6,1); + std::copy(coords,coords+6,myCoords->getPointer()); + mesh->setCoords(myCoords); + myCoords->decrRef(); + return mesh; +} + +MEDCouplingUMesh *MEDLoaderTest::build2DCurveMesh_1() +{ + double coords[12]={ 0.0,0.0, 0.3,0.3, 0.75,0.75, 1.0,1.0, 1.4,1.4, 1.3,1.3 }; + int conn[9]={ 0,1, 1,2, 2,3 , 3,4,5}; + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setName("2DCurveMesh_1"); + mesh->setMeshDimension(1); + mesh->allocateCells(4); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4); + mesh->insertNextCell(INTERP_KERNEL::NORM_SEG3,3,conn+6); + mesh->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(6,2); + std::copy(coords,coords+12,myCoords->getPointer()); + mesh->setCoords(myCoords); + myCoords->decrRef(); + return mesh; +} + +MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1() +{ + double targetCoords[24]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4}; + MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New(); + targetMesh->setMeshDimension(2); + targetMesh->allocateCells(6); + targetMesh->setName("2DMesh_1"); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+20); + targetMesh->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(12,2); + std::copy(targetCoords,targetCoords+24,myCoords->getPointer()); + targetMesh->setCoords(myCoords); + myCoords->decrRef(); + return targetMesh; +} + +MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1() +{ + double targetCoords[36]={-0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3 }; + int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4}; + MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New(); + targetMesh->setMeshDimension(2); + targetMesh->allocateCells(6); + targetMesh->setName("3DSurfMesh_1"); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+20); + targetMesh->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(12,3); + std::copy(targetCoords,targetCoords+36,myCoords->getPointer()); + targetMesh->setCoords(myCoords); + myCoords->decrRef(); + return targetMesh; +} + +MEDCouplingUMesh *MEDLoaderTest::build3DMesh_1() +{ + double coords[180]={ + 0.,0.,0., 1.,1.,0., 1.,1.25,0., 0.,1.,0., 1.,1.5,0., 2.,0.,0., 2.,1.,0., 1.,2.,0., 0.,2.,0., 3.,1.,0., + 3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0., + 0.,0.,1., 1.,1.,1., 1.,1.25,1., 0.,1.,1., 1.,1.5,1., 2.,0.,1., 2.,1.,1., 1.,2.,1., 0.,2.,1., 3.,1.,1., + 3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1., + 0.,0.,2., 1.,1.,2., 1.,1.25,2., 0.,1.,2., 1.,1.5,2., 2.,0.,2., 2.,1.,2., 1.,2.,2., 0.,2.,2., 3.,1.,2., + 3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2., + 0.,0.,3., 1.,1.,3., 1.,1.25,3., 0.,1.,3., 1.,1.5,3., 2.,0.,3., 2.,1.,3., 1.,2.,3., 0.,2.,3., 3.,1.,3., + 3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.}; + + int conn[354]={ + // 0 + 0,11,1,3,15,26,16,18, 1,2,4,7,13,6,-1,1,16,21,6,-1,6,21,28,13,-1,13,7,22,28,-1,7,4,19,22,-1,4,2,17,19,-1,2,1,16,17,-1,16,21,28,22,19,17, + 1,6,5,3,16,21,20,18, 13,10,9,6,28,25,24,21, + 11,8,7,4,2,1,-1,11,26,16,1,-1,1,16,17,2,-1,2,17,19,4,-1,4,19,22,7,-1,7,8,23,22,-1,8,11,26,23,-1,26,16,17,19,22,23, + 7,12,14,13,22,27,29,28, + // 1 + 15,26,16,18,30,41,31,33, 16,17,19,22,28,21,-1,16,31,36,21,-1,21,36,43,28,-1,28,22,37,43,-1,22,19,34,37,-1,19,17,32,34,-1,17,16,31,32,-1,31,36,43,37,34,32, + 16,21,20,18,31,36,35,33, 28,25,24,21,43,40,39,36, + 26,23,22,19,17,16,-1,26,41,31,16,-1,16,31,32,17,-1,17,32,34,19,-1,19,34,37,22,-1,22,23,38,37,-1,23,26,41,38,-1,41,31,32,34,37,38, + 22,27,29,28,37,42,44,43, + // 2 + 30,41,31,33,45,56,46,48, 31,32,34,37,43,36,-1,31,46,51,36,-1,36,51,58,43,-1,43,37,52,58,-1,37,34,49,52,-1,34,32,47,49,-1,32,31,46,47,-1,46,51,58,52,49,47, + 31,36,35,33,46,51,50,48, 43,40,39,36,58,55,54,51, + 41,38,37,34,32,31,-1,41,56,46,31,-1,31,46,47,32,-1,32,47,49,34,-1,34,49,52,37,-1,37,38,53,52,-1,38,41,56,53,-1,56,46,47,49,52,53, + 37,42,44,43,52,57,59,58 + }; + // + MEDCouplingUMesh *ret=MEDCouplingUMesh::New(); + ret->setName("3DMesh_1"); + ret->setMeshDimension(3); + ret->allocateCells(18); + // + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn); + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+51); + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+59); + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+110); + // + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+118); + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+169); + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+177); + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+228); + // + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+236); + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+287); + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+295); + ret->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+346); + // + ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+8); + ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+67); + ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+126); + ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+185); + ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+244); + ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,conn+303); + // + ret->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(60,3); + std::copy(coords,coords+180,myCoords->getPointer()); + ret->setCoords(myCoords); + myCoords->decrRef(); + return ret; +} diff --git a/src/MEDLoader/Test/MEDLoaderTest.hxx b/src/MEDLoader/Test/MEDLoaderTest.hxx new file mode 100644 index 000000000..ae15fdb79 --- /dev/null +++ b/src/MEDLoader/Test/MEDLoaderTest.hxx @@ -0,0 +1,53 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDLOADERTEST_HXX__ +#define __MEDLOADERTEST_HXX__ + +#include + +namespace ParaMEDMEM +{ + class MEDCouplingUMesh; + + class MEDLoaderTest : public CppUnit::TestFixture + { + CPPUNIT_TEST_SUITE(MEDLoaderTest); + CPPUNIT_TEST( testMesh1DRW ); + CPPUNIT_TEST( testMesh2DCurveRW ); + CPPUNIT_TEST( testMesh2DRW ); + CPPUNIT_TEST( testMesh3DSurfRW ); + CPPUNIT_TEST( testMesh3DRW ); + CPPUNIT_TEST_SUITE_END(); + public: + void testMesh1DRW(); + void testMesh2DCurveRW(); + void testMesh2DRW(); + void testMesh3DSurfRW(); + void testMesh3DRW(); + private: + MEDCouplingUMesh *build1DMesh_1(); + MEDCouplingUMesh *build2DCurveMesh_1(); + MEDCouplingUMesh *build2DMesh_1(); + MEDCouplingUMesh *build3DSurfMesh_1(); + MEDCouplingUMesh *build3DMesh_1(); + }; +} + +#endif diff --git a/src/MEDLoader/Test/Makefile.am b/src/MEDLoader/Test/Makefile.am new file mode 100755 index 000000000..ec26493b2 --- /dev/null +++ b/src/MEDLoader/Test/Makefile.am @@ -0,0 +1,28 @@ +# Copyright (C) 2007-2010 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +bin_PROGRAMS= TestMEDLoader + +TestMEDLoader_CPPFLAGS=@CPPUNIT_INCLUDES@ @PTHREAD_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../../INTERP_KERNEL/Bases -I$(srcdir)/../../INTERP_KERNELTest -I$(srcdir)/../../INTERP_KERNEL -I$(srcdir)/../../INTERP_KERNEL/Geometric2D -I$(srcdir)/../../MEDCoupling + +TestMEDLoader_LDFLAGS = @CPPUNIT_LIBS@ ../libmedloader.la ../../MEDCoupling/libmedcoupling.la ../../INTERP_KERNEL/libinterpkernel.la + +dist_TestMEDLoader_SOURCES = TestMEDLoader.cxx MEDLoaderTest.cxx diff --git a/src/MEDLoader/Test/TestMEDLoader.cxx b/src/MEDLoader/Test/TestMEDLoader.cxx new file mode 100644 index 000000000..a48da92f5 --- /dev/null +++ b/src/MEDLoader/Test/TestMEDLoader.cxx @@ -0,0 +1,25 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "CppUnitTest.hxx" +#include "MEDLoaderTest.hxx" + +CPPUNIT_TEST_SUITE_REGISTRATION( ParaMEDMEM::MEDLoaderTest ); + +#include "BasicMainTest.hxx" -- 2.39.2