From 2196ee77784b18e16957298464cca7734e369856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Hanousek=20-=20vz?= <vithanousek@seznam.cz> Date: Tue, 2 Oct 2018 20:07:55 +0200 Subject: [PATCH] FIX DistributedGrid IO test --- .../DistributedGridIO_MeshFunction.h | 9 ++++--- .../DistributedMeshes/DistributedGridIOTest.h | 24 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h index f5467da6c8..d2f7a18edb 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h @@ -57,7 +57,8 @@ class DistributedGridIO<Functions::MeshFunction<MeshType>,LocalCopy,Device> newMesh->setOrigin(origin+TNL::Containers::Scale(spaceSteps,localBegin)); File meshFile; - meshFile.open( fileName+String("-mesh-")+distrGrid->printProcessCoords()+String(".tnl"),IOMode::write); + bool ok=meshFile.open( fileName+String("-mesh-")+distrGrid->printProcessCoords()+String(".tnl"),IOMode::write); + TNL_ASSERT_TRUE(ok,"Not able to open mesh file to write"); newMesh->save( meshFile ); meshFile.close(); @@ -72,7 +73,8 @@ class DistributedGridIO<Functions::MeshFunction<MeshType>,LocalCopy,Device> CopyEntitiesHelper<MeshFunctionType>::Copy(meshFunction,newMeshFunction,localBegin,zeroCoord,localSize); File file; - file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), IOMode::write ); + ok=file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), IOMode::write ); + TNL_ASSERT_TRUE(ok,"Not able to open file to write"); bool ret=newMeshFunction.save(file); file.close(); @@ -110,7 +112,8 @@ class DistributedGridIO<Functions::MeshFunction<MeshType>,LocalCopy,Device> zeroCoord.setValue(0); File file; - file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), IOMode::read ); + bool ok=file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), IOMode::read ); + TNL_ASSERT_TRUE(ok,"Not able to open file to read"); bool result=newMeshFunction.boundLoad(file); file.close(); CopyEntitiesHelper<MeshFunctionType>::Copy(newMeshFunction,meshFunction,zeroCoord,localBegin,localSize); diff --git a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTest.h b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTest.h index 9ac299621b..5a0a43bcfb 100644 --- a/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTest.h +++ b/src/UnitTests/Meshes/DistributedMeshes/DistributedGridIOTest.h @@ -244,8 +244,8 @@ class TestDistributedGridIO linearFunctionEvaluator.evaluateAllEntities(meshFunctionptr , linearFunctionPtr); - String FileName=String("/tmp/test-file.tnl"); - DistributedGridIO<MeshFunctionType> ::save(FileName, *meshFunctionptr ); + String fileName=String("test-file-distriburtegrid-io-save.tnl"); + DistributedGridIO<MeshFunctionType> ::save(fileName, *meshFunctionptr ); //create similar local mesh function and evaluate linear function on it @@ -273,8 +273,10 @@ class TestDistributedGridIO loadDof.setValue(-1); + String localFileName= fileName+String("-")+distributedGrid.printProcessCoords()+String(".tnl"); + File file; - file.open( FileName+String("-")+distributedGrid.printProcessCoords(), IOMode::read ); + file.open(localFileName, IOMode::read ); loadMeshFunctionptr->boundLoad(file); file.close(); @@ -282,6 +284,11 @@ class TestDistributedGridIO { EXPECT_EQ( localDof.getElement(i), loadDof.getElement(i)) << "Compare Loaded and evaluated Dof Failed for: "<< i; } + + EXPECT_EQ( std::remove( localFileName.getString()) , 0 ); + + //remove meshfile + EXPECT_EQ( std::remove( (fileName+String("-mesh-")+distributedGrid.printProcessCoords()+String(".tnl")).getString()) , 0 ); } static void TestLoad() @@ -326,9 +333,10 @@ class TestDistributedGridIO linearFunctionEvaluator.evaluateAllEntities(localMeshFunctionptr , linearFunctionPtr); - String FileName=String("/tmp/test-file.tnl"); + String fileName=String("test-file-distributedgrid-io-load.tnl"); + String localFileName=fileName+String("-")+distributedGrid.printProcessCoords()+String(".tnl"); File file; - file.open( FileName+String("-")+distributedGrid.printProcessCoords(), IOMode::write ); + file.open( localFileName, IOMode::write ); localMeshFunctionptr->save(file); file.close(); @@ -343,7 +351,7 @@ class TestDistributedGridIO loadDof.setValue(0); loadMeshFunctionptr->bind(loadGridptr,loadDof); - DistributedGridIO<MeshFunctionType> ::load(FileName, *loadMeshFunctionptr ); + DistributedGridIO<MeshFunctionType> ::load(fileName, *loadMeshFunctionptr ); loadMeshFunctionptr->template synchronize<CommunicatorType>(); //need synchronization for overlaps to be filled corectly in loadDof @@ -363,7 +371,9 @@ class TestDistributedGridIO for(int i=0;i<dof.getSize();i++) { EXPECT_EQ( dof.getElement(i), loadDof.getElement(i)) << "Compare Loaded and evaluated Dof Failed for: "<< i; - } + } + + EXPECT_EQ( std::remove( localFileName.getString()) , 0 ); } }; -- GitLab