# -*- tcl -*-
# Commands covered:	None, introductory text
#
# This file contains a collection of tests for one or more of the commands
# the piTcl extension. Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1998 Andreas Kupries (a.kupries@westend.com)
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: memchan.test,v 1.7 1999/09/18 13:36:07 aku Exp $

if {[string compare test [info procs test]] == 1} then {source defs}


test memchan-basics-1.0 {Create memory channels} {
    set m [memchan]
    close $m
    regsub -all {[0-9]} $m {} m
    set m
} {mem}

test memchan-basics-1.1 {Check tell on memory channels} {
    set m [memchan]
    set res [tell $m]
    close $m
    set res
} {0}

test memchan-basics-1.2 {Check seek on memory channels} {
    set m [memchan]
    set res [seek $m 0]
    close $m
    set res
} {}

test memchan-basics-1.3 {Check fconfigure/get on memory channels} {
    set m [memchan]
    set resf [fconfigure $m]
    set res [list]
    lappend res [lrange $resf [set x [lsearch -exact $resf -length]] [incr x]]
    lappend res [lrange $resf [set x [lsearch -exact $resf -allocated]] [incr x]]
    close $m
    set res
} {{-length 0} {-allocated 0}}

test memchan-basics-1.4 {Check fconfigure/get -length} {
    set m [memchan]
    set res [fconfigure $m -length]
    close $m
    set res
} {0}

test memchan-basics-1.5 {check -initial-size} {
    set m   [memchan -init 1024]
    set res [fconfigure $m -allocated]
    close $m
    set res
} {1024}

test memchan-readwrite-1.0 {Write, length and tell} {
    set m [memchan]
    puts -nonewline $m {hello world}
    set res [list [fconfigure $m -length] [tell $m]]
    close $m
    set res
} {11 11}

test memchan-readwrite-1.1 {Write, seek and read} {
    set m [memchan]
    puts -nonewline $m {hello world!}
    set res [list [fconfigure $m -length] [tell $m]]
    seek $m 0
    lappend res [read $m]
    close $m
    set res
} {12 12 {hello world!}}


catch {unset m}
catch {unset res}
