gir-repository r56 - in trunk: . gir



Author: walters
Date: Thu Aug 21 23:10:11 2008
New Revision: 56
URL: http://svn.gnome.org/viewvc/gir-repository?rev=56&view=rev

Log:
2008-08-21  Colin Walters  <walters verbum org>

	* gir/test.py:
	* gir/Makefile.am: Add basic test program.
	Please add to it.




Added:
   trunk/gir/tests.py   (contents, props changed)
Modified:
   trunk/ChangeLog
   trunk/gir/Makefile.am

Modified: trunk/gir/Makefile.am
==============================================================================
--- trunk/gir/Makefile.am	(original)
+++ trunk/gir/Makefile.am	Thu Aug 21 23:10:11 2008
@@ -1,4 +1,5 @@
 CLEANFILES = 
+EXTRA_DIST = 
 
 CUSTOM_GIRSOURCES = cairo.gir fontconfig.gir freetype2.gir xft.gir xlib.gir GL.gir
 BUILT_GIRSOURCES =
@@ -290,3 +291,7 @@
 
 %.typelib.gdb: %.gir
 	libtool --mode=execute gdb --args $(G_IR_COMPILER) $< --raw -o $@
+
+TESTS = tests.py
+
+EXTRA_DIST += $(TESTS)
\ No newline at end of file

Added: trunk/gir/tests.py
==============================================================================
--- (empty file)
+++ trunk/gir/tests.py	Thu Aug 21 23:10:11 2008
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+import os
+import sys
+from xml.etree.cElementTree import parse
+
+CORE_NS = "http://www.gtk.org/introspection/core/1.0";
+C_NS = "http://www.gtk.org/introspection/c/1.0";
+GLIB_NS = "http://www.gtk.org/introspection/glib/1.0";
+
+
+def _corens(tag):
+    return '{%s}%s' % (CORE_NS, tag)
+
+
+def _glibns(tag):
+    return '{%s}%s' % (GLIB_NS, tag)
+
+
+def _cns(tag):
+    return '{%s}%s' % (C_NS, tag)
+
+
+_nsmap = {'c': C_NS,
+          'glib': GLIB_NS}
+def myxpath(node, expr):
+    elts = expr.split('/')
+    curnode = node
+    for elt in elts:
+        if elt == '':
+            continue
+        try:
+            (elt, qual) = elt.split('[', 1)
+            qual = qual[1:-1]
+            pairs = [x.split('=', 1) for x in qual.split(',')]
+            exp_attrs = [(x[0], x[1][1:-1]) for x in pairs]
+        except ValueError, e:
+            (elt, exp_attrs) = elt, []
+        try:
+            (ns,elt) = elt.split(':', 1)
+            ns = _nsmap[ns]
+            elt = '{%s}%s' % (ns, elt)
+        except ValueError, e:
+            elt = _corens(elt)
+        curnodes = curnode.findall(elt)
+        #print "LOOK: %r %r => %d elts" % (curnode, elt, len(curnodes))
+        if not curnodes:
+            return None
+        found = True
+        for node in curnodes:
+            passes = True
+            for (name,val) in exp_attrs:
+                a = node.attrib.get(name)
+                if not a or a != val:
+                    passes = False
+                    break
+            if passes:
+                found = True
+                #print 'ATTR PASS: %r' % (node, )
+                curnode = node
+                break
+            found = False
+        if not found:
+            return None
+    return curnode
+
+def _assert_find(node, path, attribs=[]):
+    elt = myxpath(node, path)
+    if elt is None:
+        raise AssertionError("Failed to find %r" % (path, ))
+    for (name,expvalue) in attribs:
+        value = elt.attrib.get(name) 
+        if not value:
+            raise AssertionError("Failed to find attibute %r in node %r" % (name, elt, ))
+        if value != expvalue:
+            raise AssertionError("Attibute %r in node %r has unexpected value %r" % (name, elt, expvalue))
+
+def _check(fname, *args):
+    print "=== CHECKING %s (%d assertions) ===" % (fname, len(args))
+    doc = parse(fname)
+    root = doc.getroot()
+    for arg in args:
+        _assert_find(root, arg)
+    print "=== PASSED %s ===" % (fname, )
+
+def main():
+    os.chdir(os.environ['srcdir'])
+    _check("GdkPixbuf.gir",
+           "/namespace/class[ name='Pixbuf']",
+           "/namespace/enumeration[ name='Error']/member[ name='failed']",
+           "/namespace/class[ name='AnimationIter']/method[ name='get_width']/return-value/type[ name='int']",
+           "/namespace/class[ name='AnimationIter']/method[ name='get_static_image']/return-value/type[ name='Pixbuf']",
+           "/namespace/class[ name='AnimationIter']/method[ name='get_iter']/parameters/parameter[ name='start_time']/type[ name='GLib.TimeVal']")
+    _check("Gtk.gir",
+           "/namespace/class[ name='Window']",
+           "/namespace/enumeration[ name='TreeViewDropPosition']/member[ name='into-or-before']",
+           "/namespace/bitfield[ name='AttachOptions']/member[ name='expand']",
+           "/namespace/class[ name='Object']/method[ name='sink']/parameters/parameter/type[ name='Object']")
+    _check("WebKit.gir",
+           "/namespace/class[ name='WebFrame']",
+           "/namespace/class[ name='WebView']/constructor[ name='new']/return-value/type[ name='Gtk.Widget']",
+           "/namespace/class[ name='WebView']/method[ name='can_go_back']",
+           "/namespace/class[ name='WebView']/property[ name='copy-target-list']/type[ name='Gtk.TargetList']",
+           "/namespace/class[ name='WebView']/callback[ name='window_object_cleared']/parameters/parameter[ name='context']/type[ name='JSCore.GlobalContextRef']")
+    return 0
+
+sys.exit(main())



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]