# -*- tcl -*-
# Commands covered:	random
#
# 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: random.test,v 1.2 2004/06/04 14:09:11 patthoyts Exp $

test random-1.0 {Create random devices} {
    list [catch {
        set chan [random]
        close $chan
        regsub -all {[0-9]} $chan {} chan
        set chan
    } msg] $msg
} {0 random}

test random-1.1 {Check tell on random devices} {
    list [catch {
        set chan [random]
        set res [tell $chan]
        close $chan
        set res
    } msg] $msg
} {0 -1}

test random-1.2 {Write, length, tell} {
    list [catch {
        set chan [random]
        catch {seek $chan 0} res
        close $chan
        regsub -all $chan $res XXX res
        set res
    } msg] $msg
} {0 {error during seek on "XXX": invalid argument}}

test random-1.3 {Write, length and tell} {
    list [catch {
        set chan [random]
        puts -nonewline $chan \x00\x01\x02\x03
        set res [tell $chan]
        close $chan
        set res
    } msg] $msg
} {0 -1}

test random-1.4 {Write and read} {
    list [catch {
        set chan [random]
        puts -nonewline $chan \x00\x01\x02\x03
        set res [tell $chan]
        lappend res [string length [read $chan 64]]
        close $chan
        set res
    } msg] $msg
} {0 {-1 64}}

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

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

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