#
# item.test --
#
#     This file contains some automated tests to exercise code in
#     c3dlight.c. Essentially all that is tested is the limit of 8 light
#     sources per scene.
#

package require tcltest 2.2
namespace import -force ::tcltest::*

package require Tk
package require Canvas3d

set ::COORDS {1.0 1.0 1.0}

canvas3d .win

test canvas-light.1.1 {} -body {
  for {set i 0} {$i < 8} {incr i} {
    lappend ::ids [.win create light $::COORDS]
  }

  set rc [catch {
    .win create light $::COORDS
  } msg]

  list $rc $msg
} -result {1 {Maximum light source count exceeded}}

test canvas-light.1.2 {} -body {
  set d [lindex $::ids 0]
  set ::ids [lreplace $::ids 0 0]
  .win delete $d

  catch {
    lappend ::ids [.win create light $::COORDS]
  }
} -result {0}

test canvas-light.1.3 {} -body {
  set rc [catch {
    .win create light $::COORDS
  } msg]

  list $rc $msg
} -result {1 {Maximum light source count exceeded}}

test canvas-light.1.4 {} -body {
  set d [lindex $::ids 7]
  set ::ids [lreplace $::ids 7 7]
  .win delete $d

  catch {
    lappend ::ids [.win create light $::COORDS]
  }
} -result {0}

test canvas-light.1.5 {} -body {
  set rc [catch {
    .win create light $::COORDS
  } msg]

  list $rc $msg
} -result {1 {Maximum light source count exceeded}}

test canvas-light.1.6 {} -body {
  set d [lindex $::ids 3]
  set ::ids [lreplace $::ids 3 3]
  .win delete $d

  catch {
    lappend ::ids [.win create light $::COORDS]
  }
} -result {0}

destroy .win

# cleanup
cleanupTests
return
