summaryrefslogtreecommitdiff
path: root/tests/test_overrides_gdkpixbuf.py
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2018-06-17 12:20:10 +0200
committerChristoph Reiter <reiter.christoph@gmail.com>2018-06-17 12:34:54 +0200
commit898bbe50005223f5f04994764b3e95f13dffe2d2 (patch)
tree45bcc5733473eec7bb54534a2bd6c3815ddfe170 /tests/test_overrides_gdkpixbuf.py
parent4b92d6d1d92b711f3640238504b9714a7d89ea29 (diff)
downloadpygobject-pixbuf-new-from-data.tar.gz
Add override for GdkPixbuf.Pixbuf.new_from_data. Fixes #225pixbuf-new-from-data
new_from_data isn't bindable (see https://bugzilla.gnome.org/show_bug.cgi?id=721497) and will result in use after free. While we could try to move people away from it and skip it in GI a github code search turns up quite a few users. This adds an override for it, wrapping GdkPixbuf.Pixbuf.new_from_bytes, and marks any usage of the callback args as deprecated.
Diffstat (limited to 'tests/test_overrides_gdkpixbuf.py')
-rw-r--r--tests/test_overrides_gdkpixbuf.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test_overrides_gdkpixbuf.py b/tests/test_overrides_gdkpixbuf.py
new file mode 100644
index 00000000..5b2d3707
--- /dev/null
+++ b/tests/test_overrides_gdkpixbuf.py
@@ -0,0 +1,49 @@
+# Copyright 2018 Christoph Reiter <reiter.christoph@gmail.com>
+#
+# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+# USA
+
+from __future__ import absolute_import
+
+import pytest
+
+from gi import PyGIDeprecationWarning
+GdkPixbuf = pytest.importorskip("gi.repository.GdkPixbuf")
+
+
+def test_new_from_data():
+ width = 600
+ height = 32769
+ pixbuf = GdkPixbuf.Pixbuf.new(
+ GdkPixbuf.Colorspace.RGB, True, 8, width, height)
+ pixels = pixbuf.get_pixels()
+ new_pixbuf = GdkPixbuf.Pixbuf.new_from_data(
+ pixels, GdkPixbuf.Colorspace.RGB, True, 8,
+ pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride())
+ del pixbuf
+ del pixels
+ new_pixels = new_pixbuf.get_pixels()
+ assert len(new_pixels) == width * height * 4
+
+
+def test_new_from_data_deprecated_args():
+ GdkPixbuf.Pixbuf.new_from_data(b"1234", 0, True, 8, 1, 1, 4)
+ GdkPixbuf.Pixbuf.new_from_data(b"1234", 0, True, 8, 1, 1, 4, None)
+ with pytest.warns(PyGIDeprecationWarning, match=".*destroy_fn.*"):
+ GdkPixbuf.Pixbuf.new_from_data(
+ b"1234", 0, True, 8, 1, 1, 4, object(), object(), object())
+ with pytest.warns(PyGIDeprecationWarning, match=".*destroy_fn_data.*"):
+ GdkPixbuf.Pixbuf.new_from_data(
+ b"1234", 0, True, 8, 1, 1, 4, object(), object(), object())