From 4cad9594345ebf6197d134dd781410a38168b885 Mon Sep 17 00:00:00 2001 From: azv Date: Sun, 9 Dec 2018 12:43:17 +0300 Subject: [PATCH] [Code coverage Config]: Unit test for Config_PropManager --- lcov_reports.sh | 5 +++++ src/Config/CMakeLists.txt | 6 +++++ src/Config/ConfigAPI.i | 8 +++++++ src/Config/Test/TestConfig.py | 42 +++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 src/Config/Test/TestConfig.py diff --git a/lcov_reports.sh b/lcov_reports.sh index 6a1f43b64..098afcdd3 100755 --- a/lcov_reports.sh +++ b/lcov_reports.sh @@ -68,6 +68,11 @@ done # remove SketchPlugin's Ellipse feature (unsupported yet) lcov -r covElse SketchPlugin*Ellipse* --output-file covElse_res -q mv -f covElse_res covElse +# remove GUI related files from Config plugin +for MASK in 'DataModelReader' 'Translator' 'PointerMessage'; do +lcov -r covElse *Config_${MASK}API* --output-file covElse_res -q +mv -f covElse_res covElse +done rm -rf lcov_htmlElse genhtml covElse --output-directory lcov_htmlElse -q diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index 05bafb324..1918d4fa4 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -19,6 +19,7 @@ ## INCLUDE(Common) +INCLUDE(UnitTest) INCLUDE(XMLProcessing) FIND_PACKAGE(SWIG REQUIRED) INCLUDE(${SWIG_USE_FILE}) @@ -150,3 +151,8 @@ INSTALL(FILES ${XML_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) INSTALL(TARGETS _ConfigAPI DESTINATION ${SHAPER_INSTALL_SWIG}) INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION ${SHAPER_INSTALL_SWIG}) + + +ADD_UNIT_TESTS( + TestConfig.py +) diff --git a/src/Config/ConfigAPI.i b/src/Config/ConfigAPI.i index 2bf42f1a0..f5fb5461a 100644 --- a/src/Config/ConfigAPI.i +++ b/src/Config/ConfigAPI.i @@ -29,8 +29,16 @@ #define CONFIG_EXPORT %include "typemaps.i" +%include "std_list.i" %include "std_string.i" +%include "std_vector.i" %include "Config_ModuleReader.h" %include "Config_PropManager.h" %include "Config_Prop.h" + +// std::list -> [] +%template(ListOfString) std::list< std::string >; +%template(listOfProp) std::list< Config_Prop* >; +// std::vector -> [] +%template(VectorOfInteger) std::vector; diff --git a/src/Config/Test/TestConfig.py b/src/Config/Test/TestConfig.py new file mode 100644 index 000000000..a98d534fc --- /dev/null +++ b/src/Config/Test/TestConfig.py @@ -0,0 +1,42 @@ +## Copyright (C) 2018-20xx 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 +## + +from ModelAPI import * +from ConfigAPI import * + +# register boolean property +Config_PropManager().registerProp("TestSection", "PropBool", "PropTitle", Config_Prop.Boolean) +# check property once again +Config_PropManager().registerProp("TestSection", "PropBool", "PropTitle", Config_Prop.Boolean, "true") +# check property value +assert(Config_PropManager().boolean("TestSection", "PropBool")) + +# register real property +Config_PropManager().registerProp("TestSection", "PropDouble", "PropTitle", Config_Prop.Double, "12,5") +# check property (',' should be substituted by ".") +assert(Config_PropManager().real("TestSection", "PropDouble") == 12.5) + +# register color property +Config_PropManager().registerProp("TestSection", "PropColor", "PropTitle", Config_Prop.Color, "#B00F00") +assert(len(Config_PropManager().color("TestSection", "PropColor")) == 3) + +# check sections and properties are not empty +assert(len(Config_PropManager().getSections()) > 0) +assert(len(Config_PropManager().getProperties()) > 0) -- 2.39.2