hindi update
[empathy-mirror.git] / tools / glib-errors-check-gen.py
blob553fc9cafdf9c04fa8ec43d7b5100685707ac2aa
1 #!/usr/bin/python
3 import sys
4 import xml.dom.minidom
6 from libglibcodegen import NS_TP, get_docstring, get_descendant_text
8 class Generator(object):
9 def __init__(self, dom):
10 self.dom = dom
11 self.errors = self.dom.getElementsByTagNameNS(NS_TP, 'errors')[0]
13 def __call__(self):
15 print '{'
16 print ' GEnumClass *klass;'
17 print ' GEnumValue *value_by_name;'
18 print ' GEnumValue *value_by_nick;'
19 print ''
20 print ' g_type_init ();'
21 print ' klass = g_type_class_ref (TP_TYPE_ERROR);'
23 for error in self.errors.getElementsByTagNameNS(NS_TP, 'error'):
24 ns = error.parentNode.getAttribute('namespace')
25 nick = error.getAttribute('name').replace(' ', '')
26 enum = ('TP_ERROR_' +
27 error.getAttribute('name').replace(' ', '_').replace('.', '_').upper())
28 s = ('TP_ERROR_STR_' +
29 error.getAttribute('name').replace(' ', '_').replace('.', '_').upper())
31 print ''
32 print ' /* %s.%s */' % (ns, nick)
33 print (' value_by_name = g_enum_get_value_by_name (klass, "%s");'
34 % enum)
35 print (' value_by_nick = g_enum_get_value_by_nick (klass, "%s");'
36 % nick)
37 print (' g_assert (value_by_name != NULL);')
38 print (' g_assert (value_by_nick != NULL);')
39 print (' g_assert_cmpint (value_by_name->value, ==, %s);'
40 % enum)
41 print (' g_assert_cmpint (value_by_nick->value, ==, %s);'
42 % enum)
43 print (' g_assert_cmpstr (value_by_name->value_name, ==, "%s");'
44 % enum)
45 print (' g_assert_cmpstr (value_by_nick->value_name, ==, "%s");'
46 % enum)
47 print (' g_assert_cmpstr (value_by_name->value_nick, ==, "%s");'
48 % nick)
49 print (' g_assert_cmpstr (value_by_nick->value_nick, ==, "%s");'
50 % nick)
51 print (' g_assert_cmpstr (%s, ==, TP_ERROR_PREFIX ".%s");'
52 % (s, nick))
54 print '}'
56 if __name__ == '__main__':
57 argv = sys.argv[1:]
58 Generator(xml.dom.minidom.parse(argv[0]))()