6 from libglibcodegen
import NS_TP
, get_docstring
, get_descendant_text
8 class Generator(object):
9 def __init__(self
, dom
):
11 self
.errors
= self
.dom
.getElementsByTagNameNS(NS_TP
, 'errors')[0]
16 print ' GEnumClass *klass;'
17 print ' GEnumValue *value_by_name;'
18 print ' GEnumValue *value_by_nick;'
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(' ', '')
27 error
.getAttribute('name').replace(' ', '_').replace('.', '_').upper())
28 s
= ('TP_ERROR_STR_' +
29 error
.getAttribute('name').replace(' ', '_').replace('.', '_').upper())
32 print ' /* %s.%s */' % (ns
, nick
)
33 print (' value_by_name = g_enum_get_value_by_name (klass, "%s");'
35 print (' value_by_nick = g_enum_get_value_by_nick (klass, "%s");'
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);'
41 print (' g_assert_cmpint (value_by_nick->value, ==, %s);'
43 print (' g_assert_cmpstr (value_by_name->value_name, ==, "%s");'
45 print (' g_assert_cmpstr (value_by_nick->value_name, ==, "%s");'
47 print (' g_assert_cmpstr (value_by_name->value_nick, ==, "%s");'
49 print (' g_assert_cmpstr (value_by_nick->value_nick, ==, "%s");'
51 print (' g_assert_cmpstr (%s, ==, TP_ERROR_PREFIX ".%s");'
56 if __name__
== '__main__':
58 Generator(xml
.dom
.minidom
.parse(argv
[0]))()