From cbaf8303bdbf50c2b94856dae681bfd74b78f12b Mon Sep 17 00:00:00 2001 From: mertz Date: Thu, 16 Oct 2003 13:16:04 +0000 Subject: initial release --- Perl/t/text.t | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Perl/t/text.t (limited to 'Perl/t') diff --git a/Perl/t/text.t b/Perl/t/text.t new file mode 100644 index 0000000..8cb2836 --- /dev/null +++ b/Perl/t/text.t @@ -0,0 +1,131 @@ +#!/usr/bin/perl -w + +# +# $Id: text.t,v 1.1 2003-10-16 13:16:04 mertz Exp $ +# Author: Christophe Mertz +# + +# testing text item + +# this script can be used with an optionnal argument, an integer giving +# the delay in seconds during which the graphic updates will be displayed +# this is usefull for visual inspection! + +my $mw; +BEGIN { + if (!eval q{ + use Test::More qw(no_plan); +# use Test::More tests => 31; + 1; + }) { + print "# tests only work properly with installed Test::More module\n"; + print "1..1\n"; + print "ok 1\n"; + exit; + } + if (!eval q{ + use Tk::Zinc; + 1; + }) { + print "unable to load Tk::Zinc"; + print "1..1\n"; + print "ok 1\n"; + exit; + } + if (!eval q{ + $mw = MainWindow->new(); + 1; + }) { + print "# tests only work properly when it is possible to create a mainwindow in your env\n"; + print "1..1\n"; + print "ok 1\n"; + exit; + } +} + +use strict; + +my $zinc = $mw->Zinc(-render => 0, + -width => 400, -height => 1200)->pack; + +like ($zinc, qr/^Tk::Zinc=HASH/ , "zinc has been created"); + + +my $g1 = $zinc->add('group',1, -tags => "gr1"); + + +my $TEXT = ""; + +my @families = $zinc->fontFamilies; +#print "@families\n"; + +my $family; +if ( grep /^verdana$/i , @families) { + $family = "verdana"; +# $family = "helvetica"; +} elsif ( grep /^helvetica$/i , @families) { + $family = "helvetica"; +} elsif ( grep /^arial$/i , @families) { + $family = "arial"; +} + +### creating text items with many different fonts: + +my $size = 8; +my $y = 10 ; + +$zinc->fontCreate("font$size", -family => $family, -size => -$size, -weight => 'normal'); +$zinc->add('text', $g1, -position => [10,$y], -tags => ["txt$size"], -font => "font$size", + -text => "$size pixels $family"); +$zinc->remove('txt8'); +$zinc->fontDelete("font$size"); +$zinc->fontCreate("font$size", -family => $family, -size => -$size, -weight => 'normal'); +$zinc->add('text', $g1, -position => [10,$y], -tags => ["txt$size"], -font => "font$size", + -text => "$size pixels $family"); + + +foreach my $size (9..60) { + $zinc->fontCreate("font$size", -family => $family, -size => -$size, -weight => 'normal'); + $zinc->add('text', $g1, -position => [10,$y], -tags => ["txt$size"], -font => "font$size", + -text => "$size pixels $family"); + $zinc->update; + + # deleting both the font and the text item and recreating it 10 times + foreach my $count (1..-10) { + $zinc->fontDelete("font$size"); + $zinc->remove('txt8'); + $zinc->fontCreate("font$size", -family => $family, -size => -$size, -weight => 'normal'); + $zinc->add('text', $g1, -position => [10,$y], -tags => ["txt$size"], -font => "font$size", + -text => "$size pixels $family"); + $zinc->update; + } + &pass("creating and deleting 10 times a text item with a $family font of size $size"); + $y += $size; +} + + +&wait; + +## we should certainly test much much other things! + + + +sub wait { + $zinc->update; + ok (1, $_[0]); + + my $delay = $ARGV[0]; + if (defined $delay) { + $zinc->update; + if ($delay =~ /^\d+$/) { + sleep $delay; + } else { + sleep 1; + } + } + +} + + + +diag("############## end of text test"); -- cgit v1.1