diff --git a/python/testing/CMakeLists.txt b/python/testing/CMakeLists.txt index c2d019a225..73624a718a 100644 --- a/python/testing/CMakeLists.txt +++ b/python/testing/CMakeLists.txt @@ -5,6 +5,11 @@ list(APPEND pyf3dTests_list TestPythonUtils.py ) +if(NOT F3D_EXCLUDE_DEPRECATED) + list(APPEND pyf3dTests_list + TestPythonImageDataDeprecated.py) +endif() + if(NOT F3D_MACOS_BUNDLE) list(APPEND pyf3dTests_list TestPythonPlugins.py diff --git a/python/testing/TestPythonImageDataDeprecated.py b/python/testing/TestPythonImageDataDeprecated.py new file mode 100644 index 0000000000..49926df52c --- /dev/null +++ b/python/testing/TestPythonImageDataDeprecated.py @@ -0,0 +1,55 @@ +import sys +if sys.platform.startswith('win32'): + import os + os.add_dll_directory(sys.argv[1]) + +import f3d + +engine = f3d.engine(f3d.window.NATIVE_OFFSCREEN) +window = engine.getWindow() +window.setSize(300, 200) + + +'''with background -> RGB image''' + +img = window.renderToImage() +width = img.getWidth() +height = img.getHeight() +depth = img.getChannelCount() +data = img.getData() + +assert width == window.getWidth() +assert height == window.getHeight() +assert depth == 3 +assert isinstance(data, (bytes, bytearray)) +assert len(data) == depth * width * height + + +'''without background -> RGBA image''' + +img = window.renderToImage(True) +width = img.getWidth() +height = img.getHeight() +depth = img.getChannelCount() +data = img.getData() + +assert width == window.getWidth() +assert height == window.getHeight() +assert depth == 4 +assert isinstance(data, (bytes, bytearray)) +assert len(data) == depth * width * height + + +'''set data back''' + +img.setData(data) +assert img.getData() == data + + +'''attempt to set partial data back''' + +try: + img.setData(data[:-1]) + assert False, 'expected exception' +except ValueError: + assert True