#!/usr/bin/perl -w # # $Id: text.t,v 1.3 2003-11-28 09:40:47 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");