[perl-Gtk3] Add helper functions Gtk3->get_version_info, Gtk3->GET_VERSION_INFO



commit bef74db61410fd83f5f93ef1cf1f88658024a2fe
Author: Jeffrey Ratcliffe <Jeffrey Ratcliffe gmail com>
Date:   Wed May 2 17:45:19 2018 +0200

    Add helper functions Gtk3->get_version_info, Gtk3->GET_VERSION_INFO
    
    https://bugzilla.gnome.org/show_bug.cgi?id=795778

 lib/Gtk3.pm |   24 ++++++++++++++++++------
 t/00-init.t |   31 +++++++++++++++++++++++++------
 2 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index 241632d..13a366d 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -507,15 +507,27 @@ sub import {
 
 # - Overrides --------------------------------------------------------------- #
 
-=item * For backwards compatibility, C<Gtk3::CHECK_VERSION>,
-C<Gtk3::check_version>, C<Gtk3::init>, C<Gtk3::init_check>, C<Gtk3::main>,
-C<Gtk3::main_level> and C<Gtk3::main_quit> can be called as class-static or as
-normal functions: for example, C<< Gtk3->main_quit >> and C<< Gtk3::main_quit
->> are both supported.  Additionally, C<Gtk3::init> and C<Gtk3::init_check>
-automatically handle passing and updating C<@ARGV> as appropriate.
+=item * For backwards compatibility, the functions C<Gtk3::get_version_info>
+and C<Gtk3::GET_VERSION_INFO> are provided, and the functions
+C<Gtk3::CHECK_VERSION>, C<Gtk3::check_version>, C<Gtk3::init>,
+C<Gtk3::init_check>, C<Gtk3::main>, C<Gtk3::main_level> and C<Gtk3::main_quit>
+can be called as class-static or as normal functions: for example, C<<
+Gtk3->main_quit >> and C<< Gtk3::main_quit >> are both supported.
+Additionally, C<Gtk3::init> and C<Gtk3::init_check> automatically handle
+passing and updating C<@ARGV> as appropriate.
 
 =cut
 
+sub Gtk3::get_version_info {
+  return Gtk3::get_major_version (),
+         Gtk3::get_minor_version (),
+         Gtk3::get_micro_version ();
+}
+
+sub Gtk3::GET_VERSION_INFO {
+  return Gtk3->MAJOR_VERSION, Gtk3->MINOR_VERSION, Gtk3->MICRO_VERSION;
+}
+
 sub Gtk3::CHECK_VERSION {
   return not defined Gtk3::check_version(@_ == 4 ? @_[1..3] : @_);
 }
diff --git a/t/00-init.t b/t/00-init.t
index 34f5cf1..49d201b 100644
--- a/t/00-init.t
+++ b/t/00-init.t
@@ -17,12 +17,7 @@ unless (eval { Gtk3->import; 1 }) {
   }
 }
 
-plan tests => 3;
-
-diag (sprintf 'Testing against gtk+ %d.%d.%d',
-      Gtk3::get_major_version (),
-      Gtk3::get_minor_version (),
-      Gtk3::get_micro_version ());
+plan tests => 16;
 
 SKIP: {
   @ARGV = qw(--help --name gtk2perl --urgs tree);
@@ -42,3 +37,27 @@ SKIP: {
   eval { my $b = Gtk3::LinkButton->new; };
   like ($@, qr/00-init\.t/);
 }
+
+my @run_version = Gtk3->get_version_info;
+my @compile_version = Gtk3->GET_VERSION_INFO;
+
+diag 'Testing Gtk3 ', $Gtk3::VERSION;
+diag '   Running against gtk+ ', join '.', @run_version;
+diag '  Compiled against gtk+ ', join '.', @compile_version;
+
+is (@run_version, 3, 'version info is three items long' );
+is (Gtk3->check_version(0,0,0), 'GTK+ version too new (major mismatch)',
+    'check_version fail 1');
+is (Gtk3->check_version(3,0,0), undef, 'check_version pass');
+is (Gtk3->check_version(50,0,0), 'GTK+ version too old (major mismatch)',
+    'check_version fail 2');
+ok (defined (Gtk3::get_major_version()), 'major_version');
+ok (defined (Gtk3::get_minor_version()), 'minor_version');
+ok (defined (Gtk3::get_micro_version()), 'micro_version');
+
+is (@compile_version, 3, 'version info is three items long');
+ok (Gtk3->CHECK_VERSION(3,0,0), 'CHECK_VERSION pass');
+ok (!Gtk3->CHECK_VERSION(50,0,0), 'CHECK_VERSION fail');
+is (Gtk3->MAJOR_VERSION, $compile_version[0], 'MAJOR_VERSION');
+is (Gtk3->MINOR_VERSION, $compile_version[1], 'MINOR_VERSION');
+is (Gtk3->MICRO_VERSION, $compile_version[2], 'MICRO_VERSION');


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