# -*- tcl -*-
# Commands covered:	zero
#
# This file contains a collection of tests for one or more of the commands
# the Memchan extension. Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1999 Andreas Kupries (a.kupries@westend.com)
# Copyright (C) 2004 Pat Thoyts <patthoyts@users.sourceforge.net>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: zero.test,v 1.2 2004/06/04 14:09:11 patthoyts Exp $


test zero-1.0 {Create zero devices} {
    set chan [zero]
    close $chan
    regsub -all {[0-9]} $chan {} chan
    set chan
} {zero}


test zero-1.1 {Check tell on zero devices} {
    set chan [zero]
    set res [tell $chan]
    close $chan
    set res
} {-1}


test zero-1.2 {Check seek on zero devices} {
    set chan [zero]
    catch {seek $chan 0} res
    close $chan
    regsub -all $chan $res XXX res
    set res
} {error during seek on "XXX": invalid argument}


test zero-1.3 {Write, length and tell} {
    set chan [zero]
    puts -nonewline $chan {hello world}
    set res [tell $chan]
    close $chan
    set res
} {-1}

test zero-1.4 {Write and read} {
    set chan [zero]
    puts -nonewline $chan {hello world!}
    set res [tell $chan]
    lappend res [string length [read $chan 16]]
    close $chan
    set res
} {-1 16}

test zero-1.5 {presence of -delay option} {
    list [catch {
        set chan [zero]
        set res [lsearch -exact [fconfigure $chan] -delay]
        close $chan
        set res [expr {$res != -1}]
    } msg] $msg
} {0 1}

test zero-1.6 {read -delay option} {
    list [catch {
        set chan [zero]
        set res [fconfigure $chan -delay]
        close $chan
        set res
    } msg] $msg
} {0 5}

test zero-1.7 {change -delay option} {
    list [catch {
        set chan [zero]
        set res [fconfigure $chan -delay 1000]
        lappend res [fconfigure $chan -delay]
        close $chan
        set res
    } msg] $msg
} {0 {1000 1000}}

