[usocket-cvs] r599 - in usocket/branches/0.5.x: . test
Chun Tian (binghe)
ctian at common-lisp.net
Tue Mar 29 13:04:28 UTC 2011
Author: ctian
Date: Tue Mar 29 09:04:27 2011
New Revision: 599
Log:
Add some Unit Tests for Datagram sockets
Added:
usocket/branches/0.5.x/test/test-datagram.lisp (contents, props changed)
Modified:
usocket/branches/0.5.x/test/test-condition.lisp
usocket/branches/0.5.x/usocket-test.asd
Modified: usocket/branches/0.5.x/test/test-condition.lisp
==============================================================================
--- usocket/branches/0.5.x/test/test-condition.lisp (original)
+++ usocket/branches/0.5.x/test/test-condition.lisp Tue Mar 29 09:04:27 2011
@@ -11,7 +11,7 @@
(deftest timeout-error.1
(with-caught-conditions (usocket:timeout-error nil)
- (usocket:socket-connect "common-lisp.net" 81 :timeout 1)
+ (usocket:socket-connect "common-lisp.net" 81 :timeout 0)
t)
nil)
Added: usocket/branches/0.5.x/test/test-datagram.lisp
==============================================================================
--- (empty file)
+++ usocket/branches/0.5.x/test/test-datagram.lisp Tue Mar 29 09:04:27 2011
@@ -0,0 +1,45 @@
+;;;; $Id$
+;;;; $URL$
+
+(in-package :usocket-test)
+
+(defvar *echo-server*
+ (usocket:socket-server "127.0.0.1" 10243 #'identity nil
+ :in-new-thread t
+ :protocol :datagram))
+
+(defparameter *max-buffer-size* 32)
+
+(defvar *send-buffer*
+ (make-array *max-buffer-size* :element-type '(unsigned-byte 8) :initial-element 0))
+
+(defvar *receive-buffer*
+ (make-array *max-buffer-size* :element-type '(unsigned-byte 8) :initial-element 0))
+
+(defun clean-buffers ()
+ (fill *send-buffer* 0)
+ (fill *receive-buffer* 0))
+
+;;; UDP Send Test #1: connected socket
+(deftest udp-send.1
+ (let ((s (usocket:socket-connect "127.0.0.1" 10243 :protocol :datagram)))
+ (clean-buffers)
+ (replace *send-buffer* #(1 2 3 4 5))
+ (usocket:socket-send s *send-buffer* 5)
+ (usocket:wait-for-input s :timeout 3)
+ (multiple-value-bind (buffer size host port)
+ (usocket:socket-receive s *receive-buffer* *max-buffer-size*)
+ (reduce #'+ *receive-buffer* :start 0 :end 5)))
+ 15)
+
+;;; UDP Send Test #2: unconnected socket
+(deftest udp-send.2
+ (let ((s (usocket:socket-connect nil nil :protocol :datagram)))
+ (clean-buffers)
+ (replace *send-buffer* #(1 2 3 4 5))
+ (usocket:socket-send s *send-buffer* 5 :host "127.0.0.1" :port 10243)
+ (usocket:wait-for-input s :timeout 3)
+ (multiple-value-bind (buffer size host port)
+ (usocket:socket-receive s *receive-buffer* *max-buffer-size*)
+ (reduce #'+ *receive-buffer* :start 0 :end 5)))
+ 15)
Modified: usocket/branches/0.5.x/usocket-test.asd
==============================================================================
--- usocket/branches/0.5.x/usocket-test.asd (original)
+++ usocket/branches/0.5.x/usocket-test.asd Tue Mar 29 09:04:27 2011
@@ -21,11 +21,11 @@
:depends-on (:usocket
:rt)
:components ((:module "test"
+ :serial t
:components ((:file "package")
- (:file "test-usocket"
- :depends-on ("package"))
- (:file "test-condition"
- :depends-on ("test-usocket"))))))
+ (:file "test-usocket")
+ (:file "test-condition")
+ (:file "test-datagram")))))
(defmethod perform ((op test-op) (c (eql (find-system :usocket-test))))
(funcall (intern "DO-TESTS" "USOCKET-TEST")))
More information about the usocket-cvs
mailing list