# 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} {
    list [catch {GD} errMsg] $errMsg
} {1 {wrong # args: should be "GD subcommand ?args?"}}

test GD-1.2 {incorrect command usage} {
    list [catch {GD asdf} errMsg] $errMsg
} {1 {bad option "asdf": must be create, create_truecolor, create_from_jpeg, create_from_jpeg_data, create_from_png, create_from_png_data, create_from_gif, create_from_gif_data, create_from_gd, create_from_gd_data, create_from_gd2, create_from_gd2_data, create_from_gd2_part, create_from_gd2_part_data, create_from_wbmp, create_from_wbmp_data, create_from_xbm, create_from_xpm, version, or features}}

test GD-1.3 {GD version} {
    list [catch {GD version} errMsg] $errMsg
} {0 2.0.35}

test GD-1.4 {invalid GD create usage} {
    list [catch {GD create} errMsg] $errMsg
} {1 {wrong # args: should be "GD create name x y"}}

test GD-1.5 {GD create with invalid x component} {
    list [catch {GD create foo bar 100} errMsg] $errMsg
} {1 {expected integer but got "bar" while converting x component}}

test GD-1.6 {GD create with invalid y component} {
    list [catch {GD create foo bar 100} errMsg] $errMsg
} {1 {expected integer but got "bar" while converting x component}}

test GD-1.7 {valid GD create command} {
    list [catch {GD create foo 100 100} errMsg] $errMsg
} {0 foo}

test GD-1.8 {delete newly created gd command} {
    list [catch {rename foo {}} errMsg] $errMsg
} {0 {}}

test GD-1.9 {valid GD create command with self-defined object name} {
    list [catch {GD create #auto 100 100} errMsg] $errMsg
} {0 gd0}

test GD-1.10 {delete of self-defined object name} {
    list [catch {rename gd0 {}} errMsg] $errMsg
} {0 {}}

test GD-1.11 {invalid GD create_truecolor usage} {
    list [catch {GD create_truecolor} errMsg] $errMsg
} {1 {wrong # args: should be "GD create_truecolor name x y"}}

test GD-1.12 {GD create_truecolor with invalid x component} {
    list [catch {GD create_truecolor foo bar 100} errMsg] $errMsg
} {1 {expected integer but got "bar" while converting x component}}

test GD-1.13 {GD create_truecolor with invalid y component} {
    list [catch {GD create_truecolor foo bar 100} errMsg] $errMsg
} {1 {expected integer but got "bar" while converting x component}}

test GD-1.14 {valid GD create_truecolor command} {
    list [catch {GD create_truecolor foo 100 100} errMsg] $errMsg
} {0 foo}

test GD-1.15 {delete newly created_truecolor gd command} {
    list [catch {rename foo {}} errMsg] $errMsg
} {0 {}}

test GD-1.16 {valid GD create_truecolor command with self-defined object name} {
    list [catch {GD create_truecolor #auto 100 100} errMsg] $errMsg
} {0 gd1}

test GD-1.17 {delete of self-defined object name} {
    list [catch {rename gd1 {}} errMsg] $errMsg
} {0 {}}

test GD-1.18 {valid GD create} {
    list [catch {GD create img 100 100} errMsg] $errMsg
} {0 img}

test GD-1.19 {invalid invocation of GD object command -- no subcommand} {
    list [catch {img} errMsg] $errMsg
} {1 {wrong # args: should be "img option ?args?"}}

test GD-1.20 {invalid invocation of GD object command -- invalid subcommand} {
    list [catch {img asdf} errMsg] $errMsg
} {1 {bad option "asdf": must be pixel, pixelrgb, line, polygon, rectangle, filled_rectangle, arc, filled_arc, filled_ellipse, fill_to_border, fill, text, text_bounds, allocate_color, closest_color, closest_color_hwb, exact_color, resolve_color, total_colors, deallocate_color, true_color, interlace, transparent, set_anti_aliased, set_anti_aliased_dont_blend, set_brush, set_tile, set_style, set_thickness, alpha_blending, save_alpha, clip, get_alpha, bounds_safe, green_component, red_component, blue_component, rgb_components, width, height, compare_ratio, copy, copy_resized, copy_resampled, copy_rotated, copy_merge, copy_merge_grey, copy_palette, sharpen, compare, square_to_circle, write_jpeg, jpeg_data, write_gif, gif_data, gif_anim_begin, gif_anim_add, gif_anim_end, write_png, png_data, write_wbmp, wbmp_data, write_gd, gd_data, write_gd2, or gd2_data}}

test GD-2.1 {create truecolor image} {
    list [catch {GD create_truecolor im1 100 100} errMsg] $errMsg
} {0 im1}

test GD-2.2 {create indexed image} {
    list [catch {GD create im2 100 100} errMsg] $errMsg
} {0 im2}

test GD-2.3 {compare truecolor and indexed image} {
    list [catch {im1 compare im2} errMsg] $errMsg
} {0 truecolor}

test GD-2.4 {allocate color, compare truecolor and indexed image} {
    list [catch {im2 allocate_color 50 50 50; im1 compare im2} errMsg] $errMsg
} {0 {image num_colors colors truecolor}}

test GD-2.5 {allocate color, compare truecolor and interlaced indexed image} {
    list [catch {im2 interlace 1; im1 compare im2} errMsg] $errMsg
} {0 {image num_colors colors interlace truecolor}}

test GD-2.6 {set transparent color, compare truecolor and interlaced indexed image} {
    list [catch {im2 transparent 0; im1 compare im2} errMsg] $errMsg
} {0 {image num_colors colors transparent interlace truecolor}}

test GD-2.7 {compare images of different width} {
    list [catch {GD create_truecolor im3 101 100; im1 compare im3} errMsg] $errMsg
} {0 {image width}}

test GD-2.8 {compare images of different height} {
    list [catch {GD create_truecolor im4 100 101; im1 compare im4} errMsg] $errMsg
} {0 {image height}}

test GD-2.8 {compare images of different height} {
    list [catch {GD create_truecolor im4 100 101; im1 compare im4} errMsg] $errMsg
} {0 {image height}}

test GD-2.9 {compare identical-appearing truecolor and indexed images} {
    list [catch {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} errMsg] $errMsg
} {0 {num_colors transparent interlace truecolor}}

# cleanup
::tcltest::cleanupTests
return
