Skip to content
Tcl Source Code Artifact [c96acbe78c]
Login

Artifact [c96acbe78c]

Artifact c96acbe78c90b9f833935ada44a44fd4fd497ddc:


# Commands covered:  http::config, http::geturl, http::wait, http::reset
#
# This file contains a collection of tests for the http script library.
# Sourcing this file into Tcl runs the tests and generates output for errors.
# No output means no errors were found.
#
# This file is a rewrite to demostrate TIP 452 (enhancement to tcltest for
# stubs/mocks and seams).  NOTE -- due to the use of stubs/mocks, no actual
# I/O is done, so the httpd package is no longer being used. Please also note,
# the seams feature is not used, only the stub/mock feature.
#
# Copyright (c) 1991-1993 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-2000 by Ajuba Solutions.
# Copyright (c) 2017 by Gerald W. Lester.
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tcltest 2.5

if {[catch {package require http 2} version]} {
    if {[info exists http2]} {
	catch {puts "Cannot load http 2.* package"}
	return
    } else {
	catch {puts "Running http 2.* tests in slave interp"}
	set interp [interp create http2]
	$interp eval [list set http2 "running"]
	$interp eval [list set argv $argv]
	$interp eval [list source [info script]]
	interp delete $interp
	return
    }
}

proc bgerror {args} {
    global errorInfo
    puts stderr "http.test bgerror"
    puts stderr [join $args]
    puts stderr $errorInfo
}

set bindata "This is binary data\x0d\x0amore\x0dmore\x0amore\x00null"
catch {unset data}

::tcltest::test http-1.1 {http::config} {
    http::config -useragent UserAgent
    http::config
} [list -accept */* -proxyfilter http::ProxyRequired -proxyhost {} -proxyport {} -urlencoding utf-8 -useragent "UserAgent"]
::tcltest::test http-1.2 {http::config} {
    http::config -proxyfilter
} http::ProxyRequired
::tcltest::test http-1.3 {http::config} {
    catch {http::config -junk}
} 1
::tcltest::test http-1.4 {http::config} {
    set savedconf [http::config]
    http::config -proxyhost nowhere.come -proxyport 8080 \
	-proxyfilter myFilter -useragent "Tcl Test Suite" \
	-urlencoding iso8859-1
    set x [http::config]
    http::config {*}$savedconf
    set x
} {-accept */* -proxyfilter myFilter -proxyhost nowhere.come -proxyport 8080 -urlencoding iso8859-1 -useragent {Tcl Test Suite}}
::tcltest::test http-1.5 {http::config} -returnCodes error -body {
    http::config -proxyhost {} -junk 8080
} -result {Unknown option -junk, must be: -accept, -proxyfilter, -proxyhost, -proxyport, -urlencoding, -useragent}
::tcltest::test http-1.6 {http::config} -setup {
    set oldenc [http::config -urlencoding]
} -body {
    set enc [list [http::config -urlencoding]]
    http::config -urlencoding iso8859-1
    lappend enc [http::config -urlencoding]
} -cleanup {
    http::config -urlencoding $oldenc
} -result {utf-8 iso8859-1}


##
## Test http::geturl
##
::tcltest::test http-2.1 {http::geturl} \
    -setup {

    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::formatQuery
##
::tcltest::test http-3.1 {http::formatQuery}  \
    -setup {

    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::reset
##

##
## Happy path
##
::tcltest::test http-4.1 {http::reset} \
    -setup {
        array set ::http_1 {
            sock none
        }
        unset -nocomplain ::http_1(error)
        ::tcltest::testSetup {
            ::fileevent {
                * {
                    returns {Test error}
                    code {error}
                    errorcode {HTTP TEST RESET FILEEVENT}
                }
            }
            ::http::Finish {
                * {
                    returns {No Error}
                    errorcode {}
                    set {
                        ::http_1 A {
                            status {---}
                        }
                    }
                }
            }
        }
    } \
    -body {
        list [catch {::http::reset ::http_1}] [info exists ::http_1] [::tcltest::callCount]
    } \
    -result {0 1 {::fileevent,count 2 ::http::Finish,count 1}} \
    -cleanup {
        ::tcltest::testCleanup
    }

##
## Test error
#
::tcltest::test http-4.2 {http::rest} \
    -setup {
        array set ::http_1 {
            sock none
        }
        unset -nocomplain ::http_1(error)
        ::tcltest::testSetup {
            ::fileevent {
                * {
                    returns {Test error}
                    code {error}
                    errorcode {HTTP TEST RESET FILEEVENT}
                }
            }
            ::http::Finish {
                * {
                    returns {No Error}
                    errorcode {}
                    set {
                        ::http_1 A {
                            status {---}
                            error {{HTTP TEST ERROR}}
                        }
                    }
                }
            }
        }
    } \
    -body {
        list [catch {::http::reset ::http_1} result] [info exists ::http_1] [::tcltest::callCount] $result
    } \
    -result {1 0 {::fileevent,count 2 ::http::Finish,count 1} {HTTP TEST ERROR}} \
    -cleanup {
        ::tcltest::testCleanup
    }


##
## Test http::wait
##
::tcltest::test http-5.1 {http::wait} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Testhttp::data
##
::tcltest::test http-6.1 {http::data} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::error
##
::tcltest::test http-7.1 {http::error} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::status
##
::tcltest::test http-8.1 {http::status} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::code
##
::tcltest::test http-9.1 {http::code} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::ncode
##
::tcltest::test http-10.1 {http::ncode} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::size
##
::tcltest::test http-11.1 {http::size} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::me
##
::tcltest::test http-12.1 {http::size} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::cleanup
##
::tcltest::test http-13.1 {http::cleanup} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::register
##
::tcltest::test http-15.1 {http::register} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::unregister
##
::tcltest::test http-16.1 {http::unregister} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::Finish
##
::tcltest::test http-17.1 {http::Finish}  \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}



##
## Test http::Connected
##
::tcltest::test http-18.1 {http::Connected}  \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::Connect
##
::tcltest::test http-19.1 {http::Connect}  \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::Write
##
::tcltest::test http-20.1 {http::Write} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::Event
##
::tcltest::test http-21.1 {http::Event} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::IsBinaryContentType
##
::tcltest::test http-22.1 {http::IsBinaryContentType} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::CopyStart
###
::tcltest::test http-23.1 {http::CopyStart} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::CopyChunk
##
::tcltest::test http-24.1 {http::CopyChunk} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::CopyDone
##
::tcltest::test http-25.1 {http::CopyDone} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::EOF
##
::tcltest::test http-26.1 {http::EOF} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::mapReply
##
::tcltest::test http-27.1 {http::mapReply} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::ProxyRequire
##
::tcltest::test http-28.1 {http::ProxyRequire} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::CharsetToEncoding
##
::tcltest::test http-29.1 {http::CharsetToEncoding} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}

##
## Test http::ContentEncoding
##
::tcltest::test http-30.1 {http::ContentEncoding} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


##
## Test http::make-transformation-chunked
##
::tcltest::test http-31.1 {http::make-transformation-chunked} \
    -setup {
    } \
    -body {
        list Test Not Yet Implemented
    } \
    -cleanup {
        ::tcltest::testCleanup
    } \
    -result {}


# cleanup
catch {unset url}
catch {unset badurl}
catch {unset port}
catch {unset data}

rename bgerror {}
::tcltest::cleanupTests

# Local variables:
# mode: tcl
# End: