diff options
author | Timothy Pearson <[email protected]> | 2011-12-18 03:08:08 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-12-18 03:08:08 -0600 |
commit | bcc95cd92ca12c1783464b8ada6816d430dc0e98 (patch) | |
tree | 4701c447365db5392df0174b4bb00b5b5c369da4 /PerlQt/t | |
download | libtqt-perl-bcc95cd92ca12c1783464b8ada6816d430dc0e98.tar.gz libtqt-perl-bcc95cd92ca12c1783464b8ada6816d430dc0e98.zip |
Initial import of libqt-perl (not yet TQt compatible)
Diffstat (limited to 'PerlQt/t')
-rw-r--r-- | PerlQt/t/Foo/SubCodec.pm | 14 | ||||
-rw-r--r-- | PerlQt/t/My/Codec.pm | 10 | ||||
-rw-r--r-- | PerlQt/t/My/SubCodec.pm | 15 | ||||
-rw-r--r-- | PerlQt/t/a_loading.t | 6 | ||||
-rw-r--r-- | PerlQt/t/b_nogui.t | 48 | ||||
-rw-r--r-- | PerlQt/t/c_qapp.t | 23 | ||||
-rw-r--r-- | PerlQt/t/ca_i18n.t | 23 | ||||
-rw-r--r-- | PerlQt/t/d_sigslot.t | 49 | ||||
-rw-r--r-- | PerlQt/t/e_sigslot_inherit.t | 72 | ||||
-rw-r--r-- | PerlQt/t/f_import.t | 19 | ||||
-rw-r--r-- | PerlQt/t/g_gui.t | 127 |
11 files changed, 406 insertions, 0 deletions
diff --git a/PerlQt/t/Foo/SubCodec.pm b/PerlQt/t/Foo/SubCodec.pm new file mode 100644 index 0000000..15ce08a --- /dev/null +++ b/PerlQt/t/Foo/SubCodec.pm @@ -0,0 +1,14 @@ +package Foo::SubCodec; +use Qt; +use My::Codec; +use Qt::isa qw( My::Codec ); + + +sub NEW +{ + shift->SUPER::NEW(@_); +} + +sub foo {} + +1; diff --git a/PerlQt/t/My/Codec.pm b/PerlQt/t/My/Codec.pm new file mode 100644 index 0000000..93e1d01 --- /dev/null +++ b/PerlQt/t/My/Codec.pm @@ -0,0 +1,10 @@ +package My::Codec; +use Qt; +use Qt::isa qw( Qt::TextCodec ); + +sub NEW +{ + shift->SUPER::NEW(@_); +} + +1;
\ No newline at end of file diff --git a/PerlQt/t/My/SubCodec.pm b/PerlQt/t/My/SubCodec.pm new file mode 100644 index 0000000..58f8987 --- /dev/null +++ b/PerlQt/t/My/SubCodec.pm @@ -0,0 +1,15 @@ + +package My::SubCodec; +use Qt; +use My::Codec; +use Qt::isa qw( My::Codec ); + + +sub NEW +{ + shift->SUPER::NEW(@_); +} + +sub bar {} + +1;
\ No newline at end of file diff --git a/PerlQt/t/a_loading.t b/PerlQt/t/a_loading.t new file mode 100644 index 0000000..4a9f4a1 --- /dev/null +++ b/PerlQt/t/a_loading.t @@ -0,0 +1,6 @@ + +BEGIN { print "1..1\n" } + +use Qt; + +print "ok 1\n" diff --git a/PerlQt/t/b_nogui.t b/PerlQt/t/b_nogui.t new file mode 100644 index 0000000..23bdd72 --- /dev/null +++ b/PerlQt/t/b_nogui.t @@ -0,0 +1,48 @@ + +BEGIN { print "1..6\n" } + +use Qt; +use Qt::constants; + +eval {my $c = Qt::TextCodec::codecForLocale()}; + +print +$@ ? "not ok\n" : "ok 1\n"; + +eval {my $s = Qt::Variant( Qt::DateTime::currentDateTime() ) }; + +print +$@ ? "not ok\n" : "ok 2\n"; + +my $ret; +eval {$ret = Qt::Point(20,20); $ret += Qt::Point(10,10); $ret *= 2 ; $ret /= 3 }; + +print +$@ ? "not ok\n" : "ok 3\n"; + +eval { $ret = ($ret->x != 20 or $ret->y != 20) ? 1 : 0 }; + +print +($@ || $ret) ? "not ok\n" : "ok 4\n"; + +eval { my $z = Qt::GlobalSpace::qVersion() }; + +if( $@ ) +{ + print "ok 5 # skip Smoke version too old\n"; + print "ok 6 # skip Smoke version too old\n"; +} +else +{ + eval{ my $p = Qt::Point( 20, 20 ); + my $p2 = Qt::Point( 30, 30 ); + $p = $p + $p2 + $p; + $p2 = $p * 2; + $p2 = -$p2; + $ret = ($p2->x != -140 or $p2->y != -140) ? 1 : 0 + }; + print +($@ || $ret) ? "not ok\n" : "ok 5\n"; + + eval { + $str = "Fooooooooooo"; + $ts = Qt::TextStream( $str, IO_WriteOnly ); + $ts << "pi = " << 3.14; + }; + print +($str eq "pi = 3.14ooo") ? "ok 6\n":"not ok\n"; +} diff --git a/PerlQt/t/c_qapp.t b/PerlQt/t/c_qapp.t new file mode 100644 index 0000000..ee28266 --- /dev/null +++ b/PerlQt/t/c_qapp.t @@ -0,0 +1,23 @@ +BEGIN { print "1..3\n" } + +use Qt; + +$a=0; + +# testing if the Qt::Application ctor works + +eval { $a=Qt::Application(\@ARGV) }; + +print +$@ ? "not ok\n" : "ok 1\n"; + +# testing wether the global object is properly setup + +eval { Qt::app()->libraryPaths() }; + +print +$@ ? "not ok\n" : "ok 2\n"; + +# one second test of the event loop + +Qt::Timer::singleShot( 300, Qt::app(), SLOT "quit()" ); + +print Qt::app()->exec ? "not ok\n" : "ok 3\n"; diff --git a/PerlQt/t/ca_i18n.t b/PerlQt/t/ca_i18n.t new file mode 100644 index 0000000..fddbff7 --- /dev/null +++ b/PerlQt/t/ca_i18n.t @@ -0,0 +1,23 @@ +BEGIN { print "1..1\n" } + +use Qt; + +$a = Qt::Application(); +$pb=Qt::PushButton("Foooo", undef); + +{ + use bytes; + $pb->setText( "�l�gant" ); + + $b = $pb->text(); + $b2 = Qt::Widget::tr("�l�gant"); +} + + +$c = $pb->text(); +$c2= Qt::Widget::tr("�l�gant"); + +{ + use bytes; + print +($b ne $c and $b2 ne $c2) ? "ok 1\n":"not ok\n"; +} diff --git a/PerlQt/t/d_sigslot.t b/PerlQt/t/d_sigslot.t new file mode 100644 index 0000000..1b455e1 --- /dev/null +++ b/PerlQt/t/d_sigslot.t @@ -0,0 +1,49 @@ +BEGIN { print "1..3\n" } + +package MyApp; +use Qt; +use Qt::isa qw(Qt::Application); +use Qt::slots + foo => ['int'], + baz => []; +use Qt::signals + bar => ['int']; + +sub NEW { + shift->SUPER::NEW(@_); + + # 1) testing correct subclassing of Qt::Application and this pointer + print +(ref(this) eq " MyApp")? "ok 1\n" : "not ok\n"; + + this->connect(this, SIGNAL 'bar(int)', SLOT 'foo(int)'); + + # 3) automatic quitting will test Qt sig to custom slot + this->connect(this, SIGNAL 'aboutToQuit()', SLOT 'baz()'); + + # 2) testing custom sig to custom slot + emit bar(3); +} + +sub foo +{ + print +($_[0] == 3) ? "ok 2\n" : "not ok\n"; +} + +sub baz +{ + print "ok 3\n"; +} + +1; + +package main; + +use Qt; +use MyApp; + +$a = 0; +$a = MyApp(\@ARGV); + +Qt::Timer::singleShot( 300, Qt::app(), SLOT "quit()" ); + +exit Qt::app()->exec; diff --git a/PerlQt/t/e_sigslot_inherit.t b/PerlQt/t/e_sigslot_inherit.t new file mode 100644 index 0000000..aa3bd76 --- /dev/null +++ b/PerlQt/t/e_sigslot_inherit.t @@ -0,0 +1,72 @@ +BEGIN { print "1..6\n" } + +package MyApp; +use Qt; +use Qt::isa('Qt::Application'); +use Qt::slots + foo => ['int'], + baz => []; +use Qt::signals + bar => ['int']; + +sub NEW +{ + shift->SUPER::NEW(@_); + this->connect(this, SIGNAL 'bar(int)', SLOT 'foo(int)'); + this->connect(this, SIGNAL 'aboutToQuit()', SLOT 'baz()'); +} + +sub foo +{ + # 1) testing correct inheritance of sig/slots + print +($_[0] == 3) ? "ok 1\n" : "not ok\n"; +} + +sub baz +{ + print "ok 3\n"; +} + +sub coincoin +{ + print +(@_ == 2) ? "ok 5\n":"not ok\n"; + print +(ref(this) eq " MySubApp") ? "ok 6\n":"not ok\n"; +} + +1; + +package MySubApp; +use Qt; +use Qt::isa('MyApp'); + + +sub NEW +{ + shift->SUPER::NEW(@_); + emit foo(3); +} + +sub baz +{ + # 2) testing further inheritance of sig/slots + print "ok 2\n"; + # 3) testing Perl to Perl SUPER + SUPER->baz(); + # 4) 5) 6) testing non-qualified enum calls vs. Perl method/static calls + eval { &blue }; print !$@ ? "ok 4\n":"not ok\n"; + coincoin("a","b"); +} + +1; + +package main; + +use Qt; +use MySubApp; + +$a = 0; +$a = MySubApp(\@ARGV); + +Qt::Timer::singleShot( 300, Qt::app(), SLOT "quit()" ); + +exit Qt::app()->exec; diff --git a/PerlQt/t/f_import.t b/PerlQt/t/f_import.t new file mode 100644 index 0000000..c6467a3 --- /dev/null +++ b/PerlQt/t/f_import.t @@ -0,0 +1,19 @@ +BEGIN { push @INC, "./t" ; print "1..1\n" } + +package main; + +use Qt; +use My::SubCodec; +use Foo::SubCodec; + +$tc1 = My::SubCodec(); +$tc2 = Foo::SubCodec(); + +$tc1->bar(); +$tc2->foo(); + +$tc2->deleteAllCodecs; + +# all imports OK + +print "ok 1\n"; diff --git a/PerlQt/t/g_gui.t b/PerlQt/t/g_gui.t new file mode 100644 index 0000000..b47c0c0 --- /dev/null +++ b/PerlQt/t/g_gui.t @@ -0,0 +1,127 @@ + +BEGIN { print "1..1\n" } + +package ButtonsGroups; +use strict; +use Qt; +use Qt::isa qw(Qt::Widget); +use Qt::slots + slotChangeGrp3State => []; +use Qt::attributes qw( + state + rb21 + rb22 + rb23 +); + +# +# Constructor +# +# Creates all child widgets of the ButtonGroups window +# + +sub NEW { + shift->SUPER::NEW(@_); + + # Create Widgets which allow easy layouting + my $vbox = Qt::VBoxLayout(this); + my $box1 = Qt::HBoxLayout($vbox); + my $box2 = Qt::HBoxLayout($vbox); + + # ------- first group + + # Create an exclusive button group + my $bgrp1 = Qt::ButtonGroup(1, &Horizontal, "Button Group &1 (exclusive)", this); + $box1->addWidget($bgrp1); + $bgrp1->setExclusive(1); + + # insert 3 radiobuttons + Qt::RadioButton("R&adiobutton 2", $bgrp1); + Qt::RadioButton("Ra&diobutton 3", $bgrp1); + + # ------- second group + + # Create a non-exclusive buttongroup + my $bgrp2 = Qt::ButtonGroup(1, &Horizontal, "Button Group &2 (non-exclusive)", this); + $box1->addWidget($bgrp2); + $bgrp2->setExclusive(0); + + # insert 3 checkboxes + Qt::CheckBox("&Checkbox 1", $bgrp2); + my $cb12 = Qt::CheckBox("C&heckbox 2", $bgrp2); + $cb12->setChecked(1); + my $cb13 = Qt::CheckBox("Triple &State Button", $bgrp2); + $cb13->setTristate(1); + $cb13->setChecked(1); + + # ----------- third group + + # create a buttongroup which is exclusive for radiobuttons and non-exclusive for all other buttons + my $bgrp3 = Qt::ButtonGroup(1, &Horizontal, "Button Group &3 (Radiobutton-exclusive)", this); + $box2->addWidget($bgrp3); + $bgrp3->setRadioButtonExclusive(1); + + # insert three radiobuttons + rb21 = Qt::RadioButton("Rad&iobutton 1", $bgrp3); + rb22 = Qt::RadioButton("Radi&obutton 2", $bgrp3); + rb23 = Qt::RadioButton("Radio&button 3", $bgrp3); + rb23->setChecked(1); + + # insert a checkbox + state = Qt::CheckBox("E&nable Radiobuttons", $bgrp3); + state->setChecked(1); + # ...and connect its SIGNAL clicked() with the SLOT slotChangeGrp3State() + this->connect(state, SIGNAL('clicked()'), SLOT('slotChangeGrp3State()')); + + # ----------- fourth group + + # create a groupbox which layouts its childs in a columns + my $bgrp4 = Qt::ButtonGroup(1, &Horizontal, "Groupbox with &normal buttons", this); + $box2->addWidget($bgrp4); + + # insert three pushbuttons... + Qt::PushButton("&Push Button", $bgrp4); + my $tb2 = Qt::PushButton("&Toggle Button", $bgrp4); + my $tb3 = Qt::PushButton("&Flat Button", $bgrp4); + + # ... and make the second one a toggle button + $tb2->setToggleButton(1); + $tb2->setOn(1); + + # ... and make the third one a flat button + $tb3->setFlat(1); +} + +# +# SLOT slotChangeGrp3State() +# +# enables/disables the radiobuttons of the third buttongroup +# + +sub slotChangeGrp3State { + rb21->setEnabled(state->isChecked); + rb22->setEnabled(state->isChecked); + rb23->setEnabled(state->isChecked); +} + +1; + +package main; + +use Qt; +use ButtonsGroups; + +Qt::StyleFactory::keys(); # disable style plugins (hacky) + +my $a = Qt::Application(\@ARGV); + +my $buttonsgroups = ButtonsGroups; +$buttonsgroups->resize(500, 250); +$buttonsgroups->setCaption("PerlQt Test - Please wait"); +$a->setMainWidget($buttonsgroups); +$buttonsgroups->show; + +Qt::Timer::singleShot( 2000, Qt::app(), SLOT "quit()" ); +my $r = $a->exec; +print +$r?"not ok\n" : "ok 1\n"; +exit $r; |