summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2009-01-30 12:01:46 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2009-01-30 12:01:46 +0000
commitf6fa6861862acfcd55410716403e61cd66149769 (patch)
tree0f56c928b84527a87e10bd3ec69b05e6eb0ab23e /tools
parent6a091c37e5344a0b21db10093eb0186cf23a9691 (diff)
Add a test that asserts that TP_ERRORS contains every error defined by the spec
Now that we don't auto-generate TP_ERRORS, we need to verify that errors added in the spec get added to the TpError enum by the maintainer when a new spec is imported. This is done by generating a test that will be run during `make check`. Sample output: /* org.freedesktop.Telepathy.Error.Busy */ value_by_name = g_enum_get_value_by_name (klass, "TP_ERROR_BUSY"); value_by_nick = g_enum_get_value_by_nick (klass, "Busy"); g_assert (value_by_name != NULL); g_assert (value_by_nick != NULL); g_assert_cmpint (value_by_name->value, ==, TP_ERROR_BUSY); g_assert_cmpint (value_by_nick->value, ==, TP_ERROR_BUSY); g_assert_cmpstr (value_by_name->value_name, ==, "TP_ERROR_BUSY"); g_assert_cmpstr (value_by_nick->value_name, ==, "TP_ERROR_BUSY"); g_assert_cmpstr (value_by_name->value_nick, ==, "Busy"); g_assert_cmpstr (value_by_nick->value_nick, ==, "Busy");
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am1
-rw-r--r--tools/glib-errors-check-gen.py54
2 files changed, 55 insertions, 0 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 4af909ae5..4d4447157 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -16,6 +16,7 @@ EXTRA_DIST = \
git-which-branch.sh \
glib-client-gen.py \
glib-client-marshaller-gen.py \
+ glib-errors-check-gen.py \
glib-errors-enum-body-gen.py \
glib-errors-enum-header-gen.py \
glib-ginterface-gen.py \
diff --git a/tools/glib-errors-check-gen.py b/tools/glib-errors-check-gen.py
new file mode 100644
index 000000000..3d16b8e98
--- /dev/null
+++ b/tools/glib-errors-check-gen.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+
+import sys
+import xml.dom.minidom
+
+from libglibcodegen import NS_TP, camelcase_to_upper, get_docstring, \
+ get_descendant_text
+
+class Generator(object):
+ def __init__(self, dom):
+ self.dom = dom
+ self.errors = self.dom.getElementsByTagNameNS(NS_TP, 'errors')[0]
+
+ def __call__(self):
+
+ print '{'
+ print ' GEnumClass *klass;'
+ print ' GEnumValue *value_by_name;'
+ print ' GEnumValue *value_by_nick;'
+ print ''
+ print ' g_type_init ();'
+ print ' klass = g_type_class_ref (TP_TYPE_ERROR);'
+
+ for error in self.errors.getElementsByTagNameNS(NS_TP, 'error'):
+ ns = error.parentNode.getAttribute('namespace')
+ nick = error.getAttribute('name').replace(' ', '')
+ enum = 'TP_ERROR_' + camelcase_to_upper(nick.replace('.', ''))
+
+ print ''
+ print ' /* %s.%s */' % (ns, nick)
+ print (' value_by_name = g_enum_get_value_by_name (klass, "%s");'
+ % enum)
+ print (' value_by_nick = g_enum_get_value_by_nick (klass, "%s");'
+ % nick)
+ print (' g_assert (value_by_name != NULL);')
+ print (' g_assert (value_by_nick != NULL);')
+ print (' g_assert_cmpint (value_by_name->value, ==, %s);'
+ % enum)
+ print (' g_assert_cmpint (value_by_nick->value, ==, %s);'
+ % enum)
+ print (' g_assert_cmpstr (value_by_name->value_name, ==, "%s");'
+ % enum)
+ print (' g_assert_cmpstr (value_by_nick->value_name, ==, "%s");'
+ % enum)
+ print (' g_assert_cmpstr (value_by_name->value_nick, ==, "%s");'
+ % nick)
+ print (' g_assert_cmpstr (value_by_nick->value_nick, ==, "%s");'
+ % nick)
+
+ print '}'
+
+if __name__ == '__main__':
+ argv = sys.argv[1:]
+ Generator(xml.dom.minidom.parse(argv[0]))()