[vala-tests] examples: update from wiki, simplify .test creation
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala-tests] examples: update from wiki, simplify .test creation
- Date: Fri, 19 Mar 2010 01:49:10 +0000 (UTC)
commit 0cdd9b48c2d186f05cb73b3652313cc0e05192d6
Author: Marc-André Lureau <marcandre lureau gmail com>
Date: Fri Mar 19 02:48:23 2010 +0100
examples: update from wiki, simplify .test creation
Makefile | 2 +-
common.sh | 86 +++++
tests/examples/advanced.test | 31 +--
tests/examples/advanced.vala | 18 +-
tests/examples/async-gio.test | 30 --
tests/examples/async-gio.vala | 91 -----
tests/examples/basic.test | 31 +--
tests/examples/basic.vala | 4 -
tests/examples/bluez-dbus-sample.test | 30 --
tests/examples/cairo.test | 31 +--
tests/examples/cairo.vala | 29 +-
tests/examples/character.test | 3 +
tests/examples/character.vala | 33 ++
tests/examples/clutter-demo.test | 3 +
tests/examples/clutter-demo.vala | 91 +++++
tests/examples/couchdb.test | 3 +
tests/examples/couchdb.vala | 78 ++++
tests/examples/curses.test | 3 +
tests/examples/curses.vala | 25 ++
tests/examples/dbus-bluez.test | 3 +
.../{bluez-dbus-sample.vala => dbus-bluez.vala} | 10 +-
tests/examples/dbus-purple.test | 3 +
.../{dbus-sample.vala => dbus-purple.vala} | 22 +-
tests/examples/dbus-sample.test | 30 --
tests/examples/dbus-server-sample.test | 30 --
tests/examples/dbus-server-sample.vala | 58 ---
tests/examples/dbus-skype.test | 3 +
tests/examples/dbus-skype.vala | 52 +++
tests/examples/egg-clock.test | 31 +--
tests/examples/egg-clock.vala | 39 +--
tests/examples/gconf.test | 31 +--
tests/examples/gconf.vala | 221 ++++++------
tests/examples/gdl-sample.test | 3 +
tests/examples/gdl-sample.vala | 220 ++++++++++++
tests/examples/gee-iterable.test | 3 +
tests/examples/gee-iterable.vala | 72 ++++
tests/examples/gee-list.test | 3 +
tests/examples/gee-list.vala | 22 ++
tests/examples/gee-map.test | 3 +
tests/examples/gee-map.vala | 19 +
tests/examples/gee-set.test | 3 +
tests/examples/gee-set.vala | 18 +
tests/examples/gio-async-reading.test | 4 +
tests/examples/gio-async-reading.vala | 69 ++++
tests/examples/gio-async.test | 3 +
tests/examples/gio-async.vala | 70 ++++
tests/examples/gio-binary-sample.test | 3 +
tests/examples/gio-binary-sample.vala | 48 +++
tests/examples/gio-channel.test | 3 +
tests/examples/gio-channel.vala | 97 +++++
tests/examples/gio-file-operations.test | 3 +
tests/examples/gio-file-operations.vala | 49 +++
tests/examples/gio-ls.test | 3 +
tests/examples/gio-ls.vala | 25 ++
tests/examples/gio-network-client-async.test | 3 +
tests/examples/gio-network-client-async.vala | 48 +++
tests/examples/gio-network-client.test | 3 +
tests/examples/gio-network-client.vala | 30 ++
tests/examples/gio-sample.test | 3 +
tests/examples/gio-sample.vala | 27 ++
tests/examples/gio-server.test | 3 +
tests/examples/gio-server.vala | 36 ++
tests/examples/glade.test | 30 --
tests/examples/glade.vala | 46 ---
tests/examples/gnio-sock.test | 30 --
tests/examples/gnio-sock.vala | 120 -------
tests/examples/gnome-desktop-and-menu.test | 31 +--
tests/examples/gnome-desktop-and-menu.vala | 90 +++---
tests/examples/gsl-combination.test | 3 +
tests/examples/gsl-combination.vala | 26 ++
tests/examples/gsl-eigen-system.test | 3 +
tests/examples/gsl-eigen-system.vala | 37 ++
tests/examples/gsl-function.test | 3 +
tests/examples/gsl-function.vala | 21 ++
tests/examples/gsl-integration.test | 3 +
tests/examples/gsl-integration.vala | 35 ++
tests/examples/gsl-least-squares-fitting.test | 3 +
tests/examples/gsl-least-squares-fitting.vala | 130 +++++++
tests/examples/gsl-linear-algebra.test | 3 +
tests/examples/gsl-linear-algebra.vala | 33 ++
tests/examples/gsl-monte-carlo-integration.test | 3 +
tests/examples/gsl-monte-carlo-integration.vala | 72 ++++
tests/examples/gsl-multidimensional.test | 3 +
tests/examples/gsl-multidimensional.vala | 101 ++++++
tests/examples/gsl-random.test | 3 +
tests/examples/gsl-random.vala | 28 ++
tests/examples/gsl-stats.test | 3 +
tests/examples/gsl-stats.vala | 23 ++
tests/examples/gstreamer-audio-player.test | 5 +
tests/examples/gstreamer-audio-player.vala | 80 +++++
tests/examples/gstreamer-square-beep.test | 33 +--
tests/examples/gstreamer-square-beep.vala | 21 +-
tests/examples/gstreamer-video.test | 30 --
tests/examples/gstreamer-video.vala | 68 ----
tests/examples/gstreamer-videotest.test | 3 +
tests/examples/gstreamer-videotest.vala | 70 ++++
tests/examples/gtk-builder-sample.test | 31 +--
tests/examples/gtk-builder-sample.vala | 80 ++---
tests/examples/gtk-filechooser-subclass.test | 30 --
tests/examples/gtk-filechooser-subclass.vala | 42 ---
tests/examples/gtk-filechooser.test | 3 +
tests/examples/gtk-filechooser.vala | 36 ++
tests/examples/gtk-hello.test | 3 +
tests/examples/gtk-hello.vala | 25 ++
tests/examples/gtk-sample.test | 30 --
tests/examples/gtk-sample.vala | 33 --
tests/examples/gtk-search-dialog.test | 3 +
tests/examples/gtk-search-dialog.vala | 91 +++++
tests/examples/gtk-sync-sample.test | 3 +
tests/examples/gtk-sync-sample.vala | 42 +++
tests/examples/gtk-text-viewer.test | 3 +
tests/examples/gtk-text-viewer.vala | 65 ++++
tests/examples/gtk-treeview-listsample.test | 3 +
tests/examples/gtk-treeview-listsample.vala | 62 ++++
tests/examples/gtk-treeview-liststore.test | 3 +
tests/examples/gtk-treeview-liststore.vala | 53 +++
tests/examples/gtk-treeview-treestore.test | 3 +
tests/examples/gtk-treeview-treestore.vala | 66 ++++
tests/examples/gtk-valawidget.test | 31 +--
tests/examples/gtk-valawidget.vala | 223 ++++++------
tests/examples/hildon-sample.test | 3 +
tests/examples/hildon-sample.vala | 48 +++
tests/examples/input-character.test | 6 +
tests/examples/input-character.vala | 13 +
tests/examples/input-readline.test | 3 +
tests/examples/input-readline.vala | 12 +
tests/examples/input-scanf.test | 3 +
tests/examples/input-scanf.vala | 29 ++
tests/examples/input-stdin-line.test | 3 +
tests/examples/input-stdin-line.vala | 11 +
tests/examples/input-stdin.test | 3 +
tests/examples/input-stdin.vala | 26 ++
tests/examples/json-google-translator.test | 3 +
tests/examples/json-google-translator.vala | 42 +++
tests/examples/json-sample.test | 3 +
tests/examples/json-sample.vala | 30 ++
tests/examples/libxml2.test | 3 +
tests/examples/libxml2.vala | 132 +++++++
tests/examples/list.test | 31 +--
tests/examples/list.vala | 4 +-
tests/examples/lm-send-async.test | 3 +
tests/examples/lm-send-async.vala | 159 +++++++++
tests/examples/lm-send-sync.test | 3 +
tests/examples/lm-send-sync.vala | 119 +++++++
tests/examples/lua-table.test | 3 +
tests/examples/lua-table.vala | 43 +++
tests/examples/lua-test.test | 3 +
tests/examples/lua-test.vala | 24 ++
tests/examples/markup-parser.test | 3 +
tests/examples/markup-parser.vala | 75 ++++
tests/examples/number-guessing.test | 3 +
tests/examples/number-guessing.vala | 14 +-
tests/examples/opengl-glfw.test | 3 +
tests/examples/opengl-glfw.vala | 40 ++
tests/examples/opengl-glut.test | 3 +
tests/examples/opengl-glut.vala | 374 ++++++++++++++++++++
tests/examples/opengl-glx.test | 3 +
tests/examples/opengl-glx.vala | 91 +++++
tests/examples/opengl-gtkglext-spot.test | 3 +
tests/examples/opengl-gtkglext-spot.vala | 210 +++++++++++
tests/examples/opengl-gtkglext.test | 3 +
tests/examples/opengl-gtkglext.vala | 85 +++++
tests/examples/panel-applet-advanced.test | 31 +--
tests/examples/panel-applet-advanced.vala | 18 +-
tests/examples/panel-applet-simple.test | 31 +--
tests/examples/panel-applet-simple.vala | 4 +-
tests/examples/pango-cairo.test | 31 +--
tests/examples/pango-cairo.vala | 287 +++++++--------
tests/examples/poppler-sample.test | 31 +--
tests/examples/poppler-sample.vala | 82 ++---
tests/examples/postgresql.test | 3 +
tests/examples/postgresql.vala | 87 +++++
tests/examples/preprocessor.test | 3 +
tests/examples/properties-construction.test | 31 +--
tests/examples/properties-construction.vala | 56 ++--
tests/examples/properties.test | 31 +--
tests/examples/properties.vala | 58 ++--
tests/examples/sdl-sample.test | 3 +
tests/examples/sdl-sample.vala | 94 +++++
tests/examples/signals.test | 3 +
tests/examples/signals.vala | 4 +-
tests/examples/soup-http-request.test | 3 +
tests/examples/soup-http-request.vala | 26 ++
tests/examples/soup-http-server.test | 3 +
tests/examples/soup-http-server.vala | 32 ++
tests/examples/soup-twitter.test | 3 +
tests/examples/soup-twitter.vala | 24 ++
tests/examples/sqlite.test | 3 +
tests/examples/sqlite.vala | 56 +++
tests/examples/string.test | 31 +--
tests/examples/string.vala | 30 +-
tests/examples/test-gtk.test | 3 +
tests/examples/test-gtk.vala | 24 ++
tests/examples/test-simple.test | 3 +
tests/examples/test-simple.vala | 14 +
tests/examples/threading-philosophers.test | 3 +
tests/examples/threading-philosophers.vala | 91 +++++
tests/examples/threading-simple.test | 3 +
tests/examples/threading-simple.vala | 39 ++
tests/examples/tiff.test | 3 +
tests/examples/tiff.vala | 73 ++++
tests/examples/time.test | 3 +
tests/examples/time.vala | 13 +
tests/examples/type-modules-interface.test | 3 +
tests/examples/type-modules-interface.vala | 6 +
tests/examples/type-modules-main.test | 3 +
tests/examples/type-modules-main.vala | 48 +++
tests/examples/type-modules-myplugin.test | 3 +
tests/examples/type-modules-myplugin.vala | 14 +
tests/examples/update.sh | 7 +-
tests/examples/value.test | 3 +
tests/examples/value.vala | 33 +-
tests/examples/webkit-sample.test | 31 +--
tests/examples/webkit-sample.vala | 38 ++-
tests/examples/zlib.test | 3 +
tests/examples/zlib.vala | 154 ++++++++
update-from-wiki.sh | 39 ++
217 files changed, 5648 insertions(+), 1991 deletions(-)
---
diff --git a/Makefile b/Makefile
index 6a4238a..8715da7 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ VALAC = valac
all: testsuite
check: testsuite
- VALAC="$(VALAC)" gtester --verbose --g-fatal-warnings -k -o test-report.xml testsuite
+ PATH=$$PATH:`pwd` VALAC="$(VALAC)" gtester --verbose --g-fatal-warnings -k -o test-report.xml testsuite
gtester-report test-report.xml > test-report.html
testsuite: src/testsuite.vala src/testcase.vala src/posix.vapi
diff --git a/common.sh b/common.sh
new file mode 100644
index 0000000..29a2757
--- /dev/null
+++ b/common.sh
@@ -0,0 +1,86 @@
+#!/bin/bash
+
+SRCDIR=`dirname $0`
+[ -z "$VALAC" ] && VALAC=valac
+VALACEXIT="${VALACEXIT:-0}"
+VALAFLAGS="${VALAFLAGS:-}"
+
+TESTNAME=`basename $0 .test`
+TESTSRC="${TESTSRC:-$SRCDIR/$TESTNAME.vala}"
+TESTENV="${TESTENV:-G_DEBUG=fatal_warnings}"
+[ -n "$BUGID" ] && BUGZILLA="http://bugzilla.gnome.org/show_bug.cgi?id=$BUGID"
+
+VALGRINDENV="${VALGRINDENV:-G_SLICE=always-malloc G_DEBUG=gc-friendly GLIBCPP_FORCE_NEW=1 GLIBCXX_FORCE_NEW=1}"
+VALGRINDFLAGS="${VALGRINDFLAGS:---tool=memcheck --leak-check=full --error-exitcode=1 -q}"
+
+while true ; do
+ case "$1" in
+ --interact)
+ INTERACT=1 ;
+ shift ;;
+ --memcheck)
+ VALGRIND="valgrind" ;
+ shift ;;
+ --massif)
+ VALGRIND="valgrind" ;
+ VALGRINDFLAGS="--tool=massif --massif-out-file=$TESTNAME.massif -q" ;
+ shift ;;
+ --) shift ; break ;;
+ *) break ;;
+ esac
+done
+
+# hackish
+function guess_packages {
+ grep "Gtk" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gtk+-2.0" TESTRUN="${TESTRUN:-interact}"
+ grep -i " gio" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gio-2.0"
+ grep "DBus\." $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg dbus-glib-1" TESTRUN="${TESTRUN:-skip}"
+ grep -i "cairo" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg cairo" TESTRUN="${TESTRUN:-interact}"
+ grep "GConf\." $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gconf-2.0" TESTRUN="${TESTRUN:-skip}"
+ grep "Glade\." $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg libglade-2.0"
+ grep "Module\." $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gmodule-2.0"
+ grep "Gnome\.Desktop" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gnome-desktop-2.0"
+ grep "GMenu\." $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg libgnome-menu"
+ grep "Gst\." $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gstreamer-0.10"
+ grep "Gdk\.x11" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gdk-x11-2.0" TESTRUN="${TESTRUN:-interact}"
+ grep "XOverlay" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gstreamer-interfaces-0.10"
+ grep "using Panel" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg libpanelapplet-2.0" TESTRUN="${TESTRUN:-interact}"
+ grep -i "pango" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg pangocairo"
+ grep "Poppler\." $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg poppler-glib"
+ grep "SocketConnection" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gnio"
+ grep "WebKit" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg webkit-1.0" TESTRUN="${TESTRUN:-interact}"
+ grep "Gee" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gee-1.0"
+ grep "Xml" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg libxml-2.0"
+ grep "Clutter\." $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg clutter-1.0" TESTRUN="${TESTRUN:-interact}"
+ grep "CouchDB" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg couchdb-glib-1.0"
+ grep "Curses" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg curses -X -lncurses" TESTRUN="${TESTRUN:-interact}"
+}
+
+[ -z "$PACKAGES" ] && guess_packages
+
+sh -x -c "$VALAC $PACKAGES -o $TESTNAME $TESTSRC $VALAFLAGS"
+exitval="$?"
+
+if [ "$exitval" -ne "$VALACEXIT" ]; then
+ echo ""
+ echo "*** WARNING: valac was expecting to return $VALACEXIT, != $exitval ***"
+ echo ""
+ [ -n "$BUGZILLA" ] && echo "Visit bug: $BUGZILLA"
+ exit 1
+fi
+
+export TESTENV
+export VALGRINDENV
+TESTRUN="${TESTRUN:-yes}"
+if [ -n "$INTERACT" -o "x$TESTRUN" = "xyes" ]; then
+ if [ -z $VALGRIND ] ; then
+ sh -c "./$TESTNAME $TESTARGS $@"
+ else
+ sh -c "$VALGRIND $VALGRINDFLAGS ./$TESTNAME $TESTARGS $@"
+ fi
+ exit $?
+else
+ echo ""
+ [ "x$TESTRUN" = "xinteract" ] && echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
+fi
+
diff --git a/tests/examples/advanced.test b/tests/examples/advanced.test
index a23ddd3..0174331 100755
--- a/tests/examples/advanced.test
+++ b/tests/examples/advanced.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/advanced.vala b/tests/examples/advanced.vala
index ca6e622..1ec0f55 100644
--- a/tests/examples/advanced.vala
+++ b/tests/examples/advanced.vala
@@ -1,32 +1,28 @@
// http://live.gnome.org/Vala/AdvancedSample vala-test:examples/advanced.vala
-/* Advanced Vala sample code */
-
-using GLib;
-
/* class derived from GObject */
public class AdvancedSample : Object {
/* automatic property, data field is implicit */
- public string name { get; construct set; }
+ public string name { get; set; }
/* signal */
public signal void foo ();
- /* creation method, setting construction property */
+ /* creation method */
public AdvancedSample (string name) {
this.name = name;
}
/* public instance method */
public void run () {
- /* assigning anonymous method as signal handler */
- this.foo += s => {
- stdout.printf ("Lambda expression %s!\n", name);
- };
+ /* assigning anonymous function as signal handler */
+ this.foo.connect ((s) => {
+ stdout.printf ("Lambda expression %s!\n", this.name);
+ });
- /* Calling lambda expression */
+ /* emitting the signal */
this.foo ();
}
diff --git a/tests/examples/basic.test b/tests/examples/basic.test
index a23ddd3..0174331 100755
--- a/tests/examples/basic.test
+++ b/tests/examples/basic.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/basic.vala b/tests/examples/basic.vala
index 0562f3c..25e92c0 100644
--- a/tests/examples/basic.vala
+++ b/tests/examples/basic.vala
@@ -1,10 +1,6 @@
// http://live.gnome.org/Vala/BasicSample vala-test:examples/basic.vala
-/* Basic Vala sample code */
-
-using GLib;
-
/* class derived from GObject */
public class BasicSample : Object {
diff --git a/tests/examples/cairo.test b/tests/examples/cairo.test
index 642fbe3..0174331 100755
--- a/tests/examples/cairo.test
+++ b/tests/examples/cairo.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gtk+-2.0 --pkg cairo -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/cairo.vala b/tests/examples/cairo.vala
index ab70be6..07fe15d 100644
--- a/tests/examples/cairo.vala
+++ b/tests/examples/cairo.vala
@@ -1,6 +1,6 @@
-/* Cairo in Vala sample code */
-using GLib;
+// http://live.gnome.org/Vala/CairoSample vala-test:examples/cairo.vala
+
using Gtk;
using Cairo;
@@ -8,21 +8,20 @@ public class CairoSample : Gtk.Window {
private const int SIZE = 30;
- construct {
+ public CairoSample () {
this.title = "Cairo Vala Demo";
- this.destroy += Gtk.main_quit;
- this.set_default_size (450, 550);
-
- this.create_widgets ();
+ this.destroy.connect (Gtk.main_quit);
+ set_default_size (450, 550);
+ create_widgets ();
}
private void create_widgets () {
var drawing_area = new DrawingArea ();
- drawing_area.expose_event += this.on_expose;
- this.add (drawing_area);
+ drawing_area.expose_event.connect (on_expose);
+ add (drawing_area);
}
- private bool on_expose (DrawingArea da, Gdk.EventExpose event) {
+ private bool on_expose (Widget da, Gdk.EventExpose event) {
var ctx = Gdk.cairo_create (da.window);
ctx.set_source_rgb (0, 0, 0);
@@ -69,22 +68,22 @@ public class CairoSample : Gtk.Window {
ctx.new_path ();
ctx.translate (x + SIZE, y + SIZE);
bowtie (ctx);
- draw_method ();
+ draw_method ();
ctx.new_path ();
ctx.translate (3 * SIZE, 0);
square (ctx);
- draw_method ();
+ draw_method ();
ctx.new_path ();
ctx.translate (3 * SIZE, 0);
triangle (ctx);
- draw_method ();
+ draw_method ();
ctx.new_path ();
ctx.translate (3 * SIZE, 0);
inf (ctx);
- draw_method ();
+ draw_method ();
ctx.restore();
}
@@ -131,4 +130,4 @@ public class CairoSample : Gtk.Window {
return 0;
}
-}
\ No newline at end of file
+}
diff --git a/tests/examples/character.test b/tests/examples/character.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/character.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/character.vala b/tests/examples/character.vala
new file mode 100644
index 0000000..8c86f1a
--- /dev/null
+++ b/tests/examples/character.vala
@@ -0,0 +1,33 @@
+
+// http://live.gnome.org/Vala/CharacterSample vala-test:examples/character.vala
+
+void main () {
+
+ string unicode_string = "1234567890 ١٢٣٤٥٦٧٨٩۰ ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz أبتةثجØخدذرزسشصضطظعغÙ?Ù?Ù?Ù?Ù?Ù?Ù?Ù?Ù?";
+
+ for (unowned string s = unicode_string; s.get_char () != 0 ; s = s.next_char ()) {
+
+ unichar unicode_character = s.get_char ();
+ UnicodeType unicode_character_type = unicode_character.type ();
+
+ stdout.printf("'%s' is ", new StringBuilder ().append_unichar (unicode_character).str);
+
+ switch (unicode_character_type) {
+ case UnicodeType.UPPERCASE_LETTER:
+ stdout.printf ("UPPERCASE_LETTER\n");
+ break;
+ case UnicodeType.LOWERCASE_LETTER:
+ stdout.printf ("LOWERCASE_LETTER\n");
+ break;
+ case UnicodeType.OTHER_LETTER:
+ stdout.printf("OTHER_LETTER\n");
+ break;
+ case UnicodeType.DECIMAL_NUMBER:
+ stdout.printf ("OTHER_NUMBER\n");
+ break;
+ case UnicodeType.SPACE_SEPARATOR:
+ stdout.printf ("SPACE_SEPARATOR\n");
+ break;
+ }
+ }
+}
diff --git a/tests/examples/clutter-demo.test b/tests/examples/clutter-demo.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/clutter-demo.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/clutter-demo.vala b/tests/examples/clutter-demo.vala
new file mode 100644
index 0000000..a1ad9eb
--- /dev/null
+++ b/tests/examples/clutter-demo.vala
@@ -0,0 +1,91 @@
+
+// http://live.gnome.org/Vala/ClutterSamples vala-test:examples/clutter-demo.vala
+
+using Clutter;
+
+class ClutterDemo {
+
+ private Stage stage;
+ private Rectangle[] rectangles;
+
+ const string[] colors = {
+ "blanched almond",
+ "OldLace",
+ "MistyRose",
+ "White",
+ "LavenderBlush",
+ "CornflowerBlue",
+ "chartreuse",
+ "chocolate",
+ "light coral",
+ "medium violet red",
+ "LemonChiffon2",
+ "RosyBrown3"
+ };
+
+ public ClutterDemo () {
+ stage = Stage.get_default ();
+
+ rectangles = new Rectangle[colors.length];
+ stage.hide.connect (Clutter.main_quit);
+
+ create_rectangles ();
+
+ stage.color = Color () { alpha = 255 };
+ stage.show_all ();
+ }
+
+ private void create_rectangles () {
+ for (int i = 0; i < colors.length; i++) {
+ var r = new Rectangle ();
+
+ r.width = r.height = stage.height / colors.length;
+ r.color = Color.from_string (colors[i]);
+ r.anchor_gravity = Gravity.CENTER;
+ r.y = i * r.height + r.height / 2;
+
+ stage.add_actor (r);
+
+ rectangles[i] = r;
+ }
+ }
+
+ public void start () {
+ var animations = new Animation[rectangles.length];
+ for (int i = 0; i < rectangles.length; i++) {
+ animations[i] = rectangles[i].animate (
+ AnimationMode.LINEAR, 5000,
+ "x", stage.width / 2,
+ "rotation-angle-z", 500.0);
+ }
+ animations[animations.length - 1].completed.connect (() => {
+ var text = new Text.full ("Bitstream Vera Sans 40",
+ "Congratulations!",
+ Color.from_string ("white"));
+
+ text.anchor_gravity = Gravity.CENTER;
+ text.x = stage.width / 2;
+ text.y = -text.height; // Off-stage
+ stage.add_actor (text);
+ text.animate (AnimationMode.EASE_OUT_BOUNCE, 3000,
+ "y", stage.height / 2);
+
+ for (int i = 0; i < rectangles.length; i++) {
+ animations[i] = rectangles[i].animate (
+ AnimationMode.EASE_OUT_BOUNCE, 3000,
+ "x", Random.next_double () * stage.width,
+ "y", Random.next_double () * stage.height / 2
+ + stage.height / 2,
+ "rotation-angle-z", rectangles[i].rotation_angle_z,
+ "opacity", 0);
+ }
+ });
+ }
+}
+
+void main (string[] args) {
+ Clutter.init (ref args);
+ var demo = new ClutterDemo ();
+ demo.start ();
+ Clutter.main ();
+}
diff --git a/tests/examples/couchdb.test b/tests/examples/couchdb.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/couchdb.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/couchdb.vala b/tests/examples/couchdb.vala
new file mode 100644
index 0000000..8ec67c6
--- /dev/null
+++ b/tests/examples/couchdb.vala
@@ -0,0 +1,78 @@
+
+// http://live.gnome.org/Vala/CouchDBSample vala-test:examples/couchdb.vala
+
+const string DB1 = "vala1";
+const string DB2 = "vala2";
+
+int main () {
+
+ /* Connect to CouchDB */
+ var conn = new CouchDB.Connection ();
+// var conn = new CouchDB.Connection ("http://localhost:5984");
+ stdout.printf ("database hostname: %s\n", conn.get_hostname ());
+
+ try {
+
+ /* Create demo databases */
+ stdout.printf ("Creating databases\n");
+ conn.create_database (DB1);
+ conn.create_database (DB2);
+
+ /* Create a document */
+ var newdoc = new CouchDB.Document (conn);
+ newdoc.set_boolean_field ("awesome", true);
+ newdoc.set_string_field ("phone", "555-VALA");
+ newdoc.set_double_field ("pi", 3.14159);
+ newdoc.set_int_field ("meaning_of_life", 42);
+ newdoc.put (DB1); // store document
+
+ /* ... another one, this time with a custom ID and a StructField */
+ newdoc = new CouchDB.Document (conn);
+ newdoc.set_id ("my_id"); // custom ID, otherwise auto-generated
+ newdoc.set_string_field ("color", "green");
+ var sf = new CouchDB.StructField ();
+ sf.set_int_field ("foo", 47);
+ sf.set_int_field ("bar", 11);
+ newdoc.set_struct_field ("mystruct", sf);
+ newdoc.put (DB1);
+
+ /* Query document by ID */
+ var qdoc = conn.get_document (DB1, "my_id");
+ assert (qdoc.get_string_field ("color") == "green");
+ assert (qdoc.get_struct_field ("mystruct").has_field ("foo"));
+ assert (qdoc.get_struct_field ("mystruct").get_int_field ("foo") == 47);
+
+ /* List database informations and contents */
+ var dbases = conn.list_databases ();
+ foreach (var dbase in dbases) {
+ stdout.printf ("database: %s\n", dbase);
+ var dbinfo = conn.get_database_info (dbase);
+ stdout.printf ("* dbname: %s\n", dbinfo.get_dbname ());
+ stdout.printf ("* documents_count: %d\n", dbinfo.get_documents_count ());
+ stdout.printf ("* deleted_documents_count: %d\n", dbinfo.get_deleted_documents_count ());
+ stdout.printf ("* update_sequence: %d\n", dbinfo.get_update_sequence ());
+ stdout.printf ("* compact_running: %s\n", dbinfo.is_compact_running ().to_string ());
+ stdout.printf ("* disk_size: %d\n", dbinfo.get_disk_size ());
+ var docinfos = conn.list_documents (dbase);
+ foreach (var docinfo in docinfos) {
+ stdout.printf ("* document docid: %s revision: %s\n", docinfo.get_docid (),
+ docinfo.get_revision ());
+ var doc = conn.get_document (dbase, docinfo.get_docid ());
+ stdout.printf ("** full content: %s\n", doc.to_string ());
+ }
+ }
+
+ /* Delete a document */
+ qdoc.delete ();
+
+ /* Delete demo databases */
+ stdout.printf ("Deleting databases\n");
+ conn.delete_database (DB1);
+ conn.delete_database (DB2);
+
+ } catch (Error e) {
+ stderr.printf ("%s\n", e.message);
+ }
+
+ return 0;
+}
diff --git a/tests/examples/curses.test b/tests/examples/curses.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/curses.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/curses.vala b/tests/examples/curses.vala
new file mode 100644
index 0000000..5588ad6
--- /dev/null
+++ b/tests/examples/curses.vala
@@ -0,0 +1,25 @@
+
+// http://live.gnome.org/Vala/CursesSample vala-test:examples/curses.vala
+
+using Curses;
+
+int main (string[] args) {
+ /* Initialize Curses */
+ initscr ();
+
+ /* Initialize color mode and define a color pair */
+ start_color ();
+ init_pair (1, Color.GREEN, Color.RED);
+
+ /* Create a window (height/lines, width/columns, y, x) */
+ var win = new Window (LINES - 8, COLS - 8, 4, 4);
+ win.bkgdset (COLOR_PAIR (1) | Attribute.BOLD); // set background
+ win.addstr ("Hello world!"); // write string
+ win.clrtobot (); // clear to bottom (does not move cursor)
+ win.getch (); // read a character
+
+ /* Reset the terminal mode */
+ endwin ();
+
+ return 0;
+}
diff --git a/tests/examples/dbus-bluez.test b/tests/examples/dbus-bluez.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/dbus-bluez.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/bluez-dbus-sample.vala b/tests/examples/dbus-bluez.vala
similarity index 85%
rename from tests/examples/bluez-dbus-sample.vala
rename to tests/examples/dbus-bluez.vala
index 2977131..332f442 100644
--- a/tests/examples/bluez-dbus-sample.vala
+++ b/tests/examples/dbus-bluez.vala
@@ -1,4 +1,5 @@
-/* Bluetooth discovery using DBus in Vala sample code */
+
+// http://live.gnome.org/Vala/DBusClientSamples vala-test:examples/dbus-bluez.vala
using GLib;
@@ -9,7 +10,8 @@ public class BlueZDiscoverySample : GLib.Object {
public MainLoop loop { set; get; }
public void run () throws DBus.Error, GLib.Error {
- this.conn = DBus.Bus.get (DBus.BusType.SYSTEM);
+ // remove the space before SYSTEM, it is just needed for this wiki
+ this.conn = DBus.Bus.get (DBus.BusType. SYSTEM);
this.bluez = conn.get_object ("org.bluez", "/org/bluez/hci0", "org.bluez.Adapter");
@@ -50,8 +52,8 @@ public class BlueZDiscoverySample : GLib.Object {
try {
test.run ();
} catch (DBus.Error e) {
- error ("Failed to initialise: %s", e.message);
- } catch {
+ error ("Failed to initialise");
+ } catch (GLib.Error e) {
error ("Dynamic method failure");
}
diff --git a/tests/examples/dbus-purple.test b/tests/examples/dbus-purple.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/dbus-purple.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/dbus-sample.vala b/tests/examples/dbus-purple.vala
similarity index 75%
rename from tests/examples/dbus-sample.vala
rename to tests/examples/dbus-purple.vala
index 2b9a14a..c3480c9 100644
--- a/tests/examples/dbus-sample.vala
+++ b/tests/examples/dbus-purple.vala
@@ -1,6 +1,6 @@
-/* DBus in Vala sample code */
-using GLib;
+// http://live.gnome.org/Vala/DBusClientSamples vala-test:examples/dbus-purple.vala
+
using DBus;
public class DBusSample : GLib.Object {
@@ -12,7 +12,9 @@ public class DBusSample : GLib.Object {
// remove the space before SESSION, it is only required for this wiki
conn = DBus.Bus.get (DBus.BusType. SESSION);
- purple = conn.get_object ("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject", "im.pidgin.purple.PurpleInterface");
+ purple = conn.get_object ("im.pidgin.purple.PurpleService",
+ "/im/pidgin/purple/PurpleObject",
+ "im.pidgin.purple.PurpleInterface");
// async dbus call
purple.PurpleAccountsGetAllActive (getall_reply);
@@ -21,7 +23,9 @@ public class DBusSample : GLib.Object {
purple.ReceivedImMsg += msg_received;
}
- private void msg_received (dynamic DBus.Object purple, int dummy1, string sender, string message_, int dummy2, uint dummy3) {
+ private void msg_received (dynamic DBus.Object purple, int dummy1, string sender,
+ string message_, int dummy2, uint dummy3)
+ {
// dbus signal handler
message ("Message received %s %s", sender, message_);
@@ -30,7 +34,7 @@ public class DBusSample : GLib.Object {
private void getall_reply (int[] ids, GLib.Error e) {
// callback for async dbus call
if (e != null) {
- critical (e.message);
+ critical ("%s", e.message);
return;
}
try {
@@ -39,8 +43,8 @@ public class DBusSample : GLib.Object {
string s = purple.PurpleAccountGetUsername (id);
message ("Account %s", s);
}
- } catch (DBus.Error dbus_error) {
- critical (dbus_error.message);
+ } catch (GLib.Error err) {
+ critical ("%s", err.message);
}
}
@@ -53,7 +57,7 @@ public class DBusSample : GLib.Object {
} catch (DBus.Error e) {
stderr.printf ("Failed to initialise");
return 1;
- } catch {
+ } catch (GLib.Error e) {
stderr.printf ("Dynamic method failure");
return 1;
}
@@ -62,4 +66,4 @@ public class DBusSample : GLib.Object {
return 0;
}
-}
\ No newline at end of file
+}
diff --git a/tests/examples/dbus-skype.test b/tests/examples/dbus-skype.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/dbus-skype.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/dbus-skype.vala b/tests/examples/dbus-skype.vala
new file mode 100644
index 0000000..cdf6349
--- /dev/null
+++ b/tests/examples/dbus-skype.vala
@@ -0,0 +1,52 @@
+
+// http://live.gnome.org/Vala/DBusClientSamples vala-test:examples/dbus-skype.vala
+
+class SkypeStatusClient {
+
+ private DBus.Connection conn;
+ private dynamic DBus.Object skype;
+
+ public void init () throws DBus.Error {
+ this.conn = DBus.Bus.get (DBus.BusType.SESSION);
+ this.skype = conn.get_object ("com.Skype.API", "/com/Skype", "com.Skype.API");
+ }
+
+ public string send (string cmd) {
+ try {
+ return this.skype.Invoke (cmd);
+ } catch (GLib.Error e) {
+ error (e.message);
+ }
+ return "";
+ }
+
+ public void send_check (string cmd, string expected_result) {
+ string s = send (cmd);
+ if (s != expected_result) {
+ error ("Bad result '%s', expected '%s'\n", s, expected_result);
+ }
+ }
+}
+
+int main (string[] args) {
+ var client = new SkypeStatusClient ();
+
+ try {
+ client.init ();
+ } catch (DBus.Error e) {
+ error ("Failed to initialise: %s", e.message);
+ }
+
+ client.send_check ("NAME skype-status-client", "OK");
+ client.send_check ("PROTOCOL 2", "PROTOCOL 2");
+
+ // if no arguments given, show current status, otherwise update status to first argument
+ if (args.length < 2) {
+ stdout.printf ("%s\n", client.send ("GET USERSTATUS"));
+ } else {
+ // possible statuses: ONLINE OFFLINE SKYPEME AWAY NA DND INVISIBLE
+ client.send_check ("SET USERSTATUS " + args[1], "USERSTATUS " + args[1]);
+ }
+
+ return 0;
+}
diff --git a/tests/examples/egg-clock.test b/tests/examples/egg-clock.test
index 642fbe3..0174331 100755
--- a/tests/examples/egg-clock.test
+++ b/tests/examples/egg-clock.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gtk+-2.0 --pkg cairo -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/egg-clock.vala b/tests/examples/egg-clock.vala
index f3951e7..a85ccfb 100644
--- a/tests/examples/egg-clock.vala
+++ b/tests/examples/egg-clock.vala
@@ -1,4 +1,6 @@
-using GLib;
+
+// http://live.gnome.org/Vala/CustomWidgetSamples vala-test:examples/egg-clock.vala
+
using Gtk;
using Cairo;
@@ -12,31 +14,26 @@ namespace Egg {
public signal void time_changed (int hour, int minute);
- construct {
- this.expose_event += on_expose;
- this.button_press_event += on_button_press;
- this.button_release_event += on_button_release;
- this.motion_notify_event += on_motion_notify;
-
+ public ClockFace () {
add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
update ();
// update the clock once a second
Timeout.add (1000, update);
}
- private bool on_expose (ClockFace clock, Gdk.EventExpose event) {
+ public override bool expose_event (Gdk.EventExpose event) {
var cr = Gdk.cairo_create (this.window);
cr.rectangle (event.area.x, event.area.y,
- event.area.width, event.area.height);
+ event.area.width, event.area.height);
cr.clip ();
draw (cr);
return false;
}
- private bool on_button_press (ClockFace clock, Gdk.EventButton event) {
+ public override bool button_press_event (Gdk.EventButton event) {
var minutes = this.time.minute + this.minute_offset;
// From
@@ -62,7 +59,7 @@ namespace Egg {
return false;
}
- private bool on_button_release (ClockFace clock, Gdk.EventButton event) {
+ public override bool button_release_event (Gdk.EventButton event) {
if (this.dragging) {
this.dragging = false;
emit_time_changed_signal ((int) event.x, (int) event.y);
@@ -70,7 +67,7 @@ namespace Egg {
return false;
}
- private bool on_motion_notify (ClockFace clock, Gdk.EventMotion event) {
+ public override bool motion_notify_event (Gdk.EventMotion event) {
if (this.dragging) {
emit_time_changed_signal ((int) event.x, (int) event.y);
}
@@ -110,8 +107,8 @@ namespace Egg {
private void draw (Context cr) {
var x = this.allocation.x + this.allocation.width / 2;
var y = this.allocation.y + this.allocation.height / 2;
- var radius = Math.fmin (this.allocation.width / 2,
- this.allocation.height / 2) - 5;
+ var radius = double.min (this.allocation.width / 2,
+ this.allocation.height / 2) - 5;
// clock back
cr.arc (x, y, radius, 0, 2 * Math.PI);
@@ -124,7 +121,7 @@ namespace Egg {
for (int i = 0; i < 12; i++) {
int inset;
- cr.save (); // stack pen-size
+ cr.save (); // stack pen-size
if (i % 3 == 0) {
inset = (int) (0.2 * radius);
@@ -154,9 +151,9 @@ namespace Egg {
cr.set_line_width (2.5 * cr.get_line_width ());
cr.move_to (x, y);
cr.line_to (x + radius / 2 * Math.sin (Math.PI / 6 * hours
- + Math.PI / 360 * minutes),
+ + Math.PI / 360 * minutes),
y + radius / 2 * -Math.cos (Math.PI / 6 * hours
- + Math.PI / 360 * minutes));
+ + Math.PI / 360 * minutes));
cr.stroke ();
cr.restore ();
@@ -183,7 +180,7 @@ namespace Egg {
return;
}
- weak Gdk.Region region = this.window.get_clip_region ();
+ unowned Gdk.Region region = this.window.get_clip_region ();
// redraw the cairo canvas completely by exposing it
this.window.invalidate_region (region, true);
this.window.process_updates (true);
@@ -194,7 +191,7 @@ namespace Egg {
var window = new Window (WindowType.TOPLEVEL);
var clock = new ClockFace ();
window.add (clock);
- window.destroy += Gtk.main_quit;
+ window.destroy.connect (Gtk.main_quit);
window.show_all ();
Gtk.main ();
return 0;
diff --git a/tests/examples/gconf.test b/tests/examples/gconf.test
index 0851d8d..0174331 100755
--- a/tests/examples/gconf.test
+++ b/tests/examples/gconf.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gconf-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/gconf.vala b/tests/examples/gconf.vala
index 3fff5e1..fb60192 100644
--- a/tests/examples/gconf.vala
+++ b/tests/examples/gconf.vala
@@ -1,131 +1,120 @@
+
+// http://live.gnome.org/Vala/GConfSample vala-test:examples/gconf.vala
+
/*
- * vala-gconf.vala
- * Various operations with GConf: Getting, Setting, Unsetting and Notifying
- */
+ * Various operations with GConf: getting, setting, unsetting and notifying
+ */
-using GLib;
using GConf;
-public static GConf.Client gc;
-
-// Stupid function which just sets a boolean key to true
-bool set_key (string key)
-{
- bool success;
- // For the Client API see
- // http://www.vala-project.org/doc/references/gconf-2.0.vapi/GConf/Client.htm
- success = gc.set_bool(key, true);
- // The set_* functions return a boolean to indicate whether the operation
- // was successful
- return success;
-}
+public class GConfSample {
-bool get_key (string key)
-{
- return gc.get_bool(key);
-}
+ public void run () throws GLib.Error {
-// A callback which gets called everytime a defined keys change
-void gconf_cb (GConf.Client gc, uint cxnid, GConf.Entry entry)
-{
- // For the Entry API see
- // http://www.vala-project.org/doc/references/gconf-2.0.vapi/GConf/Entry.htm
- string key = entry.key;
- // For the Value API see
- // http://www.vala-project.org/doc/references/gconf-2.0.vapi/GConf/Value.htm
- // We have to set the "weak" keyword, because the reference on that
- // Value object isn't counted
- weak GConf.Value gconf_value = entry.get_value();
- // We silently assume, that this Value contains a bool, we should check it
- // first
- bool new_value = gconf_value.get_bool();
-
- stdout.printf("Callback called with Entry %s, new value: %s\n",
- key,
- new_value?"True":"False"
- );
-}
+ // You don't create a GConf.Client with "new GConf.Client ()" but
+ // rather this way:
+ var gc = GConf.Client.get_default ();
+
+ // A root directory to work in
+ string root = "/apps/myapp";
+
+ /*
+ * Set and retrieve a boolean key, see API for more information on how
+ * to retrieve other types
+ */
+
+ // Sub directories are created automatically
+ string key = root + "/foo/baz";
+ gc.set_bool (key, true);
+
+ bool result = gc.get_bool (key);
+ stdout.printf ("Value of %s is %s\n", key, result.to_string ());
+
+ /*
+ * Getting a list of keys in a directory
+ */
+
+ // first, create a few more entries
+ gc.set_bool (root + "/bar", true);
+ gc.set_bool (root + "/baz", true);
+ gc.set_bool (root + "/qux", true);
+
+ SList<GConf.Entry> entries = gc.all_entries (root);
+ stdout.printf ("Entry list has %u items\n", entries.length ());
+ foreach (var entry in entries) {
+ stdout.printf ("Key: %s Value: %s\n", entry.get_key (),
+ entry.get_value ().get_bool ().to_string ());
+ }
+ /*
+ * Getting a list of subdirectories in a directory
+ */
-int main ()
-{
- // You don't create a GConf.Client with "new GConf.Client();" but rather
- // this way:
- gc = GConf.Client.get_default();
-
- // A root directory to work in
- string root = "/apps/myapp";
-
- // Set and retrieve a boolean key, see API for more information on how to
- // retrieve other types
- string key = root + "foo/baz"; // Sub directories are created automatically
- set_key(key);
-
- bool result = true;
- result = get_key(key);
- stdout.printf("Result is %s\n", result?"True":"False");
-
-
-
- // Getting a list of keys in a directory
-
- // first, create a few more entries
- set_key(root+"/baz"); set_key(root+"/baz"); set_key(root+"/qux");
-
- // You might also want to have a look at the GConf documentation:
- // http://library.gnome.org/devel/gconf/2.23/gconf-GConfClient.html#gconf-client-all-entries
- // For a strange reason we have to define the type of the lists entries
- // ourselves.
- weak GLib.SList<GConf.Entry> entrylist = gc.all_entries(root);
- stdout.printf("Entrylist has %u items\n", entrylist.length() );
- foreach (weak GConf.Entry entry in entrylist) {
- // You must define entry to be weak until bug 549061 is resolved
- stdout.printf("Key: %s Value: %s\n",
- entry.key,
- entry.get_value().get_bool()?"True":"False"
- );
+ // first, create a few more directories
+ gc.set_bool (root + "/bar/baz", true);
+ gc.set_bool (root + "/baz/baz", true);
+ gc.set_bool (root + "/qux/baz", true);
+
+ SList<string> dir_list = gc.all_dirs (root);
+ stdout.printf ("Directory list has %u items\n", dir_list.length ());
+ foreach (string dir in dir_list) {
+ stdout.printf ("Directory: %s\n", dir);
+ }
+
+ /*
+ * Installing a callback function which gets called everytime
+ * a certain key changes
+ */
+
+ string listening_dir = root + "/foo";
+ gc.add_dir (listening_dir, GConf.ClientPreloadType.ONELEVEL);
+ stdout.printf ("Listening on %s\n", listening_dir);
+
+ string listening_key = listening_dir + "/baz";
+ gc.notify_add (listening_key, gconf_cb);
+ stdout.printf ("Having ourselves notified on %s\n", listening_key);
+
+ /*
+ * You may now run 'gconf-editor' and change the value for
+ * key '/apps/myapp/foo/baz' or comment loop.run () to remove the key.
+ */
+
+ var loop = new MainLoop (null, false);
+ loop.run ();
+
+ // This operation unsets values from keys. If a key is unset or a
+ // directory doesn't have subkeys anymore, they get deleted. They might
+ // be visible with gconf-editor until GConf has collected its garbage
+ // though. There is just one valid flag in GConf.UnsetFlags according to
+ // http://references.valadoc.org/gconf-2.0/GConf.UnsetFlags.html
+ gc.recursive_unset (root, GConf.UnsetFlags.NAMES);
}
+ /*
+ * A callback which gets called everytime a defined key changes
+ *
+ * For API documentation on Entry and Value see:
+ * http://references.valadoc.org/gconf-2.0/GConf.Entry.html
+ * http://references.valadoc.org/gconf-2.0/GConf.Value.html
+ */
+ private static void gconf_cb (GConf.Client gc, uint cxnid, GConf.Entry entry) {
+ // We silently assume, that this Value contains a bool, we should
+ // check it first
+ bool new_value = entry.get_value ().get_bool ();
+ stdout.printf ("Callback called with entry %s, new value: %s\n",
+ entry.get_key (), new_value.to_string ());
+ }
+}
+int main () {
+ var sample = new GConfSample ();
- // Getting a list of subdirectories in a directory
- // first, create a few more directories
- set_key(root+"/bar/baz"); set_key(root+"/baz/baz"); set_key(root+"/qux/baz");
- // You might also want to have a look at the GConf documentation:
- // http://library.gnome.org/devel/gconf/2.23/gconf-GConfClient.html#gconf-client-all-dirs
- // For a strange reason we have to define the type of the lists entries
- // ourselves.
- weak GLib.SList<string> dirlist = gc.all_dirs(root);
- stdout.printf("Dirlist has %u items\n", dirlist.length() );
- foreach (string dir in dirlist) {
- stdout.printf("Dir: %s\n", dir);
+ try {
+ sample.run ();
+ } catch (GLib.Error e) {
+ stderr.printf ("%s\n", e.message);
}
-
-
-
-
- // Now installing the callback function which gets called everytime
- // the key changes
- string listeningdir = "/apps/myapp/foo";
- //gc.add_dir(listeningdir, GConf.ClientPreloadType.ONELEVEL);
- stdout.printf("Listening on %s\n", listeningdir);
- string listeningkey = "/apps/myapp/foo/baz";
- //gc.notify_add(listeningkey, gconf_cb, null);
- stdout.printf("Having ourselves notified on %s\n", listeningkey);
-
- GLib.MainLoop main = new GLib.MainLoop(null,false);
- main.run();
- // You may now run gconf-editor and change the value for @listeningkey
- // Or comment main.run() to remove the key
-
-
- // This operation unsets values from keys. If a key is unset or a directory
- // doesn't have subkeys anymore, they get deleted. They might be visible
- // with gconf-editor until GConf has collected its garbage though.
- // There is just one valid flag in GConf.UnsetFlags according to
- // http://www.vala-project.org/doc/references/gconf-2.0.vapi/GConf/UnsetFlags.htm
- gc.recursive_unset("/apps/myapp", GConf.UnsetFlags.NAMES);
-
+
return 0;
-}
\ No newline at end of file
+}
diff --git a/tests/examples/gdl-sample.test b/tests/examples/gdl-sample.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gdl-sample.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gdl-sample.vala b/tests/examples/gdl-sample.vala
new file mode 100644
index 0000000..6306922
--- /dev/null
+++ b/tests/examples/gdl-sample.vala
@@ -0,0 +1,220 @@
+
+// http://live.gnome.org/Vala/GdlSample vala-test:examples/gdl-sample.vala
+
+using Gtk;
+using Gdl;
+
+class MainWindow : Window {
+
+ private DockMaster master;
+ private DockLayout layout;
+
+ private void save_layout_cb () {
+ var dialog = new Dialog.with_buttons ("New Layout", null,
+ DialogFlags.MODAL |
+ DialogFlags.DESTROY_WITH_PARENT,
+ STOCK_OK,
+ ResponseType.OK);
+
+ var hbox = new HBox (false, 8);
+ hbox.border_width = 8;
+ dialog.vbox.pack_start (hbox, false, false, 0);
+
+ var label = new Label ("Name:");
+ hbox.pack_start (label, false, false, 0);
+
+ var entry = new Entry ();
+ hbox.pack_start (entry, true, true, 0);
+
+ hbox.show_all ();
+ var response = dialog.run ();
+
+ if (response == ResponseType.OK) {
+ this.layout.save_layout (entry.text);
+ }
+ dialog.destroy ();
+ }
+
+ private void run_layout_manager_cb () {
+ this.layout.run_manager ();
+ }
+
+ private void button_dump_cb () {
+ try {
+ /* Dump XML tree. */
+ this.layout.save_to_file ("layout.xml");
+ Process.spawn_command_line_async ("cat layout.xml");
+ } catch (Error e) {
+ stderr.printf ("%s\n", e.message);
+ }
+ }
+
+ private RadioButton create_style_button (VBox box,
+ RadioButton? group,
+ SwitcherStyle style,
+ string style_text)
+ {
+ var button = new RadioButton.with_label_from_widget (group, style_text);
+ button.show ();
+ button.active = (this.master.switcher_style == style);
+ button.toggled.connect (() => {
+ if (button.active) {
+ this.master.switcher_style = style;
+ }
+ });
+ box.pack_start (button, false, false, 0);
+ return button;
+ }
+
+ private Widget create_styles_item (Dock dock) {
+ var vbox = new VBox (false, 0);
+ vbox.show ();
+
+ RadioButton group;
+ group = create_style_button (vbox, null, SwitcherStyle.ICON,
+ "Only icon");
+ group = create_style_button (vbox, group, SwitcherStyle.TEXT,
+ "Only text");
+ group = create_style_button (vbox, group, SwitcherStyle.BOTH,
+ "Both icons and texts");
+ group = create_style_button (vbox, group, SwitcherStyle.TOOLBAR,
+ "Desktop toolbar style");
+ group = create_style_button (vbox, group, SwitcherStyle.TABS,
+ "Notebook tabs");
+ return vbox;
+ }
+
+ private Widget create_item (string button_title) {
+ var vbox = new VBox (false, 0);
+ vbox.show ();
+
+ var button = new Button.with_label (button_title);
+ button.show ();
+ vbox.pack_start (button, true, true, 0);
+
+ return vbox;
+ }
+
+ /* creates a simple widget with a textbox inside */
+ private Widget create_text_item () {
+ var vbox = new VBox (false, 0);
+ vbox.show ();
+
+ var scroll = new ScrolledWindow (null, null);
+ scroll.show ();
+ vbox.pack_start (scroll, true, true, 0);
+ scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
+ scroll.shadow_type = ShadowType.ETCHED_IN;
+ var text = new TextView ();
+ text.wrap_mode = WrapMode.WORD;
+ text.show ();
+ scroll.add (text);
+
+ return vbox;
+ }
+
+ public MainWindow () {
+ this.destroy.connect (Gtk.main_quit);
+ this.title = "Docking widget test";
+ set_default_size (400, 400);
+
+ var table = new VBox (false, 5);
+ table.border_width = 10;
+ add (table);
+
+ /* create the dock */
+ var dock = new Dock ();
+ this.master = dock.master;
+
+ /* ... and the layout manager */
+ this.layout = new DockLayout (dock);
+
+ /* create the dockbar */
+ var dockbar = new DockBar (dock);
+ dockbar.set_style (DockBarStyle.TEXT);
+
+ var box = new HBox (false, 5);
+ table.pack_start (box, true, true, 0);
+
+ box.pack_start (dockbar, false, false, 0);
+ box.pack_end (dock, true, true, 0);
+
+ /* create the dock items */
+ var item1 = new DockItem ("item1", "Item #1", DockItemBehavior.LOCKED);
+ item1.add (create_text_item ());
+ dock.add_item (item1, DockPlacement.TOP);
+ item1.show ();
+
+ var item2 = new DockItem.with_stock ("item2",
+ "Item #2: Select the switcher style for notebooks",
+ Gtk.STOCK_EXECUTE, DockItemBehavior.NORMAL);
+ item2.resize = false;
+ item2.add (create_styles_item (dock));
+ dock.add_item (item2, DockPlacement.RIGHT);
+ item2.show ();
+
+ var item3 = new DockItem.with_stock ("item3",
+ "Item #3 has accented characters (áéÃóúñ)",
+ Gtk.STOCK_CONVERT,
+ DockItemBehavior.NORMAL | DockItemBehavior.CANT_CLOSE);
+ item3.add (create_item ("Button 3"));
+ dock.add_item (item3, DockPlacement.BOTTOM);
+ item3.show ();
+
+ var items = new DockItem[4];
+ items[0] = new DockItem.with_stock ("Item #4", "Item #4",
+ Gtk.STOCK_JUSTIFY_FILL,
+ DockItemBehavior.NORMAL |
+ DockItemBehavior.CANT_ICONIFY);
+ items[0].add (create_text_item ());
+ items[0].show ();
+ dock.add_item (items[0], DockPlacement.BOTTOM);
+ for (int i = 1; i < 3; i++) {
+ string name = "Item #%d".printf (i + 4);
+ items[i] = new DockItem.with_stock (name, name, Gtk.STOCK_NEW,
+ DockItemBehavior.NORMAL);
+ items[i].add (create_text_item ());
+ items[i].show ();
+
+ items[0].dock (items[i], DockPlacement.CENTER, null);
+ }
+
+ /* tests: manually dock and move around some of the items */
+ item3.dock_to (item1, DockPlacement.TOP, -1);
+
+ item2.dock_to (item3, DockPlacement.RIGHT, -1);
+
+ item2.dock_to (item3, DockPlacement.LEFT, -1);
+
+ item2.dock_to (null, DockPlacement.FLOATING, -1);
+
+ box = new HBox (true, 5);
+ table.pack_end (box, false, false, 0);
+
+ var button = new Button.from_stock (Gtk.STOCK_SAVE);
+ button.clicked.connect (this.save_layout_cb);
+ box.pack_end (button, false, true, 0);
+
+ button = new Button.with_label ("Layout Manager");
+ button.clicked.connect (this.run_layout_manager_cb);
+ box.pack_end (button, false, true, 0);
+
+ button = new Button.with_label ("Dump XML");
+ button.clicked.connect (this.button_dump_cb);
+ box.pack_end (button, false, true, 0);
+
+ new DockPlaceholder ("ph1", dock, DockPlacement.TOP, false);
+ new DockPlaceholder ("ph2", dock, DockPlacement.BOTTOM, false);
+ new DockPlaceholder ("ph3", dock, DockPlacement.LEFT, false);
+ new DockPlaceholder ("ph4", dock, DockPlacement.RIGHT, false);
+ }
+}
+
+void main (string[] args) {
+ Gtk.init (ref args);
+
+ var win = new MainWindow ();
+ win.show_all ();
+
+ Gtk.main ();
+}
diff --git a/tests/examples/gee-iterable.test b/tests/examples/gee-iterable.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gee-iterable.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gee-iterable.vala b/tests/examples/gee-iterable.vala
new file mode 100644
index 0000000..0e1ee2a
--- /dev/null
+++ b/tests/examples/gee-iterable.vala
@@ -0,0 +1,72 @@
+
+// http://live.gnome.org/Vala/GeeSamples vala-test:examples/gee-iterable.vala
+
+using Gee;
+
+private class RangeIterator : Object, Iterator<int> {
+
+ private Range range;
+ private int current;
+
+ public RangeIterator (Range range) {
+ this.range = range;
+ this.current = range.from - 1;
+ }
+
+ public bool next () {
+ if (!has_next ()) {
+ return false;
+ }
+ this.current++;
+ return true;
+ }
+
+ public bool has_next () {
+ return this.current < this.range.to;
+ }
+
+ public bool first () {
+ this.current = range.from;
+ return true;
+ }
+
+ /* Here the 'new' keyword is used because Object already
+ has a 'get' method. This will hide the original method.
+ Otherwise you'll get a warning. */
+ public new int get () {
+ return this.current;
+ }
+
+ public void remove () {
+ assert_not_reached ();
+ }
+}
+
+public class Range : Object, Iterable<int> {
+
+ public int from { get; private set; }
+ public int to { get; private set; }
+
+ public Range (int from, int to) {
+ assert (from < to);
+ this.from = from;
+ this.to = to;
+ }
+
+ public Type element_type {
+ get { return typeof (int); }
+ }
+
+ public Iterator<int> iterator () {
+ return new RangeIterator (this);
+ }
+}
+
+static int main (string[] args) {
+
+ foreach (int i in new Range (10, 20)) {
+ stdout.printf ("%d\n", i);
+ }
+
+ return 0;
+}
diff --git a/tests/examples/gee-list.test b/tests/examples/gee-list.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gee-list.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gee-list.vala b/tests/examples/gee-list.vala
new file mode 100644
index 0000000..92847b7
--- /dev/null
+++ b/tests/examples/gee-list.vala
@@ -0,0 +1,22 @@
+
+// http://live.gnome.org/Vala/GeeSamples vala-test:examples/gee-list.vala
+
+using Gee;
+
+static int main (string[] args) {
+
+ var list = new ArrayList<int> ();
+ list.add (1);
+ list.add (2);
+ list.add (5);
+ list.add (4);
+ list.insert (2, 3);
+ list.remove_at (3);
+ foreach (int i in list) {
+ stdout.printf ("%d\n", i);
+ }
+ list[2] = 10; // same as list.set (2, 10)
+ stdout.printf ("%d\n", list[2]); // same as list.get (2)
+
+ return 0;
+}
diff --git a/tests/examples/gee-map.test b/tests/examples/gee-map.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gee-map.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gee-map.vala b/tests/examples/gee-map.vala
new file mode 100644
index 0000000..e218244
--- /dev/null
+++ b/tests/examples/gee-map.vala
@@ -0,0 +1,19 @@
+
+// http://live.gnome.org/Vala/GeeSamples vala-test:examples/gee-map.vala
+
+using Gee;
+
+static int main (string[] args) {
+
+ var map = new HashMap<string, int> ();
+ map.set ("one", 1);
+ map.set ("two", 2);
+ map.set ("three", 3);
+ map["four"] = 4; // same as map.set ("four", 4)
+ map["five"] = 5;
+ foreach (string key in map.keys) {
+ stdout.printf ("%d\n", map[key]); // same as map.get (key)
+ }
+
+ return 0;
+}
diff --git a/tests/examples/gee-set.test b/tests/examples/gee-set.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gee-set.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gee-set.vala b/tests/examples/gee-set.vala
new file mode 100644
index 0000000..d3a51cc
--- /dev/null
+++ b/tests/examples/gee-set.vala
@@ -0,0 +1,18 @@
+
+// http://live.gnome.org/Vala/GeeSamples vala-test:examples/gee-set.vala
+
+using Gee;
+
+static int main (string[] args) {
+
+ var my_set = new HashSet<string> ();
+ my_set.add ("one");
+ my_set.add ("two");
+ my_set.add ("three");
+ my_set.add ("two"); // will not be added because it's a duplicate
+ foreach (string s in my_set) {
+ stdout.printf ("%s\n", s);
+ }
+
+ return 0;
+}
diff --git a/tests/examples/gio-async-reading.test b/tests/examples/gio-async-reading.test
new file mode 100755
index 0000000..be38952
--- /dev/null
+++ b/tests/examples/gio-async-reading.test
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+TESTARGS="$0"
+. common.sh
diff --git a/tests/examples/gio-async-reading.vala b/tests/examples/gio-async-reading.vala
new file mode 100644
index 0000000..1d9b908
--- /dev/null
+++ b/tests/examples/gio-async-reading.vala
@@ -0,0 +1,69 @@
+
+// http://live.gnome.org/Vala/GIOSamples vala-test:examples/gio-async-reading.vala
+
+// Async stream reading with GIO in Vala sample code for async syntax
+// This example will need recent version of vala from git (after 14. September 2009)
+
+public class AsyncReadLineTest: Object {
+ public static GLib.MainLoop main_loop;
+ private DataInputStream di_stream;
+ private string adress;
+ private string sourcetext = "";
+
+ private signal void reading_finished();
+
+ public AsyncReadLineTest(string adress = "http://www.gnome.org") {
+ this.adress = adress;
+ File f = File.new_for_uri(adress);
+ try {
+ di_stream = new DataInputStream(f.read(null));
+ } catch (GLib.Error e) {
+ print("Error 01!\n");
+ }
+ reading_finished.connect(on_reading_finished);
+ }
+
+ private async void read_something_async() {
+ print("start...\n\n");
+ size_t a;
+ string buf = null;
+
+ try {
+ do {
+ buf = yield di_stream.read_line_async(GLib.Priority.DEFAULT, null, out a);
+ sourcetext = sourcetext + buf;
+ } while (buf!=null);
+ }
+ catch(GLib.Error e) {
+ print("%s\n", e.message);
+ }
+ print("\nREADY\n");
+ reading_finished(); // signal finish
+ return;
+ }
+
+ private void on_reading_finished() {
+ print("sourcetext: \n%s\n", sourcetext);
+ main_loop.quit();
+ }
+
+ public static int main(string[] args) {
+ main_loop = new MainLoop(null, false);
+
+ AsyncReadLineTest async_test;
+ if(args[1]!=null) {
+ File f = File.new_for_commandline_arg(args[1]);
+
+ if(f.query_exists(null))
+ async_test = new AsyncReadLineTest( f.get_uri());
+ else
+ async_test = new AsyncReadLineTest();
+ }
+ else {
+ async_test = new AsyncReadLineTest();
+ }
+ async_test.read_something_async();
+ main_loop.run();
+ return 0;
+ }
+}
diff --git a/tests/examples/gio-async.test b/tests/examples/gio-async.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gio-async.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gio-async.vala b/tests/examples/gio-async.vala
new file mode 100644
index 0000000..9151617
--- /dev/null
+++ b/tests/examples/gio-async.vala
@@ -0,0 +1,70 @@
+
+// http://live.gnome.org/Vala/GIOSamples vala-test:examples/gio-async.vala
+
+using Gtk;
+
+/**
+ * Loads the list of files in user's home directory and displays them
+ * in a GTK+ list view.
+ */
+public class ASyncGIOSample : Window {
+
+ private ListStore model;
+
+ public ASyncGIOSample () {
+
+ // Set up the window
+ set_default_size (300, 200);
+ this.destroy.connect (Gtk.main_quit);
+
+ // Set up the list widget and its model
+ this.model = new ListStore (1, typeof (string));
+ var list = new TreeView.with_model (this.model);
+ list.insert_column_with_attributes (-1, "Filename",
+ new CellRendererText (), "text", 0);
+
+ // Put list widget into a scrollable area and add it to the window
+ var scroll = new ScrolledWindow (null, null);
+ scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
+ scroll.add (list);
+ add (scroll);
+
+ // start file listing process
+ list_directory.begin ();
+ }
+
+ private async void list_directory () {
+ stdout.printf ("Start scanning home directory\n");
+ var dir = File.new_for_path (Environment.get_home_dir ());
+ try {
+ // asynchronous call, to get directory entries
+ var e = yield dir.enumerate_children_async (FILE_ATTRIBUTE_STANDARD_NAME,
+ 0, Priority.DEFAULT, null);
+ while (true) {
+ // asynchronous call, to get entries so far
+ var files = yield e.next_files_async (10, Priority.DEFAULT, null);
+ if (files == null) {
+ break;
+ }
+ // append the files found so far to the list
+ foreach (var info in files) {
+ TreeIter iter;
+ this.model.append (out iter);
+ this.model.set (iter, 0, info.get_name ());
+ }
+ }
+ } catch (Error err) {
+ stderr.printf ("Error: list_files failed: %s\n", err.message);
+ }
+ }
+
+ static int main (string[] args) {
+ Gtk.init (ref args);
+
+ var demo = new ASyncGIOSample ();
+ demo.show_all ();
+
+ Gtk.main ();
+ return 0;
+ }
+}
diff --git a/tests/examples/gio-binary-sample.test b/tests/examples/gio-binary-sample.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gio-binary-sample.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gio-binary-sample.vala b/tests/examples/gio-binary-sample.vala
new file mode 100644
index 0000000..be308bd
--- /dev/null
+++ b/tests/examples/gio-binary-sample.vala
@@ -0,0 +1,48 @@
+
+// http://live.gnome.org/Vala/GIOSamples vala-test:examples/gio-binary-sample.vala
+
+static int main (string[] args) {
+ try {
+
+ // Reference a BMP image file
+ var file = File.new_for_uri ("http://wvnvaxa.wvnet.edu/vmswww/images/test8.bmp");
+// var file = File.new_for_path ("sample.bmp");
+
+ // Open file for reading
+ var file_stream = file.read (null);
+ var data_stream = new DataInputStream (file_stream);
+ data_stream.set_byte_order (DataStreamByteOrder.LITTLE_ENDIAN);
+
+ // Read the signature
+ uint16 signature = data_stream.read_uint16 (null);
+ if (signature != 0x4d42) { // this hex code means "BM"
+ stderr.printf ("Error: %s is not a valid BMP file\n", file.get_basename ());
+ return 1;
+ }
+
+ data_stream.skip (8, null); // skip uninteresting data fields
+ uint32 image_data_offset = data_stream.read_uint32 (null);
+
+ data_stream.skip (4, null);
+ uint32 width = data_stream.read_uint32 (null);
+ uint32 height = data_stream.read_uint32 (null);
+
+ data_stream.skip (8, null);
+ uint32 image_data_size = data_stream.read_uint32 (null);
+
+ // Seek and read the image data chunk
+ uint8[] buffer = new uint8[image_data_size];
+ file_stream.seek (image_data_offset, SeekType.CUR, null);
+ data_stream.read (buffer, image_data_size, null);
+
+ // Show information
+ stdout.printf ("Width: %ld px\n", width);
+ stdout.printf ("Height: %ld px\n", height);
+ stdout.printf ("Image data size: %ld bytes\n", image_data_size);
+
+ } catch (Error e) {
+ stderr.printf ("Error: %s\n", e.message);
+ return 1;
+ }
+ return 0;
+}
diff --git a/tests/examples/gio-channel.test b/tests/examples/gio-channel.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gio-channel.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gio-channel.vala b/tests/examples/gio-channel.vala
new file mode 100644
index 0000000..1f47eee
--- /dev/null
+++ b/tests/examples/gio-channel.vala
@@ -0,0 +1,97 @@
+
+// http://live.gnome.org/Vala/IoChannelsSample vala-test:examples/gio-channel.vala
+
+public class PipeTalker : Object {
+
+ // reading callback
+ private bool gio_in(IOChannel gio, IOCondition condition) {
+ IOStatus ret;
+ string msg;
+ size_t len;
+
+ if((condition & IOCondition.HUP) == IOCondition.HUP)
+ print("Read end of pipe died!\n");
+
+ try {
+ ret = gio.read_line(out msg, out len, null);
+ }
+ catch(IOChannelError e) {
+ print("Error reading: %s\n", e.message);
+ }
+ catch(ConvertError e) {
+ print("Error reading: %s\n", e.message);
+ }
+
+ print("Read %u bytes: %s\n", (uint)len, msg);
+
+ return true;
+ }
+
+ // writing callback
+ private bool gio_out(IOChannel gio, IOCondition condition) {
+ string msg = "The price of greatness is responsibility.\n";
+ IOStatus ret;
+ size_t len;
+
+ if((condition & IOCondition.HUP) == IOCondition.HUP)
+ print("Write end of pipe died!\n");
+
+ try {
+ ret = gio.write_chars((char[])msg, out len);
+ }
+ catch(IOChannelError e) {
+ print("Error writing: %s\n", e.message);
+ }
+ catch(ConvertError e) {
+ print("Error writing: %s\n", e.message);
+ }
+
+ print("Wrote %u bytes.\n", (uint)len);
+
+ return true;
+ }
+
+ public void init_channels() {
+ IOChannel io_read, io_write;
+ int[] fd = new int[2]; // file descriptor
+ int ret;
+
+ // setup a pipe
+ ret = Posix.pipe(fd);
+ if(ret == -1) {
+ print("Creating pipe failed: %s\n", strerror(errno));
+ return;
+ }
+
+ // setup iochannels
+ io_read = new IOChannel.unix_new(fd[0]);
+ io_write = new IOChannel.unix_new(fd[1]);
+
+ if((io_read == null) || (io_write == null)) {
+ print("Cannot create new IOChannel!\n");
+ return;
+ }
+
+ // The watch calls the gio_in function, if there data is available for
+ // reading without locking
+ if(!(io_read.add_watch(IOCondition.IN | IOCondition.HUP, gio_in) != 0)) {
+ print("Cannot add watch on IOChannel!\n");
+ return;
+ }
+
+ // The watch calls the gio_out function if there data is available for
+ // writing without locking
+ if(!(io_write.add_watch(IOCondition.OUT | IOCondition.HUP, gio_out) != 0)) {
+ print("Cannot add watch on IOChannel!\n");
+ return;
+ }
+ }
+
+ public static int main() {
+ var loop = new MainLoop(null, false);
+ var pt = new PipeTalker();
+ pt.init_channels();
+ loop.run();
+ return 0;
+ }
+}
diff --git a/tests/examples/gio-file-operations.test b/tests/examples/gio-file-operations.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gio-file-operations.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gio-file-operations.vala b/tests/examples/gio-file-operations.vala
new file mode 100644
index 0000000..2b0a052
--- /dev/null
+++ b/tests/examples/gio-file-operations.vala
@@ -0,0 +1,49 @@
+
+// http://live.gnome.org/Vala/GIOSamples vala-test:examples/gio-file-operations.vala
+
+static int main (string[] args) {
+ try {
+
+ // Reference a local file name
+ var file = File.new_for_path ("samplefile.txt");
+
+ {
+ // Create a new file with this name
+ var file_stream = file.create (FileCreateFlags.NONE, null);
+
+ // Test for the existence of file
+ if (file.query_exists (null)) {
+ stdout.printf ("File successfully created.\n");
+ }
+
+ // Write text data to file
+ var data_stream = new DataOutputStream (file_stream);
+ data_stream.put_string ("Hello, world", null);
+ }
+
+ // Determine the size of file as well as other attributes
+ var file_info = file.query_info ("*", FileQueryInfoFlags.NONE, null);
+ stdout.printf ("File size: %lld bytes\n", file_info.get_size ());
+ stdout.printf ("Content type: %s\n", file_info.get_content_type ());
+
+ // Make a copy of file
+ var destination = File.new_for_path ("samplefile.bak");
+ file.copy (destination, FileCopyFlags.NONE, null, null);
+
+ // Delete copy
+ destination.delete (null);
+
+ // Rename file
+ var renamed = file.set_display_name ("samplefile.data", null);
+
+ // Move file to trash
+ renamed.trash (null);
+
+ stdout.printf ("Everything cleaned up.\n");
+
+ } catch (Error e) {
+ stderr.printf ("Error: %s\n", e.message);
+ return 1;
+ }
+ return 0;
+}
diff --git a/tests/examples/gio-ls.test b/tests/examples/gio-ls.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gio-ls.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gio-ls.vala b/tests/examples/gio-ls.vala
new file mode 100644
index 0000000..43a47b1
--- /dev/null
+++ b/tests/examples/gio-ls.vala
@@ -0,0 +1,25 @@
+
+// http://live.gnome.org/Vala/GIOSamples vala-test:examples/gio-ls.vala
+
+int main (string[] args) {
+ try {
+ var directory = File.new_for_path (".");
+
+ if (args.length > 1) {
+ directory = File.new_for_commandline_arg (args[1]);
+ }
+
+ var enumerator = directory.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
+
+ FileInfo file_info;
+ while ((file_info = enumerator.next_file (null)) != null) {
+ stdout.printf ("%s\n", file_info.get_name ());
+ }
+
+ } catch (Error e) {
+ stderr.printf ("Error: %s\n", e.message);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/examples/gio-network-client-async.test b/tests/examples/gio-network-client-async.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gio-network-client-async.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gio-network-client-async.vala b/tests/examples/gio-network-client-async.vala
new file mode 100644
index 0000000..3b5c87c
--- /dev/null
+++ b/tests/examples/gio-network-client-async.vala
@@ -0,0 +1,48 @@
+
+// http://live.gnome.org/Vala/GIONetworkingSample vala-test:examples/gio-network-client-async.vala
+
+class AsyncDemo {
+
+ private MainLoop loop;
+
+ public AsyncDemo (MainLoop loop) {
+ this.loop = loop;
+ }
+
+ public async void http_request () throws Error {
+ try {
+ var resolver = Resolver.get_default ();
+ var addresses = yield resolver.lookup_by_name_async ("www.google.com", null);
+ var address = addresses.nth_data (0);
+ print ("(async) resolved www.google.com to %s\n", address.to_string ());
+
+ var socket_address = new InetSocketAddress (address, 80);
+ var client = new SocketClient ();
+ var conn = yield client.connect_async (socket_address, null);
+ print ("(async) connected to www.google.com\n");
+
+ var message = "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n";
+ yield conn.output_stream.write_async (message, message.size (), 1, null);
+ print ("(async) wrote request\n");
+
+ // we set the socket back to blocking here for the convenience
+ // of DataInputStream
+ conn.socket.set_blocking (true);
+
+ var input = new DataInputStream (conn.input_stream);
+ message = input.read_line (null, null).strip ();
+ print ("(async) received status line: %s\n", message);
+ } catch (Error e) {
+ stderr.printf ("%s\n", e.message);
+ }
+
+ this.loop.quit ();
+ }
+}
+
+void main () {
+ var loop = new MainLoop (null, false);
+ var demo = new AsyncDemo (loop);
+ demo.http_request.begin ();
+ loop.run ();
+}
diff --git a/tests/examples/gio-network-client.test b/tests/examples/gio-network-client.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gio-network-client.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gio-network-client.vala b/tests/examples/gio-network-client.vala
new file mode 100644
index 0000000..b0427e2
--- /dev/null
+++ b/tests/examples/gio-network-client.vala
@@ -0,0 +1,30 @@
+
+// http://live.gnome.org/Vala/GIONetworkingSample vala-test:examples/gio-network-client.vala
+
+void main () {
+ try {
+ // Resolve hostname to IP address
+ var resolver = Resolver.get_default ();
+ var addresses = resolver.lookup_by_name ("www.google.com", null);
+ var address = addresses.nth_data (0);
+ print ("(sync) resolved www.google.com to %s\n", address.to_string ());
+
+ // Connect
+ var client = new SocketClient ();
+ var conn = client.connect (new InetSocketAddress (address, 80), null);
+ print ("(sync) connected to www.google.com\n");
+
+ // Send HTTP GET request
+ string message = "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n";
+ conn.output_stream.write (message, message.size (), null);
+ print ("(sync) wrote request\n");
+
+ // Receive response
+ var input = new DataInputStream (conn.input_stream);
+ message = input.read_line (null, null).strip ();
+ print ("(sync) received status line: %s\n", message);
+
+ } catch (Error e) {
+ stderr.printf ("%s\n", e.message);
+ }
+}
diff --git a/tests/examples/gio-sample.test b/tests/examples/gio-sample.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gio-sample.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gio-sample.vala b/tests/examples/gio-sample.vala
new file mode 100644
index 0000000..785069f
--- /dev/null
+++ b/tests/examples/gio-sample.vala
@@ -0,0 +1,27 @@
+
+// http://live.gnome.org/Vala/GIOSamples vala-test:examples/gio-sample.vala
+
+static int main (string[] args) {
+ // A reference to our file
+ var file = File.new_for_path ("data.txt");
+
+ if (!file.query_exists (null)) {
+ stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
+ return 1;
+ }
+
+ try {
+ // Open file for reading and wrap returned FileInputStream into a
+ // DataInputStream, so we can read line by line
+ var in_stream = new DataInputStream (file.read (null));
+ string line;
+ // Read lines until end of file (null) is reached
+ while ((line = in_stream.read_line (null, null)) != null) {
+ stdout.printf ("%s\n", line);
+ }
+ } catch (Error e) {
+ error ("%s", e.message);
+ }
+
+ return 0;
+}
diff --git a/tests/examples/gio-server.test b/tests/examples/gio-server.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gio-server.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gio-server.vala b/tests/examples/gio-server.vala
new file mode 100644
index 0000000..a0fd9cb
--- /dev/null
+++ b/tests/examples/gio-server.vala
@@ -0,0 +1,36 @@
+
+// http://live.gnome.org/Vala/GIONetworkingSample vala-test:examples/gio-server.vala
+
+void process_request (InputStream input, OutputStream output) throws Error {
+ var data_in = new DataInputStream (input);
+ string line;
+ while ((line = data_in.read_line (null, null)) != null) {
+ stdout.printf ("%s\n", line);
+ if (line.strip () == "") break;
+ }
+
+ string content = "<html><h1>Hello from Vala server</h1></html>";
+ var header = new StringBuilder ();
+ header.append ("HTTP/1.0 200 OK\r\n");
+ header.append ("Content-Type: text/html\r\n");
+ header.append_printf ("Content-Length: %lu\r\n\r\n", content.size ());
+
+ output.write (header.str, header.len, null);
+ output.write (content, content.size (), null);
+ output.flush (null);
+}
+
+int main () {
+ try {
+ var service = new SocketService ();
+ service.add_inet_port (8080, null);
+ service.start ();
+ while (true) {
+ var conn = service.accept (null, null);
+ process_request (conn.input_stream, conn.output_stream);
+ }
+ } catch (Error e) {
+ stderr.printf ("%s\n", e.message);
+ }
+ return 0;
+}
diff --git a/tests/examples/gnome-desktop-and-menu.test b/tests/examples/gnome-desktop-and-menu.test
index 784d34d..0174331 100755
--- a/tests/examples/gnome-desktop-and-menu.test
+++ b/tests/examples/gnome-desktop-and-menu.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gnome-desktop-2.0 --pkg libgnome-menu -o $TESTNAME $SRCDIR/$TESTNAME.vala -X "-DGMENU_I_KNOW_THIS_IS_UNSTABLE" $VALAFLAGS
-
-if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/gnome-desktop-and-menu.vala b/tests/examples/gnome-desktop-and-menu.vala
index 7dcf333..a86d179 100644
--- a/tests/examples/gnome-desktop-and-menu.vala
+++ b/tests/examples/gnome-desktop-and-menu.vala
@@ -1,79 +1,75 @@
-/* GnomeDesktop and GMenu in Vala sample code */
-using GLib;
+// http://live.gnome.org/Vala/GnomeDesktopAndGMenuExample vala-test:examples/gnome-desktop-and-menu.vala
-public class GnomeDesktopAndGMenuExample : GLib.Object {
+public class GMenuExample {
- private List<GMenu.TreeDirectory> getMainDirectories () {
+ public List<GMenu.TreeDirectory> get_main_directories () {
var tree = GMenu.Tree.lookup ("applications.menu", GMenu.TreeFlags.INCLUDE_EXCLUDED);
var root = tree.get_root_directory ();
- var mainDirectoryEntries = new List<GMenu.TreeDirectory> ();
+ var dirs = new List<GMenu.TreeDirectory> ();
- foreach (GMenu.TreeItem item in root.get_contents()) {
- if (item.get_type() == GMenu.TreeItemType.DIRECTORY) {
- mainDirectoryEntries.append((GMenu.TreeDirectory) item);
+ foreach (GMenu.TreeItem item in root.get_contents ()) {
+ if (item.get_type () == GMenu.TreeItemType.DIRECTORY) {
+ dirs.append ((GMenu.TreeDirectory) item);
}
}
- return mainDirectoryEntries;
+ return dirs;
}
- private List<GMenu.TreeEntry> getEntriesFlat (GMenu.TreeDirectory directory ) {
+ public List<GMenu.TreeEntry> get_entries_flat (GMenu.TreeDirectory directory) {
var entries = new List<GMenu.TreeEntry> ();
foreach (GMenu.TreeItem item in directory.get_contents ()) {
switch (item.get_type ()) {
- case GMenu.TreeItemType.DIRECTORY:
- entries.concat (getEntriesFlat ((GMenu.TreeDirectory) item));
- break;
- case GMenu.TreeItemType.ENTRY:
- entries.append ((GMenu.TreeEntry) item);
- break;
+ case GMenu.TreeItemType.DIRECTORY:
+ entries.concat (get_entries_flat ((GMenu.TreeDirectory) item));
+ break;
+ case GMenu.TreeItemType.ENTRY:
+ entries.append ((GMenu.TreeEntry) item);
+ break;
}
}
return entries;
}
- private Gnome.DesktopItem getDesktopItemForMenuEntry (GMenu.TreeEntry entry) throws GLib.Error {
- return new Gnome.DesktopItem.from_file (entry.get_desktop_file_path (), Gnome.DesktopItemLoadFlags.ONLY_IF_EXISTS);
+ public DesktopAppInfo get_desktop_app_info (GMenu.TreeEntry entry) {
+ return new DesktopAppInfo.from_filename (entry.get_desktop_file_path ());
}
- private void launch (Gnome.DesktopItem item) {
+ /* Launch an application described in DesktopAppInfo */
+ public void launch_desktop_app_info (DesktopAppInfo info) {
try {
- item.launch (new List<string> (), Gnome.DesktopItemLaunchFlags.ONLY_ONE);
+ info.launch (null, new AppLaunchContext ());
} catch (Error error) {
stdout.printf ("Error: %s\n", error.message);
}
}
+}
- static int main (string[] args) {
- GnomeVFS.init ();
- var desktopAndMenu = new GnomeDesktopAndGMenuExample ();
+static int main (string[] args) {
+ var sample = new GMenuExample ();
- stdout.printf ("\nGet all main directories:\n");
- var directories = desktopAndMenu.getMainDirectories ();
- foreach (GMenu.TreeDirectory directory in directories) {
- stdout.printf ("%s\n", directory.get_name ());
- }
+ stdout.printf ("\nGet all main directories:\n");
+ var directories = sample.get_main_directories ();
+ foreach (var directory in directories) {
+ stdout.printf ("%s\n", directory.get_name ());
+ }
- stdout.printf ("\nGet all entries/directories for the first directory:\n");
- var entries = desktopAndMenu.getEntriesFlat (directories.nth_data(0));
- foreach (GMenu.TreeEntry entry in entries) {
- stdout.printf ("%s\n", entry.get_name ());
- }
+ stdout.printf ("\nGet all entries/directories for the first directory:\n");
+ var entries = sample.get_entries_flat (directories.nth_data (0));
+ foreach (var entry in entries) {
+ stdout.printf ("%s\n", entry.get_name ());
+ }
- stdout.printf ("\nGet desktop item for first menu entry and display Name, Generic name, Description and Icon name:\n");
- try {
- var item = desktopAndMenu.getDesktopItemForMenuEntry (entries.nth_data (0));
- stdout.printf ("Name: %s\n", item.get_string(Gnome.DESKTOP_ITEM_NAME));
- stdout.printf ("GenericName: %s\n", item.get_string(Gnome.DESKTOP_ITEM_GENERIC_NAME));
- stdout.printf ("Comment: %s\n", item.get_string(Gnome.DESKTOP_ITEM_COMMENT));
- stdout.printf ("Exec: %s\n", item.get_string(Gnome.DESKTOP_ITEM_EXEC));
- stdout.printf ("Icon: %s\n", item.get_string(Gnome.DESKTOP_ITEM_ICON));
- } catch (GLib.Error e) {
- stdout.printf ("Failed to get desktop iten.");
- }
+ stdout.printf ("\nGet desktop item for first menu entry via GIO and display\n");
+ stdout.printf ("name, description and icon name:\n");
+
+ var app_info = sample.get_desktop_app_info (entries.nth_data (0));
+ stdout.printf ("Name: %s\n", app_info.get_name ());
+ stdout.printf ("Comment: %s\n", app_info.get_description ());
+ stdout.printf ("Exec: %s\n", app_info.get_commandline ());
+ stdout.printf ("Icon: %s\n", app_info.get_icon ().to_string ());
- return 0;
- }
-}
\ No newline at end of file
+ return 0;
+}
diff --git a/tests/examples/gsl-combination.test b/tests/examples/gsl-combination.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-combination.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-combination.vala b/tests/examples/gsl-combination.vala
new file mode 100644
index 0000000..7e7245c
--- /dev/null
+++ b/tests/examples/gsl-combination.vala
@@ -0,0 +1,26 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-combination.vala
+
+using GLib;
+using Gsl;
+
+public class Test : GLib.Object
+{
+ public static void main (string[] args)
+ {
+ Combination c;
+ size_t i;
+
+ stdout.printf("All subsets of {0,1,2,3} by size:\n");
+ for (i=0; i<=4; i++)
+ {
+ c = new Combination.with_zeros (4, i);
+ do
+ {
+ stdout.printf ("{");
+ Combination.fprintf (stdout, c, " %u");
+ stdout.printf (" }\n");
+ } while (c.next() == Status.SUCCESS);
+ }
+ }
+}
diff --git a/tests/examples/gsl-eigen-system.test b/tests/examples/gsl-eigen-system.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-eigen-system.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-eigen-system.vala b/tests/examples/gsl-eigen-system.vala
new file mode 100644
index 0000000..7eb81ee
--- /dev/null
+++ b/tests/examples/gsl-eigen-system.vala
@@ -0,0 +1,37 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-eigen-system.vala
+
+using GLib;
+using Gsl;
+
+public class Test : GLib.Object
+{
+ public static void main (string[] args)
+ {
+ double[] data = new double[] { 1.0 , 1/2.0, 1/3.0, 1/4.0,
+ 1/2.0, 1/3.0, 1/4.0, 1/5.0,
+ 1/3.0, 1/4.0, 1/5.0, 1/6.0,
+ 1/4.0, 1/5.0, 1/6.0, 1/7.0 };
+
+ MatrixView m = MatrixView.array (data, 4, 4);
+
+ Vector eval = new Vector (4);
+ Matrix evec = new Matrix (4, 4);
+
+ EigenSymmvWorkspace w = new EigenSymmvWorkspace (4);
+
+ w.init ((Matrix)(&m.matrix), eval, evec);
+
+ EigenSort.symmv_sort (eval, evec, EigenSortType.ABS_ASC);
+
+ for (int i=0; i<4; i++)
+ {
+ double eval_i = eval.get (i);
+ VectorView evec_i = evec.column (i);
+
+ stdout.printf("eigenvalue = %g\n", eval_i);
+ stdout.printf("eigenvector = \n");
+ Vector.fprintf(stdout, (Vector)(&evec_i.vector), "%g");
+ }
+ }
+}
diff --git a/tests/examples/gsl-function.test b/tests/examples/gsl-function.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-function.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-function.vala b/tests/examples/gsl-function.vala
new file mode 100644
index 0000000..329e778
--- /dev/null
+++ b/tests/examples/gsl-function.vala
@@ -0,0 +1,21 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-function.vala
+
+using GLib;
+using Gsl;
+
+public class Test : GLib.Object
+{
+ public static void main (string[] args)
+ {
+ double x = 5.0;
+ Result res;
+
+ double expected = -0.17759677131433830434739701;
+
+ Bessel.J0_e (x, out res);
+
+ stdout.printf("J0(5.0) = %.18f\n+/- %.18f\n", res.val, res.err);
+ stdout.printf("exact = %.18f\n", expected);
+ }
+}
diff --git a/tests/examples/gsl-integration.test b/tests/examples/gsl-integration.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-integration.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-integration.vala b/tests/examples/gsl-integration.vala
new file mode 100644
index 0000000..412c14d
--- /dev/null
+++ b/tests/examples/gsl-integration.vala
@@ -0,0 +1,35 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-integration.vala
+
+using GLib;
+using Gsl;
+
+public class IntegrationSample : GLib.Object
+{
+ public static double f (double x, double* params)
+ {
+ double alpha = *params;
+ double f = Math.log (alpha*x) / Math.sqrt(x);
+ return f;
+ }
+
+ public static void main (string[] args)
+ {
+ IntegrationWorkspace w = new IntegrationWorkspace (1000);
+
+ double integration_result, error;
+
+ double expected = -4.0;
+ double alpha = 1.0;
+
+ Function F = Function () { function = f, params = &alpha };
+
+ Integration.qags (&F, 0, 1, 0, 1e-7, 1000, w, out integration_result, out error);
+ stdout.printf ("result = %.18f\n", integration_result);
+ stdout.printf ("exact result = %.18f\n", expected);
+ stdout.printf ("extimated error = %.18f\n", error);
+ stdout.printf ("actual error = %.18f\n", integration_result - expected);
+ stdout.printf ("intervals = %i\n", (int)w.size);
+
+ }
+}
diff --git a/tests/examples/gsl-least-squares-fitting.test b/tests/examples/gsl-least-squares-fitting.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-least-squares-fitting.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-least-squares-fitting.vala b/tests/examples/gsl-least-squares-fitting.vala
new file mode 100644
index 0000000..cdf9f0e
--- /dev/null
+++ b/tests/examples/gsl-least-squares-fitting.vala
@@ -0,0 +1,130 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-least-squares-fitting.vala
+
+using GLib;
+using Gsl;
+
+public class FitSample
+{
+ struct Data
+ {
+ public size_t n;
+ public double* y;
+ public double* sigma;
+ }
+
+ static int expb_f (Vector x, void* data, Vector f)
+ {
+ size_t n = ((Data*)data)->n;
+ double* y = ((Data*)data)->y;
+ double* sigma = ((Data*)data)->sigma;
+ double A = x.get (0);
+ double lambda = x.get (1);
+ double b = x.get (2);
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ /* Model Yi = A * exp(-lambda * i) + b */
+ double t = i;
+ double Yi = A * Math.exp (-lambda * t) + b;
+ f.set (i, (Yi - y[i])/sigma[i]);
+ }
+ return Status.SUCCESS;
+ }
+
+ static int expb_df (Vector x, void* data, Matrix J)
+ {
+ size_t n = ((Data*)data)->n;
+ double* sigma = ((Data*)data)->sigma;
+ double A = x.get (0);
+ double lambda = x.get (1);
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ {
+ /* Jacobian matrix J(i,j) = dfi / dxj, */
+ /* where fi = (Yi - yi)/sigma[i], */
+ /* Yi = A * exp(-lambda * i) + b */
+ /* and the xj are the parameters (A,lambda,b) */
+ double t = i;
+ double s = sigma[i];
+ double e = Math.exp(-lambda * t);
+ J.set (i, 0, e/s);
+ J.set (i, 1, -t * A * e/s);
+ J.set (i, 2, 1/s);
+ }
+ return Status.SUCCESS;
+ }
+
+ static int expb_fdf (Vector x, void* data, Vector f, Matrix J)
+ {
+ expb_f (x, data, f);
+ expb_df (x, data, J);
+ return Status.SUCCESS;
+ }
+
+ static void print_state (size_t iter, MultifitFdfsolver s)
+ {
+ stdout.printf ("iter: %3u x = % 15.8f % 15.8f % 15.8f\n", (uint)iter, s.x.get (0), s.x.get (1), s.x.get (2));
+ }
+
+ public static void main (string[] args)
+ {
+ MultifitFdfsolverType* T;
+ MultifitFdfsolver s;
+ int status = 0;
+ uint i, iter = 0;
+ size_t n = 40;
+ size_t p = 3;
+
+ Matrix covar = new Matrix (p, p);
+ double[] y = new double[40];
+ double[] sigma = new double[40];
+ Data d = Data () { n = n, y = y, sigma = sigma};
+
+ double[] x_init = new double[] { 1.0, 0.0, 0.0 };
+ VectorView x = VectorView.array (x_init);
+
+ RNGType* type;
+ RNG r;
+
+ RNG.env_setup ();
+
+ type = (RNGType*)RNGTypes.default;
+ r = new RNG (type);
+
+ MultifitFunctionFdf f = MultifitFunctionFdf () { f = expb_f, df = expb_df, fdf = expb_fdf, n = n, p = p, params = &d };
+
+ for (i = 0; i < n; i++)
+ {
+ double t = i;
+ y[i] = 1.0 + 5 * Math.exp (-0.1 * t) + Randist.gaussian (r, 0.1);
+ sigma[i] = 0.1;
+ stdout.printf ("data: %u %g %g\n", i, y[i], sigma[i]);
+ }
+
+ T = (MultifitFdfsolverType*)MultifitFdfsolverTypes.lmsder;
+ s = new MultifitFdfsolver (T, n, p);
+ s.set (&f, (Vector)(&x.vector));
+
+ print_state (iter, s);
+
+ do
+ {
+ iter++;
+ status = s.iterate ();
+ stdout.printf ("status = %s\n", Gsl.Error.strerror (status));
+ print_state (iter, s);
+ if ((bool)status)
+ break;
+ status = MultifitTest.delta (s.dx, s.x, 1e-4, 1e-4);
+ } while (status == Status.CONTINUE && iter < 500);
+
+ Multifit.covar ((Matrix)(s.J), 0.0, covar);
+
+ stdout.printf ("A = %.5f\n", s.x.get (0));
+ stdout.printf ("lambda = %.5f\n", s.x.get (1));
+ stdout.printf ("b = %.5f\n", s.x.get (2));
+ stdout.printf ("status = %s\n", Gsl.Error.strerror (status));
+ }
+}
diff --git a/tests/examples/gsl-linear-algebra.test b/tests/examples/gsl-linear-algebra.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-linear-algebra.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-linear-algebra.vala b/tests/examples/gsl-linear-algebra.vala
new file mode 100644
index 0000000..dca31a7
--- /dev/null
+++ b/tests/examples/gsl-linear-algebra.vala
@@ -0,0 +1,33 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-linear-algebra.vala
+
+using GLib;
+using Gsl;
+
+public class Test : GLib.Object
+{
+ public static void main (string[] args)
+ {
+ double[] a_data = new double[] { 0.18, 0.60, 0.57, 0.96,
+ 0.41, 0.24, 0.99, 0.58,
+ 0.14, 0.30, 0.97, 0.66,
+ 0.51, 0.13, 0.19, 0.85 };
+
+ double[] b_data = new double[] { 1.0, 2.0, 3.0, 4.0 };
+
+ MatrixView m = MatrixView.array (a_data, 4, 4);
+ VectorView b = VectorView.array (b_data);
+
+ Vector x = new Vector (4);
+
+ int s;
+
+ Permutation p = new Permutation (4);
+
+ LinAlg.LU_decomp ((Matrix)(&m.matrix), p, out s);
+ LinAlg.LU_solve ((Matrix)(&m.matrix), p, (Vector)(&b.vector), x);
+
+ stdout.printf("x = \n");
+ Vector.fprintf(stdout, x, "%g");
+ }
+}
diff --git a/tests/examples/gsl-monte-carlo-integration.test b/tests/examples/gsl-monte-carlo-integration.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-monte-carlo-integration.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-monte-carlo-integration.vala b/tests/examples/gsl-monte-carlo-integration.vala
new file mode 100644
index 0000000..19c9393
--- /dev/null
+++ b/tests/examples/gsl-monte-carlo-integration.vala
@@ -0,0 +1,72 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-monte-carlo-integration.vala
+
+using GLib;
+using Gsl;
+
+public class MonteSample : GLib.Object
+{
+ static double exact = 1.3932039296856768591842462603255;
+
+ static double g (double* k, size_t dim, void* params)
+ {
+ double A = 1.0 / (Math.PI * Math.PI * Math.PI);
+ return A / (1.0 - Math.cos(k[0]) * Math.cos(k[1]) * Math.cos(k[2]));
+ }
+
+ static void display_results (string title, double result, double error)
+ {
+ stdout.printf ("%s ==================\n", title);
+ stdout.printf ("result = % .6f\n", result);
+ stdout.printf ("sigma = % .6f\n", error);
+ stdout.printf ("exact = % .6f\n", exact);
+ stdout.printf ("error = % .6f = %.1g sigma\n", result - exact, Math.fabs (result-exact)/error);
+ }
+
+ public static void main (string[] args)
+ {
+ double res, err;
+
+ double[] xl = new double[] { 0, 0, 0 };
+ double[] xu = new double[] { Math.PI, Math.PI, Math.PI };
+
+ RNGType* T;
+ RNG r;
+
+ MonteFunction G = { g, 3, null};
+
+ size_t calls = 500000;
+
+ RNG.env_setup ();
+
+ T = (RNGType*)RNGTypes.default;
+ r = new RNG (T);
+
+ {
+ MontePlainState s = new MontePlainState (3);
+ MontePlainState.integrate (&G, xl, xu, 3, calls, r, s, out res, out err);
+ display_results ("plain", res, err);
+ }
+
+ {
+ MonteMiserState s = new MonteMiserState (3);
+ MonteMiserState.integrate (&G, xl, xu, 3, calls, r, s, out res, out err);
+ display_results ("miser", res, err);
+ }
+
+ {
+ MonteVegasState s = new MonteVegasState (3);
+ MonteVegasState.integrate (&G, xl, xu, 3, 10000, r, s, out res, out err);
+ display_results ("vegas warm_up", res, err);
+ stdout.printf ("converging...\n");
+
+ do
+ {
+ MonteVegasState.integrate (&G, xl, xu, 3, calls/5, r, s, out res, out err);
+ stdout.printf ("result = % .6f sigma = % .6f chisq/dof = %.1f\n", res, err, s.chisq);
+ } while (Math.fabs (s.chisq - 1.0) > 0.5 );
+
+ display_results ("vegas final", res, err);
+ }
+ }
+}
diff --git a/tests/examples/gsl-multidimensional.test b/tests/examples/gsl-multidimensional.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-multidimensional.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-multidimensional.vala b/tests/examples/gsl-multidimensional.vala
new file mode 100644
index 0000000..ec8ad69
--- /dev/null
+++ b/tests/examples/gsl-multidimensional.vala
@@ -0,0 +1,101 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-multidimensional.vala
+
+using GLib;
+using Gsl;
+
+public class MultiRootSample : GLib.Object
+{
+ struct RParams
+ {
+ public double a;
+ public double b;
+ }
+
+ static int rosenbrock_f (Vector x, void* params, Vector f)
+ {
+ double a = ((RParams*)params)->a;
+ double b = ((RParams*)params)->b;
+
+ double x0 = x.get (0);
+ double x1 = x.get (1);
+
+ double y0 = a*(1-x0);
+ double y1 = b*(x1-x0*x0);
+
+ f.set (0, y0);
+ f.set (1, y1);
+
+ return Status.SUCCESS;
+ }
+
+ static int rosenbrock_df (Vector x, void* params, Matrix J)
+ {
+ double a = ((RParams*)params)->a;
+ double b = ((RParams*)params)->b;
+
+ double x0 = x.get (0);
+ //double x1 = x.get (1);
+
+ double df00 = -a;
+ double df01 = 0;
+ double df10 = -2*b*x0;
+ double df11 = b;
+
+ J.set (0, 0, df00);
+ J.set (0, 1, df01);
+ J.set (1, 0, df10);
+ J.set (1, 1, df11);
+
+ return Status.SUCCESS;
+ }
+
+ static int rosenbrock_fdf (Vector x, void* params, Vector f, Matrix J)
+ {
+ rosenbrock_f (x, params, f);
+ rosenbrock_df (x, params, J);
+ return Status.SUCCESS;
+ }
+
+ static void print_state (size_t iter, MultirootFdfsolver s)
+ {
+ stdout.printf ("iter = %3u x = % .3f % .3f f(x) = % .3e % .3e\n", (uint)iter, s.x.get (0), s.x.get (1), s.f.get (0), s.f.get (1));
+ }
+
+ public static void main (string[] args)
+ {
+ MultirootFdfsolverType* T;
+ MultirootFdfsolver s;
+
+ int status = 0;
+ size_t iter=0;
+
+ size_t n = 2;
+
+ RParams p = { 1.0, 10.0 };
+ MultirootFunctionFdf f = MultirootFunctionFdf () { f = rosenbrock_f, df = rosenbrock_df, fdf = rosenbrock_fdf, n = n, params = &p };
+
+ double[] x_init = new double[] { -10.0, -5.0 };
+ Vector x = new Vector (n);
+
+ x.set (0, x_init[0]);
+ x.set (1, x_init[1]);
+
+ T = (MultirootFdfsolverType*)MultirootFdfsolverTypes.gnewton;
+ s = new MultirootFdfsolver (T, n);
+ s.set (&f, x);
+
+ print_state (iter, s);
+
+ do
+ {
+ iter++;
+ status = s.iterate ();
+ print_state (iter, s);
+ if ((bool)status)
+ break;
+ status = MultirootTest.residual (s.f, 1.0e-7);
+ } while (status==Status.CONTINUE && iter < 1000);
+
+ }
+}
diff --git a/tests/examples/gsl-random.test b/tests/examples/gsl-random.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-random.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-random.vala b/tests/examples/gsl-random.vala
new file mode 100644
index 0000000..88ee4e4
--- /dev/null
+++ b/tests/examples/gsl-random.vala
@@ -0,0 +1,28 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-random.vala
+
+using GLib;
+using Gsl;
+
+public class RNGSample : GLib.Object
+{
+ public static void main (string[] args)
+ {
+ RNGType* T;
+ RNG r;
+
+ int i, n=10;
+
+ RNG.env_setup ();
+
+ T = (RNGType*)RNGTypes.default;
+ r = new RNG (T);
+
+ for (i=0; i<n; i++)
+ {
+ double u = r.uniform ();
+ stdout.printf ("%d %.5f\n", i, u);
+ }
+
+ }
+}
diff --git a/tests/examples/gsl-stats.test b/tests/examples/gsl-stats.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gsl-stats.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gsl-stats.vala b/tests/examples/gsl-stats.vala
new file mode 100644
index 0000000..5f83e22
--- /dev/null
+++ b/tests/examples/gsl-stats.vala
@@ -0,0 +1,23 @@
+
+// http://live.gnome.org/Vala/GSLSample vala-test:examples/gsl-stats.vala
+
+using GLib;
+using Gsl;
+
+public class Test : GLib.Object
+{
+ public static void main (string[] args)
+ {
+ double mean, max, min;
+
+ double[] data = new double[] { 17.2, 18.1, 16.5, 18.3, 12.6 };
+
+ mean = Stats.mean (data, 1, data.length);
+
+ Stats.minmax (out min, out max, data, 1, data.length);
+
+ stdout.printf("promedio %g\n", mean);
+ stdout.printf("minimo %g\n", min);
+ stdout.printf("maximo %g\n", max);
+ }
+}
diff --git a/tests/examples/gstreamer-audio-player.test b/tests/examples/gstreamer-audio-player.test
new file mode 100755
index 0000000..e9ebbf3
--- /dev/null
+++ b/tests/examples/gstreamer-audio-player.test
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+#FIXME, have a timeout in test for instance
+TESTRUN=interact
+. common.sh
diff --git a/tests/examples/gstreamer-audio-player.vala b/tests/examples/gstreamer-audio-player.vala
new file mode 100644
index 0000000..b639b69
--- /dev/null
+++ b/tests/examples/gstreamer-audio-player.vala
@@ -0,0 +1,80 @@
+
+// http://live.gnome.org/Vala/GStreamerSample vala-test:examples/gstreamer-audio-player.vala
+
+using Gst;
+
+public class StreamPlayer {
+
+ private MainLoop loop = new MainLoop (null, false);
+
+ private void foreach_tag (Gst.TagList list, string tag) {
+ switch (tag) {
+ case "title":
+ string tag_string;
+ list.get_string (tag, out tag_string);
+ stdout.printf ("tag: %s = %s\n", tag, tag_string);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private bool bus_callback (Gst.Bus bus, Gst.Message message) {
+ switch (message.type) {
+ case MessageType.ERROR:
+ GLib.Error err;
+ string debug;
+ message.parse_error (out err, out debug);
+ stdout.printf ("Error: %s\n", err.message);
+ loop.quit ();
+ break;
+ case MessageType.EOS:
+ stdout.printf ("end of stream\n");
+ break;
+ case MessageType.STATE_CHANGED:
+ Gst.State oldstate;
+ Gst.State newstate;
+ Gst.State pending;
+ message.parse_state_changed (out oldstate, out newstate,
+ out pending);
+ stdout.printf ("state changed: %s->%s:%s\n",
+ oldstate.to_string (), newstate.to_string (),
+ pending.to_string ());
+ break;
+ case MessageType.TAG:
+ Gst.TagList tag_list;
+ stdout.printf ("taglist found\n");
+ message.parse_tag (out tag_list);
+ tag_list.foreach (foreach_tag);
+ break;
+ default:
+ break;
+ }
+
+ return true;
+ }
+
+ public void play (string stream) {
+ dynamic Element play = ElementFactory.make ("playbin", "play");
+ play.uri = stream;
+
+ Bus bus = play.get_bus ();
+ bus.add_watch (bus_callback);
+
+ play.set_state (State.PLAYING);
+
+ loop.run ();
+ }
+}
+
+const string DEFAULT_STREAM = "http://scfire-dtc-aa06.stream.aol.com:80/stream/1018";
+
+int main (string[] args) {
+
+ Gst.init (ref args);
+
+ var player = new StreamPlayer ();
+ player.play (args.length > 1 ? args[1] : DEFAULT_STREAM);
+
+ return 0;
+}
diff --git a/tests/examples/gstreamer-square-beep.test b/tests/examples/gstreamer-square-beep.test
index a509517..99012d4 100755
--- a/tests/examples/gstreamer-square-beep.test
+++ b/tests/examples/gstreamer-square-beep.test
@@ -1,30 +1,5 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gstreamer-0.10 -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+#FIXME use num-buffers on source element, for instance
+TESTRUN=interact
+. common.sh
diff --git a/tests/examples/gstreamer-square-beep.vala b/tests/examples/gstreamer-square-beep.vala
index 058eb19..dba3a29 100644
--- a/tests/examples/gstreamer-square-beep.vala
+++ b/tests/examples/gstreamer-square-beep.vala
@@ -1,24 +1,18 @@
-/* GStreamer in Vala sample code */
-using GLib;
+// http://live.gnome.org/Vala/GStreamerSample vala-test:examples/gstreamer-square-beep.vala
+
using Gst;
-public void main (string[] args) {
- MainLoop loop;
+void main (string[] args) {
+ Pipeline pipeline;
Element src;
Element sink;
- Pipeline pipeline;
-
- // Creating a GLib main loop with a default context
- loop = new MainLoop (null, false);
// Initializing GStreamer
Gst.init (ref args);
// Creating pipeline and elements
- // NOTE: The return type of the pipeline construction method is Element,
- // not Pipeline, so we have to cast
- pipeline = (Pipeline) new Pipeline ("test");
+ pipeline = new Pipeline ("test");
src = ElementFactory.make ("audiotestsrc", "my_src");
sink = ElementFactory.make ("autoaudiosink", "my_sink");
@@ -34,6 +28,9 @@ public void main (string[] args) {
// Set pipeline state to PLAYING
pipeline.set_state (State.PLAYING);
+ // Creating a GLib main loop with a default context
+ var loop = new MainLoop (null, false);
+
// Start GLib mainloop
loop.run ();
-}
\ No newline at end of file
+}
diff --git a/tests/examples/gstreamer-videotest.test b/tests/examples/gstreamer-videotest.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gstreamer-videotest.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gstreamer-videotest.vala b/tests/examples/gstreamer-videotest.vala
new file mode 100644
index 0000000..fbc2962
--- /dev/null
+++ b/tests/examples/gstreamer-videotest.vala
@@ -0,0 +1,70 @@
+
+// http://live.gnome.org/Vala/GStreamerSample vala-test:examples/gstreamer-videotest.vala
+
+using Gtk;
+using Gst;
+
+public class VideoSample : Window {
+
+ private DrawingArea drawing_area;
+ private Pipeline pipeline;
+ private Element src;
+ private Element sink;
+
+ public VideoSample () {
+ create_widgets ();
+ setup_gst_pipeline ();
+ }
+
+ private void create_widgets () {
+ var vbox = new VBox (false, 0);
+ this.drawing_area = new DrawingArea ();
+ this.drawing_area.set_size_request (300, 150);
+ vbox.pack_start (this.drawing_area, true, true, 0);
+
+ var play_button = new Button.from_stock (STOCK_MEDIA_PLAY);
+ play_button.clicked.connect (on_play);
+ var stop_button = new Button.from_stock (STOCK_MEDIA_STOP);
+ stop_button.clicked.connect (on_stop);
+ var quit_button = new Button.from_stock (STOCK_QUIT);
+ quit_button.clicked.connect (Gtk.main_quit);
+
+ var bb = new HButtonBox ();
+ bb.add (play_button);
+ bb.add (stop_button);
+ bb.add (quit_button);
+ vbox.pack_start (bb, false, true, 0);
+
+ add (vbox);
+ }
+
+ private void setup_gst_pipeline () {
+ this.pipeline = new Pipeline ("mypipeline");
+ this.src = ElementFactory.make ("videotestsrc", "video");
+ this.sink = ElementFactory.make ("xvimagesink", "sink");
+ this.pipeline.add_many (this.src, this.sink);
+ this.src.link (this.sink);
+ }
+
+ private void on_play () {
+ var xoverlay = this.sink as XOverlay;
+ xoverlay.set_xwindow_id (Gdk.x11_drawable_get_xid (this.drawing_area.window));
+ this.pipeline.set_state (State.PLAYING);
+ }
+
+ private void on_stop () {
+ this.pipeline.set_state (State.READY);
+ }
+
+ public static int main (string[] args) {
+ Gst.init (ref args);
+ Gtk.init (ref args);
+
+ var sample = new VideoSample ();
+ sample.show_all ();
+
+ Gtk.main ();
+
+ return 0;
+ }
+}
diff --git a/tests/examples/gtk-builder-sample.test b/tests/examples/gtk-builder-sample.test
index 44aee5a..0174331 100755
--- a/tests/examples/gtk-builder-sample.test
+++ b/tests/examples/gtk-builder-sample.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gtk+-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/gtk-builder-sample.vala b/tests/examples/gtk-builder-sample.vala
index 7e19d3d..9495ec6 100644
--- a/tests/examples/gtk-builder-sample.vala
+++ b/tests/examples/gtk-builder-sample.vala
@@ -1,62 +1,30 @@
-/* GtkTreeView and GtkBuilder in Vala sample code */
-using GLib;
-using Gtk;
-
-public class BuilderExample : Gtk.Builder {
-
- string uifile = "main_window.ui";
-
- public bool create_widgets () {
- try {
- add_from_file (uifile);
- Gtk.Widget window = (Gtk.Widget) get_object ("window");
- setup_treeview ((Gtk.TreeView) get_object ("treeview1"));
- window.show_all ();
- window.destroy += Gtk.main_quit;
- } catch (GLib.Error err) {
- var msg = new Gtk.MessageDialog (
- null, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL,
- "Failed to load UI\n" + err.message);
- msg.run();
-
- return false;
- }
- return true;
- }
-
- public void setup_treeview (Gtk.TreeView view) {
-
- /* use liststore to hold accountname, accounttype, balance and color attribute */
- /* for more info how gtkTreeview works take a look in the GTK API */
-
- var listmodel = new Gtk.ListStore(4, typeof(string), typeof(string), typeof(string), typeof(string));
- view.set_model(listmodel);
+// http://live.gnome.org/Vala/GTKSample vala-test:examples/gtk-builder-sample.vala
- view.insert_column_with_attributes (-1, "Account Name", new Gtk.CellRendererText(), "text", 0, null);
- view.insert_column_with_attributes (-1, "Type", new Gtk.CellRendererText(), "text", 1, null);
-
- var cell = new Gtk.CellRendererText ();
- cell.set ("foreground_set", true, null);
- view.insert_column_with_attributes (-1, "Balance", cell, "text", 2, "foreground", 3, null);
-
- Gtk.TreeIter iter;
- listmodel.append (out iter);
- listmodel.set (iter, 0, "My Visacard", 1, "card", 2, "102,10", 3, "red", -1);
-
- listmodel.append (out iter);
- listmodel.set (iter, 0, "My Mastercard", 1, "card", 2, "10,20", 3, "red", -1);
- }
-
- public static int main (string[] args) {
- Gtk.init (ref args);
+using Gtk;
- var mainapp = new BuilderExample ();
- if (mainapp.create_widgets ()) {
- Gtk.main ();
- }
+public void on_button1_clicked (Button source) {
+ source.label = "Thank you!";
+}
- return 0;
- }
+public void on_button2_clicked (Button source) {
+ source.label = "Thanks!";
}
+int main (string[] args) {
+ Gtk.init (ref args);
+
+ try {
+ var builder = new Builder ();
+ builder.add_from_file ("sample.ui");
+ builder.connect_signals (null);
+ var window = builder.get_object ("window") as Window;
+ window.show_all ();
+ Gtk.main ();
+ } catch (Error e) {
+ stderr.printf ("Could not load UI: %s\n", e.message);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/examples/gtk-filechooser.test b/tests/examples/gtk-filechooser.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gtk-filechooser.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gtk-filechooser.vala b/tests/examples/gtk-filechooser.vala
new file mode 100644
index 0000000..393f635
--- /dev/null
+++ b/tests/examples/gtk-filechooser.vala
@@ -0,0 +1,36 @@
+
+// http://live.gnome.org/Vala/GTKSample vala-test:examples/gtk-filechooser.vala
+
+public class OpenFileDialog : FileChooserDialog {
+
+ private string last_folder;
+
+ public OpenFileDialog () {
+ this.title = "Open File";
+ this.action = FileChooserAction.OPEN;
+
+ add_button (STOCK_CANCEL, ResponseType.CANCEL);
+ add_button (STOCK_OPEN, ResponseType.ACCEPT);
+ set_default_response (ResponseType.ACCEPT);
+
+ if (this.last_folder != null) {
+ set_current_folder (this.last_folder);
+ }
+ }
+
+ public override void response (int type) {
+ if (type == ResponseType.ACCEPT) {
+ this.last_folder = get_current_folder ();
+ }
+ }
+
+ public static void main (string[] args) {
+ Gtk.init (ref args);
+
+ var ofd = new OpenFileDialog ();
+
+ if (ofd.run () == ResponseType.OK) {
+ stdout.printf ("filename = %s\n".printf (ofd.get_filename ()));
+ }
+ }
+}
diff --git a/tests/examples/gtk-hello.test b/tests/examples/gtk-hello.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gtk-hello.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gtk-hello.vala b/tests/examples/gtk-hello.vala
new file mode 100644
index 0000000..2602e98
--- /dev/null
+++ b/tests/examples/gtk-hello.vala
@@ -0,0 +1,25 @@
+
+// http://live.gnome.org/Vala/GTKSample vala-test:examples/gtk-hello.vala
+
+using Gtk;
+
+int main (string[] args) {
+ Gtk.init (ref args);
+
+ var window = new Window (WindowType.TOPLEVEL);
+ window.title = "First GTK+ Program";
+ window.set_default_size (300, 50);
+ window.position = WindowPosition.CENTER;
+ window.destroy.connect (Gtk.main_quit);
+
+ var button = new Button.with_label ("Click me!");
+ button.clicked.connect ((source) => {
+ source.label = "Thank you";
+ });
+
+ window.add (button);
+ window.show_all ();
+
+ Gtk.main ();
+ return 0;
+}
diff --git a/tests/examples/gtk-search-dialog.test b/tests/examples/gtk-search-dialog.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gtk-search-dialog.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gtk-search-dialog.vala b/tests/examples/gtk-search-dialog.vala
new file mode 100644
index 0000000..49d939e
--- /dev/null
+++ b/tests/examples/gtk-search-dialog.vala
@@ -0,0 +1,91 @@
+
+// http://live.gnome.org/Vala/GTKSample vala-test:examples/gtk-search-dialog.vala
+
+using Gtk;
+
+public class SearchDialog : Dialog {
+
+ private Entry search_entry;
+ private CheckButton match_case;
+ private CheckButton find_backwards;
+ private Widget find_button;
+
+ public signal void find_next (string text, bool case_sensitivity);
+ public signal void find_previous (string text, bool case_sensitivity);
+
+ public SearchDialog () {
+ this.title = "Find";
+ this.has_separator = false;
+ this.border_width = 5;
+ set_default_size (350, 100);
+ create_widgets ();
+ connect_signals ();
+ }
+
+ private void create_widgets () {
+
+ // Create and setup widgets
+ this.search_entry = new Entry ();
+ var search_label = new Label.with_mnemonic ("_Search for:");
+ search_label.mnemonic_widget = this.search_entry;
+ this.match_case = new CheckButton.with_mnemonic ("_Match case");
+ this.find_backwards = new CheckButton.with_mnemonic ("Find _backwards");
+
+ // Layout widgets
+ var hbox = new HBox (false, 20);
+ hbox.pack_start (search_label, false, true, 0);
+ hbox.pack_start (this.search_entry, true, true, 0);
+ this.vbox.pack_start (hbox, false, true, 0);
+ this.vbox.pack_start (this.match_case, false, true, 0);
+ this.vbox.pack_start (this.find_backwards, false, true, 0);
+ this.vbox.spacing = 10;
+
+ // Add buttons to button area at the bottom
+ add_button (STOCK_HELP, ResponseType.HELP);
+ add_button (STOCK_CLOSE, ResponseType.CLOSE);
+ this.find_button = add_button (STOCK_FIND, ResponseType.APPLY);
+ this.find_button.sensitive = false;
+
+ show_all ();
+ }
+
+ private void connect_signals () {
+ this.search_entry.changed.connect ((source) => {
+ this.find_button.sensitive = (this.search_entry.text != "");
+ });
+ this.response.connect (on_response);
+ }
+
+ private void on_response (Dialog source, int response_id) {
+ switch (response_id) {
+ case ResponseType.HELP:
+ // show_help ();
+ break;
+ case ResponseType.APPLY:
+ on_find_clicked ();
+ break;
+ case ResponseType.CLOSE:
+ destroy ();
+ break;
+ }
+ }
+
+ private void on_find_clicked () {
+ string text = this.search_entry.text;
+ bool cs = this.match_case.active;
+ if (this.find_backwards.active) {
+ find_previous (text, cs);
+ } else {
+ find_next (text, cs);
+ }
+ }
+}
+
+int main (string[] args) {
+ Gtk.init (ref args);
+ var dialog = new SearchDialog ();
+ dialog.destroy.connect (Gtk.main_quit);
+ dialog.show ();
+ Gtk.main ();
+ return 0;
+}
diff --git a/tests/examples/gtk-sync-sample.test b/tests/examples/gtk-sync-sample.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gtk-sync-sample.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gtk-sync-sample.vala b/tests/examples/gtk-sync-sample.vala
new file mode 100644
index 0000000..b161455
--- /dev/null
+++ b/tests/examples/gtk-sync-sample.vala
@@ -0,0 +1,42 @@
+
+// http://live.gnome.org/Vala/GTKSample vala-test:examples/gtk-sync-sample.vala
+
+using Gtk;
+
+public class SyncSample : Window {
+
+ private SpinButton spin_box;
+ private HScale slider;
+
+ public SyncSample () {
+ this.title = "Enter your age";
+ this.position = WindowPosition.CENTER;
+ this.destroy.connect (Gtk.main_quit);
+ set_default_size (300, 20);
+
+ spin_box = new SpinButton.with_range (0, 130, 1);
+ slider = new HScale.with_range (0, 130, 1);
+ spin_box.value_changed.connect ((s) => {
+ slider.set_value (s.get_value ());
+ });
+ slider.value_changed.connect ((s) => {
+ spin_box.set_value (s.get_value ());
+ });
+ spin_box.value = 35;
+
+ var hbox = new HBox (true, 5);
+ hbox.add (spin_box);
+ hbox.add (slider);
+ add (hbox);
+ }
+
+ public static int main (string[] args) {
+ Gtk.init (ref args);
+
+ var window = new SyncSample ();
+ window.show_all ();
+
+ Gtk.main ();
+ return 0;
+ }
+}
diff --git a/tests/examples/gtk-text-viewer.test b/tests/examples/gtk-text-viewer.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gtk-text-viewer.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gtk-text-viewer.vala b/tests/examples/gtk-text-viewer.vala
new file mode 100644
index 0000000..f4f1fe7
--- /dev/null
+++ b/tests/examples/gtk-text-viewer.vala
@@ -0,0 +1,65 @@
+
+// http://live.gnome.org/Vala/GTKSample vala-test:examples/gtk-text-viewer.vala
+
+using Gtk;
+
+public class TextFileViewer : Window {
+
+ private TextView text_view;
+
+ public TextFileViewer () {
+ this.title = "Text File Viewer";
+ this.position = WindowPosition.CENTER;
+ set_default_size (400, 300);
+
+ var toolbar = new Toolbar ();
+ var open_button = new ToolButton.from_stock (STOCK_OPEN);
+ toolbar.add (open_button);
+ open_button.clicked.connect (on_open_clicked);
+
+ this.text_view = new TextView ();
+ this.text_view.editable = false;
+ this.text_view.cursor_visible = false;
+
+ var scroll = new ScrolledWindow (null, null);
+ scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
+ scroll.add (this.text_view);
+
+ var vbox = new VBox (false, 0);
+ vbox.pack_start (toolbar, false, true, 0);
+ vbox.pack_start (scroll, true, true, 0);
+ add (vbox);
+ }
+
+ private void on_open_clicked () {
+ var file_chooser = new FileChooserDialog ("Open File", this,
+ FileChooserAction.OPEN,
+ STOCK_CANCEL, ResponseType.CANCEL,
+ STOCK_OPEN, ResponseType.ACCEPT, null);
+ if (file_chooser.run () == ResponseType.ACCEPT) {
+ open_file (file_chooser.get_filename ());
+ }
+ file_chooser.destroy ();
+ }
+
+ private void open_file (string filename) {
+ try {
+ string text;
+ FileUtils.get_contents (filename, out text, null);
+ this.text_view.buffer.text = text;
+ } catch (Error e) {
+ stderr.printf ("Error: %s\n", e.message);
+ }
+ }
+
+ public static int main (string[] args) {
+ Gtk.init (ref args);
+
+ var window = new TextFileViewer ();
+ window.destroy.connect (Gtk.main_quit);
+ window.show_all ();
+
+ Gtk.main ();
+ return 0;
+ }
+}
diff --git a/tests/examples/gtk-treeview-listsample.test b/tests/examples/gtk-treeview-listsample.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gtk-treeview-listsample.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gtk-treeview-listsample.vala b/tests/examples/gtk-treeview-listsample.vala
new file mode 100644
index 0000000..5bbfb1f
--- /dev/null
+++ b/tests/examples/gtk-treeview-listsample.vala
@@ -0,0 +1,62 @@
+
+// http://live.gnome.org/Vala/GTKSample vala-test:examples/gtk-treeview-listsample.vala
+
+using Gtk;
+
+public class ListSample : Gtk.Window {
+
+ private ListStore _list_store;
+ private TreeView _tree_view;
+
+ private enum Columns {
+ TOGGLE,
+ TEXT,
+ N_COLUMNS
+ }
+
+ public ListSample () {
+ this.title = "List Sample";
+ this.destroy.connect (Gtk.main_quit);
+ set_size_request (200, 200);
+
+ _list_store = new ListStore (Columns.N_COLUMNS, typeof (bool), typeof (string));
+ _tree_view = new TreeView.with_model (_list_store);
+
+ var toggle = new CellRendererToggle ();
+ toggle.toggled.connect ((toggle, path) => {
+ var tree_path = new TreePath.from_string (path);
+ TreeIter iter;
+ _list_store.get_iter (out iter, tree_path);
+ _list_store.set (iter, Columns.TOGGLE, !toggle.active);
+ });
+
+ var column = new TreeViewColumn ();
+ column.pack_start (toggle, false);
+ column.add_attribute (toggle, "active", Columns.TOGGLE);
+ _tree_view.append_column (column);
+
+ var text = new CellRendererText ();
+
+ column = new TreeViewColumn ();
+ column.pack_start (text, true);
+ column.add_attribute (text, "text", Columns.TEXT);
+ _tree_view.append_column (column);
+
+ _tree_view.set_headers_visible (false);
+
+ TreeIter iter;
+ _list_store.append (out iter);
+ _list_store.set (iter, Columns.TOGGLE, true, Columns.TEXT, "item 1");
+ _list_store.append (out iter);
+ _list_store.set (iter, Columns.TOGGLE, false, Columns.TEXT, "item 2");
+
+ add (_tree_view);
+ }
+
+ public static void main (string[] args) {
+ Gtk.init (ref args);
+ var list_sample = new ListSample ();
+ list_sample.show_all ();
+ Gtk.main ();
+ }
+}
diff --git a/tests/examples/gtk-treeview-liststore.test b/tests/examples/gtk-treeview-liststore.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gtk-treeview-liststore.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gtk-treeview-liststore.vala b/tests/examples/gtk-treeview-liststore.vala
new file mode 100644
index 0000000..ecd82d0
--- /dev/null
+++ b/tests/examples/gtk-treeview-liststore.vala
@@ -0,0 +1,53 @@
+
+// http://live.gnome.org/Vala/GTKSample vala-test:examples/gtk-treeview-liststore.vala
+
+using Gtk;
+
+public class TreeViewSample : Window {
+
+ public TreeViewSample () {
+ this.title = "TreeView Sample";
+ set_default_size (250, 100);
+ var view = new TreeView ();
+ setup_treeview (view);
+ add (view);
+ this.destroy.connect (Gtk.main_quit);
+ }
+
+ private void setup_treeview (TreeView view) {
+
+ /*
+ * Use ListStore to hold accountname, accounttype, balance and
+ * color attribute. For more info on how TreeView works take a
+ * look at the GTK+ API.
+ */
+
+ var listmodel = new ListStore (4, typeof (string), typeof (string),
+ typeof (string), typeof (string));
+ view.set_model (listmodel);
+
+ view.insert_column_with_attributes (-1, "Account Name", new CellRendererText (), "text", 0);
+ view.insert_column_with_attributes (-1, "Type", new CellRendererText (), "text", 1);
+
+ var cell = new CellRendererText ();
+ cell.set ("foreground_set", true);
+ view.insert_column_with_attributes (-1, "Balance", cell, "text", 2, "foreground", 3);
+
+ TreeIter iter;
+ listmodel.append (out iter);
+ listmodel.set (iter, 0, "My Visacard", 1, "card", 2, "102,10", 3, "red");
+
+ listmodel.append (out iter);
+ listmodel.set (iter, 0, "My Mastercard", 1, "card", 2, "10,20", 3, "red");
+ }
+
+ public static int main (string[] args) {
+ Gtk.init (ref args);
+
+ var sample = new TreeViewSample ();
+ sample.show_all ();
+ Gtk.main ();
+
+ return 0;
+ }
+}
diff --git a/tests/examples/gtk-treeview-treestore.test b/tests/examples/gtk-treeview-treestore.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/gtk-treeview-treestore.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/gtk-treeview-treestore.vala b/tests/examples/gtk-treeview-treestore.vala
new file mode 100644
index 0000000..d8b94e6
--- /dev/null
+++ b/tests/examples/gtk-treeview-treestore.vala
@@ -0,0 +1,66 @@
+
+// http://live.gnome.org/Vala/GTKSample vala-test:examples/gtk-treeview-treestore.vala
+
+using Gtk;
+
+public class TreeViewSample : Window {
+
+ public TreeViewSample () {
+ this.title = "TreeView Sample";
+ set_default_size (250, 100);
+ var view = new TreeView ();
+ setup_treeview (view);
+ add (view);
+ this.destroy.connect (Gtk.main_quit);
+ }
+
+ private void setup_treeview (TreeView view) {
+
+ var store = new TreeStore (2, typeof (string), typeof (string));
+ view.set_model (store);
+
+ view.insert_column_with_attributes (-1, "Product", new CellRendererText (), "text", 0, null);
+ view.insert_column_with_attributes (-1, "Price", new CellRendererText (), "text", 1, null);
+
+ TreeIter root;
+ TreeIter category_iter;
+ TreeIter product_iter;
+
+ store.append (out root, null);
+ store.set (root, 0, "All Products", -1);
+
+ store.append (out category_iter, root);
+ store.set (category_iter, 0, "Books", -1);
+
+ store.append (out product_iter, category_iter);
+ store.set (product_iter, 0, "Moby Dick", 1, "$10.36", -1);
+ store.append (out product_iter, category_iter);
+ store.set (product_iter, 0, "Heart of Darkness", 1, "$4.99", -1);
+ store.append (out product_iter, category_iter);
+ store.set (product_iter, 0, "Ulysses", 1, "$26.09", -1);
+ store.append (out product_iter, category_iter);
+ store.set (product_iter, 0, "Effective Vala", 1, "$38.99", -1);
+
+ store.append (out category_iter, root);
+ store.set (category_iter, 0, "Films", -1);
+
+ store.append (out product_iter, category_iter);
+ store.set (product_iter, 0, "Amores Perros", 1, "$7.99", -1);
+ store.append (out product_iter, category_iter);
+ store.set (product_iter, 0, "Twin Peaks", 1, "$14.99", -1);
+ store.append (out product_iter, category_iter);
+ store.set (product_iter, 0, "Vertigo", 1, "$20.49", -1);
+
+ view.expand_all ();
+ }
+
+ public static int main (string[] args) {
+ Gtk.init (ref args);
+
+ var sample = new TreeViewSample ();
+ sample.show_all ();
+ Gtk.main ();
+
+ return 0;
+ }
+}
diff --git a/tests/examples/gtk-valawidget.test b/tests/examples/gtk-valawidget.test
index 0210813..0174331 100755
--- a/tests/examples/gtk-valawidget.test
+++ b/tests/examples/gtk-valawidget.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gtk+-2.0 --pkg cairo --pkg pangocairo -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/gtk-valawidget.vala b/tests/examples/gtk-valawidget.vala
index 3275d5a..c4f199f 100644
--- a/tests/examples/gtk-valawidget.vala
+++ b/tests/examples/gtk-valawidget.vala
@@ -1,140 +1,147 @@
-//
-// Johan Dahlin 2008
-//
-// A quite simple Gtk.Widget subclass which demonstrates how to subclass
-// and do realizing, sizing and drawing. Based on widget.py in PyGTK
-//
-
-using GLib;
-using Gtk;
-using Cairo;
-
-public class ValaWidget : Gtk.Widget {
- private static const string text = "Hello World!\n";
- private static const int _BORDER_WIDTH = 10;
- private Pango.Layout _layout;
-
- construct {
- this._layout = this.create_pango_layout (ValaWidget.text);
- }
- // The realize method is responsible for creating GDK (windowing system)
- // resources. In this example we will create a new gdk.Window which we
- // then draw on
+// http://live.gnome.org/Vala/CustomWidgetSamples vala-test:examples/gtk-valawidget.vala
- public override void realize ()
- {
- // First set an internal flag telling that we're realized
- this.set_flags (Gtk.WidgetFlags.REALIZED);
+/*
+ * Johan Dahlin 2008
+ *
+ * A quite simple Gtk.Widget subclass which demonstrates how to subclass
+ * and do realizing, sizing and drawing. Based on widget.py in PyGTK
+ */
+
+using Gtk;
+using Cairo;
+
+public class ValaWidget : Widget {
+
+ private static const string TEXT = "Hello World!";
+ private static const int BORDER_WIDTH = 10;
+ private Pango.Layout layout;
+
+ construct {
+ this.layout = create_pango_layout (TEXT);
+ }
+
+ /*
+ * This method Gtk+ is calling on a widget to ask
+ * the widget how large it wishes to be. It's not guaranteed
+ * that Gtk+ will actually give this size to the widget.
+ */
+ public override void size_request (out Gtk.Requisition requisition) {
+ int width, height;
- // Create a new gdk.Window which we can draw on.
+ // In this case, we say that we want to be as big as the
+ // text is, plus a little border around it.
+ this.layout.get_size (out width, out height);
+ requisition.width = width / Pango.SCALE + BORDER_WIDTH * 4;
+ requisition.height = height / Pango.SCALE + BORDER_WIDTH * 4;
+ }
+
+ /*
+ * This method gets called by Gtk+ when the actual size is known
+ * and the widget is told how much space could actually be allocated.
+ * It is called every time the widget size changes, for example when the
+ * user resizes the window.
+ */
+ public override void size_allocate (Gdk.Rectangle allocation) {
+ // The base method will save the allocation and move/resize the
+ // widget's GDK window if the widget is already realized.
+ base.size_allocate (allocation);
+
+ // Move/resize other realized windows if necessary
+ }
+
+ /*
+ * This method is responsible for creating GDK (windowing system)
+ * resources. In this example we will create a new GDK window which we
+ * then draw on.
+ */
+ public override void realize () {
+ // Create a new Gdk.Window which we can draw on.
// Also say that we want to receive exposure events by setting
// the event_mask
- var attrs = Gdk.WindowAttr ();
- attrs.window_type = Gdk.WindowType.CHILD;
- attrs.width = this.allocation.width;
- attrs.wclass = Gdk.WindowClass.INPUT_OUTPUT;
- attrs.event_mask = this.get_events() | Gdk.EventMask.EXPOSURE_MASK;
- this.window = new Gdk.Window (this.get_parent_window (), attrs, 0);
-
- // Associate the gdk.Window with ourselves, Gtk+ needs a reference
- // between the widget and the gdk window
+ var attrs = Gdk.WindowAttr () {
+ window_type = Gdk.WindowType.CHILD,
+ wclass = Gdk.WindowClass.INPUT_OUTPUT,
+ event_mask = get_events () | Gdk.EventMask.EXPOSURE_MASK
+ };
+ this.window = new Gdk.Window (get_parent_window (), attrs, 0);
+ this.window.move_resize (this.allocation.x, this.allocation.y,
+ this.allocation.width, this.allocation.height);
+
+ // Associate the GDK window with ourselves, Gtk+ needs a reference
+ // between the widget and the GDK window
this.window.set_user_data (this);
- // Attach the style to the gdk.Window, a style contains colors and
- // GC contextes used for drawing
+ // Attach the style to the GDK window. A style contains colors and
+ // GC contexts used for drawing
this.style = this.style.attach (this.window);
// The default color of the background should be what
- // the style (theme engine) tells us.
+ // the style (theme engine) tells us
this.style.set_background (this.window, Gtk.StateType.NORMAL);
- this.window.move_resize (this.allocation.x, this.allocation.y,
- this.allocation.width, this.allocation.height);
- }
-
- // The unrealized method is responsible for freeing the GDK resources
- public override void unrealize ()
- {
- // De-associate the window we created in realize with ourselves
- this.window.set_user_data (null);
- }
-
- // The size_request method Gtk+ is calling on a widget to ask
- // it the widget how large it wishes to be. It's not guaranteed
- // that gtk+ will actually give this size to the widget
- public override void size_request (out Gtk.Requisition requisition)
- {
- int width, height;
-
- // In this case, we say that we want to be as big as the
- // text is, plus a little border around it.
- this._layout.get_size (out width, out height);
- requisition.width = width / Pango.SCALE + this._BORDER_WIDTH*4;
- requisition.height = height / Pango.SCALE + this._BORDER_WIDTH*4;
- }
-
- // The size_allocate is called by when the actual size is known
- // and the widget is told how much space could actually be allocated
- public override void size_allocate (Gdk.Rectangle allocation)
- {
-
- // Save the allocated space
- this.allocation = (Gtk.Allocation)allocation;
+ // Set an internal flag telling that we're realized
+ set_flags (WidgetFlags.REALIZED);
+ }
+
+ /*
+ * This method is called when the widget is asked to draw itself.
+ * Remember that this will be called a lot of times, so it's usually
+ * a good idea to write this code as optimized as it can be, don't
+ * create any resources in here.
+ */
+ public override bool expose_event (Gdk.EventExpose event) {
+ // Cairo context to draw on
+ var cr = Gdk.cairo_create (this.window);
- // If we're realized, move and resize the window to the
- // requested coordinates/positions
- if ((this.get_flags () & Gtk.WidgetFlags.REALIZED) == 0)
- return;
- this.window.move_resize (this.allocation.x, this.allocation.y,
- this.allocation.width, this.allocation.height);
- }
-
- // The do_expose_event is called when the widget is asked to draw itself
- // Remember that this will be called a lot of times, so it's usually
- // a good idea to write this code as optimized as it can be, don't
- // Create any resources in here.
- public override bool expose_event (Gdk.EventExpose event)
- {
// In this example, draw a rectangle in the foreground color
- var cr = Gdk.cairo_create (this.window);
Gdk.cairo_set_source_color (cr, this.style.fg[this.state]);
- cr.rectangle (this._BORDER_WIDTH,
- this._BORDER_WIDTH,
- this.allocation.width - 2*this._BORDER_WIDTH,
- this.allocation.height - 2*this._BORDER_WIDTH);
+ cr.rectangle (BORDER_WIDTH, BORDER_WIDTH,
+ this.allocation.width - 2 * BORDER_WIDTH,
+ this.allocation.height - 2 * BORDER_WIDTH);
cr.set_line_width (5.0);
- cr.set_line_join (Cairo.LineJoin.ROUND);
+ cr.set_line_join (LineJoin.ROUND);
cr.stroke ();
// And draw the text in the middle of the allocated space
int fontw, fonth;
- this._layout.get_pixel_size (out fontw, out fonth);
- cr.move_to ((this.allocation.width - fontw)/2,
- (this.allocation.height - fonth)/2);
- Pango.cairo_update_layout (cr, this._layout);
- Pango.cairo_show_layout (cr, this._layout);
- return true;
- }
-
- static int main (string[] args) {
+ this.layout.get_pixel_size (out fontw, out fonth);
+ cr.move_to ((this.allocation.width - fontw) / 2,
+ (this.allocation.height - fonth) / 2);
+ Pango.cairo_update_layout (cr, this.layout);
+ Pango.cairo_show_layout (cr, this.layout);
+ return true;
+ }
+
+ /*
+ * This method is responsible for freeing the GDK resources.
+ */
+ public override void unrealize () {
+ // The base method will de-associate the GDK window we created in
+ // method 'realize' with ourselves.
+ base.unrealize ();
+
+ // De-associate other windows with 'set_user_data (null)' if necessary
+ }
+
+ static int main (string[] args) {
Gtk.init (ref args);
- Gtk.Window win = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
- win.set_border_width (5);
- win.set_title ("Widget test");
- win.destroy += Gtk.main_quit;
+ var win = new Window (WindowType.TOPLEVEL);
+ win.border_width = 5;
+ win.title = "Widget test";
+ win.destroy.connect (Gtk.main_quit);
- Gtk.Frame frame = new Gtk.Frame ("Example Vala Widget");
+ var frame = new Frame ("Example Vala Widget");
win.add (frame);
- ValaWidget w = new ValaWidget ();
- frame.add (w);
+ var widget = new ValaWidget ();
+ frame.add (widget);
win.show_all ();
Gtk.main ();
return 0;
- }
+ }
}
diff --git a/tests/examples/hildon-sample.test b/tests/examples/hildon-sample.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/hildon-sample.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/hildon-sample.vala b/tests/examples/hildon-sample.vala
new file mode 100644
index 0000000..74ba9ae
--- /dev/null
+++ b/tests/examples/hildon-sample.vala
@@ -0,0 +1,48 @@
+
+// http://live.gnome.org/Vala/HildonSample vala-test:examples/hildon-sample.vala
+
+/* Hildon Vala Sample Code */
+using Gtk;
+using Hildon;
+
+public class Sample : Hildon.Program {
+
+ private Hildon.Window window;
+
+ construct {
+ window = new Hildon.Window ();
+ window.destroy.connect (Gtk.main_quit);
+
+ add_window (window);
+
+ Environment.set_application_name ("Hildon Vala Sample");
+
+ var label = new Gtk.Label ("Vala for Hildon Desktop!");
+ var button = new Gtk.Button.with_label ("Press Me!");
+
+ button.clicked.connect (() => {
+ label.set_markup ("<big><b>Hello Vala!</b></big>");
+ });
+
+ var vbox = new Gtk.VBox (false, 2);
+
+ vbox.pack_start (label, true, true, 2);
+ vbox.pack_start (button, false, true, 2);
+
+ window.add (vbox);
+ }
+
+ public void run () {
+ window.show_all ();
+ Gtk.main ();
+ }
+
+ static int main (string[] args) {
+ Gtk.init (ref args);
+
+ var app = new Sample ();
+ app.run ();
+
+ return 0;
+ }
+}
diff --git a/tests/examples/input-character.test b/tests/examples/input-character.test
new file mode 100755
index 0000000..133a552
--- /dev/null
+++ b/tests/examples/input-character.test
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+TESTRUN=skip
+. common.sh
+
+echo 1 2 0 | sh -c "./$TESTNAME $TESTARGS $@"
\ No newline at end of file
diff --git a/tests/examples/input-character.vala b/tests/examples/input-character.vala
new file mode 100644
index 0000000..07bfe76
--- /dev/null
+++ b/tests/examples/input-character.vala
@@ -0,0 +1,13 @@
+
+// http://live.gnome.org/Vala/InputSamples vala-test:examples/input-character.vala
+
+public static void main (string[] args) {
+ int c = 0;
+ stdout.printf ("Type something and press enter. Type '0' to quit\n");
+ do {
+ c = stdin.getc ();
+ if (c > 10) {
+ stdout.printf ("%c (%d)\n", c, c);
+ }
+ } while (c != '0');
+}
diff --git a/tests/examples/input-readline.test b/tests/examples/input-readline.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/input-readline.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/input-readline.vala b/tests/examples/input-readline.vala
new file mode 100644
index 0000000..0d7c6b1
--- /dev/null
+++ b/tests/examples/input-readline.vala
@@ -0,0 +1,12 @@
+
+// http://live.gnome.org/Vala/InputSamples vala-test:examples/input-readline.vala
+
+void main () {
+ while (true) {
+ var name = Readline.readline ("Please enter your name: ");
+ if (name != null && name != "") {
+ stdout.printf ("Hello, %s\n", name);
+ Readline.History.add (name);
+ }
+ }
+}
diff --git a/tests/examples/input-scanf.test b/tests/examples/input-scanf.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/input-scanf.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/input-scanf.vala b/tests/examples/input-scanf.vala
new file mode 100644
index 0000000..b0b3e0c
--- /dev/null
+++ b/tests/examples/input-scanf.vala
@@ -0,0 +1,29 @@
+
+// http://live.gnome.org/Vala/InputSamples vala-test:examples/input-scanf.vala
+
+public static void main() {
+
+ float f;
+ double d;
+ int i;
+ long l;
+
+ stdout.printf("Enter a float : ");
+ stdin.scanf("%f", out f);
+
+ stdout.printf("Enter a double : ");
+ stdin.scanf("%lf", out d);
+
+ stdout.printf("Enter an integer: ");
+ stdin.scanf("%d", out i);
+
+ stdout.printf("Enter a long : ");
+ stdin.scanf("%ld", out l);
+
+ stdout.printf("The numbers you entered\n");
+ stdout.printf("Float : %f\n",f);
+ stdout.printf("Double : %lf\n",d);
+ stdout.printf("Integer: %d\n",i);
+ stdout.printf("Long : %ld\n",l);
+
+}
diff --git a/tests/examples/input-stdin-line.test b/tests/examples/input-stdin-line.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/input-stdin-line.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/input-stdin-line.vala b/tests/examples/input-stdin-line.vala
new file mode 100644
index 0000000..265a3ee
--- /dev/null
+++ b/tests/examples/input-stdin-line.vala
@@ -0,0 +1,11 @@
+
+// http://live.gnome.org/Vala/InputSamples vala-test:examples/input-stdin-line.vala
+
+int main () {
+ stdout.printf ("Please enter your name: ");
+ string? name = stdin.read_line ();
+ if (name != null) {
+ stdout.printf ("Hello, %s!\n", name);
+ }
+ return 0;
+}
diff --git a/tests/examples/input-stdin.test b/tests/examples/input-stdin.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/input-stdin.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/input-stdin.vala b/tests/examples/input-stdin.vala
new file mode 100644
index 0000000..567eb14
--- /dev/null
+++ b/tests/examples/input-stdin.vala
@@ -0,0 +1,26 @@
+
+// http://live.gnome.org/Vala/InputSamples vala-test:examples/input-stdin.vala
+
+/*
+ * We use the fact that char[] allocates space
+ * and that FileStream.gets takes a char[] but returns a string!
+ *
+ * Note that stdin.gets uses the "safe" fgets(), not the unsafe gets()
+ */
+string read_stdin () {
+ var input = new StringBuilder ();
+ var buffer = new char[1024];
+ while (!stdin.eof ()) {
+ string read_chunk = stdin.gets (buffer);
+ if (read_chunk != null) {
+ input.append (read_chunk);
+ }
+ }
+ return input.str;
+}
+
+int main () {
+ string name = read_stdin ();
+ stdout.printf ("\n-----\n%s\n", name);
+ return 0;
+}
diff --git a/tests/examples/json-google-translator.test b/tests/examples/json-google-translator.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/json-google-translator.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/json-google-translator.vala b/tests/examples/json-google-translator.vala
new file mode 100644
index 0000000..4313939
--- /dev/null
+++ b/tests/examples/json-google-translator.vala
@@ -0,0 +1,42 @@
+
+// http://live.gnome.org/Vala/JsonSample vala-test:examples/json-google-translator.vala
+
+string translate (string text, string input_language, string output_language) throws Error {
+
+ string uri = "http://ajax.googleapis.com/ajax/services/language/translate";
+ string version = "1.0";
+ string full_uri = "%s?v=%s&q=%s&langpair=%s|%s".printf (uri, version,
+ Soup.URI.encode (text, null),
+ input_language, output_language);
+
+ var session = new Soup.SessionAsync ();
+ var message = new Soup.Message ("GET", full_uri);
+ session.send_message (message);
+
+ var parser = new Json.Parser ();
+ parser.load_from_data (message.response_body.flatten ().data, -1);
+
+ var root_object = parser.get_root ().get_object ();
+ string translated_text = root_object.get_object_member ("responseData")
+ .get_string_member ("translatedText");
+
+ /* Here you can get the value of responseDetails */
+// int64 response_details = root_object.get_int_member ("responseDetails");
+// stdout.printf ("Response Details : %lld\n", response_details);
+
+ /* Here you can get the value of responseStatus */
+// int64 response_status = root_object.get_int_member ("responseStatus");
+// stdout.printf ("Response Status : %lld\n", response_status);
+
+ return translated_text;
+}
+
+void main () {
+ try {
+ string original_text = "Hello World";
+ string translated_text = translate (original_text, "en", "ar");
+ stdout.printf ("Translated text: %s\n", translated_text);
+ } catch (Error e) {
+ stderr.printf ("I think something went wrong!\n");
+ }
+}
diff --git a/tests/examples/json-sample.test b/tests/examples/json-sample.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/json-sample.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/json-sample.vala b/tests/examples/json-sample.vala
new file mode 100644
index 0000000..f8aed23
--- /dev/null
+++ b/tests/examples/json-sample.vala
@@ -0,0 +1,30 @@
+
+// http://live.gnome.org/Vala/JsonSample vala-test:examples/json-sample.vala
+
+void main () {
+ var uri = "http://ws.geonames.org/searchJSON?formatted=true&q=%s&maxRows=100&lang=en&style=medium".printf ("asakusa");
+
+ var session = new Soup.SessionSync ();
+ var message = new Soup.Message ("GET", uri);
+ session.send_message (message);
+
+ try {
+ var parser = new Json.Parser ();
+ parser.load_from_data (message.response_body.flatten ().data, -1);
+
+ var root_object = parser.get_root ().get_object ();
+ int64 count = root_object.get_int_member ("totalResultsCount");
+ stdout.printf ("%lld results:\n\n", count);
+
+ foreach (var geonode in root_object.get_array_member ("geonames").get_elements ()) {
+ var geoname = geonode.get_object ();
+ stdout.printf ("%s\n%s\n%f\n%f\n\n",
+ geoname.get_string_member ("name"),
+ geoname.get_string_member ("countryName"),
+ geoname.get_double_member ("lng"),
+ geoname.get_double_member ("lat"));
+ }
+ } catch (Error e) {
+ stderr.printf ("I guess something is not working...\n");
+ }
+}
diff --git a/tests/examples/libxml2.test b/tests/examples/libxml2.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/libxml2.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/libxml2.vala b/tests/examples/libxml2.vala
new file mode 100644
index 0000000..736be74
--- /dev/null
+++ b/tests/examples/libxml2.vala
@@ -0,0 +1,132 @@
+
+// http://live.gnome.org/Vala/XmlSample vala-test:examples/libxml2.vala
+
+/*
+ * Various operations with libxml2: Parsing and creating an XML file
+ */
+
+using Xml;
+
+class XmlSample {
+
+ // Line indentation
+ private int indent = 0;
+
+ private void print_indent (string node, string content, char token = '+') {
+ string indent = string.nfill (this.indent * 2, ' ');
+ stdout.printf ("%s%c%s: %s\n", indent, token, node, content);
+ }
+
+ public void parse_file (string path) {
+ // Parse the document from path
+ Xml.Doc* doc = Parser.parse_file (path);
+ if (doc == null) {
+ stderr.printf ("File %s not found or permissions missing", path);
+ return;
+ }
+
+ // Get the root node. notice the dereferencing operator -> instead of .
+ Xml.Node* root = doc->get_root_element ();
+ if (root == null) {
+ // Free the document manually before returning
+ delete doc;
+ stderr.printf ("The xml file '%s' is empty", path);
+ return;
+ }
+
+ print_indent ("XML document", path, '-');
+
+ // Print the root node's name
+ print_indent ("Root node", root->name);
+
+ // Let's parse those nodes
+ parse_node (root);
+
+ // Free the document
+ delete doc;
+ }
+
+ private void parse_node (Xml.Node* node) {
+ this.indent++;
+ // Loop over the passed node's children
+ for (Xml.Node* iter = node->children; iter != null; iter = iter->next) {
+ // Spaces between tags are also nodes, discard them
+ if (iter->type != ElementType.ELEMENT_NODE) {
+ continue;
+ }
+
+ // Get the node's name
+ string node_name = iter->name;
+ // Get the node's content with <tags> stripped
+ string node_content = iter->get_content ();
+ print_indent (node_name, node_content);
+
+ // Now parse the node's properties (attributes) ...
+ parse_properties (iter);
+
+ // Followed by its children nodes
+ parse_node (iter);
+ }
+ this.indent--;
+ }
+
+ private void parse_properties (Xml.Node* node) {
+ // Loop over the passed node's properties (attributes)
+ for (Xml.Attr* prop = node->properties; prop != null; prop = prop->next) {
+ string attr_name = prop->name;
+
+ // Notice the ->children which points to a Node*
+ // (Attr doesn't feature content)
+ string attr_content = prop->children->content;
+ print_indent (attr_name, attr_content, '|');
+ }
+ }
+
+ public static string create_simple_xml () {
+ Xml.Doc* doc = new Xml.Doc ("1.0");
+
+ Xml.Ns* ns = new Xml.Ns (null, "", "foo");
+ ns->type = Xml.ElementType.ELEMENT_NODE;
+ Xml.Node* root = new Xml.Node (ns, "simple");
+ doc->set_root_element (root);
+
+ root->new_prop ("property", "value");
+
+ Xml.Node* subnode = root->new_text_child (ns, "subnode", "");
+ subnode->new_text_child (ns, "textchild", "another text" );
+ subnode->new_prop ("subprop", "escaping \" and < and >" );
+
+ Xml.Node* comment = new Xml.Node.comment ("This is a comment");
+ root->add_child (comment);
+
+ string xmlstr;
+ // This throws a compiler warning, see bug 547364
+ doc->dump_memory (out xmlstr);
+
+ delete doc;
+ return xmlstr;
+ }
+}
+
+int main (string[] args) {
+
+ if (args.length < 2) {
+ stderr.printf ("Argument required!\n");
+ return 1;
+ }
+
+ // Initialisation, not instantiation since the parser is a static class
+ Parser.init ();
+
+ string simple_xml = XmlSample.create_simple_xml ();
+ stdout.printf ("Simple XML is:\n%s\n", simple_xml);
+
+ var sample = new XmlSample ();
+ // Parse the file listed in the first passed argument
+ sample.parse_file (args[1]);
+
+ // Do the parser cleanup to free the used memory
+ Parser.cleanup ();
+
+ return 0;
+}
diff --git a/tests/examples/list.test b/tests/examples/list.test
index a23ddd3..0174331 100755
--- a/tests/examples/list.test
+++ b/tests/examples/list.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/list.vala b/tests/examples/list.vala
index c5bfea6..4fe64ca 100644
--- a/tests/examples/list.vala
+++ b/tests/examples/list.vala
@@ -1,8 +1,8 @@
// http://live.gnome.org/Vala/ListSample vala-test:examples/list.vala
-public static int main (string[] args) {
- List<string> list = new List<string> ();
+int main (string[] args) {
+ var list = new List<string> ();
list.append ("one");
list.append ("two");
list.append ("three");
diff --git a/tests/examples/lm-send-async.test b/tests/examples/lm-send-async.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/lm-send-async.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/lm-send-async.vala b/tests/examples/lm-send-async.vala
new file mode 100644
index 0000000..99a604d
--- /dev/null
+++ b/tests/examples/lm-send-async.vala
@@ -0,0 +1,159 @@
+
+// http://live.gnome.org/Vala/LoudmouthSample vala-test:examples/lm-send-async.vala
+
+using Gtk;
+using Lm;
+
+class MainWindow : Window {
+
+ private Label status;
+ private Button dconnect;
+ private Button send;
+ private Entry server;
+ private Entry message;
+ private Entry recipient;
+ private Entry username;
+ private Entry password;
+ private Entry resource;
+
+ private Connection cn;
+
+ public MainWindow () {
+ this.title = "jabber-send";
+ create_widgets ();
+ this.destroy.connect (on_quit);
+ this.send.clicked.connect (send_message);
+ this.dconnect.clicked.connect (do_connect);
+ }
+
+ private void create_widgets () {
+ var hboxbut = new HBox (false, 5);
+ status = new Label ("");
+ dconnect = new Button.with_label ("Connect");
+ send = new Button.with_label ("Send Message");
+
+ server = new Entry ();
+ username = new Entry ();
+ password = new Entry ();
+ resource = new Entry ();
+ recipient = new Entry ();
+ message = new Entry ();
+
+ send.sensitive = false;
+ status.label = "Disconnected";
+ resource.text = "jabber-send";
+
+ hboxbut.add (dconnect);
+ hboxbut.add (send);
+
+ var vbox = new VBox (false, 5);
+ vbox.pack_start (hbox ("Server:", server), false, false, 0);
+ vbox.pack_start (hbox ("Username:", username), false, false, 0);
+ vbox.pack_start (hbox ("Password:", password), false, false, 0);
+ vbox.pack_start (hbox ("Resource:", resource), false, false, 0);
+ vbox.pack_start (hbox ("Recipient:", recipient), false, false, 0);
+ vbox.pack_start (hbox ("Message:", message), false, false, 0);
+ vbox.pack_start (status, true, true, 0);
+ vbox.pack_start (hboxbut, false, false, 0);
+ add (vbox);
+ }
+
+ private HBox hbox (string label, Widget w) {
+ var box = new HBox (false, 5);
+ box.pack_start (new Label.with_mnemonic (label), false, false, 5);
+ box.pack_start (w, true, true, 5);
+ return box;
+ }
+
+ private void on_quit () {
+ if (cn != null) {
+ do_disconnect ();
+ }
+ Gtk.main_quit ();
+ }
+
+ private void connected (Connection connection, bool success) {
+ if (success) {
+ status.label = "Opened connection and authenticated";
+ dconnect.label = "Disconnect";
+ dconnect.clicked.disconnect (do_connect);
+ dconnect.clicked.connect (do_disconnect);
+ send.sensitive = true;
+ } else {
+ status.label = "Authentication failed";
+ }
+ dconnect.sensitive = true;
+ }
+
+ private void send_message () {
+ var m = new Message (recipient.text, Lm.MessageType.MESSAGE);
+ m.node.add_child ("body", message.text);
+
+ try {
+ cn.send (m);
+ status.label = "Message sent";
+ } catch (GLib.Error e) {
+ status.label = "Error: " + e.message;
+ }
+ }
+
+ private void auth (Connection connection, bool success) {
+ if (!success) {
+ status.label = "Connection failed";
+ dconnect.sensitive = true;
+ return;
+ }
+
+ status.label = "Authenticating with " + server.text;
+ try {
+ connection.authenticate (username.text, password.text,
+ resource.text, connected, null);
+ } catch (GLib.Error e) {
+ status.label = "Error: " + e.message;
+ }
+ }
+
+ private void do_connect () {
+ if (cn != null && cn.is_open ()) {
+ try {
+ cn.close ();
+ } catch (GLib.Error e) {
+ status.label = "Error: " + e.message;
+ return;
+ }
+ }
+
+ cn = new Connection (server.text);
+
+ try {
+ cn.open (auth, null);
+ status.label = "Loading connection to " + server.text;
+ dconnect.sensitive = false;
+ } catch (GLib.Error e) {
+ status.label = "Error: " + e.message;
+ }
+ }
+
+ private void do_disconnect () {
+ try {
+ cn.close ();
+ status.label = "Disconnected";
+ dconnect.clicked.disconnect (do_disconnect);
+ dconnect.clicked.connect (do_connect);
+ dconnect.label = "Connect";
+ send.sensitive = false;
+ } catch (GLib.Error e) {
+ status.label = "Error: " + e.message;
+ }
+ }
+
+ static int main (string[] args) {
+ Gtk.init (ref args);
+
+ var window = new MainWindow ();
+ window.show_all ();
+
+ Gtk.main ();
+ return 0;
+ }
+}
diff --git a/tests/examples/lm-send-sync.test b/tests/examples/lm-send-sync.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/lm-send-sync.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/lm-send-sync.vala b/tests/examples/lm-send-sync.vala
new file mode 100644
index 0000000..c5234d5
--- /dev/null
+++ b/tests/examples/lm-send-sync.vala
@@ -0,0 +1,119 @@
+
+// http://live.gnome.org/Vala/LoudmouthSample vala-test:examples/lm-send-sync.vala
+
+/*
+ * Copyright (C) 2004 Imendio AB
+ * Copyright (C) 2009 Harley Laue <losinggeneration gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Description:
+ * A little program that let you send jabber messages to another person.
+ * Note: The synchronous API is being removed in the 2.0 branch of Loudmouth.
+ *
+ * Build instructions:
+ * valac --pkg loudmouth-1.0 lm-send-sync.vala
+ */
+
+using Lm;
+
+class LmSyncDemo {
+
+ static string server = null;
+ static string message = null;
+ static string username = null;
+ static string password = null;
+ static string recipient = null;
+ static string resource;
+ static uint port;
+
+ const OptionEntry[] options = {
+ { "server", 's', 0, OptionArg.STRING, ref server, "Server to connect to. You need to have a valid login on that server.", "server.org" },
+ { "username", 'u', 0, OptionArg.STRING, ref username, "Username to used for the server you selected.", "some_username" },
+ { "password", 'p', 0, OptionArg.STRING, ref password, "Password to use for entered username.", "some_password" },
+ { "recipient",'t', 0, OptionArg.STRING, ref recipient, "User to send message to.", "someone server org" },
+ { "message", 'm', 0, OptionArg.STRING, ref message, "Message to send to recipient.", "\"some message to send\"" },
+ { "resource", 'r', OptionFlags.OPTIONAL_ARG, OptionArg.STRING, ref resource, "Resource to use when connecting.", "jabber-send" },
+ { "port", 'o', OptionFlags.OPTIONAL_ARG, OptionArg.INT, ref port, "Port to use when connecting to selected server.", "5222" },
+ { null }
+ };
+
+ static int main (string[] args) {
+ resource = "jabber-send";
+ port = Connection.DEFAULT_PORT;
+
+ try {
+ var opt_context = new OptionContext ("- Loudmouth Synchronous Sample");
+ opt_context.set_help_enabled (true);
+ opt_context.add_main_entries (options, null);
+ opt_context.parse (ref args);
+ if (server == null || message == null || recipient == null
+ || username == null || password == null)
+ {
+ print ("You must provide at least username, password, server, recipient, and message\n");
+ print ("%s", opt_context.get_help (true, null));
+ return 1;
+ }
+ } catch (OptionError e) {
+ stdout.printf ("%s\n", e.message);
+ stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]);
+ return 1;
+ }
+
+ var connection = new Connection (server);
+
+ try {
+ print ("Connecting to %s\n", server);
+ connection.open_and_block ();
+
+ print ("Authenticating as '%s' with '%s' and the resource '%s'\n",
+ username, password, resource);
+ connection.authenticate_and_block (username, password, resource);
+
+ var m = new Message (recipient, MessageType.MESSAGE);
+ m.node.add_child ("body", message);
+
+ print ("Sending message '%s' to %s\n", message, recipient);
+ connection.send (m);
+
+ print ("Closing connection\n");
+ connection.close ();
+ } catch (GLib.Error e) {
+ stderr.printf ("Error: %s\n", e.message);
+ return 1;
+ } finally {
+ /* This will become a lot easier with RAII support in
+ Loudmouth 1.5.x. You won't need to manually close the connection
+ and the whole 'finally' block will become unnecessary, since
+ the connection will get closed by its destructor if it's open. */
+ if (connection.is_open ()) {
+ finally_close (connection);
+ }
+ }
+
+ return 0;
+ }
+
+ static void finally_close (Connection connection) {
+ try {
+ connection.close ();
+ } catch (GLib.Error e) {
+ error ("Can't close connection.");
+ }
+ }
+}
diff --git a/tests/examples/lua-table.test b/tests/examples/lua-table.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/lua-table.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/lua-table.vala b/tests/examples/lua-table.vala
new file mode 100644
index 0000000..c84028d
--- /dev/null
+++ b/tests/examples/lua-table.vala
@@ -0,0 +1,43 @@
+
+// http://live.gnome.org/Vala/LuaSample vala-test:examples/lua-table.vala
+
+using Lua;
+
+static int main () {
+
+ var vm = new LuaVM ();
+ vm.open_libs ();
+
+ // Create a Lua table with name 'foo'
+ vm.new_table ();
+ for (int i = 1; i <= 5; i++) {
+ vm.push_number (i); // Push the table index
+ vm.push_number (i * 2); // Push the cell value
+ vm.raw_set (-3); // Stores the pair in the table
+ }
+ vm.set_global ("foo");
+
+ // Ask Lua to run our little script
+ vm.do_string ("""
+
+ -- Receives a table, returns the sum of its components.
+ io.write("The table the script received has:\n");
+ x = 0
+ for i = 1, #foo do
+ print(i, foo[i])
+ x = x + foo[i]
+ end
+ io.write("Returning data back to C\n");
+ return x
+
+ """);
+
+ // Get the returned value at the top of the stack (index -1)
+ var sum = vm.to_number (-1);
+
+ stdout.printf ("Script returned: %.0f\n", sum);
+
+ vm.pop (1); // Take the returned value out of the stack
+
+ return 0;
+}
diff --git a/tests/examples/lua-test.test b/tests/examples/lua-test.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/lua-test.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/lua-test.vala b/tests/examples/lua-test.vala
new file mode 100644
index 0000000..bc16020
--- /dev/null
+++ b/tests/examples/lua-test.vala
@@ -0,0 +1,24 @@
+
+// http://live.gnome.org/Vala/LuaSample vala-test:examples/lua-test.vala
+
+using Lua;
+
+static int my_func (LuaVM vm) {
+ stdout.printf ("Vala Code From Lua Code! (%f)\n", vm.to_number (1));
+ return 1;
+}
+
+static int main (string[] args) {
+
+ string code = """
+ print "Lua Code From Vala Code!"
+ my_func(33)
+ """;
+
+ var vm = new LuaVM ();
+ vm.open_libs ();
+ vm.register ("my_func", my_func);
+ vm.do_string (code);
+
+ return 0;
+}
diff --git a/tests/examples/markup-parser.test b/tests/examples/markup-parser.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/markup-parser.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/markup-parser.vala b/tests/examples/markup-parser.vala
new file mode 100644
index 0000000..d5424c2
--- /dev/null
+++ b/tests/examples/markup-parser.vala
@@ -0,0 +1,75 @@
+
+// http://live.gnome.org/Vala/MarkupSample vala-test:examples/markup-parser.vala
+
+class TestParser: Object {
+
+ const MarkupParser parser = { // It's a structure, not an object
+ start,// when an element opens
+ end, // when an element closes
+ text, // when text is found
+ null, // when comments are found
+ null // when errors occur
+ };
+
+ MarkupParseContext context;
+
+ int depth = 0; // used to indent the output
+
+ construct {
+ context = new MarkupParseContext(
+ parser, // the structure with the callbacks
+ 0, // MarkupParseFlags
+ this, // extra argument for the callbacks, methods in this case
+ destroy // when the parsing ends
+ );
+ }
+
+ void print_indent () {
+ for (var i=0; i < depth; i++)
+ print ("\t");
+ }
+
+ void destroy() {
+ print ("Releasing any allocated resource\n");
+ }
+
+ public bool parse(string content) throws MarkupError {
+ return context.parse(
+ content,
+ -1); // content size or -1 if it's zero-terminated
+ }
+
+ void start (MarkupParseContext context, string name,
+ string[] attr_names, string[] attr_values) throws MarkupError {
+ print_indent ();
+ print ("begin %s {", name);
+ for (int i = 0; i < attr_names.length; i++)
+ print ("%s: %s", attr_names[i], attr_values[i]);
+ print ("}\n");
+ depth ++;
+ }
+
+ void end (MarkupParseContext context, string name) throws MarkupError {
+ depth --;
+ print_indent ();
+ print ("end %s\n", name);
+ }
+
+ void text (MarkupParseContext context,
+ string text, size_t text_len) throws MarkupError {
+ print_indent ();
+ print ("text '%s'\n", text);
+ }
+}
+
+void main()
+{
+ TestParser parser = new TestParser ();
+ string data = "<elm1 attrib ='hello'><elm2/><elm3>muhehehe</elm3></elm1>";
+ try {
+ parser.parse (data);
+ }
+ catch (Error e) {
+ print ("%s\n", e.message);
+ }
+}
diff --git a/tests/examples/number-guessing.test b/tests/examples/number-guessing.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/number-guessing.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/number-guessing.vala b/tests/examples/number-guessing.vala
index 2b06c24..ae4bba9 100644
--- a/tests/examples/number-guessing.vala
+++ b/tests/examples/number-guessing.vala
@@ -25,7 +25,7 @@ public class NumberGuessing {
stdout.printf ("Try #%d\n", try_count);
stdout.printf ("Please enter a number between %d and %d: ", min, max);
- int input = read_line ().to_int ();
+ int input = stdin.read_line ().to_int ();
if (number == input) {
stdout.printf ("Congratulations! You win.\n");
@@ -43,15 +43,3 @@ public class NumberGuessing {
return 0;
}
}
-
-/* This method could be included in glib-2.0.vapi for
- class FileStream, see Bugzilla entry #582178 */
-static string read_line () {
- var input = new StringBuilder ();
- while (!stdin.eof ()) {
- char c = (char) stdin.getc ();
- if (c == '\n') break;
- input.append_c (c);
- }
- return input.str;
-}
diff --git a/tests/examples/opengl-glfw.test b/tests/examples/opengl-glfw.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/opengl-glfw.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/opengl-glfw.vala b/tests/examples/opengl-glfw.vala
new file mode 100644
index 0000000..f6d178f
--- /dev/null
+++ b/tests/examples/opengl-glfw.vala
@@ -0,0 +1,40 @@
+
+// http://live.gnome.org/Vala/OpenGLSamples vala-test:examples/opengl-glfw.vala
+
+using GLFW;
+using GL;
+
+int main () {
+ bool running = true;
+
+ // Initialize GLFW
+ glfwInit ();
+
+ // Open an OpenGL window (you can also try Mode.FULLSCREEN)
+ if (!glfwOpenWindow (640, 480, 0, 0, 0, 0, 0, 0, Mode.WINDOW)) {
+ glfwTerminate ();
+ return 1;
+ }
+
+ // Main loop
+ while (running) {
+ // OpenGL rendering goes here...
+ glClear (GL_COLOR_BUFFER_BIT);
+ glBegin (GL_TRIANGLES);
+ glVertex3f ( 0.0f, 1.0f, 0.0f);
+ glVertex3f (-1.0f,-1.0f, 0.0f);
+ glVertex3f ( 1.0f,-1.0f, 0.0f);
+ glEnd ();
+
+ // Swap front and back rendering buffers
+ glfwSwapBuffers ();
+ // Check if ESC key was pressed or window was closed
+ running = !glfwGetKey (Key.ESC) && (bool) glfwGetWindowParam (WindowParam.OPENED);
+ }
+
+ // Close window and terminate GLFW
+ glfwTerminate ();
+
+ // Exit program
+ return 0;
+}
diff --git a/tests/examples/opengl-glut.test b/tests/examples/opengl-glut.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/opengl-glut.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/opengl-glut.vala b/tests/examples/opengl-glut.vala
new file mode 100644
index 0000000..b77e0c7
--- /dev/null
+++ b/tests/examples/opengl-glut.vala
@@ -0,0 +1,374 @@
+
+// http://live.gnome.org/Vala/OpenGLSamples vala-test:examples/opengl-glut.vala
+
+using GLib;
+using GL;
+using GLU;
+using GLUT;
+
+public enum EColorBack {BLACK, DARKRED, DARKGREEN, DARKBLUE}
+public enum EColorDraw {WHITE, LIGHTRED, LIGHTGREEN, LIGHTBLUE}
+public enum ESolid {WIRE, SOLID}
+public enum EModel {TEAPOT, CUBE, SPHERE, CONE, TORUS, DODECAHEDRON, OCTAHEDRON, TETRAHEDRON, ICOSAHEDRON}
+public enum EAxes {AXESNO, AXESSIMPLE}
+
+public struct SRgba {
+ public GLdouble R;
+ public GLdouble G;
+ public GLdouble B;
+ public GLdouble A;
+
+ public SRgba (GLdouble r = 0, GLdouble g = 0, GLdouble b = 0, GLdouble a = 1) {
+ R = r;
+ G = g;
+ B = b;
+ A = a;
+ }
+}
+
+public struct SPreferences {
+ public SRgba ColorFondo;
+ public SRgba ColorDibujo;
+ public bool Iluminacion;
+ public ESolid Solid;
+ public EModel Model;
+ public EAxes Axes;
+ public bool Animation;
+
+ public SPreferences () {
+ ColorFondo = SRgba (0.0f, 0.0f, 0.0f, 1.0f);
+ ColorDibujo = SRgba (1.0f, 1.0f, 1.0f, 1.0f);
+ Iluminacion = true;
+ Solid = ESolid.WIRE;
+ Model = EModel.TEAPOT;
+ Axes = EAxes.AXESNO;
+ Animation = false;
+ }
+}
+
+public class Example : Object {
+
+ private static GLfloat alpha;
+ private static GLfloat beta;
+ private static int x0;
+ private static int y0;
+ private static SPreferences preferences;
+
+ protected static void on_glutDisplayFunc () {
+
+ glClearColor ((GLclampf) preferences.ColorFondo.R,
+ (GLclampf) preferences.ColorFondo.G,
+ (GLclampf) preferences.ColorFondo.B,
+ (GLclampf) preferences.ColorFondo.A);
+
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glColor3d (preferences.ColorDibujo.R,
+ preferences.ColorDibujo.G,
+ preferences.ColorDibujo.B);
+
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+ gluPerspective (20.0f, 1.0f, 1.0f, 10.0f);
+ glMatrixMode (GL_MODELVIEW);
+ glLoadIdentity ();
+ gluLookAt (0.0f, 0.0f, 5.0f,
+ 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f);
+ glRotatef (alpha, 1.0f, 0.0f, 0.0f);
+ glRotatef (beta, 0.0f, 1.0f, 0.0f);
+
+ if (preferences.Axes == EAxes.AXESSIMPLE) {
+ glBegin (GL_LINES);
+ glVertex3f (0.0f, 0.0f, 0.0f);
+ glVertex3f (0.8f, 0.0f, 0.0f);
+ glVertex3f (0.0f, 0.0f, 0.0f);
+ glVertex3f (0.0f, 0.8f, 0.0f);
+ glVertex3f (0.0f, 0.0f, 0.0f);
+ glVertex3f (0.0f, 0.0f, 0.8f);
+ glEnd ();
+ }
+
+ if (preferences.Solid == ESolid.WIRE ) {
+ switch (preferences.Model) {
+ case EModel.TEAPOT:
+ glutWireTeapot (0.5);
+ break;
+ case EModel.CUBE:
+ glutWireCube (0.5);
+ break;
+ case EModel.SPHERE:
+ glutWireSphere (0.5, 40, 40);
+ break;
+ case EModel.CONE:
+ glutWireCone (0.5, 0.8, 40, 40);
+ break;
+ case EModel.TORUS:
+ glutWireTorus (0.2, 0.5, 40, 40);
+ break;
+ case EModel.DODECAHEDRON:
+ glutWireDodecahedron ();
+ break;
+ case EModel.OCTAHEDRON:
+ glutWireOctahedron ();
+ break;
+ case EModel.TETRAHEDRON:
+ glutWireTetrahedron ();
+ break;
+ case EModel.ICOSAHEDRON:
+ glutWireIcosahedron ();
+ break;
+ }
+ } else { // ESolid.SOLID
+ switch (preferences.Model) {
+ case EModel.TEAPOT:
+ glutSolidTeapot (0.5);
+ break;
+ case EModel.CUBE:
+ glutSolidCube (0.5);
+ break;
+ case EModel.SPHERE:
+ glutSolidSphere (0.5, 40, 40);
+ break;
+ case EModel.CONE:
+ glutSolidCone (0.5, 0.8, 40, 40);
+ break;
+ case EModel.TORUS:
+ glutSolidTorus (0.2, 0.5, 40, 40);
+ break;
+ case EModel.DODECAHEDRON:
+ glutSolidDodecahedron ();
+ break;
+ case EModel.OCTAHEDRON:
+ glutSolidOctahedron ();
+ break;
+ case EModel.TETRAHEDRON:
+ glutSolidTetrahedron ();
+ break;
+ case EModel.ICOSAHEDRON:
+ glutSolidIcosahedron ();
+ break;
+ }
+ }
+
+ glFlush ();
+ glutSwapBuffers ();
+ }
+
+ protected static void on_glutMouseFunc (int button, int state, int x, int y) {
+ if ((button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN)) {
+ x0 = x;
+ y0 = y;
+ }
+ }
+
+ protected static void on_glutMotionFunc (int x, int y) {
+ alpha = (alpha + (y - y0));
+ beta = (beta + (x - x0));
+ x0 = x;
+ y0 = y;
+ glutPostRedisplay();
+ }
+
+ protected static void on_glutCreateMenu (int opcion) { }
+
+ protected static void on_glutCreateMenu_EColorBack (int opcion) {
+ switch (opcion) {
+ case EColorBack.BLACK:
+ preferences.ColorFondo.R = 0.0f;
+ preferences.ColorFondo.G = 0.0f;
+ preferences.ColorFondo.B = 0.0f;
+ break;
+ case EColorBack.DARKRED:
+ preferences.ColorFondo.R = 0.25f;
+ preferences.ColorFondo.G = 0.05f;
+ preferences.ColorFondo.B = 0.05f;
+ break;
+ case EColorBack.DARKGREEN:
+ preferences.ColorFondo.R = 0.05f;
+ preferences.ColorFondo.G = 0.25f;
+ preferences.ColorFondo.B = 0.05f;
+ break;
+ case EColorBack.DARKBLUE:
+ preferences.ColorFondo.R = 0.05f;
+ preferences.ColorFondo.G = 0.05f;
+ preferences.ColorFondo.B = 0.25f;
+ break;
+ }
+ glutPostRedisplay();
+ }
+
+ protected static void on_glutCreateMenu_EColorDraw (int opcion) {
+ switch (opcion) {
+ case EColorDraw.WHITE:
+ preferences.ColorDibujo.R = 1.0f;
+ preferences.ColorDibujo.G = 1.0f;
+ preferences.ColorDibujo.B = 1.0f;
+ break;
+ case EColorDraw.LIGHTRED:
+ preferences.ColorDibujo.R = 0.65f;
+ preferences.ColorDibujo.G = 0.05f;
+ preferences.ColorDibujo.B = 0.05f;
+ break;
+ case EColorDraw.LIGHTGREEN:
+ preferences.ColorDibujo.R = 0.05f;
+ preferences.ColorDibujo.G = 0.65f;
+ preferences.ColorDibujo.B = 0.05f;
+ break;
+ case EColorDraw.LIGHTBLUE:
+ preferences.ColorDibujo.R = 0.05f;
+ preferences.ColorDibujo.G = 0.05f;
+ preferences.ColorDibujo.B = 0.65f;
+ break;
+ }
+ glutPostRedisplay();
+ }
+
+ protected static void on_glutCreateMenu_ESolid (int opcion) {
+ preferences.Solid = (ESolid) opcion;
+ glutPostRedisplay();
+ }
+
+ protected static void on_glutCreateMenu_EModel (int opcion) {
+ preferences.Model = (EModel) opcion;
+ glutPostRedisplay();
+ }
+
+ protected static void on_glutCreateMenu_EAxes (int opcion) {
+ preferences.Axes = (EAxes) opcion;
+ glutPostRedisplay();
+ }
+
+ protected static void on_glutCreateMenu_Animation (int opcion) {
+ switch (opcion) {
+ case 0:
+ preferences.Animation = false;
+ break;
+ case 1:
+ preferences.Animation = true;
+ glutTimerFunc (20, on_glutTimerFunc, 1);
+ break;
+ }
+ glutPostRedisplay();
+ }
+
+ protected static void on_glutTimerFunc () {
+ glutPostRedisplay();
+ beta ++;
+ if (preferences.Animation == true)
+ glutTimerFunc (20, on_glutTimerFunc, 1);
+ }
+
+ protected static void Init_Window (string[] args) {
+ glutInit (ref args.length, args);
+ glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
+ glutInitWindowSize (400, 400);
+ glutInitWindowPosition (100, 100);
+ glutCreateWindow ("Glut example");
+ }
+
+ protected static void Init_Events () {
+ glutDisplayFunc (on_glutDisplayFunc);
+ glutMouseFunc (on_glutMouseFunc);
+ glutMotionFunc (on_glutMotionFunc);
+ }
+
+ protected static void Init_Menu () {
+ int menuMain, menuBack, menuDraw, menuSolid, menuModel, menuAxes, menuAnimation;
+
+ menuBack = glutCreateMenu (on_glutCreateMenu_EColorBack);
+ glutAddMenuEntry ("Black", EColorBack.BLACK);
+ glutAddMenuEntry ("Dark red", EColorBack.DARKRED);
+ glutAddMenuEntry ("Dark green", EColorBack.DARKGREEN);
+ glutAddMenuEntry ("Dark blue", EColorBack.DARKBLUE);
+
+ menuDraw = glutCreateMenu (on_glutCreateMenu_EColorDraw);
+ glutAddMenuEntry ("White", EColorDraw.WHITE);
+ glutAddMenuEntry ("Light red", EColorDraw.LIGHTRED);
+ glutAddMenuEntry ("Light green", EColorDraw.LIGHTGREEN);
+ glutAddMenuEntry ("Light blue", EColorDraw.LIGHTBLUE);
+
+ menuSolid = glutCreateMenu (on_glutCreateMenu_ESolid);
+ glutAddMenuEntry ("Wire", ESolid.WIRE);
+ glutAddMenuEntry ("Solid", ESolid.SOLID);
+
+ menuModel = glutCreateMenu (on_glutCreateMenu_EModel);
+ glutAddMenuEntry ("Teapot", EModel.TEAPOT);
+ glutAddMenuEntry ("Cube", EModel.CUBE);
+ glutAddMenuEntry ("Sphere", EModel.SPHERE);
+ glutAddMenuEntry ("Cone", EModel.CONE);
+ glutAddMenuEntry ("Torus", EModel.TORUS);
+ glutAddMenuEntry ("Dodecahedron", EModel.DODECAHEDRON);
+ glutAddMenuEntry ("Octahedron", EModel.OCTAHEDRON);
+ glutAddMenuEntry ("Tetrahedron", EModel.TETRAHEDRON);
+ glutAddMenuEntry ("Icosahedron", EModel.ICOSAHEDRON);
+
+ menuAxes = glutCreateMenu (on_glutCreateMenu_EAxes);
+ glutAddMenuEntry ("No axes", EAxes.AXESNO);
+ glutAddMenuEntry ("Simple axes", EAxes.AXESSIMPLE);
+
+ menuAnimation = glutCreateMenu (on_glutCreateMenu_Animation);
+ glutAddMenuEntry ("Disable", 0);
+ glutAddMenuEntry ("Enable", 1);
+
+ menuMain = glutCreateMenu(on_glutCreateMenu);
+ glutAddSubMenu ("Background color", menuBack);
+ glutAddSubMenu ("Color drawing", menuDraw);
+ glutAddSubMenu ("Type of representation", menuSolid);
+ glutAddSubMenu ("Model", menuModel);
+ glutAddSubMenu ("Axes", menuAxes);
+ glutAddSubMenu ("Animation", menuAnimation);
+
+ glutAttachMenu (GLUT_RIGHT_BUTTON);
+ }
+
+ protected static void Init_Options () {
+ glPolygonMode (GL_FRONT, GL_FILL);
+ glFrontFace (GL_CCW);
+ glCullFace (GL_BACK);
+ glEnable (GL_CULL_FACE);
+// glShadeModel (GL_FLAT);
+ glShadeModel (GL_SMOOTH);
+ glDepthFunc (GL_LEQUAL);
+ glEnable (GL_DEPTH_TEST);
+ glEnable (GL_NORMALIZE);
+ }
+
+ protected static void Init_Lighting () {
+ GLfloat[] position = {0.0f, 1.0f, 1.0f, 1.0f};
+ GLfloat[] diffuse = {0.7f, 0.7f, 0.7f, 1.0f};
+ GLfloat[] specular = {0.2f, 0.2f, 0.2f, 1.0f};
+ GLfloat[] ambient = {0.2f, 0.2f, 0.2f, 1.0f};
+
+ glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambient);
+ glLightfv (GL_LIGHT0, GL_POSITION, position);
+ glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse);
+ glLightfv (GL_LIGHT0, GL_SPECULAR, specular);
+
+ glEnable (GL_LIGHTING);
+ glEnable (GL_LIGHT0);
+ }
+
+ protected static void Init_Material () {
+ GLfloat[] colorAmbientDiffuse = {0.1f, 0.5f, 0.8f, 1.0f};
+ GLfloat[] colorSpecular = {1.0f, 1.0f, 1.0f, 1.0f};
+ GLfloat[] shineSpecular = {10.0f};
+
+ glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colorAmbientDiffuse);
+ glMaterialfv (GL_FRONT, GL_SPECULAR, colorSpecular);
+ glMaterialfv (GL_FRONT, GL_SHININESS, shineSpecular);
+ }
+
+ public static void main (string[] args) {
+ preferences = SPreferences ();
+
+ Init_Window (args);
+ Init_Events ();
+ Init_Menu ();
+ Init_Options ();
+ Init_Lighting ();
+ Init_Material ();
+
+ glutMainLoop();
+ }
+}
diff --git a/tests/examples/opengl-glx.test b/tests/examples/opengl-glx.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/opengl-glx.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/opengl-glx.vala b/tests/examples/opengl-glx.vala
new file mode 100644
index 0000000..1d5ac4a
--- /dev/null
+++ b/tests/examples/opengl-glx.vala
@@ -0,0 +1,91 @@
+
+// http://live.gnome.org/Vala/OpenGLSamples vala-test:examples/opengl-glx.vala
+
+using Gtk;
+using Gdk;
+using GLX;
+using GL;
+
+class GLXSample : Gtk.Window {
+
+ private X.Display xdisplay;
+ private GLX.Context context;
+ private XVisualInfo xvinfo;
+
+ public GLXSample () {
+ this.title = "OpenGL with GLX";
+ set_reallocate_redraws (true);
+ destroy.connect (Gtk.main_quit);
+
+ int[] attrlist = {
+ GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER, 0
+ };
+
+ this.xdisplay = x11_get_default_xdisplay ();
+ if (!glXQueryExtension (xdisplay, null, null)) {
+ stderr.printf ("OpenGL not supported\n");
+ }
+
+ this.xvinfo = glXChooseVisual (xdisplay, x11_get_default_screen (), attrlist);
+ if (xvinfo == null) {
+ stderr.printf ("Error configuring OpenGL\n");
+ }
+
+ var drawing_area = new DrawingArea ();
+ drawing_area.set_size_request (300, 300);
+ drawing_area.set_double_buffered (false);
+
+ this.context = glXCreateContext (xdisplay, xvinfo, null, true);
+
+ drawing_area.configure_event.connect (on_configure_event);
+ drawing_area.expose_event.connect (on_expose_event);
+
+ add (drawing_area);
+ }
+
+ private bool on_configure_event (Widget widget, Gdk.EventConfigure event) {
+ if (!glXMakeCurrent (xdisplay, x11_drawable_get_xid (widget.window), context))
+ return false;
+
+ glViewport (0, 0, (GLsizei) widget.allocation.width,
+ (GLsizei) widget.allocation.height);
+
+ return true;
+ }
+
+ private bool on_expose_event (Widget widget, Gdk.EventExpose event) {
+ if (!glXMakeCurrent (xdisplay, x11_drawable_get_xid (widget.window), context))
+ return false;
+
+ glClear (GL_COLOR_BUFFER_BIT);
+
+ glBegin (GL_TRIANGLES);
+ glIndexi (0);
+ glColor3f (1.0f, 0.0f, 0.0f);
+ glVertex2i (0, 1);
+ glIndexi (0);
+ glColor3f (0.0f, 1.0f, 0.0f);
+ glVertex2i (-1, -1);
+ glIndexi (0);
+ glColor3f (0.0f, 0.0f, 1.0f);
+ glVertex2i (1, -1);
+ glEnd ();
+
+ glXSwapBuffers (xdisplay, x11_drawable_get_xid (widget.window));
+
+ return true;
+ }
+}
+
+void main (string[] args) {
+ Gtk.init (ref args);
+
+ var sample = new GLXSample ();
+ sample.show_all ();
+
+ Gtk.main ();
+}
diff --git a/tests/examples/opengl-gtkglext-spot.test b/tests/examples/opengl-gtkglext-spot.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/opengl-gtkglext-spot.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/opengl-gtkglext-spot.vala b/tests/examples/opengl-gtkglext-spot.vala
new file mode 100644
index 0000000..99e00df
--- /dev/null
+++ b/tests/examples/opengl-gtkglext-spot.vala
@@ -0,0 +1,210 @@
+
+// http://live.gnome.org/Vala/OpenGLSamples vala-test:examples/opengl-gtkglext-spot.vala
+
+using Gtk;
+using Gdk;
+using GL;
+using GLU;
+
+class SpotSample : Gtk.Window {
+
+ static GLfloat xRot = 0.0f;
+ static GLfloat yRot = 0.0f;
+
+ static int iShade = 2;
+ static int iTess = 3;
+
+ static const GLfloat[] lightPos = { 0.0f, 0.0f, 75.0f, 1.0f };
+ static const GLfloat[] specular = { 1.0f, 1.0f, 1.0f, 1.0f };
+ static const GLfloat[] specref = { 1.0f, 1.0f, 1.0f, 1.0f };
+ static const GLfloat[] ambientLight = { 0.5f, 0.5f, 0.5f, 1.0f };
+ static const GLfloat[] spotDir = { 0.0f, 0.0f, -1.0f };
+
+ public SpotSample () {
+ this.title = "OpenGL with GtkGLExt";
+ this.destroy.connect (Gtk.main_quit);
+ set_reallocate_redraws (true);
+
+ var drawing_area = new DrawingArea ();
+ drawing_area.set_size_request (800, 600);
+
+ var glconfig = new GLConfig.by_mode (GLConfigMode.RGB
+ | GLConfigMode.DOUBLE
+ | GLConfigMode.DEPTH);
+
+ WidgetGL.set_gl_capability (drawing_area, glconfig, null, true,
+ GLRenderType.RGBA_TYPE);
+
+ drawing_area.realize.connect (on_realize);
+ drawing_area.configure_event.connect (on_configure_event);
+ drawing_area.expose_event.connect (on_expose_event);
+
+ drawing_area.add_events (Gdk.EventMask.KEY_PRESS_MASK);
+ drawing_area.can_focus = true;
+ drawing_area.key_press_event.connect (on_key_press_event);
+
+ add (drawing_area);
+ }
+
+ /* Widget gets initialized */
+ private void on_realize (Widget widget) {
+ GLContext glcontext = WidgetGL.get_gl_context (widget);
+ GLDrawable gldrawable = WidgetGL.get_gl_drawable (widget);
+
+ if (!gldrawable.gl_begin (glcontext))
+ return;
+
+ glEnable (GL_DEPTH_TEST);
+ glEnable (GL_CULL_FACE);
+ glFrontFace (GL_CCW);
+
+ glEnable (GL_LIGHTING);
+
+ glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambientLight);
+
+ glLightfv (GL_LIGHT0, GL_DIFFUSE, ambientLight);
+ glLightfv (GL_LIGHT0, GL_SPECULAR, specular);
+ glLightfv (GL_LIGHT0, GL_POSITION, lightPos);
+
+ glLightf (GL_LIGHT0, GL_SPOT_CUTOFF, 50.0f);
+
+ glEnable (GL_LIGHT0);
+
+ glEnable (GL_COLOR_MATERIAL);
+
+ glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+
+ glMaterialfv (GL_FRONT, GL_SPECULAR, specref);
+ glMateriali (GL_FRONT, GL_SHININESS,128);
+
+ glClearColor (0.0f, 0.0f, 0.0f, 1.0f);
+
+ gldrawable.gl_end ();
+ }
+
+ /* Widget is resized */
+ private bool on_configure_event (Widget widget, EventConfigure event) {
+ GLContext glcontext = WidgetGL.get_gl_context (widget);
+ GLDrawable gldrawable = WidgetGL.get_gl_drawable (widget);
+
+ if (!gldrawable.gl_begin (glcontext))
+ return false;
+
+ int w = widget.allocation.width;
+ int h = widget.allocation.height;
+
+ glViewport (0, 0, (GLsizei) w, (GLsizei) h);
+
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+
+ GLfloat fAspect = (GLfloat) w / (GLfloat) h;
+ gluPerspective (35.0f, fAspect, 1.0f, 500.0f);
+
+ glMatrixMode (GL_MODELVIEW);
+ glLoadIdentity ();
+ glTranslatef (0.0f, 0.0f, -250.0f);
+
+ gldrawable.gl_end ();
+ return true;
+ }
+
+ /* Widget is asked to paint itself */
+ private bool on_expose_event (Widget widget, EventExpose event) {
+ GLContext glcontext = WidgetGL.get_gl_context (widget);
+ GLDrawable gldrawable = WidgetGL.get_gl_drawable (widget);
+
+ if (!gldrawable.gl_begin (glcontext))
+ return false;
+
+ if (iShade == 1)
+ glShadeModel (GL_FLAT);
+ else
+ glShadeModel (GL_SMOOTH);
+
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix ();
+ glRotatef (xRot, 1.0f, 0.0f, 0.0f);
+ glRotatef (yRot, 0.0f, 1.0f, 0.0f);
+
+ glLightfv (GL_LIGHT0, GL_POSITION, lightPos);
+ glLightfv (GL_LIGHT0, GL_SPOT_DIRECTION, spotDir);
+
+ glColor3ub (255,0,0);
+
+ glTranslatef (lightPos[0], lightPos[1], lightPos[2]);
+ GLDraw.cone (true, 4.0f, 6.0f, 15, 15);
+
+ glPushAttrib (GL_LIGHTING_BIT);
+
+ glDisable (GL_LIGHTING);
+ glColor3ub (255,255,0);
+ GLDraw.sphere (true, 3.0f, 15, 15);
+
+ glPopAttrib ();
+
+ glPopMatrix ();
+
+ glColor3ub (0, 0, 255);
+
+ if (iTess == 1) {
+ GLDraw.sphere (true, 30.0f, 7, 7);
+ } else {
+ if (iTess == 2)
+ GLDraw.sphere (true, 30.0f, 15, 15);
+ else
+ GLDraw.sphere (true, 30.0f, 50, 50);
+ }
+
+ if (gldrawable.is_double_buffered ())
+ gldrawable.swap_buffers ();
+ else
+ glFlush ();
+
+ gldrawable.gl_end ();
+ return true;
+ }
+
+ /* A key was pressed */
+ private bool on_key_press_event (Widget drawing_area, EventKey event) {
+ string key = Gdk.keyval_name (event.keyval);
+
+ if (key == "Up")
+ xRot-= 5.0f;
+
+ if (key == "Down")
+ xRot += 5.0f;
+
+ if (key == "Left")
+ yRot -= 5.0f;
+
+ if (key == "Right")
+ yRot += 5.0f;
+
+ if (xRot > 356.0f)
+ xRot = 0.0f;
+
+ if (xRot < -1.0f)
+ xRot = 355.0f;
+
+ if (yRot > 356.0f)
+ yRot = 0.0f;
+
+ if (yRot < -1.0f)
+ yRot = 355.0f;
+
+ queue_draw ();
+ return true;
+ }
+}
+
+void main (string[] args) {
+ Gtk.init (ref args);
+ Gtk.gl_init (ref args);
+
+ var sample = new SpotSample ();
+ sample.show_all ();
+
+ Gtk.main ();
+}
diff --git a/tests/examples/opengl-gtkglext.test b/tests/examples/opengl-gtkglext.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/opengl-gtkglext.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/opengl-gtkglext.vala b/tests/examples/opengl-gtkglext.vala
new file mode 100644
index 0000000..05a929a
--- /dev/null
+++ b/tests/examples/opengl-gtkglext.vala
@@ -0,0 +1,85 @@
+
+// http://live.gnome.org/Vala/OpenGLSamples vala-test:examples/opengl-gtkglext.vala
+
+using Gtk;
+using Gdk;
+using GL;
+
+class GtkGLExtSample : Gtk.Window {
+
+ public GtkGLExtSample () {
+ this.title = "OpenGL with GtkGLExt";
+ this.destroy.connect (Gtk.main_quit);
+ set_reallocate_redraws (true);
+
+ var drawing_area = new DrawingArea ();
+ drawing_area.set_size_request (200, 200);
+
+ var glconfig = new GLConfig.by_mode (GLConfigMode.RGB
+ | GLConfigMode.DOUBLE);
+
+ WidgetGL.set_gl_capability (drawing_area, glconfig, null, true,
+ GLRenderType.RGBA_TYPE);
+
+ drawing_area.configure_event.connect (on_configure_event);
+ drawing_area.expose_event.connect (on_expose_event);
+
+ add (drawing_area);
+ }
+
+ /* Widget is resized */
+ private bool on_configure_event (Widget widget, EventConfigure event) {
+ GLContext glcontext = WidgetGL.get_gl_context (widget);
+ GLDrawable gldrawable = WidgetGL.get_gl_drawable (widget);
+
+ if (!gldrawable.gl_begin (glcontext))
+ return false;
+
+ glViewport (0, 0, (GLsizei) widget.allocation.width,
+ (GLsizei) widget.allocation.height);
+
+ gldrawable.gl_end ();
+ return true;
+ }
+
+ /* Widget is asked to paint itself */
+ private bool on_expose_event (Widget widget, EventExpose event) {
+ GLContext glcontext = WidgetGL.get_gl_context (widget);
+ GLDrawable gldrawable = WidgetGL.get_gl_drawable (widget);
+
+ if (!gldrawable.gl_begin (glcontext))
+ return false;
+
+ glClear (GL_COLOR_BUFFER_BIT);
+
+ glBegin (GL_TRIANGLES);
+ glIndexi (0);
+ glColor3f (1.0f, 0.0f, 0.0f);
+ glVertex2i (0, 1);
+ glIndexi (0);
+ glColor3f (0.0f, 1.0f, 0.0f);
+ glVertex2i (-1, -1);
+ glIndexi (0);
+ glColor3f (0.0f, 0.0f, 1.0f);
+ glVertex2i (1, -1);
+ glEnd ();
+
+ if (gldrawable.is_double_buffered ())
+ gldrawable.swap_buffers ();
+ else
+ glFlush ();
+
+ gldrawable.gl_end ();
+ return true;
+ }
+}
+
+void main (string[] args) {
+ Gtk.init (ref args);
+ Gtk.gl_init (ref args);
+
+ var sample = new GtkGLExtSample ();
+ sample.show_all ();
+
+ Gtk.main ();
+}
diff --git a/tests/examples/panel-applet-advanced.test b/tests/examples/panel-applet-advanced.test
index 52b6d2f..0174331 100755
--- a/tests/examples/panel-applet-advanced.test
+++ b/tests/examples/panel-applet-advanced.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gtk+-2.0 --pkg libpanelapplet-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/panel-applet-advanced.vala b/tests/examples/panel-applet-advanced.vala
index c438437..2364d1a 100644
--- a/tests/examples/panel-applet-advanced.vala
+++ b/tests/examples/panel-applet-advanced.vala
@@ -1,15 +1,17 @@
-using GLib;
+
+// http://live.gnome.org/Vala/PanelAppletSample vala-test:examples/panel-applet-advanced.vala
+
using Panel;
public class MainApplet : Panel.Applet {
- public static bool factory (Panel.Applet applet, string iid) {
+ public static bool factory (Applet applet, string iid) {
((MainApplet) applet).create ();
return true;
}
- private void on_change_background (MainApplet applet, Panel.AppletBackgroundType type,
- ref Gdk.Color color, Gdk.Pixmap pixmap) {
+ private void on_change_background (Panel.Applet applet, Panel.AppletBackgroundType type,
+ Gdk.Color? color, Gdk.Pixmap? pixmap) {
applet.set_style (null);
var rc_style = new Gtk.RcStyle ();
@@ -27,14 +29,14 @@ public class MainApplet : Panel.Applet {
}
private void create () {
- change_background += on_change_background;
+ change_background.connect (on_change_background);
var label = new Gtk.Label ("Vala Panel");
add (label);
- string menu_definition =
+ string menu_definition =
"<popup name=\"button3\">" +
- "<menuitem debuname=\"About\" verb=\"About\" _label=\"_About...\" pixtype=\"stock\" pixname=\"gnome-stock-about\"/>" +
+ "<menuitem debuname=\"About\" verb=\"About\" _label=\"_About...\" pixtype=\"stock\" pixname=\"gnome-stock-about\"/>" +
"</popup>";
var verb = BonoboUI.Verb ();
@@ -46,7 +48,7 @@ public class MainApplet : Panel.Applet {
show_all();
}
-
+
private static void on_about_clicked (BonoboUI.Component component,
void* user_data, string cname) {
var dialog = new Gtk.MessageDialog (
diff --git a/tests/examples/panel-applet-simple.test b/tests/examples/panel-applet-simple.test
index 52b6d2f..0174331 100755
--- a/tests/examples/panel-applet-simple.test
+++ b/tests/examples/panel-applet-simple.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gtk+-2.0 --pkg libpanelapplet-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/panel-applet-simple.vala b/tests/examples/panel-applet-simple.vala
index 333d671..986a1af 100644
--- a/tests/examples/panel-applet-simple.vala
+++ b/tests/examples/panel-applet-simple.vala
@@ -1,4 +1,6 @@
-using GLib;
+
+// http://live.gnome.org/Vala/PanelAppletSample vala-test:examples/panel-applet-simple.vala
+
using Panel;
public class MainApplet : GLib.Object {
diff --git a/tests/examples/pango-cairo.test b/tests/examples/pango-cairo.test
index 78d675c..0174331 100755
--- a/tests/examples/pango-cairo.test
+++ b/tests/examples/pango-cairo.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg cairo --pkg pangocairo -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME ../Makefile $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/pango-cairo.vala b/tests/examples/pango-cairo.vala
index a89d24e..a7c7153 100644
--- a/tests/examples/pango-cairo.vala
+++ b/tests/examples/pango-cairo.vala
@@ -1,3 +1,6 @@
+
+// http://live.gnome.org/Vala/PangoCairoSample vala-test:examples/pango-cairo.vala
+
//======================================================================
// pags.vala - Converting text to rendered image files of the text.
// It may e.g. be used for rendering text files to put
@@ -7,175 +10,151 @@
// Sat Jun 28 22:50:57 2008
//----------------------------------------------------------------------
-using GLib;
using Cairo;
-void clear_page(Cairo.Context cr,
- int width,
- int height,
- double margin,
- double top_margin,
- bool do_rotate)
-{
- cr.identity_matrix();
- cr.set_source_rgb (1.0, 1.0, 1.0);
- cr.rectangle(0,0,width,height);
- cr.fill();
- cr.set_source_rgb (0.0, 0.0, 0.0);
- if (do_rotate) {
- cr.translate(width,0);
- cr.rotate(Math.PI/2);
+public class Pags {
+
+ static void clear_page(Cairo.Context cr, int width, int height,
+ double margin, double top_margin, bool do_rotate)
+ {
+ cr.identity_matrix();
+ cr.set_source_rgb (1.0, 1.0, 1.0);
+ cr.rectangle(0, 0, width, height);
+ cr.fill();
+ cr.set_source_rgb (0.0, 0.0, 0.0);
+ if (do_rotate) {
+ cr.translate(width, 0);
+ cr.rotate(Math.PI / 2);
+ }
+ cr.move_to(margin, top_margin);
}
- cr.move_to(margin, top_margin);
-}
-int main(string[] args)
-{
- int argp = 1;
- int width=320;
- int height=240;
- string font_family = "Sans";
- double font_size = 14;
- double margin = font_size;
- double top_margin = margin*2;
- double bottom_margin = margin;
- bool do_justify = false;
- bool do_rotate = false;
-
- while(argp < args.length && args[argp][0]=='-') {
- string S_=args[argp++];
-
- if (S_=="--help") {
- stdout.printf(
- "pags - render text to files\n"
- +"\n"
- +"Syntax:\n"
- +" pags [--help] [--width w] [--height h] [--family]\n"
- +" [--font_size fs] [--margin m] [--justify]\n"
- +" [--rotate] file\n"
- );
- return 0;
- }
- if (S_=="--width") {
- width = args[argp++].to_int();
- continue;
- }
- if (S_=="--height") {
- height = args[argp++].to_int();
- continue;
+ const OptionEntry[] option_entries = {
+ { "width", 'w', 0, OptionArg.INT, ref width, "Image width", "PIXELS" },
+ { "height", 'h', 0, OptionArg.INT, ref height, "Image height", "PIXELS" },
+ { "family", 'f', 0, OptionArg.STRING, ref font_family, "Font family", "NAME" },
+ { "font-size", 's', 0, OptionArg.DOUBLE, ref font_size, "Font size", "VALUE" },
+ { "margin", 'm', 0, OptionArg.DOUBLE, ref margin, "Margin", "VALUE" },
+ { "justify", 'j', 0, OptionArg.NONE, ref do_justify, "Justify", null },
+ { "rotate", 'r', 0, OptionArg.NONE, ref do_rotate, "Rotate", null },
+ { "", 0, 0, OptionArg.FILENAME_ARRAY, ref filenames, null, "FILE" },
+ { null }
+ };
+
+ static int width = 320;
+ static int height = 240;
+ static string font_family;
+ static double font_size;
+ static double margin;
+ static bool do_justify = false;
+ static bool do_rotate = false;
+ static string[] filenames;
+
+ static int main(string[] args)
+ {
+ font_family = "Sans";
+ font_size = 14;
+ margin = font_size;
+
+ try {
+ var opt_context = new OptionContext("- Render text files to image files");
+ opt_context.set_help_enabled(true);
+ opt_context.add_main_entries(option_entries, "pags");
+ opt_context.parse(ref args);
+ } catch (OptionError e) {
+ stderr.printf("Option parsing failed: %s\n", e.message);
+ return -1;
}
- if (S_=="--family") {
- font_family = args[argp++];
- continue;
- }
- if (S_=="--font_size") {
- font_size = args[argp++].to_double();
- continue;
- }
- if (S_=="--margin") {
- margin = args[argp++].to_double();
- continue;
- }
- if (S_=="--justify") {
- do_justify = true;
- continue;
- }
- if (S_=="--rotate") {
- do_rotate = true;
- continue;
+
+ double top_margin = margin * 2;
+ double bottom_margin = margin;
+
+ if (filenames == null) {
+ stdout.printf("Need name of text file!\n");
+ return -1;
}
- stderr.printf("Unknown option %s!\n", S_);
- return -1;
- }
- if (argp >= args.length) {
- stdout.printf("Need name of text file!\n");
- return -1;
- }
+ Pango.Rectangle ink_rect, logical_rect;
- string filename = args[argp++];
- Pango.Rectangle ink_rect, logical_rect;
+ string text;
+ try {
+ FileUtils.get_contents(filenames[0], out text);
+ } catch (FileError e) {
+ stderr.printf("Failed reading file %s!\n", filenames[0]);
+ return -1;
+ }
- string text;
- try { FileUtils.get_contents(filename, out text); }
- catch (FileError err) {
- stderr.printf("Failed reading file %s!\n", filename);
- return -1;
- }
+ var surface = new Cairo.ImageSurface(Cairo.Format.RGB24, width, height);
+ var cr = new Cairo.Context(surface);
- var surface = new Cairo.ImageSurface(Cairo.Format.RGB24, width, height);
- var cr = new Cairo.Context(surface);
+ var font_description = new Pango.FontDescription();
+ font_description.set_family(font_family);
+ font_description.set_size((int)(font_size * Pango.SCALE));
- var font_description = new Pango.FontDescription();
- font_description.set_family(font_family);
- font_description.set_size((int)(font_size * Pango.SCALE));
+ var rwidth = width;
+ var rheight = height;
+ if (do_rotate) {
+ rwidth = height;
+ rheight = width;
+ }
+ var layout = Pango.cairo_create_layout(cr);
+ layout.set_font_description(font_description);
+ layout.set_justify(do_justify);
+ layout.set_width((int)((rwidth - 2 * margin) * Pango.SCALE));
+ layout.set_text(text, -1);
+
+ var pagenum_font_description = new Pango.FontDescription();
+ pagenum_font_description.set_family("Sans");
+ pagenum_font_description.set_size((int)(9 * Pango.SCALE));
+ var pagenum_layout = Pango.cairo_create_layout(cr);
+ pagenum_layout.set_font_description(pagenum_font_description);
+
+ // tbd - move to the baseline pos of the first line
+ int page_num = 1;
+ double ybottom = rheight - top_margin - bottom_margin;
+ unowned Pango.LayoutIter iter = layout.get_iter();
- var rwidth = width;
- var rheight = height;
- if (do_rotate) {
- rwidth = height;
- rheight = width;
- }
- var layout = Pango.cairo_create_layout (cr);
- layout.set_font_description(font_description);
- layout.set_justify(do_justify);
- layout.set_width((int)((rwidth-2*margin)*Pango.SCALE));
- layout.set_text(text,-1);
-
- var pagenum_font_description = new Pango.FontDescription();
- pagenum_font_description.set_family("Sans");
- pagenum_font_description.set_size((int)(9 * Pango.SCALE));
- var pagenum_layout = Pango.cairo_create_layout(cr);
- pagenum_layout.set_font_description(pagenum_font_description);
-
- // tbd - move to the baseline pos of the first line
- int page_num = 1;
- bool quit = false;
- double ybottom = rheight-top_margin-bottom_margin;
- weak Pango.LayoutIter iter = layout.get_iter();
-
- clear_page(cr, width, height, margin, top_margin, do_rotate);
- while(!iter.at_last_line()) {
- double y_pos;
- y_pos = 0;
- bool first_line = true;
-
- while(!iter.at_last_line()) {
- iter.get_line_extents(out ink_rect, out logical_rect);
- var line = iter.get_line_readonly();
- iter.next_line();
-
- // Decrease paragraph spacing
- if (ink_rect.width == 0) {
- double dy = font_size/2;
- y_pos += dy;
- if (!first_line)
- cr.rel_move_to(0,dy);
- }
- else {
- double xstart=1.0*logical_rect.x/Pango.SCALE;
- cr.rel_move_to(xstart,0);
- Pango.cairo_show_layout_line(cr, line);
- cr.rel_move_to(-xstart,(int)(logical_rect.height/Pango.SCALE));
- y_pos += logical_rect.height/Pango.SCALE;
+ clear_page(cr, width, height, margin, top_margin, do_rotate);
+ while (!iter.at_last_line()) {
+ double y_pos = 0;
+ bool first_line = true;
+
+ while (!iter.at_last_line()) {
+ iter.get_line_extents(out ink_rect, out logical_rect);
+ var line = iter.get_line_readonly();
+ iter.next_line();
+
+ // Decrease paragraph spacing
+ if (ink_rect.width == 0) {
+ double dy = font_size / 2;
+ y_pos += dy;
+ if (!first_line)
+ cr.rel_move_to(0, dy);
+ } else {
+ double xstart = 1.0 * logical_rect.x / Pango.SCALE;
+ cr.rel_move_to(xstart, 0);
+ Pango.cairo_show_layout_line(cr, line);
+ cr.rel_move_to(-xstart, (int)(logical_rect.height / Pango.SCALE));
+ y_pos += logical_rect.height / Pango.SCALE;
+ }
+
+ if (y_pos > ybottom)
+ break;
+ first_line = false;
}
- if (y_pos > ybottom)
- break;
- first_line = false;
- }
+ // draw page at bottom
+ pagenum_layout.set_text(page_num.to_string(), -1);
+ pagenum_layout.get_extents(out ink_rect, out logical_rect);
+ cr.move_to(rwidth - logical_rect.width / Pango.SCALE, rheight - margin);
+ Pango.cairo_show_layout(cr, pagenum_layout);
- // draw page at bottom
- pagenum_layout.set_text(page_num.to_string(),-1);
- pagenum_layout.get_extents(out ink_rect, out logical_rect);
- cr.move_to(rwidth-logical_rect.width/Pango.SCALE,rheight-margin);
- Pango.cairo_show_layout(cr, pagenum_layout);
+ surface.write_to_png("page-%03d.png".printf(page_num));
+ page_num++;
+ cr.show_page();
+ clear_page(cr, width, height, margin, top_margin, do_rotate);
+ }
- surface.write_to_png("page-" + page_num.to_string("%03d") + ".png");
- page_num++;
- cr.show_page();
- clear_page(cr, width, height, margin, top_margin, do_rotate);
+ return 0;
}
-
- return 0;
}
diff --git a/tests/examples/poppler-sample.test b/tests/examples/poppler-sample.test
index da51126..0174331 100755
--- a/tests/examples/poppler-sample.test
+++ b/tests/examples/poppler-sample.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gtk+-2.0 --pkg poppler-glib -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/poppler-sample.vala b/tests/examples/poppler-sample.vala
index db3fb08..2462df5 100644
--- a/tests/examples/poppler-sample.vala
+++ b/tests/examples/poppler-sample.vala
@@ -1,81 +1,69 @@
-/* Using Poppler for PDF rendering in Vala sample code */
-using GLib;
+// http://live.gnome.org/Vala/PopplerSample vala-test:examples/poppler-sample.vala
+
+/* Using Poppler for PDF rendering in Vala sample code */
-public class PopplerSample : GLib.Object {
+using Gtk;
- private Gtk.Window win;
+public class PopplerSample : Window {
// To store the document and the current page
private Poppler.Document document;
+ private Image image;
private int index = 0;
- private string _file_uri;
- public string file_uri {
- construct {
- // When constructing, turn the file name into a uri
- this._file_uri = "file://%s".printf (value);
- }
- get {
- return this._file_uri;
- }
- }
-
// To create an application object with the name of the file to display
public PopplerSample (string file_name) {
- this.file_uri = file_name;
- }
-
- construct {
- this.document = new Poppler.Document.from_file (this.file_uri, "");
+ try {
+ this.document = new Poppler.Document.from_file (Filename.to_uri (file_name), "");
+ } catch (Error e) {
+ error ("%s", e.message);
+ }
- // Render the first page
- var page = this.document.get_page (this.index);
+ // Create an image and render first page to image
var pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.RGB, false, 8, 800, 600);
- page.render_to_pixbuf (0, 0, 800, 600, 1.0, 0, pixbuf);
+ this.image = new Image.from_pixbuf (pixbuf);
+ render_page ();
- // Create a window to show an image, and set that image to show the buffer just rendered
- this.win = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
- var image = new Gtk.Image.from_pixbuf (pixbuf);
- this.win.add (image);
+ add (this.image);
- this.win.key_press_event += next_cb;
- this.win.destroy += Gtk.main_quit;
+ this.key_press_event.connect (on_key_pressed);
+ this.destroy.connect (Gtk.main_quit);
}
- private bool next_cb (Gtk.Window w, Gdk.EventKey e) {
+ private bool on_key_pressed (Widget source, Gdk.EventKey key) {
// If the key pressed was q, quit, else show the next page
- if (e.str == "q") {
+ if (key.str == "q") {
Gtk.main_quit ();
}
- var image = (Gtk.Image) this.win.get_child ();
- var pixbuf = image.get_pixbuf ();
-
// Render the next page, or the first if we were at the last
- this.index = (++this.index) % this.document.get_n_pages ();
- var page = this.document.get_page (this.index);
- page.render_to_pixbuf (0, 0, 800, 600, 1.0, 0, pixbuf);
- image.set_from_pixbuf (pixbuf);
+ this.index++;
+ this.index %= this.document.get_n_pages ();
+ render_page ();
return false;
}
- public void run () {
- this.win.show_all ();
-
- Gtk.main ();
+ private void render_page () {
+ var pixbuf = this.image.get_pixbuf ();
+ var page = this.document.get_page (this.index);
+ page.render_to_pixbuf (0, 0, 800, 600, 1.0, 0, pixbuf);
+ this.image.set_from_pixbuf (pixbuf);
}
- public static void main (string[] args) {
+ public static int main (string[] args) {
if (args.length != 2) {
stderr.printf ("Usage: %s /full/path/to/some.pdf\n", args[0]);
- return;
+ return 1;
}
Gtk.init (ref args);
- var app = new PopplerSample (args[1]);
- app.run ();
+ var sample = new PopplerSample (args[1]);
+ sample.show_all ();
+
+ Gtk.main ();
+ return 0;
}
-}
\ No newline at end of file
+}
diff --git a/tests/examples/postgresql.test b/tests/examples/postgresql.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/postgresql.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/postgresql.vala b/tests/examples/postgresql.vala
new file mode 100644
index 0000000..ecbd32c
--- /dev/null
+++ b/tests/examples/postgresql.vala
@@ -0,0 +1,87 @@
+
+// http://live.gnome.org/Vala/PostgreSQL vala-test:examples/postgresql.vala
+
+/**
+ * To compile:
+ * valac --pkg libpq test.vala -X -lpq
+ */
+
+using GLib;
+using Postgres;
+
+public static int main (string[] args)
+{
+ string conninfo;
+
+ if (args.length > 1) {
+ conninfo = args[1];
+ } else {
+ conninfo = "dbname = postgres";
+ }
+
+ /* Make a connection to the database */
+ Database conn = Postgres.connect_db (conninfo);
+
+ /* Check to see that the backend connection was successfully made */
+ if (conn.get_status () != ConnectionStatus.OK) {
+ stderr.printf ("Connection to database failed: %s", conn.get_error_message ());
+ return 1;
+ }
+
+ /*
+ * Our test case here involves using a cursor, for which we must be inside
+ * a transaction block. We could do the whole thing with a single
+ * PQexec() of "select * from pg_database", but that's too trivial to make
+ * a good example.
+ */
+
+ /* Start a transaction block */
+ Result res = conn.exec ("BEGIN");
+ if (res.get_status () != ExecStatus.COMMAND_OK) {
+ stderr.printf ("BEGIN command failed: %s", conn.get_error_message ());
+ return 1;
+ }
+
+ /*
+ * Fetch rows from pg_database, the system catalog of databases
+ */
+ res = conn.exec ("DECLARE myportal CURSOR FOR select * from pg_database");
+ if (res.get_status () != ExecStatus.COMMAND_OK) {
+ stderr.printf ("DECLARE CURSOR failed: %s", conn.get_error_message ());
+ return 1;
+ }
+
+ res = conn.exec ("FETCH ALL in myportal");
+ if (res.get_status () != ExecStatus.TUPLES_OK) {
+ stderr.printf ("FETCH ALL failed: %s", conn.get_error_message ());
+ return 1;
+ }
+
+ /* first, print out the attribute names */
+ int nFields = res.get_n_fields ();
+ for (int i = 0; i < nFields; i++) {
+ stdout.printf ("%-15s", res.get_field_name (i));
+ }
+ stdout.printf ("\n\n");
+
+ /* next, print out the rows */
+ for (int i = 0; i < res.get_n_tuples(); i++) {
+ for (int j = 0; j < nFields; j++) {
+ stdout.printf ("%-15s", res.get_value (i, j));
+ }
+ stdout.printf ("\n");
+ }
+
+ ConnectionOptions opt = Postgres.get_default_options ();
+ stdout.printf ("label=%s, keyword=%s\n", opt.label, opt.keyword);
+
+ stdout.printf ("db=%s, user=%s, passwd=%s, host=%s, port=%s, tty=%s, options=%s\n", conn.get_db (), conn.get_user (), conn.get_passwd (), conn.get_host (), conn.get_port (), conn.get_tty (), conn.get_options ());
+
+ /* close the portal ... we don't bother to check for errors ... */
+ res = conn.exec ("CLOSE myportal");
+
+ /* end the transaction */
+ res = conn.exec ("END");
+
+ return 0;
+}
diff --git a/tests/examples/preprocessor.test b/tests/examples/preprocessor.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/preprocessor.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/properties-construction.test b/tests/examples/properties-construction.test
index a23ddd3..0174331 100755
--- a/tests/examples/properties-construction.test
+++ b/tests/examples/properties-construction.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/properties-construction.vala b/tests/examples/properties-construction.vala
index 063757d..d3e7326 100644
--- a/tests/examples/properties-construction.vala
+++ b/tests/examples/properties-construction.vala
@@ -1,18 +1,20 @@
// http://live.gnome.org/Vala/PropertiesSample vala-test:examples/properties-construction.vala
-using GLib;
-
public class MyProperty : Object {
private static uint step = 0;
+
+ /* Property-backing fields */
private int _c_g_s_prop;
private int _c_o_prop;
private int _g_s_prop;
+ /* Properties */
+
public int construct_only_prop {
construct {
- stdout.printf ("==== Step %u: construct_only ====\n", step);
+ stdout.printf ("---- Step %u: construct_only ----\n", step);
stdout.printf ("construct_only (before): %d\n", _c_o_prop);
_c_o_prop = value;
stdout.printf ("construct_only (after): %d\n\n", _c_o_prop);
@@ -25,7 +27,7 @@ public class MyProperty : Object {
public int construct_get_set_prop {
construct set {
- stdout.printf ("==== Step %u: construct_get_set ====\n", step);
+ stdout.printf ("---- Step %u: construct_get_set ----\n", step);
stdout.printf ("construct_get_set (before): %d\n", _c_g_s_prop);
_c_g_s_prop = value;
stdout.printf ("construct_get_set (after): %d\n\n", _c_g_s_prop);
@@ -38,7 +40,7 @@ public class MyProperty : Object {
public int get_set_prop {
set {
- stdout.printf ("======= Step %u: get_set =======\n", step);
+ stdout.printf ("---- Step %u: get_set ----\n", step);
stdout.printf ("get_set_prop (before): %d\n", _g_s_prop);
_g_s_prop = value;
stdout.printf ("get_set_prop (after): %d\n\n", _g_s_prop);
@@ -49,36 +51,26 @@ public class MyProperty : Object {
}
}
- construct {
- stdout.printf ("================ Step %u: constructor =================\n", step);
- stdout.printf ("construct_only, construct_set_get, get_set %d, %d, %d\n\n",
- this.construct_only_prop, this.construct_get_set_prop,
- this.get_set_prop);
- step++;
- this.get_set_prop = 5; // You shouldn't do that! Better set some fields in construct.
- stdout.printf ("construct_only, construct_set_get, get_set %d, %d, %d\n",
- this.construct_only_prop, this.construct_get_set_prop,
- this.get_set_prop);
- stdout.printf ("================== end of constructor =================\n\n");
- }
+ /* Creation method */
- public MyProperty (int construct_only_prop,
- int construct_get_set_prop,
- int get_set_prop) {
- this.construct_only_prop = construct_only_prop;
- this.construct_get_set_prop = construct_get_set_prop;
- this.get_set_prop = get_set_prop;
+ public MyProperty (int a, int b, int c) {
+ Object (construct_only_prop: a, construct_get_set_prop: b);
+ this.get_set_prop = c;
}
-}
-public class Test {
+ /* Construct block */
- public static void main (string[] args) {
- stdout.printf ("=========== Construction process: MyProperty (1, 2, 3) ==========\n\n");
- var prop_test = new MyProperty (1, 2, 3);
- stdout.printf ("================== End of construction process ==================\n\n");
- stdout.printf ("======== Set construct_get_set = 222, get_set_prop = 333 ========\n\n");
- prop_test.construct_get_set_prop = 222;
- prop_test.get_set_prop = 333;
+ construct {
+ stdout.printf ("++++++++++ construct block +++++++++++++++\n\n");
+ this.get_set_prop = 5;
+ stdout.printf ("++++++++++ end of construct block ++++++++\n\n");
}
}
+
+void main () {
+ stdout.printf ("===== Construction process: MyProperty (1, 2, 3) ====\n\n");
+ var demo = new MyProperty (1, 2, 3);
+ stdout.printf ("===== End of construction process ===================\n\n");
+ demo.construct_get_set_prop = 222;
+ demo.get_set_prop = 333;
+}
diff --git a/tests/examples/properties.test b/tests/examples/properties.test
index a23ddd3..0174331 100755
--- a/tests/examples/properties.test
+++ b/tests/examples/properties.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/properties.vala b/tests/examples/properties.vala
index 595fdcf..712b898 100644
--- a/tests/examples/properties.vala
+++ b/tests/examples/properties.vala
@@ -1,55 +1,49 @@
// http://live.gnome.org/Vala/PropertiesSample vala-test:examples/properties.vala
-using GLib;
+public class PropertyDemo : Object {
-public class Sample : Object {
-
- private string automatic { get; set; }
+ /* Property-backing fields */
private string _name;
- [Notify] // will be unnecessary with Vala 0.3.5
+ private string _read_only;
+
+ /* Properties */
+
+ public string automatic { get; set; }
+
public string name {
get { return _name; }
set { _name = value; }
}
- private string _read_only;
public string read_only {
get { return _read_only; }
}
- public Sample (string name) {
- this.name = name;
- }
-
- construct {
- _automatic = "InitialAutomatic";
+ public PropertyDemo (string name) {
+ this.automatic = "InitialAutomatic";
+ _name = name;
_read_only = "InitialReadOnly";
}
+}
- public void run () {
- notify += (s, p) => {
- stdout.printf ("property `%s' has changed!\n", p.name);
- };
-
- automatic = "TheNewAutomatic";
- name = "TheNewName";
-
- // The following statement would be rejected
- // read_only = "TheNewReadOnly";
+void main () {
+ var demo = new PropertyDemo ("InitialName");
- stdout.printf ("automatic: %s\n", automatic);
- stdout.printf ("name: %s\n", name);
- stdout.printf ("read_only: %s\n", read_only);
- stdout.printf ("automatic: %s\n", automatic);
- }
+ // Every class derived from 'Object' has a 'notify' signal that gets
+ // emitted every time a property changes
+ demo.notify.connect ((s, p) => {
+ stdout.printf ("property '%s' has changed!\n", p.name);
+ });
- static int main (string[] args) {
- var test = new Sample ("InitialName");
+ demo.automatic = "TheNewAutomatic";
+ demo.name = "TheNewName";
- test.run ();
+ // The following statement would be rejected:
+ // demo.read_only = "TheNewReadOnly";
- return 0;
- }
+ stdout.printf ("automatic: %s\n", demo.automatic);
+ stdout.printf ("name: %s\n", demo.name);
+ stdout.printf ("read_only: %s\n", demo.read_only);
}
diff --git a/tests/examples/sdl-sample.test b/tests/examples/sdl-sample.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/sdl-sample.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/sdl-sample.vala b/tests/examples/sdl-sample.vala
new file mode 100644
index 0000000..00e1629
--- /dev/null
+++ b/tests/examples/sdl-sample.vala
@@ -0,0 +1,94 @@
+
+// http://live.gnome.org/Vala/SDLSample vala-test:examples/sdl-sample.vala
+
+using SDL;
+using SDLGraphics;
+
+public class SDLSample : Object {
+
+ private const int SCREEN_WIDTH = 640;
+ private const int SCREEN_HEIGHT = 480;
+ private const int SCREEN_BPP = 32;
+ private const int DELAY = 10;
+
+ private unowned SDL.Screen screen;
+ private GLib.Rand rand;
+ private bool done;
+
+ public SDLSample () {
+ this.rand = new GLib.Rand ();
+ }
+
+ public void run () {
+ init_video ();
+
+ while (!done) {
+ draw ();
+ process_events ();
+ SDL.Timer.delay (DELAY);
+ }
+ }
+
+ private void init_video () {
+ uint32 video_flags = SurfaceFlag.DOUBLEBUF
+ | SurfaceFlag.HWACCEL
+ | SurfaceFlag.HWSURFACE;
+
+ this.screen = Screen.set_video_mode (SCREEN_WIDTH, SCREEN_HEIGHT,
+ SCREEN_BPP, video_flags);
+ if (this.screen == null) {
+ stderr.printf ("Could not set video mode.\n");
+ }
+
+ SDL.WindowManager.set_caption ("Vala SDL Demo", "");
+ }
+
+ private void draw () {
+ int16 x = (int16) rand.int_range (0, screen.w);
+ int16 y = (int16) rand.int_range (0, screen.h);
+ int16 radius = (int16) rand.int_range (0, 100);
+ uint32 color = rand.next_int ();
+
+ Circle.fill_color (this.screen, x, y, radius, color);
+ Circle.outline_color_aa (this.screen, x, y, radius, color);
+
+ this.screen.flip ();
+ }
+
+ private void process_events () {
+ Event event = Event ();
+ while (Event.poll (event) == 1) {
+ switch (event.type) {
+ case EventType.QUIT:
+ this.done = true;
+ break;
+ case EventType.KEYDOWN:
+ this.on_keyboard_event (event.key);
+ break;
+ }
+ }
+ }
+
+ private void on_keyboard_event (KeyboardEvent event) {
+ if (is_alt_enter (event.keysym)) {
+ WindowManager.toggle_fullscreen (screen);
+ }
+ }
+
+ private static bool is_alt_enter (Key key) {
+ return ((key.mod & KeyModifier.LALT)!=0)
+ && (key.sym == KeySymbol.RETURN
+ || key.sym == KeySymbol.KP_ENTER);
+ }
+
+ public static int main (string[] args) {
+ SDL.init (InitFlag.VIDEO);
+
+ var sample = new SDLSample ();
+ sample.run ();
+
+ SDL.quit ();
+
+ return 0;
+ }
+}
diff --git a/tests/examples/signals.test b/tests/examples/signals.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/signals.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/signals.vala b/tests/examples/signals.vala
index 80c3de6..2032ab3 100644
--- a/tests/examples/signals.vala
+++ b/tests/examples/signals.vala
@@ -19,8 +19,8 @@ static void callback_b () {
static int main (string[] args) {
var foo = new Foo ();
- foo.some_event += callback_a; // connecting the callback functions
- foo.some_event += callback_b;
+ foo.some_event.connect (callback_a); // connecting the callback functions
+ foo.some_event.connect (callback_b);
foo.method ();
return 0;
}
diff --git a/tests/examples/soup-http-request.test b/tests/examples/soup-http-request.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/soup-http-request.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/soup-http-request.vala b/tests/examples/soup-http-request.vala
new file mode 100644
index 0000000..2aff265
--- /dev/null
+++ b/tests/examples/soup-http-request.vala
@@ -0,0 +1,26 @@
+
+// http://live.gnome.org/Vala/LibSoupSample vala-test:examples/soup-http-request.vala
+
+void main () {
+
+ var session = new Soup.SessionAsync ();
+ var message = new Soup.Message ("GET", "http://adi.roiban.ro");
+
+ /* see if we need HTTP auth */
+ session.authenticate.connect ((sess, msg, auth, retrying) => {
+ if (!retrying) {
+ stdout.printf ("Authentication required\n");
+ auth.authenticate ("user", "password");
+ }
+ });
+
+ /* send a sync request */
+ session.send_message (message);
+ message.response_headers.foreach ((name, val) => {
+ stdout.printf ("Name: %s -> Value: %s\n", name, val);
+ });
+
+ stdout.printf ("Message length: %lld\n%s\n",
+ message.response_body.length,
+ message.response_body.data);
+}
diff --git a/tests/examples/soup-http-server.test b/tests/examples/soup-http-server.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/soup-http-server.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/soup-http-server.vala b/tests/examples/soup-http-server.vala
new file mode 100644
index 0000000..5ae1838
--- /dev/null
+++ b/tests/examples/soup-http-server.vala
@@ -0,0 +1,32 @@
+
+// http://live.gnome.org/Vala/LibSoupSample vala-test:examples/soup-http-server.vala
+
+void default_handler (Soup.Server server, Soup.Message msg, string path,
+ GLib.HashTable? query, Soup.ClientContext client)
+{
+ string response_text = """
+ <html>
+ <body>
+ <p>Current location: %s</p>
+ <p><a href="/xml">Test XML</a></p>
+ </body>
+ </html>""".printf (path);
+
+ msg.set_response ("text/html", Soup.MemoryUse.COPY,
+ response_text, response_text.size ());
+}
+
+void xml_handler (Soup.Server server, Soup.Message msg, string path,
+ GLib.HashTable? query, Soup.ClientContext client)
+{
+ string response_text = "<node><subnode>test</subnode></node>";
+ msg.set_response ("text/xml", Soup.MemoryUse.COPY,
+ response_text, response_text.size ());
+}
+
+void main () {
+ var server = new Soup.Server (Soup.SERVER_PORT, 8088);
+ server.add_handler ("/", default_handler);
+ server.add_handler ("/xml", xml_handler);
+ server.run ();
+}
diff --git a/tests/examples/soup-twitter.test b/tests/examples/soup-twitter.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/soup-twitter.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/soup-twitter.vala b/tests/examples/soup-twitter.vala
new file mode 100644
index 0000000..9da13ed
--- /dev/null
+++ b/tests/examples/soup-twitter.vala
@@ -0,0 +1,24 @@
+
+// http://live.gnome.org/Vala/LibSoupSample vala-test:examples/soup-twitter.vala
+
+using Soup;
+
+void main () {
+ // add your twitter username
+ string username = "";
+
+ // format the URL to use the username as the filename
+ string url = "http://twitter.com/users/%s.xml".printf (username);
+
+ stdout.printf ("Getting status for %s\n".printf (username));
+
+ // create an HTTP session to twitter
+ var session = new Soup.SessionAsync ();
+ var message = new Soup.Message ("GET", url);
+
+ // send the HTTP request
+ session.send_message (message);
+
+ // output the XML result to stdout
+ stdout.printf (message.response_body.flatten ().data);
+}
diff --git a/tests/examples/sqlite.test b/tests/examples/sqlite.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/sqlite.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/sqlite.vala b/tests/examples/sqlite.vala
new file mode 100644
index 0000000..34628a0
--- /dev/null
+++ b/tests/examples/sqlite.vala
@@ -0,0 +1,56 @@
+
+// http://live.gnome.org/Vala/SqliteSample vala-test:examples/sqlite.vala
+
+/**
+ * Using SQLite in Vala Sample Code
+ * Port of an example found on the SQLite site.
+ * http://www.sqlite.org/quickstart.html
+ */
+
+using GLib;
+using Sqlite;
+
+public class SqliteSample : GLib.Object {
+
+ public static int callback (int n_columns, string[] values,
+ string[] column_names)
+ {
+ for (int i = 0; i < n_columns; i++) {
+ stdout.printf ("%s = %s\n", column_names[i], values[i]);
+ }
+ stdout.printf ("\n");
+
+ return 0;
+ }
+
+ public static int main (string[] args) {
+ Database db;
+ int rc;
+
+ if (args.length != 3) {
+ stderr.printf ("Usage: %s DATABASE SQL-STATEMENT\n", args[0]);
+ return 1;
+ }
+
+ if (!FileUtils.test (args[1], FileTest.IS_REGULAR)) {
+ stderr.printf ("Database %s does not exist or is directory\n", args[1]);
+ return 1;
+ }
+
+ rc = Database.open (args[1], out db);
+
+ if (rc != Sqlite.OK) {
+ stderr.printf ("Can't open database: %d, %s\n", rc, db.errmsg ());
+ return 1;
+ }
+
+ rc = db.exec (args[2], callback, null);
+
+ if (rc != Sqlite.OK) {
+ stderr.printf ("SQL error: %d, %s\n", rc, db.errmsg ());
+ return 1;
+ }
+
+ return 0;
+ }
+}
diff --git a/tests/examples/string.test b/tests/examples/string.test
index a23ddd3..0174331 100755
--- a/tests/examples/string.test
+++ b/tests/examples/string.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/string.vala b/tests/examples/string.vala
index 8489a07..252c850 100644
--- a/tests/examples/string.vala
+++ b/tests/examples/string.vala
@@ -1,11 +1,11 @@
// http://live.gnome.org/Vala/StringSample vala-test:examples/string.vala
-static void println (string str) {
+void println (string str) {
stdout.printf ("%s\n", str);
}
-static int main (string[] args) {
+void main () {
/* Strings are of data type 'string' and can get concatenated with the plus
* operator resulting in a new string:
@@ -18,8 +18,9 @@ static int main (string[] args) {
/* If you want to have a mutable string you should use StringBuilder.
* With its help you are able to build strings ad libitum by prepending,
- * appending, inserting or removing parts. In order to obtain the final
- * product you access the field '.str'.
+ * appending, inserting or removing parts. It's faster than multiple
+ * concatenations. In order to obtain the final product you access the
+ * field '.str'.
*/
var builder = new StringBuilder ();
@@ -38,6 +39,15 @@ static int main (string[] args) {
string formatted = "PI %s equals %g.".printf ("approximately", Math.PI);
println (formatted);
+ /* Strings prefixed with '@' are string templates. They can evaluate
+ * embedded variables and expressions prefixed with '$'.
+ * Since Vala 0.7.8.
+ */
+
+ string name = "Dave";
+ println (@"Good morning, $name!");
+ println (@"4 + 3 = $(4 + 3)");
+
/* The equality operator compares the content of two strings, contrary to
* Java's behaviour which in this case would check for referential equality.
*/
@@ -58,8 +68,8 @@ static int main (string[] args) {
// Switch statement
- string s = "vala";
- switch (s) {
+ string pl = "vala";
+ switch (pl) {
case "java":
assert_not_reached ();
case "vala":
@@ -105,18 +115,16 @@ They may contain quotes and may span multiple lines.""";
*/
string dessert = "crème brûlée";
- stdout.printf ("The string '%s' is %ld characters long and is stored in %zd bytes\n",
+ stdout.printf ("The string '%s' is %ld characters long and is stored in %Zd bytes\n",
dessert, dessert.len (), dessert.size ());
// Regular expressions
try {
var regex = new Regex ("(jaguar|tiger|leopard)");
- s = "wolf, tiger, eagle, jaguar, leopard, bear";
- println (regex.replace (s, s.size (), 0, "kitty"));
+ string animals = "wolf, tiger, eagle, jaguar, leopard, bear";
+ println (regex.replace (animals, -1, 0, "kitty"));
} catch (RegexError e) {
warning ("%s", e.message);
}
-
- return 0;
}
diff --git a/tests/examples/test-gtk.test b/tests/examples/test-gtk.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/test-gtk.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/test-gtk.vala b/tests/examples/test-gtk.vala
new file mode 100644
index 0000000..1b1dd5e
--- /dev/null
+++ b/tests/examples/test-gtk.vala
@@ -0,0 +1,24 @@
+
+// http://live.gnome.org/Vala/TestSample vala-test:examples/test-gtk.vala
+
+void add_foo_tests () {
+ Test.add_func ("/vala/test", () => {
+ var widget = new Gtk.Button ();
+ assert (widget is Gtk.Button);
+ });
+}
+
+void main (string[] args) {
+ Gtk.init (ref args);
+ Test.init (ref args);
+
+ add_foo_tests ();
+
+ Idle.add (() => {
+ Test.run ();
+ Gtk.main_quit ();
+ return false;
+ });
+
+ Gtk.main ();
+}
diff --git a/tests/examples/test-simple.test b/tests/examples/test-simple.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/test-simple.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/test-simple.vala b/tests/examples/test-simple.vala
new file mode 100644
index 0000000..b5c41e0
--- /dev/null
+++ b/tests/examples/test-simple.vala
@@ -0,0 +1,14 @@
+
+// http://live.gnome.org/Vala/TestSample vala-test:examples/test-simple.vala
+
+void add_foo_tests () {
+ Test.add_func ("/vala/test", () => {
+ assert ("foo" + "bar" == "foobar");
+ });
+}
+
+void main (string[] args) {
+ Test.init (ref args);
+ add_foo_tests ();
+ Test.run ();
+}
diff --git a/tests/examples/threading-philosophers.test b/tests/examples/threading-philosophers.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/threading-philosophers.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/threading-philosophers.vala b/tests/examples/threading-philosophers.vala
new file mode 100644
index 0000000..a9589be
--- /dev/null
+++ b/tests/examples/threading-philosophers.vala
@@ -0,0 +1,91 @@
+
+// http://live.gnome.org/Vala/ThreadingSamples vala-test:examples/threading-philosophers.vala
+
+/** Fork pool used by the philosophers */
+class Forks {
+
+ private bool[] fork = new bool[5]; // initially false, i.e. not used
+
+ private Cond cond = new Cond ();
+ private Mutex mutex = new Mutex ();
+
+ // Try to pick up the forks with the designated numbers
+ public void pick_up (int left, int right) {
+ mutex.lock ();
+ while (fork[left] || fork[right]) {
+ cond.wait (mutex);
+ }
+ fork[left] = true;
+ fork[right] = true;
+ mutex.unlock ();
+ }
+
+ // Lay down the forks with the designated numbers
+ public void lay_down (int left, int right) {
+ mutex.lock ();
+ fork[left] = false;
+ fork[right] = false;
+ cond.broadcast ();
+ mutex.unlock ();
+ }
+}
+
+/** A dining philosopher */
+class Philosopher {
+
+ private int number; // this philosopher's number
+ private int think_delay; // how long does this philosopher think?
+ private int eat_delay; // how long does this philosopher eat?
+ private int left; // left fork number
+ private int right; // right fork number
+ private Forks forks; // forks used by all philosophers
+
+ public Philosopher (int number, int think_delay, int eat_delay, Forks forks) {
+ this.number = number;
+ this.think_delay = think_delay;
+ this.eat_delay = eat_delay;
+ this.forks = forks;
+ this.left = number == 0 ? 4 : number - 1;
+ this.right = (number + 1) % 5;
+ }
+
+ public void* run () {
+ while (true) {
+ Thread.usleep (think_delay);
+ forks.pick_up (left, right);
+ stdout.printf ("Philosopher %d starts eating...\n", number);
+ Thread.usleep (eat_delay);
+ forks.lay_down (left, right);
+ stdout.printf ("Philosopher %d stops eating...\n", number);
+ }
+ }
+}
+
+static int main (string[] args) {
+
+ if (!Thread.supported ()) {
+ error ("Cannot run without thread support.");
+ }
+
+ var forks = new Forks ();
+
+ Philosopher[] philos = {
+ new Philosopher (0, 100000, 500000, forks),
+ new Philosopher (1, 200000, 400000, forks),
+ new Philosopher (2, 300000, 300000, forks),
+ new Philosopher (3, 400000, 200000, forks),
+ new Philosopher (4, 500000, 100000, forks)
+ };
+
+ try {
+ foreach (var philosopher in philos) {
+ Thread.create (philosopher.run, false);
+ }
+ } catch (ThreadError e) {
+ error ("%s\n", e.message);
+ }
+
+ new MainLoop (null, true).run ();
+
+ return 0;
+}
diff --git a/tests/examples/threading-simple.test b/tests/examples/threading-simple.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/threading-simple.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/threading-simple.vala b/tests/examples/threading-simple.vala
new file mode 100644
index 0000000..08396d6
--- /dev/null
+++ b/tests/examples/threading-simple.vala
@@ -0,0 +1,39 @@
+
+// http://live.gnome.org/Vala/ThreadingSamples vala-test:examples/threading-simple.vala
+
+class MyThread {
+
+ private string name;
+ private int count = 0;
+
+ public MyThread (string name) {
+ this.name = name;
+ }
+
+ public void* thread_func () {
+ while (true) {
+ stdout.printf ("%s: %i\n", this.name, this.count);
+ this.count++;
+ }
+ }
+}
+
+static int main (string[] args) {
+ if (!Thread.supported ()) {
+ error ("Cannot run without thread support.");
+ }
+
+ var thread_a_data = new MyThread ("A");
+ var thread_b_data = new MyThread ("B");
+
+ try {
+ unowned Thread thread_a = Thread.create (thread_a_data.thread_func, true);
+ unowned Thread thread_b = Thread.create (thread_b_data.thread_func, true);
+ thread_a.join ();
+ thread_b.join ();
+ } catch (ThreadError e) {
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/examples/tiff.test b/tests/examples/tiff.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/tiff.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/tiff.vala b/tests/examples/tiff.vala
new file mode 100644
index 0000000..53f6dff
--- /dev/null
+++ b/tests/examples/tiff.vala
@@ -0,0 +1,73 @@
+
+// http://live.gnome.org/Vala/TiffSample vala-test:examples/tiff.vala
+
+using Tiff;
+using GLib;
+
+public class TiffReadWrite : Object {
+
+ private uint32[] raster;
+ private uint32 width;
+ private uint32 height;
+ private uint32 size;
+
+ private string fname { get ; set; }
+ private string fmode { get; set; }
+
+ public TiffReadWrite (string filename, string mode) {
+ this.fname = filename;
+ this.fmode = mode;
+ }
+
+ public void read_image () {
+
+ var tif = new TIFF (fname, fmode);
+
+ if (tif == null) {
+ error ("Couldn't open file %s\n", fname);
+ }
+
+ tif.GetField (TIFFTAG_IMAGEWIDTH, out this.width);
+ tif.GetField (TIFFTAG_IMAGELENGTH, out this.height);
+ this.size = this.width * this.height;
+
+ raster = new uint32[size];
+ if (!tif.ReadRGBAImage (this.width, this.height, this.raster, 0)) {
+ error ("Couldn't read image %s!\n", this.fname);
+ }
+ }
+
+ public void write_image (string filename) {
+ var newtif = new TIFF (filename, "w");
+ var row = new uint8[width];
+
+ newtif.SetField (TIFFTAG_IMAGEWIDTH, this.width);
+ newtif.SetField (TIFFTAG_IMAGELENGTH, this.height);
+ newtif.SetField (TIFFTAG_BITSPERSAMPLE, 8);
+ newtif.SetField (TIFFTAG_COMPRESSION, COMPRESSION_LZW);
+ newtif.SetField (TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+ newtif.SetField (TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
+
+ for (uint32 h = 0; h < this.height; h++) {
+ for (uint32 w = 0; w < this.width; w++) {
+ row[w] = (uint8) raster[this.width * h + w];
+ }
+ newtif.WriteScanline ((tdata_t) row, h, 0);
+ }
+ }
+
+ public static int main (string[] args) {
+ string in_arg = args[1];
+ if (in_arg == null) {
+ stderr.printf ("Argument required!\n");
+ return 1;
+ }
+
+ var tt = new TiffReadWrite (in_arg, "r");
+
+ tt.read_image ();
+ tt.write_image ("/tmp/test.tiff");
+
+ return 0;
+ }
+}
diff --git a/tests/examples/time.test b/tests/examples/time.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/time.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/time.vala b/tests/examples/time.vala
new file mode 100644
index 0000000..8efa67e
--- /dev/null
+++ b/tests/examples/time.vala
@@ -0,0 +1,13 @@
+
+// http://live.gnome.org/Vala/TimeSample vala-test:examples/time.vala
+
+public class Main : GLib.Object {
+
+ static int main (string[] args) {
+ GLib.Time myTime = GLib.Time();
+ string input_string = "2009-03-03T10:53:47+00:00";
+ myTime.strptime ( input_string, "%Y-%m-%dT%T");
+ stdout.printf("Original date: %s, Parsed date: %s\n",input_string, myTime.format("%FT%T%z"));
+ return 0;
+ }
+}
diff --git a/tests/examples/type-modules-interface.test b/tests/examples/type-modules-interface.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/type-modules-interface.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/type-modules-interface.vala b/tests/examples/type-modules-interface.vala
new file mode 100644
index 0000000..39f7b6b
--- /dev/null
+++ b/tests/examples/type-modules-interface.vala
@@ -0,0 +1,6 @@
+
+// http://live.gnome.org/Vala/TypeModules vala-test:examples/type-modules-interface.vala
+
+public interface TestPlugin : Object {
+ public abstract void hello ();
+}
diff --git a/tests/examples/type-modules-main.test b/tests/examples/type-modules-main.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/type-modules-main.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/type-modules-main.vala b/tests/examples/type-modules-main.vala
new file mode 100644
index 0000000..0772674
--- /dev/null
+++ b/tests/examples/type-modules-main.vala
@@ -0,0 +1,48 @@
+
+// http://live.gnome.org/Vala/TypeModules vala-test:examples/type-modules-main.vala
+
+public class PluginRegistrar<T> : Object {
+
+ public string path { get; private set; }
+
+ private Type type;
+ private Module module;
+
+ private delegate Type RegisterPluginFunction ();
+
+ public PluginRegistrar (string name) {
+ assert (Module.supported ());
+ this.path = Module.build_path (Environment.get_variable ("PWD"), name);
+ }
+
+ public bool load () {
+ stdout.printf ("Loading plugin with path: '%s'\n", path);
+
+ module = Module.open (path, ModuleFlags.BIND_LAZY);
+ if (module == null) {
+ return false;
+ }
+
+ stdout.printf ("Loaded module: '%s'\n", module.name ());
+
+ void* function;
+ module.symbol ("register_plugin", out function);
+ RegisterPluginFunction register_plugin = (RegisterPluginFunction) function;
+
+ type = register_plugin ();
+ stdout.printf ("Plugin type: %s\n\n", type.name ());
+ return true;
+ }
+
+ public T new_object () {
+ return Object.new (type);
+ }
+}
+
+void main () {
+ var registrar = new PluginRegistrar<TestPlugin> ("plugin");
+ registrar.load ();
+
+ var plugin = registrar.new_object ();
+ plugin.hello ();
+}
diff --git a/tests/examples/type-modules-myplugin.test b/tests/examples/type-modules-myplugin.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/type-modules-myplugin.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/type-modules-myplugin.vala b/tests/examples/type-modules-myplugin.vala
new file mode 100644
index 0000000..623e781
--- /dev/null
+++ b/tests/examples/type-modules-myplugin.vala
@@ -0,0 +1,14 @@
+
+// http://live.gnome.org/Vala/TypeModules vala-test:examples/type-modules-myplugin.vala
+
+class MyPlugin : Object, TestPlugin {
+ public void hello () {
+ stdout.printf ("Hello world!\n");
+ }
+}
+
+[ModuleInit]
+public Type register_plugin () {
+ // types are registered automatically
+ return typeof (MyPlugin);
+}
diff --git a/tests/examples/update.sh b/tests/examples/update.sh
index 9318c05..0a6d9ff 100755
--- a/tests/examples/update.sh
+++ b/tests/examples/update.sh
@@ -12,14 +12,16 @@ glade
gnio-sock
gstreamer-square-beep
gstreamer-video
-gtk-sample
+gtk-hello
gtk-builder-sample
-gtk-filechooser-subclass
+gtk-filechooser
+gtk-search-dialog
gtk-valawidget
panel-applet-advanced
panel-applet-simple
poppler-sample
webkit-sample
+number-guessing
"
deprecated="
@@ -65,6 +67,7 @@ grep "Gee" $file >/dev/null && PACKAGES="$PACKAGES --pkg gee-1.0"
VALAFLAGS=
[ "$test" = "glade" ] && VALAFLAGS='-X "-Wl,--export-dynamic"'
[ "$test" = "gnome-desktop-and-menu" ] && VALAFLAGS='-X "-DGMENU_I_KNOW_THIS_IS_UNSTABLE"'
+[ "$test" = "preprocessor" ] && VALAFLAGS='-D FOO -D BAR -D FOOBAR -D NOFOO'
TESTARGS=
[ "$test" = "pango-cairo" ] && TESTARGS="../Makefile"
diff --git a/tests/examples/value.test b/tests/examples/value.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/value.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/value.vala b/tests/examples/value.vala
index 08ea652..77e2eff 100644
--- a/tests/examples/value.vala
+++ b/tests/examples/value.vala
@@ -1,26 +1,23 @@
// http://live.gnome.org/Vala/ValueSample vala-test:examples/value.vala
-public static int main (string[] args) {
- // initialize a GLib.Value of type int (G_TYPE_INT)
- Value prop_val = Value (typeof(int));
+void main () {
+ // initialize a GLib.Value of type int (G_TYPE_INT)
+ Value prop_val = Value (typeof (int));
- // set a value
- prop_val.set_int (5);
- print ("value: %d\n", prop_val.get_int ());
+ // set a value
+ prop_val.set_int (5);
+ print ("value: %d\n", prop_val.get_int ());
- // reset to its default value
- prop_val.reset ();
- print ("value: %d\n", prop_val.get_int ());
+ // reset to its default value
+ prop_val.reset ();
+ print ("value: %d\n", prop_val.get_int ());
- // unset the value
- prop_val.unset ();
+ // unset the value
+ prop_val.unset ();
- // init with type string
- prop_val.init (typeof(string));
- prop_val.set_string ("string");
- print ("value: %s\n", prop_val.get_string ());
-
- // return from this main method
- return 0;
+ // init with type string
+ prop_val.init (typeof (string));
+ prop_val.set_string ("string");
+ print ("value: %s\n", prop_val.get_string ());
}
diff --git a/tests/examples/webkit-sample.test b/tests/examples/webkit-sample.test
index de17989..0174331 100755
--- a/tests/examples/webkit-sample.test
+++ b/tests/examples/webkit-sample.test
@@ -1,30 +1,3 @@
-#!/bin/sh
-
-set -e
-
-SRCDIR=../tests/examples
-
-if [ "x$VALAC" = "x" ] ; then
- VALAC=valac
- SRCDIR=`dirname $0`
-fi
-
-while true ; do
- case "$1" in
- --interact) INTERACT=1 ; shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
-
-TESTNAME=`basename $0 .test`
-
-$VALAC --pkg gtk+-2.0 --pkg webkit-1.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala $VALAFLAGS
-
-if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
- ./$TESTNAME $@
-else
- echo ""
- echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+#!/bin/bash
+. common.sh
diff --git a/tests/examples/webkit-sample.vala b/tests/examples/webkit-sample.vala
index eac5964..b3dd71c 100644
--- a/tests/examples/webkit-sample.vala
+++ b/tests/examples/webkit-sample.vala
@@ -1,4 +1,6 @@
-using GLib;
+
+// http://live.gnome.org/Vala/WebKitSample vala-test:examples/webkit-sample.vala
+
using Gtk;
using WebKit;
@@ -17,10 +19,16 @@ public class ValaBrowser : Window {
private ToolButton forward_button;
private ToolButton reload_button;
- construct {
+ public ValaBrowser () {
this.title = ValaBrowser.TITLE;
set_default_size (800, 600);
- this.protocol_regex = new Regex (".*://.*");
+
+ try {
+ this.protocol_regex = new Regex (".*://.*");
+ } catch (RegexError e) {
+ critical ("%s", e.message);
+ }
+
create_widgets ();
connect_signals ();
this.url_bar.grab_focus ();
@@ -50,18 +58,18 @@ public class ValaBrowser : Window {
}
private void connect_signals () {
- this.destroy += Gtk.main_quit;
- this.url_bar.activate += on_activate;
- this.web_view.title_changed += (s, w, t) => {
- this.title = "%s - %s".printf (t, ValaBrowser.TITLE);
- };
- this.web_view.load_committed += (s, f) => {
- this.url_bar.text = f.get_uri ();
+ this.destroy.connect (Gtk.main_quit);
+ this.url_bar.activate.connect (on_activate);
+ this.web_view.title_changed.connect ((source, frame, title) => {
+ this.title = "%s - %s".printf (title, ValaBrowser.TITLE);
+ });
+ this.web_view.load_committed.connect ((source, frame) => {
+ this.url_bar.text = frame.get_uri ();
update_buttons ();
- };
- this.back_button.clicked += this.web_view.go_back;
- this.forward_button.clicked += this.web_view.go_forward;
- this.reload_button.clicked += this.web_view.reload;
+ });
+ this.back_button.clicked.connect (this.web_view.go_back);
+ this.forward_button.clicked.connect (this.web_view.go_forward);
+ this.reload_button.clicked.connect (this.web_view.reload);
}
private void update_buttons () {
@@ -92,4 +100,4 @@ public class ValaBrowser : Window {
return 0;
}
-}
\ No newline at end of file
+}
diff --git a/tests/examples/zlib.test b/tests/examples/zlib.test
new file mode 100755
index 0000000..0174331
--- /dev/null
+++ b/tests/examples/zlib.test
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+. common.sh
diff --git a/tests/examples/zlib.vala b/tests/examples/zlib.vala
new file mode 100644
index 0000000..d18f124
--- /dev/null
+++ b/tests/examples/zlib.vala
@@ -0,0 +1,154 @@
+
+// http://live.gnome.org/Vala/ZLib vala-test:examples/zlib.vala
+
+/*
+ * Deflate and inflate a file in gzip format
+ */
+
+using ZLib;
+
+class ZLibTest : Object {
+ // 16 KB buffer size
+ private const int CHUNK = 16 * 1024;
+
+ public int inflate (InputStream source, OutputStream dest) throws Error {
+ var buf_in = new uchar[CHUNK];
+ var buf_out = new uchar[CHUNK];
+ int ret = Status.OK;
+ var strm = InflateStream.full (15 | 32); // no way to check if this failed...
+
+ // decompress until stream ends or end of file
+ do {
+ strm.avail_in = (int) source.read (buf_in, CHUNK, null);
+ if (strm.avail_in == 0) {
+ print ("Inflate: strm not avail\n");
+ break;
+ }
+ strm.next_in = buf_in;
+
+ // run inflate() on input until output buffer not full
+ do {
+ strm.avail_out = buf_out.length;
+ strm.next_out = buf_out;
+
+ ret = strm.inflate (Flush.NO_FLUSH);
+ assert (ret != Status.STREAM_ERROR); // state not clobbered
+ if (ret == Status.NEED_DICT) {
+ ret = Status.DATA_ERROR; // and fall through
+ }
+ switch (ret) {
+ case Status.DATA_ERROR:
+ case Status.MEM_ERROR:
+ return ret;
+ }
+
+ uint have = CHUNK - strm.avail_out;
+ if (dest.write (buf_out, have, null) != have) {
+ return Status.ERRNO;
+ }
+ } while (strm.avail_out == 0);
+
+ // done when inflate () says it's done
+ } while (ret != Status.STREAM_END);
+
+ if (ret == Status.STREAM_END) {
+ print ("Inflate: Status.OK\n");
+ } else {
+ print ("Inflate: Status.DATA_ERROR\n");
+ }
+
+ return ret == Status.STREAM_END ? Status.OK : Status.DATA_ERROR;
+ }
+
+ public int deflate (InputStream source, OutputStream dest) throws Error {
+ var buf_in = new uchar[CHUNK];
+ var buf_out = new uchar[CHUNK];
+ int flush = Flush.NO_FLUSH;
+ int ret = Status.OK;
+ var strm = DeflateStream.full (Level.BEST_COMPRESSION,
+ Algorithm.DEFLATED,
+ (15 + 16), // + 16 for gzip output format
+ 8, Strategy.DEFAULT_STRATEGY);
+
+ // compress until deflate stream ends or end of file
+ do {
+ strm.avail_in = (int) source.read (buf_in, CHUNK, null);
+
+ if (strm.avail_in == 0) {
+ flush = Flush.FINISH;
+ } else {
+ flush = Flush.NO_FLUSH;
+ }
+
+ strm.next_in = buf_in;
+
+ // run deflate() on input until output buffer not full
+ do {
+ strm.avail_out = buf_out.length;
+ strm.next_out = buf_out;
+
+ ret = strm.deflate (flush);
+ assert (ret != Status.STREAM_ERROR); // state not clobbered
+ uint have = CHUNK - strm.avail_out;
+ if (dest.write (buf_out, have, null) != have) {
+ print ("write error\n");
+ return Status.ERRNO;
+ }
+ } while (strm.avail_out == 0);
+ assert (strm.avail_in == 0);
+ } while (flush != Flush.FINISH);
+
+ if (ret == Status.STREAM_END) {
+ print ("Deflate: Status.OK\n");
+ } else {
+ print ("Deflate: Status.DATA_ERROR\n");
+ }
+
+ return (ret == Status.STREAM_END) ? Status.OK : Status.DATA_ERROR;
+ }
+}
+
+
+int main (string[] args) {
+ if (args.length <= 1) {
+ print ("usage: zlibexample FILE\n");
+ return 0;
+ }
+
+ var infile = File.new_for_commandline_arg (args[1]);
+ if (!infile.query_exists (null)) {
+ print ("FILE does not exist.\n");
+ return 0;
+ }
+
+ var zippedfile = File.new_for_commandline_arg (args[1] + ".gz");
+ var outfile = File.new_for_commandline_arg (args[1] + "_out");
+
+ var zlib_test = new ZLibTest ();
+
+ try {
+ var instream = infile.read (null);
+ if (zippedfile.query_exists (null)) {
+ zippedfile.delete (null);
+ }
+ var zipstream = zippedfile.create (FileCreateFlags.NONE, null);
+ zlib_test.deflate (instream, zipstream);
+ } catch (Error e) {
+ stderr.printf ("Deflate error: %s\n", e.message);
+ return 1;
+ }
+
+ try {
+ var zipinstream = zippedfile.read (null);
+ if (outfile.query_exists (null)) {
+ outfile.delete (null);
+ }
+ var outstream = outfile.create (FileCreateFlags.NONE, null);
+ zlib_test.inflate (zipinstream, outstream);
+ } catch (Error e) {
+ stderr.printf ("Inflate error: %s\n", e.message);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/update-from-wiki.sh b/update-from-wiki.sh
index 1e19d3a..75c6697 100755
--- a/update-from-wiki.sh
+++ b/update-from-wiki.sh
@@ -10,6 +10,44 @@ StringSample
SignalsAndCallbacks
PropertiesSample
PreprocessorSample
+GeeSamples
+GIOSamples
+GIONetworkingSample
+LibSoupSample
+DBusClientSamples
+GTKSample
+CustomWidgetSamples
+GdlSample
+HildonSample
+WebKitSample
+GStreamerSample
+CairoSample
+ClutterSamples
+PangoCairoSample
+PopplerSample
+SDLSample
+OpenGLSamples
+GConfSample
+GnomeDesktopAndGMenuExample
+PanelAppletSample
+IoChannelsSample
+MarkupSample
+TypeModules
+TestSample
+TimeSample
+ThreadingSamples
+CouchDBSample
+SqliteSample
+PostgreSQL
+InputSamples
+GSLSample
+CursesSample
+LoudmouthSample
+LuaSample
+TiffSample
+JsonSample
+XmlSample
+ZLib
"
if [ "$#" != "0" ]; then
@@ -42,4 +80,5 @@ for page in $PAGES ; do
done < "$page-raw"
rm "$page-raw"
+ sleep 20 # don't overload live.gnome.org...
done
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]