[perl-Glib-Object-Introspection] Add initial tests



commit 018c95e659b310e7efcede389f67b24ce43900ba
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Tue Nov 9 21:25:22 2010 +0100

    Add initial tests

 Makefile.PL     |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 t/basic-types.t |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 t/inc/setup.pl  |   21 ++++++++++++++++++++
 3 files changed, 133 insertions(+), 0 deletions(-)
---
diff --git a/Makefile.PL b/Makefile.PL
index 32e5f51..ac345ce 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -67,6 +67,8 @@ my %pod_files = (
 
 mkdir 'build', 0777;
 
+compile_test_libraries();
+
 my $deps = ExtUtils::Depends->new ('Glib::Object::Introspection' => 'Glib');
 $deps->set_inc ($cfg{cflags});
 $deps->set_libs ($cfg{libs});
@@ -97,3 +99,57 @@ sub MY::postamble
 {
   return Glib::MakeHelper->postamble_clean ();
 }
+
+sub compile_test_libraries {
+  chdir 'build';
+  my $build_dir = cwd();
+
+  local $| = 1;
+  print 'Trying to build test libraries... ';
+
+  my $success = eval {
+    my $gidatadir = ExtUtils::PkgConfig->variable ('gobject-introspection-1.0',
+                                                   'gidatadir');
+    my $testsdir = $gidatadir . '/tests';
+    my %cairo_flags = ExtUtils::PkgConfig->find ('cairo');
+    my %gio_flags = ExtUtils::PkgConfig->find ('gio-2.0');
+    my %glib_flags = ExtUtils::PkgConfig->find ('glib-2.0');
+
+       !system (qq(gcc -shared \\
+                   $cairo_flags{cflags} $cairo_flags{libs} \\
+                   $gio_flags{cflags} $gio_flags{libs} \\
+                   $testsdir/regress.c \\
+                   -o libregress.so 1>/dev/null 2>/dev/null))
+    && !system (qq(LD_LIBRARY_PATH=$build_dir \\
+                   g-ir-scanner \\
+                   --include=cairo-1.0 --include=Gio-2.0 \\
+                   --namespace=Regress --nsversion=1.0 \\
+                   --quiet --warn-all --warn-error \\
+                   --library=regress \\
+                   --output=Regress-1.0.gir \\
+                   $testsdir/regress.h $testsdir/regress.c \\
+                   1>/dev/null 2>/dev/null))
+    && !system (qq(g-ir-compiler Regress-1.0.gir -o Regress-1.0.typelib \\
+                   1>/dev/null 2>/dev/null))
+    #&& !system (qq(gcc -shared \\
+    #               $glib_flags{cflags} $glib_flags{libs} \\
+    #               $testsdir/gimarshallingtests.c \\
+    #               -o libgimarshallingtests.so 1>/dev/null 2>/dev/null))
+    #&& !system (qq(LD_LIBRARY_PATH=$build_dir \\
+    #               g-ir-scanner \\
+    #               --include=GObject-2.0 \\
+    #               --namespace=GIMarshallingTests \\
+    #               --symbol-prefix=gi_marshalling_tests --nsversion=1.0 \\
+    #               --quiet --warn-all --warn-error \\
+    #               --library=gimarshallingtests \\
+    #               --output=GIMarshallingTests-1.0.gir \\
+    #               $testsdir/gimarshallingtests.h $testsdir/gimarshallingtests.c \\
+    #               1>/dev/null 2>/dev/null))
+    #&& !system (qq(g-ir-compiler GIMarshallingTests-1.0.gir \\
+    #               -o GIMarshallingTests-1.0.typelib 1>/dev/null 2>/dev/null))
+  };
+
+  print $success ? "OK\n" : "not OK\n";
+
+  chdir '..';
+}
diff --git a/t/basic-types.t b/t/basic-types.t
new file mode 100644
index 0000000..ab233dc
--- /dev/null
+++ b/t/basic-types.t
@@ -0,0 +1,56 @@
+#!/usr/bin/env perl
+
+BEGIN { do './t/inc/setup.pl' };
+
+use strict;
+use warnings;
+
+use utf8;
+use POSIX qw(FLT_MIN FLT_MAX DBL_MIN DBL_MAX);
+
+plan tests => 30;
+
+ok (test_boolean (1));
+ok (!test_boolean (0));
+is (test_int8 (-127), -127);
+is (test_uint8 (255), 255);
+is (test_int16 (-32767), -32767);
+is (test_uint16 (65535), 65535);
+is (test_int32 (-2147483647), -2147483647);
+is (test_uint32 (4294967295), 4294967295);
+is (test_int64 ('-9223372036854775807'), '-9223372036854775807');
+is (test_uint64 ('18446744073709551615'), '18446744073709551615');
+delta_ok (test_float (FLT_MIN), FLT_MIN);
+delta_ok (test_float (FLT_MAX), FLT_MAX);
+delta_ok (test_double (DBL_MIN), DBL_MIN);
+delta_ok (test_double (DBL_MAX), DBL_MAX);
+
+is (test_gtype ('Glib::Object'), 'Glib::Object');
+TODO: {
+  local $TODO = 'Is that how we want to handle unregistered GTypes?';
+  is (test_gtype ('GIRepository'),
+      'Glib::Object::_Unregistered::GIRepository');
+}
+is (test_gtype ('Inexistant'), undef);
+
+ok (defined test_utf8_const_return ());
+ok (defined test_utf8_nonconst_return ());
+test_utf8_const_in (test_utf8_const_return ());
+ok (defined test_utf8_out ());
+is (test_utf8_inout (test_utf8_const_return ()), test_utf8_nonconst_return ());
+test_utf8_null_in (undef);
+is (test_utf8_null_out (), undef);
+
+my $filenames = test_filename_return ();
+is (scalar @$filenames, 2);
+
+is (test_int_out_utf8 ('Παν�'), 4);
+my ($one, $two) = test_multi_double_args (my $pi = 3.1415);
+delta_ok ($one, 2*$pi);
+delta_ok ($two, 3*$pi);
+($one, $two) = test_utf8_out_out ();
+ok (defined $one);
+ok (defined $two);
+($one, $two) = test_utf8_out_nonconst_return ();
+ok (defined $one);
+ok (defined $two);
diff --git a/t/inc/setup.pl b/t/inc/setup.pl
new file mode 100644
index 0000000..0d9f164
--- /dev/null
+++ b/t/inc/setup.pl
@@ -0,0 +1,21 @@
+use Glib::Object::Introspection;
+use Test::More;
+
+unless ($ENV{LD_LIBRARY_PATH} =~ m/\bbuild\b/) {
+  plan skip_all => 'Need "build" in LD_LIBRARY_PATH';
+}
+unless (-e 'build/libregress.so') {
+  plan skip_all => 'Need the test libraries';
+}
+
+Glib::Object::Introspection->setup(
+  basename => 'Regress',
+  version => '1.0',
+  package => 'main',
+  search_path => 'build');
+
+# Inspired by Test::Number::Delta
+sub delta_ok ($$;$) {
+	my ($a, $b, $msg) = @_;
+	ok (abs ($a - $b) < 1e-6, $msg);
+}



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