# This file is a Tcl script to test out the procedures in tkMacFont.c. # It is organized in the standard fashion for Tcl tests. # # Some of these tests are visually oriented and cannot be checked # programmatically (such as "does an underlined font appear to be # underlined?"); these tests attempt to exercise the code in question, # but there are no results that can be checked. # # Copyright (c) 1996 Sun Microsystems, Inc. # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # # RCS: @(#) $Id: macFont.test,v 1.1.1.1 2007/07/10 15:05:18 duncan Exp $ package require tcltest 2.1 namespace import -force tcltest::configure namespace import -force tcltest::testsDirectory configure -testdir [file join [pwd] [file dirname [info script]]] configure -loadfile [file join [testsDirectory] constraints.tcl] tcltest::loadTestedCommands catch {destroy .b} toplevel .b update idletasks set courier {Courier 12} set cx [font measure $courier 0] set fixed {Monaco 12} label .b.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left -text "0" -font $fixed pack .b.l canvas .b.c -closeenough 0 set t [.b.c create text 0 0 -anchor nw -just left -font $courier] pack .b.c update set ax [winfo reqwidth .b.l] set ay [winfo reqheight .b.l] proc getsize {} { update return "[winfo reqwidth .b.l] [winfo reqheight .b.l]" } testConstraint gothic 0 set gothic {gothic 12} set mx [font measure $gothic \u4e4e] if {[font actual $gothic -family] != [font actual system -family]} { testConstraint gothic 1 } test macFont-1.1 {TkpFontPkgInit} {macOnly} { } {} test macfont-2.1 {TkpGetNativeFont: not native} {macOnly} { list [catch {font measure {} xyz} msg] $msg } {1 {font "" doesn't exist}} test macFont-2.2 {TkpGetNativeFont: native} {macOnly} { font measure system "0" font measure application "0" set x {} } {} test macFont-3.1 {TkpGetFontFromAttributes: no family} {macOnly} { font actual {-underline 1} -family } [font actual system -family] test macFont-3.2 {TkpGetFontFromAttributes: long family name} {macOnly} { set x "12345678901234567890123456789012345678901234567890" set x "$x$x$x$x$x$x" font actual "-family $x" -family } [font actual system -family] test macFont-3.3 {TkpGetFontFromAttributes: family} {macOnly} { font actual {-family Courier} -family } {Courier} test macFont-3.4 {TkpGetFontFromAttributes: Times fonts} {macOnly} { set x {} lappend x [font actual {-family "Times"} -family] lappend x [font actual {-family "Times New Roman"} -family] } {Times Times} test macFont-3.5 {TkpGetFontFromAttributes: Courier fonts} {macOnly} { set x {} lappend x [font actual {-family "Courier"} -family] lappend x [font actual {-family "Courier New"} -family] } {Courier Courier} test macFont-3.6 {TkpGetFontFromAttributes: Helvetica fonts} {macOnly} { set x {} lappend x [font actual {-family "Geneva"} -family] lappend x [font actual {-family "Helvetica"} -family] lappend x [font actual {-family "Arial"} -family] } {Geneva Helvetica Helvetica} test macFont-3.7 {TkpGetFontFromAttributes: try aliases} {macOnly} { font actual {arial 10} -family } {Helvetica} test macFont-3.8 {TkpGetFontFromAttributes: try fallbacks} {macOnly} { font actual {{ms sans serif} 10} -family } {Chicago} test macFont-3.9 {TkpGetFontFromAttributes: styles} {macOnly} { font actual {-weight normal} -weight } {normal} test macFont-3.10 {TkpGetFontFromAttributes: styles} {macOnly} { font actual {-weight bold} -weight } {bold} test macFont-3.11 {TkpGetFontFromAttributes: styles} {macOnly} { font actual {-slant roman} -slant } {roman} test macFont-3.12 {TkpGetFontFromAttributes: styles} {macOnly} { font actual {-slant italic} -slant } {italic} test macFont-3.13 {TkpGetFontFromAttributes: styles} {macOnly} { font actual {-underline false} -underline } {0} test macFont-3.14 {TkpGetFontFromAttributes: styles} {macOnly} { font actual {-underline true} -underline } {1} test macFont-3.15 {TkpGetFontFromAttributes: styles} {macOnly} { font actual {-overstrike false} -overstrike } {0} test macFont-3.16 {TkpGetFontFromAttributes: styles} {macOnly} { font actual {-overstrike true} -overstrike } {0} test macFont-4.1 {TkpDeleteFont} {macOnly} { font actual {-family xyz} set x {} } {} test macFont-5.1 {TkpGetFontFamilies} {macOnly} { expr {[lsearch [font families] Geneva] > 0} } {1} test macFont-6.1 {TkpGetSubFonts} {testfont gothic macOnly} { .b.l config -text "abc\u4e4e" update set x [testfont subfonts $fixed] } "Monaco [font actual $gothic -family]" test macFont-7.1 {Tk_MeasureChars: unbounded right margin} {macOnly} { .b.l config -wrap 0 -text "000000" getsize } "[expr $ax*6] $ay" test macFont-7.2 {Tk_MeasureChars: static width buffer exceeded} {macOnly} { .b.l config -wrap 100000 -text "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" getsize } "[expr $ax*256] $ay" test macFont-7.3 {Tk_MeasureChars: all chars did fit} {macOnly} { .b.l config -wrap [expr $ax*10] -text "00000000" getsize } "[expr $ax*8] $ay" test macFont-7.4 {Tk_MeasureChars: not all chars fit} {macOnly} { .b.l config -wrap [expr $ax*6] -text "00000000" getsize } "[expr $ax*6] [expr $ay*2]" test macFont-7.5 {Tk_MeasureChars: already saw space in line} {macOnly} { .b.l config -wrap [expr $ax*12] -text "000000 0000000" getsize } "[expr $ax*7] [expr $ay*2]" test macFont-7.6 {Tk_MeasureChars: internal spaces significant} {macOnly} { .b.l config -wrap [expr $ax*12] -text "000 00 00000" getsize } "[expr $ax*7] [expr $ay*2]" test macFont-7.7 {Tk_MeasureChars: include last partial char} {macOnly} { .b.c dchars $t 0 end .b.c insert $t 0 "0000" .b.c index $t @[expr int($ax*2.5)],1 } {2} test macFont-7.8 {Tk_MeasureChars: at least one char on line} { macOnly} { .b.l config -text "000000" -wrap 1 getsize } "$ax [expr $ay*6]" test macFont-7.9 {Tk_MeasureChars: whole words} {macOnly} { .b.l config -wrap [expr $ax*8] -text "000000 0000" getsize } "[expr $ax*6] [expr $ay*2]" test macFont-7.10 {Tk_MeasureChars: make first part of word fit} {macOnly} { .b.l config -wrap [expr $ax*12] -text "0000000000000000" getsize } "[expr $ax*12] [expr $ay*2]" test macFont-7.11 {Tk_MeasureChars: numBytes == 0} {macOnly} { font measure system {} } {0} test macFont-7.12 {Tk_MeasureChars: maxLength < 0} {macOnly} { font measure $courier abcd } "[expr $cx*4]" test macFont-7.13 {Tk_MeasureChars: loop on each char} {macOnly} { font measure $courier abcd } "[expr $cx*4]" test macFont-7.14 {Tk_MeasureChars: p == end} {macOnly} { font measure $courier abcd } "[expr $cx*4]" test macFont-7.15 {Tk_MeasureChars: p > end} {macOnly} { font measure $courier abc\xc2 } "[expr $cx*4]" test macFont-7.16 {Tk_MeasureChars: thisFamilyPtr != lastFamilyPtr} {gothic macOnly} { font measure $courier abc\u4e4edef } [expr $cx*6+$mx] test macFont-7.17 {Tk_MeasureChars: measure no chars (in loop)} {gothic macOnly} { font measure $courier \u4e4edef } [expr $mx+$cx*3] test macFont-7.18 {Tk_MeasureChars: final measure} {gothic macOnly} { font measure $courier \u4e4edef } [expr $mx+$cx*3] test macFont-7.19 {Tk_MeasureChars: final measure (no chars)} {gothic macOnly} { font measure $courier \u4e4e } [expr $mx] test macFont-7.20 {Tk_MeasureChars: maxLength >= 0} {macOnly} { .b.l config -wrap [expr $ax*8] -text "000" getsize } "[expr $ax*3] $ay" test macFont-7.21 {Tk_MeasureChars: loop on each char} {macOnly} { .b.l config -wrap [expr $ax*8] -text "000" getsize } "[expr $ax*3] $ay" test macFont-7.22 {Tk_MeasureChars: p == end} {macOnly} { .b.l config -wrap [expr $ax*8] -text "000" getsize } "[expr $ax*3] $ay" test macFont-7.23 {Tk_MeasureChars: p > end} {macOnly} { .b.l config -wrap [expr $ax*8] -text "00\xc2" getsize } "[expr $ax*3] $ay" test macFont-7.24 {Tk_MeasureChars: thisFamilyPtr != lastFamilyPtr} {gothic macOnly} { .b.l config -wrap [expr $ax*8] -text "00\u4e4e00" getsize } "[expr $ax*4+$mx] $ay" test macFont-7.25 {Tk_MeasureChars: measure no chars (in loop)} {gothic macOnly} { .b.l config -wrap [expr $ax*8] -text "\u4e4e00" getsize } "[expr $mx+$ax*2] $ay" test macFont-7.26 {Tk_MeasureChars: rest == NULL} {gothic macOnly} { .b.l config -wrap [expr $ax*20] -text "000000\u4e4e\u4e4e00" getsize } "[expr $ax*8+$mx*2] $ay" test macFont-7.27 {Tk_MeasureChars: rest != NULL in first segment} {gothic macOnly} { .b.l config -wrap [expr $ax*5] -text "000000\u4e4e\u4e4f00" getsize } "[expr $ax*5] [expr $ay*3]" test macFont-7.28 {Tk_MeasureChars: rest != NULL in next segment} {gothic macOnly} { # even some of the "0"s would fit after \u4e4d, they should all wrap to next line. .b.l config -wrap [expr $ax*8] -text "\u4e4d\u4e4d000000\u4e4e\u4e4f00" getsize } "[expr $ax*6+$mx] [expr $ay*3]" test macFont-7.29 {Tk_MeasureChars: final measure} {gothic macOnly} { .b.l config -wrap [expr $ax*8] -text "\u4e4e00" getsize } "[expr $mx+$ax*2] $ay" test macFont-7.30 {Tk_MeasureChars: final measure (no chars)} {gothic macOnly} { .b.l config -wrap [expr $ax*8] -text "\u4e4e" getsize } "$mx $ay" test macFont-7.31 {Tk_MeasureChars: rest == NULL} {macOnly} { .b.l config -wrap [expr $ax*1000] -text 0000 getsize } "[expr $ax*4] $ay" test macFont-7.32 {Tk_MeasureChars: rest != NULL} {macOnly} { .b.l config -wrap [expr $ax*6] -text "00000000" getsize } "[expr $ax*6] [expr $ay*2]" test macFont-8.1 {Tk_DrawChars procedure} {macOnly} { .b.l config -text "a" update } {} test macFont-9.1 {AllocMacFont: use old font} {macOnly} { font create xyz button .c -font xyz font configure xyz -family times update destroy .c font delete xyz } {} test macFont-9.2 {AllocMacFont: extract info from style} {macOnly} { font actual {Monaco 9 bold italic underline overstrike} } {-family Monaco -size 9 -weight bold -slant italic -underline 1 -overstrike 0} test macFont-9.3 {AllocMacFont: extract text metrics} {macOnly} { font metric {Geneva 10} -fixed } {0} test macFont-9.4 {AllocMacFont: extract text metrics} {macOnly} { font metric "Monaco 9" -fixed } {1} destroy .b # cleanup ::tcltest::cleanupTests return