Andreas Raab uploaded a new version of NetworkTests to project The Trunk:
http://source.squeak.org/trunk/NetworkTests-ar.21.mcz ==================== Summary ==================== Name: NetworkTests-ar.21 Author: ar Time: 26 November 2010, 10:26:47.414 am UUID: bc0b6421-f066-2848-8216-423c91695e98 Ancestors: NetworkTests-ar.20 Add some tests for Socket. =============== Diff against NetworkTests-ar.20 =============== Item was added: + TestCase subclass: #SocketTest + instanceVariableNames: 'listenerSocket clientSocket serverSocket' + classVariableNames: '' + poolDictionaries: '' + category: 'NetworkTests-Kernel'! Item was added: + ----- Method: SocketTest>>listenerAddress (in category 'setup') ----- + listenerAddress + ^NetNameResolver localHostAddress + ! Item was added: + ----- Method: SocketTest>>listenerPort (in category 'setup') ----- + listenerPort + ^42324 + ! Item was added: + ----- Method: SocketTest>>setUp (in category 'setup') ----- + setUp + + listenerSocket := Socket newTCP listenOn: self listenerPort backlogSize: 4 interface: self listenerAddress. + ! Item was added: + ----- Method: SocketTest>>tearDown (in category 'setup') ----- + tearDown + + listenerSocket ifNotNil:[listenerSocket destroy]. + clientSocket ifNotNil:[clientSocket destroy]. + serverSocket ifNotNil:[serverSocket destroy]. + ! Item was added: + ----- Method: SocketTest>>testClientConnect (in category 'tests') ----- + testClientConnect + "Tests a client socket connection" + + clientSocket := Socket newTCP. + clientSocket connectTo: self listenerAddress port: self listenerPort. + clientSocket waitForConnectionFor: 2. + self assert: clientSocket isConnected. + ! Item was added: + ----- Method: SocketTest>>testLocalAddress (in category 'tests') ----- + testLocalAddress + "Tests the various localAddress values for sockets" + + self testServerAccept. + self assert: listenerSocket localAddress = self listenerAddress. + self assert: clientSocket localAddress = self listenerAddress. + self assert: serverSocket localAddress = self listenerAddress. + ! Item was added: + ----- Method: SocketTest>>testLocalPort (in category 'tests') ----- + testLocalPort + "Tests the various localPort values for sockets" + + self testServerAccept. + self assert: listenerSocket localPort = self listenerPort. + self assert: clientSocket localPort > 0. + self assert: serverSocket localPort > 0. + ! Item was added: + ----- Method: SocketTest>>testRemoteAddress (in category 'tests') ----- + testRemoteAddress + "Tests the various remoteAddress values for sockets" + + self testServerAccept. + self assert: listenerSocket remoteAddress = #[0 0 0 0]. + self assert: clientSocket remoteAddress = self listenerAddress. + self assert: serverSocket remoteAddress = self listenerAddress. + ! Item was added: + ----- Method: SocketTest>>testRemotePort (in category 'tests') ----- + testRemotePort + "Tests the various remoteAddress values for sockets" + + self testServerAccept. + self assert: listenerSocket remotePort = 0. + self assert: clientSocket remotePort = self listenerPort. + self assert: serverSocket remotePort > 0. + ! Item was added: + ----- Method: SocketTest>>testServerAccept (in category 'tests') ----- + testServerAccept + "Tests a server-side accept" + + self testClientConnect. + serverSocket := listenerSocket waitForAcceptFor: 2. + self assert: (serverSocket notNil). + self assert: (serverSocket isConnected). + ! |
Free forum by Nabble | Edit this page |