[pygobject] tests: add tests for functions returning invalid utf-8. See #171
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] tests: add tests for functions returning invalid utf-8. See #171
- Date: Mon, 19 Mar 2018 12:35:45 +0000 (UTC)
commit 4ffdda3b9bf6fd0c94af018166f223e501185384
Author: Christoph Reiter <reiter christoph gmail com>
Date: Mon Mar 19 13:19:45 2018 +0100
tests: add tests for functions returning invalid utf-8. See #171
I can't reproduce the error here, so I'm probably missing something.
Having this tested is a good idea either way.
tests/gimarshallingtestsextra.c | 21 +++++++++++++++++++++
tests/gimarshallingtestsextra.h | 3 +++
tests/test_gi.py | 14 +++++++++++++-
3 files changed, 37 insertions(+), 1 deletion(-)
---
diff --git a/tests/gimarshallingtestsextra.c b/tests/gimarshallingtestsextra.c
index ae6a033e..4debaf54 100644
--- a/tests/gimarshallingtestsextra.c
+++ b/tests/gimarshallingtestsextra.c
@@ -154,3 +154,24 @@ gi_marshalling_tests_extra_flags_large_in (GIMarshallingTestsExtraFlags value)
{
g_assert_cmpint (value, ==, GI_MARSHALLING_TESTS_EXTRA_FLAGS_VALUE2);
}
+
+
+/**
+ * gi_marshalling_tests_extra_utf8_full_return_invalid:
+ */
+gchar *
+gi_marshalling_tests_extra_utf8_full_return_invalid (void)
+{
+ return g_strdup ("invalid utf8 \xff\xfe");
+}
+
+
+/**
+ * gi_marshalling_tests_extra_utf8_full_out_invalid:
+ * @utf8: (out) (transfer full):
+ */
+void
+gi_marshalling_tests_extra_utf8_full_out_invalid (gchar **utf8)
+{
+ *utf8 = g_strdup ("invalid utf8 \xff\xfe");
+}
diff --git a/tests/gimarshallingtestsextra.h b/tests/gimarshallingtestsextra.h
index 57f52f46..0e777b81 100644
--- a/tests/gimarshallingtestsextra.h
+++ b/tests/gimarshallingtestsextra.h
@@ -50,4 +50,7 @@ GIMarshallingTestsExtraEnum * gi_marshalling_tests_enum_array_return_type (gsize
void gi_marshalling_tests_extra_flags_large_in (GIMarshallingTestsExtraFlags value);
+gchar *gi_marshalling_tests_extra_utf8_full_return_invalid (void);
+void gi_marshalling_tests_extra_utf8_full_out_invalid (gchar **utf8);
+
#endif /* EXTRA_TESTS */
diff --git a/tests/test_gi.py b/tests/test_gi.py
index f6d711ce..8b355ebd 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -19,8 +19,8 @@ import gi.overrides
from gi import PyGIWarning
from gi import PyGIDeprecationWarning
from gi.repository import GObject, GLib, Gio
-
from gi.repository import GIMarshallingTests
+import pytest
from .compathelper import PY2, PY3
from .helper import capture_exceptions, capture_output
@@ -667,6 +667,18 @@ class TestUtf8(unittest.TestCase):
def test_utf8_full_return(self):
self.assertEqual(CONSTANT_UTF8, GIMarshallingTests.utf8_full_return())
+ def test_extra_utf8_full_return_invalid(self):
+ with pytest.raises(UnicodeDecodeError):
+ value = GIMarshallingTests.extra_utf8_full_return_invalid()
+ if PY2:
+ value.decode("utf-8")
+
+ def test_extra_utf8_full_out_invalid(self):
+ with pytest.raises(UnicodeDecodeError):
+ value = GIMarshallingTests.extra_utf8_full_out_invalid()
+ if PY2:
+ value.decode("utf-8")
+
def test_utf8_none_in(self):
GIMarshallingTests.utf8_none_in(CONSTANT_UTF8)
if sys.version_info < (3, 0):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]