From: YOANN AUDOUIN Date: Tue, 30 Mar 2021 12:29:03 +0000 (+0200) Subject: [Test] Adding test for SerafinReader X-Git-Tag: V9_8_0a1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fb9d413353f86016506f2ae4d683d32f1ce76e7c;p=tools%2Fparavisaddons_common.git [Test] Adding test for SerafinReader --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f1b8780..957c769 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,7 @@ FIND_PACKAGE(SalomeParaView REQUIRED) # ==================== SALOME_XVERSION(${PROJECT_NAME}) SALOME_CONFIGURE_FILE(PARAVISADDONS_version.h.in PARAVISADDONS_version.h INSTALL ${SALOME_INSTALL_HEADERS}) +OPTION(PARAVISADDONS_COMMON_BUILD_TESTS "Build PARAVISADDONS_COMMON tests." ON) # Sources # ======== diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 080ef80..cf8e98b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) SET(CONFIGURATION_ROOT_DIR $ENV{CONFIGURATION_ROOT_DIR} CACHE PATH "Path to the Salome CMake files") +SET(PARAVISADDONS_COMMON_INSTALL_TESTS tests CACHE PATH "Install path: PARAVISADDONS_COMMON tests") IF(EXISTS ${CONFIGURATION_ROOT_DIR}) LIST(APPEND CMAKE_MODULE_PATH "${CONFIGURATION_ROOT_DIR}/cmake") INCLUDE(SalomeMacros) @@ -70,3 +71,8 @@ ADD_SUBDIRECTORY(ElectromagnetismVecteur) ADD_SUBDIRECTORY(ElectromagnetismStreamTraceur) ADD_SUBDIRECTORY(ElectromagnetismFluxDisc) ADD_SUBDIRECTORY(ElectromagnetismRotation) + + +# Tests +configure_file(CTestTestfileInstall.cmake.in "CTestTestfileST.cmake" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CTestTestfileST.cmake DESTINATION ${PARAVISADDONS_COMMON_INSTALL_TESTS} RENAME CTestTestfile.cmake) diff --git a/src/CTestTestfileInstall.cmake.in b/src/CTestTestfileInstall.cmake.in new file mode 100644 index 0000000..0c82b08 --- /dev/null +++ b/src/CTestTestfileInstall.cmake.in @@ -0,0 +1,27 @@ +# Copyright (C) 2015-2020 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, or (at your option) any later version. +# +# 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 +# + +SET(COMPONENT_NAME PARAVISADDONS_COMMON) +SET(TIMEOUT 120) + +SUBDIRS(SerafinReader) +SUBDIRS(ElectromagnetismFluxDisc) +SUBDIRS(ElectromagnetismRotation) +SUBDIRS(ElectromagnetismStreamTraceur) +SUBDIRS(ElectromagnetismVecteur) diff --git a/src/SerafinReader/CMakeLists.txt b/src/SerafinReader/CMakeLists.txt index bbbc3e9..baef9fb 100644 --- a/src/SerafinReader/CMakeLists.txt +++ b/src/SerafinReader/CMakeLists.txt @@ -21,6 +21,10 @@ cmake_minimum_required(VERSION 3.8) project(SerafinReader) find_package(ParaView REQUIRED) +IF(PARAVISADDONS_COMMON_BUILD_TESTS) + ADD_SUBDIRECTORY(Test) +ENDIF(PARAVISADDONS_COMMON_BUILD_TESTS) + include(GNUInstallDirs) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") diff --git a/src/SerafinReader/Test/CMakeLists.txt b/src/SerafinReader/Test/CMakeLists.txt new file mode 100644 index 0000000..cc8821a --- /dev/null +++ b/src/SerafinReader/Test/CMakeLists.txt @@ -0,0 +1,44 @@ +# Copyright (C) 2012-2020 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, or (at your option) any later version. +# +# 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 +# +# Author : Yoann Audouin (EDF) + +SET(test_SerafinReader_src + geo_3d_dp.slf + geo_dp.slf + geo_dp_le.slf + geo_sp.slf + geo_sp_le.slf + test_SerafinReader.py + ) + +SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) + +ADD_TEST(SerafinReader python test_SerafinReader.py) +SET_TESTS_PROPERTIES(SerafinReader PROPERTIES ENVIRONMENT "${tests_env}") + +#INSTALL(TARGETS test_SerafinReader DESTINATION ${PARAVISADDONS_COMMON_INSTALL_BINS}) + +# Application tests + +SET(TEST_INSTALL_DIRECTORY ${PARAVISADDONS_COMMON_INSTALL_TESTS}/SerafinReader) +INSTALL(FILES ${test_SerafinReader_src} DESTINATION ${TEST_INSTALL_DIRECTORY}) + +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${TEST_INSTALL_DIRECTORY} + RENAME CTestTestfile.cmake) diff --git a/src/SerafinReader/Test/CTestTestfileInstall.cmake b/src/SerafinReader/Test/CTestTestfileInstall.cmake new file mode 100644 index 0000000..b6bc57c --- /dev/null +++ b/src/SerafinReader/Test/CTestTestfileInstall.cmake @@ -0,0 +1,31 @@ +# Copyright (C) 2015-2020 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, or (at your option) any later version. +# +# 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 +# + +SET(TEST_NAMES + test_SerafinReader +) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) + ADD_TEST(${TEST_NAME} python ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES + LABELS "${COMPONENT_NAME}" + TIMEOUT ${TIMEOUT} + ) +ENDFOREACH() diff --git a/src/SerafinReader/Test/geo_3d_dp.slf b/src/SerafinReader/Test/geo_3d_dp.slf new file mode 100644 index 0000000..a002a47 Binary files /dev/null and b/src/SerafinReader/Test/geo_3d_dp.slf differ diff --git a/src/SerafinReader/Test/geo_dp.slf b/src/SerafinReader/Test/geo_dp.slf new file mode 100644 index 0000000..2808358 Binary files /dev/null and b/src/SerafinReader/Test/geo_dp.slf differ diff --git a/src/SerafinReader/Test/geo_dp_le.slf b/src/SerafinReader/Test/geo_dp_le.slf new file mode 100644 index 0000000..719682e Binary files /dev/null and b/src/SerafinReader/Test/geo_dp_le.slf differ diff --git a/src/SerafinReader/Test/geo_sp.slf b/src/SerafinReader/Test/geo_sp.slf new file mode 100644 index 0000000..00b2bbb Binary files /dev/null and b/src/SerafinReader/Test/geo_sp.slf differ diff --git a/src/SerafinReader/Test/geo_sp_le.slf b/src/SerafinReader/Test/geo_sp_le.slf new file mode 100644 index 0000000..806cbb9 Binary files /dev/null and b/src/SerafinReader/Test/geo_sp_le.slf differ diff --git a/src/SerafinReader/Test/test_SerafinReader.py b/src/SerafinReader/Test/test_SerafinReader.py new file mode 100644 index 0000000..a557ff4 --- /dev/null +++ b/src/SerafinReader/Test/test_SerafinReader.py @@ -0,0 +1,39 @@ +from paraview.simple import * +from vtk.util import numpy_support +import numpy as np + +paraview.simple._DisableFirstRenderCameraReset() + +# Normal single precision file +reader = SerafinReader(FileName='geo_sp.slf') +reader.UpdatePipeline() +reader_ds = servermanager.Fetch(reader) +# Checking that fields THING X THING Y are merged into THING * +list_var = [reader_ds.GetPointData().GetArrayName(i).strip() for i in range(reader_ds.GetPointData().GetNumberOfArrays())] +assert("THING *" in list_var) +assert("THING X" not in list_var) +assert("THING OTHER" in list_var) +# Checking that fields VELOCITY U, VELOCITY V are merged into VELOCITY * +assert("VELOCITY *" in list_var) +assert("VELOCITY U" not in list_var) +assert("VELOCITY STUFF" in list_var) +# Checking that VELOCITY has 3 components shoulb be on 0 +assert(reader_ds.GetPointData().GetArray(0).GetNumberOfComponents() == 3) + +# Simple read of Litte Endian file (Would crash if issue in the plugin) +reader = SerafinReader(FileName='geo_sp_le.slf') +# Simple read of Litte Endian file (Would crash if issue in the plugin) +reader = SerafinReader(FileName='geo_dp_le.slf') + +# Normal double precision file +reader = SerafinReader(FileName='geo_dp.slf') +reader.UpdatePipeline() +reader_ds = servermanager.Fetch(reader) +# Checking that values are properly read +data = numpy_support.vtk_to_numpy(reader_ds.GetPointData().GetArray(0)) +assert(np.all(data <= 1e-8)) + +# 3d mesh +reader = SerafinReader(FileName='geo_3d_dp.slf') +reader.UpdatePipeline() +reader_ds = servermanager.Fetch(reader)