From 803bb734d3e463df8037699bf00d9198ef3e01e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz> Date: Fri, 12 Apr 2019 12:59:07 +0200 Subject: [PATCH] Added missing ASSERT_NO_THROW macros to tests --- src/TNL/Object.hpp | 2 - src/UnitTests/Containers/ArrayTest.h | 24 ++++----- src/UnitTests/Containers/StaticArrayTest.cpp | 12 ++--- src/UnitTests/FileTest.h | 52 +++++++++---------- src/UnitTests/Matrices/DenseMatrixTest.h | 4 +- src/UnitTests/Matrices/SparseMatrixTest.hpp | 6 +-- src/UnitTests/Meshes/MeshTest.h | 12 ++--- src/UnitTests/ObjectTest.cpp | 22 ++++---- src/UnitTests/SaveAndLoadMeshfunctionTest.cpp | 24 ++++----- src/UnitTests/StringTest.cpp | 10 ++-- 10 files changed, 83 insertions(+), 85 deletions(-) diff --git a/src/TNL/Object.hpp b/src/TNL/Object.hpp index 1e83f036f1..92d33626db 100644 --- a/src/TNL/Object.hpp +++ b/src/TNL/Object.hpp @@ -166,6 +166,4 @@ inline void loadHeader( File& file, String& type ) file >> type; } - - } // namespace TNL diff --git a/src/UnitTests/Containers/ArrayTest.h b/src/UnitTests/Containers/ArrayTest.h index 573c79f364..62bf493cbc 100644 --- a/src/UnitTests/Containers/ArrayTest.h +++ b/src/UnitTests/Containers/ArrayTest.h @@ -479,11 +479,11 @@ TYPED_TEST( ArrayTest, SaveAndLoad ) for( int i = 0; i < 100; i ++ ) v.setElement( i, 3.14147 ); File file; - file.open( "test-file.tnl", File::Mode::Out ); - v.save( file ); - file.close(); - file.open( "test-file.tnl", File::Mode::In ); - u.load( file ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( v.save( file ) ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( u.load( file ) ); EXPECT_EQ( u, v ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); @@ -498,23 +498,23 @@ TYPED_TEST( ArrayTest, boundLoad ) for( int i = 0; i < 100; i ++ ) v.setElement( i, 3.14147 ); File file; - file.open( "test-file.tnl", File::Mode::Out ); - v.save( file ); - file.close(); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( v.save( file ) ); + ASSERT_NO_THROW( file.close() ); w.setSize( 100 ); auto u = w.getView(); - file.open( "test-file.tnl", File::Mode::In ); - u.load( file ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( u.load( file ) ); EXPECT_EQ( u, v ); EXPECT_EQ( u.getData(), w.getData() ); ArrayType z( 50 ); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); EXPECT_ANY_THROW( z.boundLoad( file ) ); v.reset(); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); EXPECT_NO_THROW( v.boundLoad( file ) ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); diff --git a/src/UnitTests/Containers/StaticArrayTest.cpp b/src/UnitTests/Containers/StaticArrayTest.cpp index 16817100f5..1297933e76 100644 --- a/src/UnitTests/Containers/StaticArrayTest.cpp +++ b/src/UnitTests/Containers/StaticArrayTest.cpp @@ -246,12 +246,12 @@ TYPED_TEST( StaticArrayTest, SaveAndLoad ) ArrayType u1( 7 ), u2; File file; - file.open( "tnl-static-array-test.tnl", File::Mode::Out ); - u1.save( file ); - file.close(); - file.open( "tnl-static-array-test.tnl", File::Mode::In ); - u2.load( file ); - file.close(); + ASSERT_NO_THROW( file.open( "tnl-static-array-test.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( u1.save( file ) ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "tnl-static-array-test.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( u2.load( file ) ); + ASSERT_NO_THROW( file.close() ); EXPECT_EQ( u1, u2 ); diff --git a/src/UnitTests/FileTest.h b/src/UnitTests/FileTest.h index 39671ba661..4a69fcb202 100644 --- a/src/UnitTests/FileTest.h +++ b/src/UnitTests/FileTest.h @@ -24,23 +24,23 @@ TEST( FileTest, OpenInvalid ) TEST( FileTest, WriteAndRead ) { File file; - file.open( String( "test-file.tnl" ), File::Mode::Out ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); int intData( 5 ); double doubleData[ 3 ] = { 1.0, 2.0, 3.0 }; const double constDoubleData = 3.14; - file.save( &intData ); - file.save( doubleData, 3 ); - file.save( &constDoubleData ); - file.close(); + ASSERT_NO_THROW( file.save( &intData ) ); + ASSERT_NO_THROW( file.save( doubleData, 3 ) ); + ASSERT_NO_THROW( file.save( &constDoubleData ) ); + ASSERT_NO_THROW( file.close() ); - file.open( String( "test-file.tnl" ), File::Mode::In ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::In ) ); int newIntData; double newDoubleData[ 3 ]; double newConstDoubleData; - file.load( &newIntData, 1 ); - file.load( newDoubleData, 3 ); - file.load( &newConstDoubleData, 1 ); + ASSERT_NO_THROW( file.load( &newIntData, 1 ) ); + ASSERT_NO_THROW( file.load( newDoubleData, 3 ) ); + ASSERT_NO_THROW( file.load( &newConstDoubleData, 1 ) ); EXPECT_EQ( newIntData, intData ); for( int i = 0; i < 3; i ++ ) @@ -58,17 +58,17 @@ TEST( FileTest, WriteAndReadWithConversion ) float floatData[ 3 ]; int intData[ 3 ]; File file; - file.open( "test-file.tnl", File::Mode::Out | File::Mode::Truncate ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out | File::Mode::Truncate ) ); file.save< double, float, Devices::Host >( doubleData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); file.load< float, float, Devices::Host >( floatData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); file.load< int, float, Devices::Host >( intData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); EXPECT_NEAR( floatData[ 0 ], 3.14159, 0.0001 ); EXPECT_NEAR( floatData[ 1 ], 2.71828, 0.0001 ); @@ -108,14 +108,14 @@ TEST( FileTest, WriteAndReadCUDA ) cudaMemcpyHostToDevice ); File file; - file.open( String( "test-file.tnl" ), File::Mode::Out ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); file.save< int, int, Devices::Cuda >( cudaIntData ); file.save< float, float, Devices::Cuda >( cudaFloatData, 3 ); file.save< const double, double, Devices::Cuda >( cudaConstDoubleData ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( String( "test-file.tnl" ), File::Mode::In ); + ASSERT_NO_THROW( file.open( String( "test-file.tnl" ), File::Mode::In ) ); int newIntData; float newFloatData[ 3 ]; double newDoubleData; @@ -147,7 +147,7 @@ TEST( FileTest, WriteAndReadCUDA ) EXPECT_EQ( newDoubleData, constDoubleData ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); -}; +} TEST( FileTest, WriteAndReadCUDAWithConversion ) { @@ -169,17 +169,17 @@ TEST( FileTest, WriteAndReadCUDAWithConversion ) cudaMemcpyHostToDevice ); File file; - file.open( String( "cuda-test-file.tnl" ), File::Mode::Out | File::Mode::Truncate ); + ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), File::Mode::Out | File::Mode::Truncate ) ); file.save< double, float, Devices::Cuda >( cudaConstDoubleData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( String( "cuda-test-file.tnl" ), File::Mode::In ); + ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), File::Mode::In ) ); file.load< float, float, Devices::Cuda >( cudaFloatData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); - file.open( String( "cuda-test-file.tnl" ), File::Mode::In ); + ASSERT_NO_THROW( file.open( String( "cuda-test-file.tnl" ), File::Mode::In ) ); file.load< int, float, Devices::Cuda >( cudaIntData, 3 ); - file.close(); + ASSERT_NO_THROW( file.close() ); cudaMemcpy( floatData, cudaFloatData, @@ -200,7 +200,7 @@ TEST( FileTest, WriteAndReadCUDAWithConversion ) EXPECT_EQ( intData[ 2 ], 1 ); EXPECT_EQ( std::remove( "cuda-test-file.tnl" ), 0 ); -}; +} #endif #endif diff --git a/src/UnitTests/Matrices/DenseMatrixTest.h b/src/UnitTests/Matrices/DenseMatrixTest.h index c67386e819..ea4b6174dc 100644 --- a/src/UnitTests/Matrices/DenseMatrixTest.h +++ b/src/UnitTests/Matrices/DenseMatrixTest.h @@ -1281,13 +1281,13 @@ void test_SaveAndLoad() for( IndexType j = 0; j < cols; j++ ) savedMatrix.setElement( i, j, value++ ); - savedMatrix.save( "denseMatrixFile" ); + ASSERT_NO_THROW( savedMatrix.save( "denseMatrixFile" ) ); Matrix loadedMatrix; loadedMatrix.reset(); loadedMatrix.setDimensions( rows, cols ); - loadedMatrix.load( "denseMatrixFile" ); + ASSERT_NO_THROW( loadedMatrix.load( "denseMatrixFile" ) ); EXPECT_EQ( savedMatrix.getElement( 0, 0 ), loadedMatrix.getElement( 0, 0 ) ); EXPECT_EQ( savedMatrix.getElement( 0, 1 ), loadedMatrix.getElement( 0, 1 ) ); diff --git a/src/UnitTests/Matrices/SparseMatrixTest.hpp b/src/UnitTests/Matrices/SparseMatrixTest.hpp index 8c3858641d..28883ae76c 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest.hpp +++ b/src/UnitTests/Matrices/SparseMatrixTest.hpp @@ -799,7 +799,7 @@ void test_SaveAndLoad() for( IndexType i = 1; i < m_cols; i++ ) // 3rd row savedMatrix.setElement( 3, i, value++ ); - savedMatrix.save( "sparseMatrixFile" ); + ASSERT_NO_THROW( savedMatrix.save( "sparseMatrixFile" ) ); Matrix loadedMatrix; loadedMatrix.reset(); @@ -810,7 +810,7 @@ void test_SaveAndLoad() loadedMatrix.setCompressedRowLengths( rowLengths2 ); - loadedMatrix.load( "sparseMatrixFile" ); + ASSERT_NO_THROW( loadedMatrix.load( "sparseMatrixFile" ) ); EXPECT_EQ( savedMatrix.getElement( 0, 0 ), loadedMatrix.getElement( 0, 0 ) ); @@ -923,4 +923,4 @@ void test_Print() EXPECT_EQ( printed.str(), couted.str() ); } -#endif \ No newline at end of file +#endif diff --git a/src/UnitTests/Meshes/MeshTest.h b/src/UnitTests/Meshes/MeshTest.h index 65ec8c353b..9d450a2935 100644 --- a/src/UnitTests/Meshes/MeshTest.h +++ b/src/UnitTests/Meshes/MeshTest.h @@ -107,13 +107,13 @@ void testMeshOnCuda( const Mesh& mesh ) EXPECT_EQ( mesh2, mesh ); // test load from file to CUDA - mesh.save( "mesh.tnl" ); - dmesh1.load( "mesh.tnl" ); + ASSERT_NO_THROW( mesh.save( "mesh.tnl" ) ); + ASSERT_NO_THROW( dmesh1.load( "mesh.tnl" ) ); EXPECT_EQ( dmesh1, mesh ); // test save into file from CUDA - dmesh1.save( "mesh.tnl" ); - mesh2.load( "mesh.tnl" ); + ASSERT_NO_THROW( dmesh1.save( "mesh.tnl" ) ); + ASSERT_NO_THROW( mesh2.load( "mesh.tnl" ) ); EXPECT_EQ( mesh2, mesh ); EXPECT_EQ( std::remove( "mesh.tnl" ), 0 ); @@ -154,8 +154,8 @@ template< typename Mesh > void testFinishedMesh( const Mesh& mesh ) { Mesh mesh2; - mesh.save( "mesh.tnl" ); - mesh2.load( "mesh.tnl" ); + ASSERT_NO_THROW( mesh.save( "mesh.tnl" ) ); + ASSERT_NO_THROW( mesh2.load( "mesh.tnl" ) ); EXPECT_EQ( std::remove( "mesh.tnl" ), 0 ); ASSERT_EQ( mesh, mesh2 ); compareStringRepresentation( mesh, mesh2 ); diff --git a/src/UnitTests/ObjectTest.cpp b/src/UnitTests/ObjectTest.cpp index ac0281afa2..8de4175078 100644 --- a/src/UnitTests/ObjectTest.cpp +++ b/src/UnitTests/ObjectTest.cpp @@ -24,11 +24,11 @@ TEST( ObjectTest, SaveAndLoadTest ) { Object testObject; File file; - file.open( "test-file.tnl", File::Mode::Out ); - testObject.save( file ); - file.close(); - file.open( "test-file.tnl", File::Mode::In ); - testObject.load( file ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( testObject.save( file ) ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); + ASSERT_NO_THROW( testObject.load( file ) ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); } @@ -80,13 +80,13 @@ TEST( HeaderTest, SaveAndLoadTest ) { Object testObject; File file; - file.open( "test-file.tnl", File::Mode::Out ); - saveHeader( file, "TYPE" ); - file.close(); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); + ASSERT_NO_THROW( saveHeader( file, "TYPE" ) ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); String type; - loadHeader( file, type ); - + ASSERT_NO_THROW( loadHeader( file, type ) ); + EXPECT_EQ( type, "TYPE" ); EXPECT_EQ( std::remove( "test-file.tnl" ), 0 ); diff --git a/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp b/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp index e7079e894b..9e4b1eaf36 100644 --- a/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp +++ b/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp @@ -8,7 +8,7 @@ #include <TNL/Functions/MeshFunction.h> -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include <gtest/gtest.h> #include "Functions/Functions.h" @@ -36,21 +36,21 @@ class TestSaveAndLoadMeshfunction typedef MeshFunction<MeshType> MeshFunctionType; typedef Vector<double,Host,int> DofType; typedef typename MeshType::Cell Cell; - typedef typename MeshType::IndexType IndexType; - typedef typename MeshType::PointType PointType; - + typedef typename MeshType::IndexType IndexType; + typedef typename MeshType::PointType PointType; + typedef typename MeshType::CoordinatesType CoordinatesType; typedef LinearFunction<double,dim> LinearFunctionType; Pointers::SharedPointer< LinearFunctionType, Host > linearFunctionPtr; - MeshFunctionEvaluator< MeshFunctionType, LinearFunctionType > linearFunctionEvaluator; + MeshFunctionEvaluator< MeshFunctionType, LinearFunctionType > linearFunctionEvaluator; PointType localOrigin; localOrigin.setValue(-0.5); PointType localProportions; localProportions.setValue(10); - + Pointers::SharedPointer<MeshType> localGridptr; localGridptr->setDimensions(localProportions); localGridptr->setDomain(localOrigin,localProportions); @@ -62,9 +62,9 @@ class TestSaveAndLoadMeshfunction linearFunctionEvaluator.evaluateAllEntities(localMeshFunctionptr , linearFunctionPtr); File file; - file.open( String( FILENAME), File::Mode::Out ); - localMeshFunctionptr->save(file); - file.close(); + ASSERT_NO_THROW( file.open( String( FILENAME), File::Mode::Out ) ); + ASSERT_NO_THROW( localMeshFunctionptr->save(file) ); + ASSERT_NO_THROW( file.close() ); //load other meshfunction on same localgrid from created file Pointers::SharedPointer<MeshType> loadGridptr; @@ -80,9 +80,9 @@ class TestSaveAndLoadMeshfunction loadDof[i]=-1; } - file.open( String( FILENAME ), File::Mode::In ); - loadMeshFunctionptr->boundLoad(file); - file.close(); + ASSERT_NO_THROW( file.open( String( FILENAME ), File::Mode::In ) ); + ASSERT_NO_THROW( loadMeshFunctionptr->boundLoad(file) ); + ASSERT_NO_THROW( file.close() ); for(int i=0;i<localDof.getSize();i++) { diff --git a/src/UnitTests/StringTest.cpp b/src/UnitTests/StringTest.cpp index f44eac1c68..755cb6419d 100644 --- a/src/UnitTests/StringTest.cpp +++ b/src/UnitTests/StringTest.cpp @@ -10,7 +10,7 @@ // Implemented by Nina Dzugasova -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST #include <gtest/gtest.h> #endif @@ -19,7 +19,7 @@ using namespace TNL; -#ifdef HAVE_GTEST +#ifdef HAVE_GTEST TEST( StringTest, BasicConstructor ) { String str; @@ -306,10 +306,10 @@ TEST( StringTest, SaveLoad ) { String str1( "testing-string" ); File file; - file.open( "test-file.tnl", File::Mode::Out ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::Out ) ); ASSERT_NO_THROW( file << str1 ); - file.close(); - file.open( "test-file.tnl", File::Mode::In ); + ASSERT_NO_THROW( file.close() ); + ASSERT_NO_THROW( file.open( "test-file.tnl", File::Mode::In ) ); String str2; ASSERT_NO_THROW( file >> str2 ); EXPECT_EQ( str1, str2 ); -- GitLab