diff options
author | Simon Feltman <sfeltman@src.gnome.org> | 2013-12-17 22:56:22 -0800 |
---|---|---|
committer | Simon Feltman <sfeltman@src.gnome.org> | 2014-01-02 14:34:42 -0800 |
commit | e6249ad007adeec2010ef8a8f8f7907b4d60fdfd (patch) | |
tree | 6f264ad769aefcd8250bd64ca3582cdd2ba96496 /tests/scanner | |
parent | 4a64ab0b8e3e6cf0ebb4f34dd9276e964e1f303c (diff) | |
download | gobject-introspection-e6249ad007adeec2010ef8a8f8f7907b4d60fdfd.tar.gz |
scanner: Fix get_symbols/comments to maintain the scanner lists
Use g_slist_copy prior to returning the lists run through g_slist_reverse.
This preserves the source scanners internally held lists where previously
they would only point to a single element after a call, leaking memory and
breaking subsequent calls. Note the functions as (transfer container) and
use g_slist_free after calls in the Python bindings.
Add new unittest file: test_sourcescanner.py for isolated unittesting of the
SourceScanner.
https://bugzilla.gnome.org/show_bug.cgi?id=581525
Diffstat (limited to 'tests/scanner')
-rw-r--r-- | tests/scanner/Makefile.am | 6 | ||||
-rw-r--r-- | tests/scanner/test_sourcescanner.py | 41 |
2 files changed, 46 insertions, 1 deletions
diff --git a/tests/scanner/Makefile.am b/tests/scanner/Makefile.am index d72d2557..e3fd4321 100644 --- a/tests/scanner/Makefile.am +++ b/tests/scanner/Makefile.am @@ -192,12 +192,16 @@ else CHECKDOCS = endif +PYTESTS = test_sourcescanner.py + XFAIL_TESTS = Typedefs-1.0.gir -TESTS = Headeronly-1.0.gir $(CHECKGIRS) $(CHECKDOCS) $(TYPELIBS) +TESTS = Headeronly-1.0.gir $(CHECKGIRS) $(CHECKDOCS) $(TYPELIBS) $(PYTESTS) TESTS_ENVIRONMENT = srcdir=$(srcdir) top_srcdir=$(top_srcdir) builddir=$(builddir) top_builddir=$(top_builddir) \ + PYTHON=$(PYTHON) UNINSTALLED_INTROSPECTION_SRCDIR=$(top_srcdir) \ $(top_srcdir)/tests/gi-tester EXTRA_DIST += \ + $(PYTESTS) \ Regress-1.0-C-expected \ Regress-1.0-Gjs-expected \ Regress-1.0-Python-expected \ diff --git a/tests/scanner/test_sourcescanner.py b/tests/scanner/test_sourcescanner.py new file mode 100644 index 00000000..3963683d --- /dev/null +++ b/tests/scanner/test_sourcescanner.py @@ -0,0 +1,41 @@ +import unittest +import tempfile +import os + +from giscanner.sourcescanner import SourceScanner + + +two_typedefs_source = """ +/** + * Spam: + */ +typedef struct _spam Spam; + +/** + * Eggs: + */ +typedef struct _eggs Eggs; +""" + + +class Test(unittest.TestCase): + def setUp(self): + self.ss = SourceScanner() + tmp_fd, tmp_name = tempfile.mkstemp() + file = os.fdopen(tmp_fd, 'wt') + file.write(two_typedefs_source) + file.close() + + self.ss.parse_files([tmp_name]) + + def test_get_symbols_length_consistency(self): + self.assertEqual(len(list(self.ss.get_symbols())), 2) + self.assertEqual(len(list(self.ss.get_symbols())), 2) + + def test_get_comments_length_consistency(self): + self.assertEqual(len(list(self.ss.get_comments())), 2) + self.assertEqual(len(list(self.ss.get_comments())), 2) + + +if __name__ == '__main__': + unittest.main() |