Salome HOME
Add a test for base64 conversion
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 6 Jun 2019 05:56:12 +0000 (07:56 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 6 Jun 2019 05:56:12 +0000 (07:56 +0200)
src/engine/Any.cxx
src/engine_swig/CMakeLists.txt
src/engine_swig/CTestTestfileInstall.cmake
src/engine_swig/testBase64Conv.py [new file with mode: 0644]

index a3c5cfa6b12f69c33b3e05e4ba660bd61fb68e01..1280c2f1dc3ba5b1aede661b0da2b6d2db17d881 100644 (file)
@@ -103,7 +103,7 @@ constexpr unsigned char TAB2[MAX_VAL_TAB2] = { 128, 128, 128, 128, 128, 128, 128
 
 unsigned char BitAtPosSimple2(char val, std::size_t bitPos)
 {
-  return (val >> 5-bitPos) & 0x1;
+  return ( val >> (5-bitPos) ) & 0x1;
 }
 
 char BitAtPosOnChunk(char pt0, char pt1, std::size_t bitPos)
index cc7436618eb14c55b7287071ff1e45b5d5552ee2..a748a044d969a9e5f5d386418a4c196763bdb436 100644 (file)
@@ -141,7 +141,9 @@ SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}"  ${SALOME_INSTALL_PYTHON} EXTRA_DPYS "
 SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
 ADD_TEST(NAME PlayGround0 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testPlayGround0.py)
 SET_TESTS_PROPERTIES(PlayGround0 PROPERTIES ENVIRONMENT "${tests_env}")
+ADD_TEST(NAME Base64Conv COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testBase64Conv.py)
+SET_TESTS_PROPERTIES(Base64Conv PROPERTIES ENVIRONMENT "${tests_env}")
 SET(LOCAL_TEST_DIR ${SALOME_YACS_INSTALL_TEST}/engine_swig)
-SET(LOCAL_TEST_FILES testPlayGround0.py)
+SET(LOCAL_TEST_FILES testPlayGround0.py testBase64Conv.py)
 INSTALL(FILES ${LOCAL_TEST_FILES} DESTINATION ${LOCAL_TEST_DIR})
 INSTALL(FILES CTestTestfileInstall.cmake DESTINATION ${LOCAL_TEST_DIR} RENAME CTestTestfile.cmake)
index bb656b96d4ff52d52d38317694d9cad6e4f56a11..16e758930958211dce261bdac0e2e0e8b2d7f66b 100644 (file)
@@ -21,4 +21,7 @@ IF(NOT WIN32)
   SET(TEST_NAME ${COMPONENT_NAME}_PlayGround0)
   ADD_TEST(${TEST_NAME} python testPlayGround0.py)
   SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}")
+  SET(TEST_NAME ${COMPONENT_NAME}_Base64Conv)
+  ADD_TEST(${TEST_NAME} python testBase64Conv.py)
+  SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}")
 ENDIF()
diff --git a/src/engine_swig/testBase64Conv.py b/src/engine_swig/testBase64Conv.py
new file mode 100644 (file)
index 0000000..92d2a88
--- /dev/null
@@ -0,0 +1,50 @@
+# Copyright (C) 2019  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
+#
+
+import pilot
+import unittest
+import pickle
+from math import sin
+
+class TestBase64Conv(unittest.TestCase):
+    
+    def test0(self):
+        """
+        This test checks that internal method for Base64 is OK with pickled objects.
+        Reason of home made conversion :
+        old boost base64 conversion failed with (see commit b0f05b249ace88109a4a3d) string of size 124 due to incorrect output after pilot.FromBase64Swig
+        old boost base64 conversion failed with string of size 157 due to an exception thrown by boost
+        """
+        for i in range(124,624):
+            st = i*"/"
+            a = pickle.dumps(st,protocol=4) # protocol 4 is important here to generate complex
+            self.assertTrue( a == pilot.FromBase64Swig(pilot.ToBase64Swig(a) ) )
+            pass
+        pass
+
+    def test1(self):
+        l = [sin(float(i)) for i in range(1000)]
+        a = pickle.dumps(l,protocol=4)
+        self.assertTrue( a == pilot.FromBase64Swig(pilot.ToBase64Swig(a) ) )
+        pass
+    
+    pass
+
+if __name__ == '__main__':
+    unittest.main()