;;; Time-stamp: <06/06/13 12:04:22 noel>
;;; Copyright (C) by Noel Welsh.

;;; This library is free software; you can redistribute it
;;; and/or modify it under the terms of the GNU Lesser
;;; General Public License as published by the Free Software
;;; Foundation; either version 2.1 of the License, or (at
;;; your option) any later version.

;;; This library is distributed in the hope that it will be
;;; useful, but WITHOUT ANY WARRANTY; without even the
;;; implied warranty of MERCHANTABILITY or FITNESS FOR A
;;; PARTICULAR PURPOSE.  See the GNU Lesser General Public
;;; License for more details.

;;; You should have received a copy of the GNU Lesser
;;; General Public License along with this library; if not,
;;; write to the Free Software Foundation, Inc., 59 Temple
;;; Place, Suite 330, Boston, MA 02111-1307 USA

;;; Author: Noel Welsh <>
;; Commentary:

(module instaweb-test mzscheme

  (require (planet "" ("schematics" "schemeunit.plt" 2)))
  (require (lib "" "net")
           (planet "" ("schematics" "port.plt" 1))

  (provide instaweb-tests)

  (define (make-dummy)
    (with-output-to-file ""
      (lambda ()
         '(module dummy mzscheme
            (require (lib "" "web-server"))
            (provide interface-version timeout start)
            (define interface-version 'v1)
            (define timeout +inf.0)
            (define (start initial-request)

  (define instaweb-tests
     "All tests for instaweb"

      "Server listens on specified port and IP"
       (let ((server
               (lambda ()
                 (instaweb "" 4567 "")))))
         (sleep 1)
         (let ((content
                 (string->url ""))))
           (check string=? (port->string content) "foo\r\n"))
         ;; Check the server is not listening on other ports
          (lambda ()
             (string->url ""))))
         (kill-thread server))))

      "Instaweb stops reading if input port returns eof"
       (let* ((op (open-output-string))
                (lambda ()
                    ((current-input-port (open-input-string ""))
                     (current-output-port op))
                    (instaweb "" 4567 ""))))))
         (sleep 1)
         (kill-thread server)
         (let ((content (get-output-string op)))
           (display content)
           (check <=
                  (string-length content)