udp tests updated

svn: r1270
This commit is contained in:
Matthew Flatt 2005-11-10 17:02:09 +00:00
parent 5be1e35c93
commit 5590bf1a10
2 changed files with 30 additions and 30 deletions

View File

@ -1283,7 +1283,7 @@
(err/rt-test (udp-send-ready-evt 5))
(err/rt-test (udp-receive-ready-evt 5))
(arity-test udp-open-socket 0 0)
(arity-test udp-open-socket 0 2)
(arity-test udp-close 1 1)
(arity-test udp? 1 1)
(arity-test udp-bound? 1 1)
@ -1389,7 +1389,7 @@
(err/rt-test (tcp-connect "other" 123) (net-reject? 'tcp-connect "other" 123 'client))
(err/rt-test (tcp-listen 123) (net-reject? 'tcp-listen #f 123 'server))
(unless (eq? 'macos (system-type)) ; no UDP in Mac OS Classic
(err/rt-test (udp-open-socket) (net-reject? 'udp-open-socket #f #f 'client))
(err/rt-test (udp-open-socket) (net-reject? 'udp-open-socket #f #f 'server))
(err/rt-test (udp-bind! early-udp "localhost" 40000) (net-reject? 'udp-bind! "localhost" 40000 'server))
(err/rt-test (udp-connect! early-udp "localhost" 40000) (net-reject? 'udp-connect! "localhost" 40000 'client))
(err/rt-test (udp-send-to early-udp "localhost" 40000 #"hi") (net-reject? 'udp-send-to "localhost" 40000 'client))))

View File

@ -19,7 +19,7 @@
(err/rt-test (udp-send* udp1 us1) exn:fail:network?)
(err/rt-test (udp-send/enable-break udp1 us1) exn:fail:network?)
(test (void) udp-send-to udp1 "localhost" 45678 #"knock knock")
(test (void) udp-send-to udp1 "127.0.0.1" 45678 #"knock knock")
(sleep 0.05)
(test-values '(#f #f #f) (lambda ()
;; The send above might cause an error on the next
@ -35,31 +35,31 @@
;; still not connected:
(err/rt-test (udp-send udp1 us1) exn:fail:network?)
(define udp2 (udp-open-socket))
(test (void) udp-bind! udp2 #f 40007)
(define udp2 (udp-open-socket "127.0.0.1"))
(test (void) udp-bind! udp2 "127.0.0.1" 40007)
(test-values '(#f #f #f) (lambda () (udp-receive!* udp2 us1)))
(test (void) udp-send-to udp1 "localhost" 40007 #"Hiya.")
(test (void) udp-send-to udp1 "127.0.0.1" 40007 #"Hiya.")
(define recv-got (call-with-values (lambda () (udp-receive! udp2 us1)) list))
(test 5 car recv-got)
(test #"127.0.0.1" cadr recv-got)
(test "127.0.0.1" cadr recv-got)
(define udp1-port (caddr recv-got))
(test #"Hiya.\0\0\0\0\0" values us1)
(test (void) udp-send-to udp1 "localhost" 40007 #"...another?..." 3 11)
(test-values (list 8 #"127.0.0.1" udp1-port) (lambda () (udp-receive! udp2 us1 1)))
(test (void) udp-send-to udp1 "127.0.0.1" 40007 #"...another?..." 3 11)
(test-values (list 8 "127.0.0.1" udp1-port) (lambda () (udp-receive! udp2 us1 1)))
(test #"Hanother?\0" values us1)
(test (void) udp-connect! udp1 "localhost" 40007)
(test (void) udp-connect! udp1 "127.0.0.1" 40007)
(test #t udp-connected? udp1)
(test #f udp-connected? udp2)
(test (void) udp-send udp1 #"truncate me")
(test-values (list 6 #"127.0.0.1" udp1-port) (lambda () (udp-receive! udp2 us1 2 8)))
(test-values (list 6 "127.0.0.1" udp1-port) (lambda () (udp-receive! udp2 us1 2 8)))
(test #"Hatrunca?\0" values us1)
(test #t udp-send* udp1 #"SKIPall of it" 4)
(test-values (list 9 #"127.0.0.1" udp1-port) (lambda () (udp-receive! udp2 us1 0)))
(test-values (list 9 "127.0.0.1" udp1-port) (lambda () (udp-receive! udp2 us1 0)))
(test #"all of it\0" values us1)
(define (flush-udp-errors udp)
@ -69,13 +69,13 @@
(udp-receive!* udp1 us1))))
;; re-connect
(test (void) udp-connect! udp1 "localhost" 40008)
(test (void) udp-connect! udp1 "127.0.0.1" 40008)
(test #t udp-connected? udp1)
(test (void) udp-send udp1 #"lots of stuff")
(sleep 0.05)
(flush-udp-errors udp1)
(test-values '(#f #f #f) (lambda () (udp-receive!* udp2 us1)))
(err/rt-test (udp-send-to udp1 "localhost" 40007 #"not ok -- currently connected") exn:fail:network?)
(err/rt-test (udp-send-to udp1 "127.0.0.1" 40007 #"not ok -- currently connected") exn:fail:network?)
(test #t udp-send* udp1 #"lots of stuff")
(sleep 0.05)
(flush-udp-errors udp1)
@ -96,11 +96,11 @@
(test #t evt? udp2-r)
(test #f sync/timeout 0.05 udp2-r)
(test (void) sync (udp-send-to-evt udp1 "localhost" 40007 #"here's more"))
(test (void) sync (udp-send-to-evt udp1 "127.0.0.1" 40007 #"here's more"))
(sleep 0.05)
(test udp2-r sync udp2-r)
(test udp2-r sync udp2-r)
(test (list 10 #"127.0.0.1" udp1-port) sync (udp-receive!-evt udp2 us1))
(test (list 10 "127.0.0.1" udp1-port) sync (udp-receive!-evt udp2 us1))
(test #f sync/timeout 0.05 udp2-r)
(test #f sync/timeout 0.05 (udp-receive!-evt udp2 us1))
@ -116,18 +116,18 @@
;; filling up an output queue is difficult; we don't even try here
(err/rt-test (udp-bind! udp1 #f #f))
(err/rt-test (udp-bind! udp1 "localhost" #f))
(err/rt-test (udp-connect! udp1 "localhost" #f) exn:application:mismatch?)
(err/rt-test (udp-bind! udp1 "127.0.0.1" #f))
(err/rt-test (udp-connect! udp1 "127.0.0.1" #f) exn:application:mismatch?)
(err/rt-test (udp-connect! udp1 #f 5) exn:application:mismatch?)
(err/rt-test (udp-send-to udp1 #f 40000 #"hello"))
(err/rt-test (udp-send-to udp1 "localhost" #f #"hello"))
(err/rt-test (udp-send-to udp1 "localhost" 40000 'hello))
(err/rt-test (udp-send-to udp1 "localhost" 40000 "hello"))
(err/rt-test (udp-send-to udp1 "localhost" 40000 #"hello" #f))
(err/rt-test (udp-send-to udp1 "localhost" 40000 #"hello" 1 #f))
(err/rt-test (udp-send-to udp1 "localhost" 40000 #"hello" 10) exn:application:mismatch?)
(err/rt-test (udp-send-to udp1 "localhost" 40000 #"hello" 1 11) exn:application:mismatch?)
(err/rt-test (udp-send-to udp1 "localhost" 40000 #"hello" 1 0) exn:application:mismatch?)
(err/rt-test (udp-send-to udp1 "127.0.0.1" #f #"hello"))
(err/rt-test (udp-send-to udp1 "127.0.0.1" 40000 'hello))
(err/rt-test (udp-send-to udp1 "127.0.0.1" 40000 "hello"))
(err/rt-test (udp-send-to udp1 "127.0.0.1" 40000 #"hello" #f))
(err/rt-test (udp-send-to udp1 "127.0.0.1" 40000 #"hello" 1 #f))
(err/rt-test (udp-send-to udp1 "127.0.0.1" 40000 #"hello" 10) exn:application:mismatch?)
(err/rt-test (udp-send-to udp1 "127.0.0.1" 40000 #"hello" 1 11) exn:application:mismatch?)
(err/rt-test (udp-send-to udp1 "127.0.0.1" 40000 #"hello" 1 0) exn:application:mismatch?)
(err/rt-test (udp-send udp1 'hello))
(err/rt-test (udp-send udp1 #"hello" #f))
(err/rt-test (udp-send udp1 #"hello" 2 #f))
@ -147,9 +147,9 @@
(test (void) udp-close udp2)
;; udp1 is now closed...
(err/rt-test (udp-bind! udp1 "localhost" 40008) exn:fail:network?)
(err/rt-test (udp-connect! udp1 "localhost" 40007) exn:fail:network?)
(err/rt-test (udp-send-to udp1 "localhost" 40000 #"hello") exn:fail:network?)
(err/rt-test (udp-bind! udp1 "127.0.0.1" 40008) exn:fail:network?)
(err/rt-test (udp-connect! udp1 "127.0.0.1" 40007) exn:fail:network?)
(err/rt-test (udp-send-to udp1 "127.0.0.1" 40000 #"hello") exn:fail:network?)
(err/rt-test (udp-send udp1 #"hello") exn:fail:network?)
(err/rt-test (udp-receive! udp1 (make-bytes 10)) exn:fail:network?)
(err/rt-test (udp-close udp1) exn:fail:network?)
@ -162,4 +162,4 @@
(let ([w (udp-receive-ready-evt udp1)])
(test w sync w))
(test #t evt? (udp-receive!-evt udp1 us1))
(test #t evt? (udp-send-to-evt udp1 "localhost" 40007 #"here's more"))
(test #t evt? (udp-send-to-evt udp1 "127.0.0.1" 40007 #"here's more"))