[vala] tests: Add ref-testing for the GIR parser



commit cf019ecba9d2eabbd06c2fd75b772cfce51e36ce
Author: Luca Bruno <lucabru src gnome org>
Date:   Fri Jun 3 18:57:34 2011 +0200

    tests: Add ref-testing for the GIR parser

 tests/Makefile.am        |    1 +
 tests/gir/bug651773.test |   24 ++++++++++++++++++++++++
 tests/testrunner.sh      |   43 +++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 66 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index df46d93..bec9a3f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -120,6 +120,7 @@ TESTS = \
 	dbus/filedescriptor.test \
 	dbus/bug596862.vala \
 	dbus/bug602003.test \
+	gir/bug651773.test \
 	$(NULL)
 
 check-TESTS: $(TESTS)
diff --git a/tests/gir/bug651773.test b/tests/gir/bug651773.test
new file mode 100644
index 0000000..e4dbdf9
--- /dev/null
+++ b/tests/gir/bug651773.test
@@ -0,0 +1,24 @@
+GIR
+
+Input:
+
+<function name="get_array" c:identifier="test_get_array">
+  <return-value transfer-ownership="none">
+    <array length="0" c:type="guchar*">
+      <type name="guint8" c:type="guchar"/>
+    </array>
+  </return-value>
+  <parameters>
+    <parameter name="len"
+	       direction="out"
+	       caller-allocates="1"
+	       transfer-ownership="full">
+      <type name="gsize" c:type="gsize*"/>
+    </parameter>
+  </parameters>
+</function>
+
+Output:
+
+[CCode (cheader_filename = "test.h", array_length_pos = 0.1, array_length_type = "gsize")]
+public static unowned uint8[] get_array ();
diff --git a/tests/testrunner.sh b/tests/testrunner.sh
index 743af63..adb20d6 100755
--- a/tests/testrunner.sh
+++ b/tests/testrunner.sh
@@ -30,6 +30,8 @@ export G_DEBUG=fatal_warnings
 
 VALAC=$topbuilddir/compiler/valac
 VALAFLAGS="--vapidir $vapidir --disable-warnings --main main --save-temps -X -g -X -O0 -X -pipe -X -lm -X -Werror=return-type -X -Werror=init-self -X -Werror=implicit -X -Werror=sequence-point -X -Werror=return-type -X -Werror=uninitialized -X -Werror=pointer-arith -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast"
+VAPIGEN=$topbuilddir/vapigen/vapigen
+VAPIGENFLAGS="--vapidir $vapidir"
 
 function testheader() {
 	if [ "$1" = "Packages:" ]; then
@@ -38,6 +40,8 @@ function testheader() {
 	elif [ "$1" = "D-Bus" ]; then
 		echo 'eval `dbus-launch --sh-syntax`' >> prepare
 		echo 'trap "kill $DBUS_SESSION_BUS_PID" INT TERM EXIT' >> prepare
+	elif [ "$1" = "GIR" ]; then
+		GIRTEST=1
 	fi
 }
 
@@ -50,13 +54,47 @@ function sourceheader() {
 		SOURCEFILES="$SOURCEFILES $SOURCEFILE"
 		echo "	case \"/$testpath\": $ns.main (); break;" >> main.vala
 		echo "namespace $ns {" > $SOURCEFILE
+	elif [ $GIRTEST -eq 1 ]; then
+		if [ "$1" = "Input:" ]; then
+			testpath=${testfile/.test/}
+			ns=${testpath//\//.}
+			ns=${ns//-/_}
+			SOURCEFILE=$ns.gir
+			cat <<EOF > $SOURCEFILE
+<?xml version="1.0"?>
+<repository version="1.2"
+			xmlns="http://www.gtk.org/introspection/core/1.0";
+			xmlns:c="http://www.gtk.org/introspection/c/1.0";
+			xmlns:glib="http://www.gtk.org/introspection/glib/1.0";>
+  <include name="GLib" version="2.0"/>
+  <include name="GObject" version="2.0"/>
+  <c:include name="test.h"/>
+  <namespace name="Test"
+			 version="1.2"
+			 c:identifier-prefixes="Test"
+			 c:symbol-prefixes="test">
+EOF
+		elif [ "$1" = "Output:" ]; then
+			testpath=${testfile/.test/}
+			ns=${testpath//\//.}
+			ns=${ns//-/_}
+			SOURCEFILE=$ns.vapi.ref
+		fi
 	fi
 }
 
 function sourceend() {
 	if [ -n "$testpath" ]; then
-		echo "}" >> $SOURCEFILE
-		echo "./test$EXEEXT /$testpath" > check
+		if [ $GIRTEST -eq 1 ]; then
+			if [ $PART -eq 1 ]; then
+				echo "  </namespace>" >> $SOURCEFILE
+				echo "</repository>" >> $SOURCEFILE
+			fi
+			echo "$VAPIGEN $VAPIGENFLAGS --library $ns $ns.gir && tail -n +5 $ns.vapi|head -n -1|diff -wu $ns.vapi.ref -" > check
+		else
+			echo "}" >> $SOURCEFILE
+			echo "./test$EXEEXT /$testpath" > check
+		fi
 	fi
 }
 
@@ -101,6 +139,7 @@ for testfile in "$@"; do
 	*.test)
 		PART=0
 		INHEADER=1
+		GIRTEST=0
 		testpath=
 		while IFS="" read -r line; do
 			if [ $PART -eq 0 ]; then



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