# Commands covered:  GD
#
# This file contains a collection of tests for one or more of the tcl.gd
# commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 2000 by Scriptics Corporation.
# Copyright (c) 2005 by Karl Lehenbauer.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: gd.test,v 1.2 2005-11-17 07:00:34 karl Exp $

package require tclgd

test GD-1.1 {incorrect command usage} -body {
    GD
} -returnCodes 1 -result {wrong # args: should be "GD subcommand ?args?"}

test GD-1.2 {incorrect command usage} -body {
    GD asdf
} -returnCodes 1 -match glob -result {bad option "asdf": must be *}

test GD-1.3 {GD version} -body {
    GD version
} -match glob -result {2.*.*}

test GD-1.4 {invalid GD create usage} -body {
    GD create
} -returnCodes 1 -result {wrong # args: should be "GD create name x y"}

test GD-1.5 {GD create with invalid x component} -body {
    GD create foo bar 100
} -returnCodes 1 -result {expected integer but got "bar" while converting x component}

test GD-1.6 {GD create with invalid y component} -body {
    GD create foo bar 100
} -returnCodes 1 -result {expected integer but got "bar" while converting x component}

test GD-1.7 {valid GD create command} -body {
    GD create foo 100 100
} -result foo

test GD-1.8 {delete newly created gd command} -body {
    rename foo {}
} -result {}

test GD-1.9 {valid GD create command with self-defined object name} -body {
    GD create #auto 100 100
} -result gd0

test GD-1.10 {delete of self-defined object name} -body {
    rename gd0 {}
} -result {}

test GD-1.11 {invalid GD create_truecolor usage} -body {
    GD create_truecolor
} -returnCodes 1 -result {wrong # args: should be "GD create_truecolor name x y"}

test GD-1.12 {GD create_truecolor with invalid x component} -body {
    GD create_truecolor foo bar 100
} -returnCodes 1 -result {expected integer but got "bar" while converting x component}

test GD-1.13 {GD create_truecolor with invalid y component} -body {
    GD create_truecolor foo bar 100
} -returnCodes 1 -result {expected integer but got "bar" while converting x component}

test GD-1.14 {valid GD create_truecolor command} -body {
    GD create_truecolor foo 100 100
} -result foo

test GD-1.15 {delete newly created_truecolor gd command} -body {
    rename foo {}
} -result {}

test GD-1.16 {valid GD create_truecolor command with self-defined object name} -body {
    GD create_truecolor #auto 100 100
} -result gd1

test GD-1.17 {delete of self-defined object name} -body {
    rename gd1 {}
} -result {}

test GD-1.18 {valid GD create} -body {
    GD create img 100 100
} -result img

test GD-1.19 {invalid invocation of GD object command -- no subcommand} -body {
    img
} -returnCodes 1 -result {wrong # args: should be "img option ?args?"}

test GD-1.20 {invalid invocation of GD object command -- invalid subcommand} -body {
    img asdf
} -returnCodes 1 -match glob -result {bad option "asdf": must be *}

test GD-2.1 {create truecolor image} -body {
    GD create_truecolor im1 100 100
} -result im1

test GD-2.2 {create indexed image} -body {
    GD create im2 100 100
} -result im2

test GD-2.3 {compare truecolor and indexed image} -body {
    im1 compare im2
} -result truecolor

test GD-2.4 {allocate color, compare truecolor and indexed image} -body {
     im2 allocate_color 50 50 50; im1 compare im2
} -result {image num_colors colors truecolor}

test GD-2.5 {allocate color, compare truecolor and interlaced indexed image} -body {
    im2 interlace 1; im1 compare im2
} -result {image num_colors colors interlace truecolor}

test GD-2.6 {set transparent color, compare truecolor and interlaced indexed image} -body {
    im2 transparent 0
    im1 compare im2
} -result {image num_colors colors transparent interlace truecolor}

test GD-2.7 {compare images of different width} -body {
    GD create_truecolor im3 101 100
    im1 compare im3
} -result {image width}

test GD-2.8 {compare images of different height} -body {
    GD create_truecolor im4 100 101
    im1 compare im4
} -result {image height}

test GD-2.8 {compare images of different height} -body {
    GD create_truecolor im4 100 101
    im1 compare im4
} -result {image height}

test GD-2.9 {compare identical-appearing truecolor and indexed images} -body {
    im2 polygon filled {0 0 0 100 100 100 100 0} 0
    im1 polygon filled {0 0 0 100 100 100 100 0} [im1 allocate_color 50 50 50]
    im1 compare im2
} -result {num_colors transparent interlace truecolor}

# cleanup
::tcltest::cleanupTests
return
