'From Squeak2.8 of 23 June 2000 [latest update: #2342] on 7 July 2000 at 11:46:51 am'! "Change Set: JMMSUnitsForFlow Date: 3 July 2000 Author: johnmci@smalltalkconsulting.com A test suite for correspondents1b4JMMChanged. In order to test 200K of smalltalk code one must have a test suite. This test suite attempts to test 'most' of the correspondents/flow functionality. It does not however fully test all the functionality added by streaming1g1JMM. "! Client subclass: #TestClientForFlow instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'System-Networking'! TestCase subclass: #TestFlowSerial instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Testing-Flow'! TestCase subclass: #TestInternetSocketAddress instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Testing-Flow'! Server subclass: #TestServerForFlow instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Testing-Flow'! Smalltalk renameClassNamed: #TestTCPSockets as: #TestSockets! TestCase subclass: #TestSockets instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Testing-Flow'! !TestClientForFlow class methodsFor: 'accessing' stamp: 'JMM 6/26/2000 17:47'! binary ^true! ! !TestClientForFlow class methodsFor: 'accessing' stamp: 'JMM 6/26/2000 17:44'! transport "Answer my mode of transport." ^#tcp! ! !TestFlowSerial methodsFor: 'checking' stamp: 'JMM 7/4/2000 14:38'! checkPort: port0 self should: [port0 baudRate = 1200]. self should: [port0 numberOfDataBits = 8]. self should: [port0 numberOfStopBits = 2.0]. self should: [port0 parityScheme = #none]. self should: [port0 useCTS = true]. self should: [port0 useDTR = true]. self should: [port0 useXOnXOffFlowControl = false]. self should: [port0 xOnByte = 19]. self should: [port0 xOffByte = 24]. self should: [port0 isActive]. self should: [port0 isOpen]. self should: [port0 timedOut = false]. self should: [port0 dataAvailable = true]. self should: [port0 handle notNil]. self should: [port0 peerAddress notNil]. self should: [port0 isConnected]. self should: [port0 peerClosed = false]. ! ! !TestFlowSerial methodsFor: 'checking' stamp: 'JMM 7/4/2000 15:29'! checkStream: echo port: port | confirmPrintOn | self should: [echo isBinary]. self should: [echo isExternal]. confirmPrintOn _ (String new: 15) writeableStream. echo printInactivityExplanationOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self shouldnt: [echo atEnd]. self should: [echo contents] raise: Error. self should: [echo dataAvailable]. self should: [echo isActive]. self should: [echo isOpen]. self should: [echo numberOfBytesRead = 0]. self shouldnt: [echo peerClosed]. self should: [echo port = port]. self should: [echo readLimit = SmallInteger maxVal]. self should: [echo isActive]. self should: [echo isOpen]. self should: [echo resource isActive]. self should: [echo resource isOpen]. ! ! !TestFlowSerial methodsFor: 'checking' stamp: 'JMM 7/4/2000 15:50'! checkStreamThenWrite2: echo port: port | theData | self checkStream: echo port: port. echo nextPutAll: 'AT'. (Delay forMilliseconds: 2000) wait. theData _ echo next: 2. self should: [theData = 'AT' asByteArray]. self should: [echo numberOfBytesRead = 2]. echo close. ! ! !TestFlowSerial methodsFor: 'checking' stamp: 'JMM 7/4/2000 15:46'! checkStreamThenWrite: echo port: port | theData | self checkStream: echo port: port. echo nextPut: $A asInteger. echo nextPut: $T asInteger. echo nextPut: Character cr asInteger. echo nextPut: Character lf asInteger. (Delay forMilliseconds: 2000) wait. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ echo next. self should: [theData = ($A asInteger)]. theData _ echo next. self should: [theData = ($T asInteger)]. self should: [echo numberOfBytesRead = 2]. echo resetNumberOfBytesRead. self should: [echo numberOfBytesRead = 0]. echo close. ! ! !TestFlowSerial methodsFor: 'testing' stamp: 'JMM 7/4/2000 15:26'! testNetStream | serial | serial _ NetStream onSerialPortAt: 1. self should: [serial baudRate = 9600]. self should: [serial numberOfDataBits = 8]. self should: [serial numberOfStopBits = 1]. self should: [serial parityScheme = #none]. self should: [serial useXOnXOffFlowControl = false]. self should: [serial useDTR = false]. self should: [serial useCTS = false]. self should: [serial xOnByte = 19]. self should: [serial xOffByte = 24]. serial reopen. serial beBinary. self checkStream: serial port: 1. serial close. ! ! !TestFlowSerial methodsFor: 'testing' stamp: 'JMM 7/4/2000 15:47'! testNetStreamWrite | serial | serial _ NetStream onSerialPortAt: 1. serial reopen. serial beBinary. self checkStreamThenWrite: serial port: 1. ! ! !TestFlowSerial methodsFor: 'testing' stamp: 'JMM 7/4/2000 15:48'! testNetStreamWrite2 | serial | serial _ NetStream onSerialPortAt: 1. serial reopen. serial beBinary. self checkStreamThenWrite2: serial port: 1. ! ! !TestFlowSerial methodsFor: 'testing' stamp: 'JMM 7/4/2000 14:27'! testOpenClose | port0 | port0 _ SerialPort new connectToSerialPortNumbered: 0 baudRate: 1200 numberOfDataBits: 8 numberOfStopBits: 2.0 parityScheme: #none useDTR: true useCTS: true useXOnXOffFlowControl: false. self checkPort: port0. port0 close. ! ! !TestFlowSerial methodsFor: 'testing' stamp: 'JMM 7/4/2000 14:27'! testOpenClose1 | port1 | port1 _ SerialPort new connectToSerialPortNumbered: 1 baudRate: 1200 numberOfDataBits: 8 numberOfStopBits: 2.0 parityScheme: #none useDTR: true useCTS: true useXOnXOffFlowControl: false. self checkPort: port1. port1 close. ! ! !TestFlowSerial methodsFor: 'testing' stamp: 'JMM 7/4/2000 14:34'! testOpenCloseChangeParms | port0 | port0 _ SerialPort new connectToSerialPortNumbered: 0 baudRate: 1200 numberOfDataBits: 8 numberOfStopBits: 2.0 parityScheme: #none useDTR: true useCTS: true useXOnXOffFlowControl: false. self checkPort: port0. port0 baudRate: 2400. self should: [port0 baudRate = 2400]. port0 numberOfDataBits: 7. self should: [port0 numberOfDataBits = 7]. port0 numberOfStopBits: 1.5. self should: [port0 numberOfStopBits = 1.5]. port0 numberOfStopBits: 1.0. self should: [port0 numberOfStopBits = 1.0]. port0 parityScheme: #even. self should: [port0 parityScheme = #even]. port0 parityScheme: #odd. self should: [port0 parityScheme = #odd]. port0 useDTR: true. self should: [port0 useDTR = true]. port0 useCTS: true. self should: [port0 useCTS = true]. port0 doNotUseXOnXOffFlowControl. self should: [port0 useXOnXOffFlowControl = false]. port0 useXOnXOffFlowControl: true. self should: [port0 useXOnXOffFlowControl = true]. port0 xOffByte: 20. self should: [port0 xOffByte = 20]. port0 xOnByte: 21. self should: [port0 xOnByte = 21]. port0 close. ! ! !TestFlowSerial methodsFor: 'testing' stamp: 'JMM 7/4/2000 14:56'! testOpenWriteClose1 "Need to pick a serial port with a modem, on my powerbook bronze 500Mhz port 1 is the modem" | port1 theData | port1 _ SerialPort new connectToSerialPortNumbered: 1 baudRate: 1200 numberOfDataBits: 8 numberOfStopBits: 2.0 parityScheme: #none useDTR: true useCTS: true useXOnXOffFlowControl: false. self checkPort: port1. port1 nextPut: 2 from: 'AT' asByteArray startingAt: 1. port1 nextPut: 2 from: String crlf asByteArray startingAt: 1. (Delay forSeconds: 2) wait. theData _ ByteArray new: 1024. port1 next: 1024 into: theData startingAt: 1. self should: [(theData asString findString: 'OK') > 0]. port1 nextPut: 2 from: 'ATI1' asByteArray startingAt: 1. port1 nextPut: 2 from: String crlf asByteArray startingAt: 1. (Delay forSeconds: 2) wait. theData _ ByteArray new: 1024. port1 next: 1024 into: theData startingAt: 1. self should: [(theData asString findString: 'OK') > 0]. port1 close. ! ! !TestFlowSerial class methodsFor: 'as yet unclassified' stamp: 'JMM 7/4/2000 15:51'! suite | testSelectors result | testSelectors _ self selectors asSortedCollection select: [:each | 'test*' match: each]. result _ TestSuite new. testSelectors do: [:each | result addTest: (self selector: each)]. ^ result! ! !TestInternetSocketAddress methodsFor: 'constants' stamp: 'JMM 6/26/2000 15:16'! altenateHostName ^'uiuc.edu'! ! !TestInternetSocketAddress methodsFor: 'constants' stamp: 'JMM 6/26/2000 15:18'! alternateHostNameIP ^'128.174.5.121'! ! !TestInternetSocketAddress methodsFor: 'constants' stamp: 'JMM 6/26/2000 14:31'! hostName ^'apple.com'! ! !TestInternetSocketAddress methodsFor: 'constants' stamp: 'JMM 6/26/2000 14:33'! hostNameIP ^'17.254.3.183'! ! !TestInternetSocketAddress methodsFor: 'checking' stamp: 'JMM 6/26/2000 15:24'! checkHost: host port: aPort | confirmPrintOn | self shouldnt: [host bytes isNil]. self should: [host bytes size = 6]. self should: [host = (host copy)]. self shouldnt: [host handleIsStale]. self should: [host hostBytes size = 4]. self should: [host port = aPort]. confirmPrintOn _ (String new: 15) writeableStream. host printOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self should: [host isActive]. self should: [host isOpen]. ! ! !TestInternetSocketAddress methodsFor: 'testing' stamp: 'JMM 6/26/2000 14:36'! testCreateForPortWithIP | host port | port _ 80. host _ InternetSocketAddress forPort: port atHostWithIPAddress: (NetNameResolver addressForName: self hostName). self shouldnt: [host unresolved]. self checkHost: host port: port. self should: [host hostNumber = self hostNameIP]. self should: [host hostname = (self hostName,'.')]. ! ! !TestInternetSocketAddress methodsFor: 'testing' stamp: 'JMM 6/26/2000 15:04'! testCreateHostNamed | host | host _ InternetSocketAddress forHostNamed: self hostName. host _ host port: 0 ipAddress: ( NetNameResolver addressForName: self hostNameIP). self shouldnt: [host unresolved]. self checkHost: host port: 0. self should: [host hostNumber = self hostNameIP]. self should: [host hostname = self hostName]. self should: [host port = 0]. ! ! !TestInternetSocketAddress methodsFor: 'testing' stamp: 'JMM 6/26/2000 15:12'! testHash | host host2 | host _ InternetSocketAddress forHostNamed: self hostName. host port: 0 ipAddress: ( NetNameResolver addressForName: self hostNameIP). self checkHost: host port: 0. host2 _ InternetSocketAddress forHostNamed: self altenateHostName. host2 port: 0 ipAddress: ( NetNameResolver addressForName: self alternateHostNameIP). self shouldnt: [host2 unresolved]. self checkHost: host2 port: 0. self shouldnt: [host = host2]. self shouldnt: [host hash = host2 hash]. ! ! !TestInternetSocketAddress methodsFor: 'setup' stamp: 'JMM 6/26/2000 13:59'! setUp NetNameResolver initializeNetworkIfFail: [self error: 'network initialization failed']. ! ! !TestServerForFlow methodsFor: 'serving' stamp: 'JMM 6/28/2000 14:48'! basicNextPacketFrom: clientStream "Answer the next packet from clientStream." ^self halt! ! !TestServerForFlow methodsFor: 'serving' stamp: 'JMM 6/28/2000 18:19'! dummyString ^'Thank you; come again.'! ! !TestServerForFlow methodsFor: 'serving' stamp: 'JMM 6/28/2000 18:20'! serve: clientStream "Serve clientStream." clientStream nextPutAll: self dummyString! ! !TestServerForFlow methodsFor: 'serving' stamp: 'JMM 6/28/2000 15:26'! servesIndefinitely "Answer whether I will serve a client indefinitely (as opposed to just once)." ^false! ! !TestServerForFlow class methodsFor: 'accessing' stamp: 'JMM 6/28/2000 14:53'! binary "Answer whether my instances should communicate in binary." ^true! ! !TestServerForFlow class methodsFor: 'accessing' stamp: 'JMM 6/29/2000 03:00'! defaultPorts "Answer the ports at which my service is typically provided." ^#(17883)! ! !TestServerForFlow class methodsFor: 'accessing' stamp: 'JMM 6/28/2000 14:51'! transport "Answer my mode of transport." ^#tcp! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/26/2000 17:23'! checkFlow: flow port: aPort host: aHost | confirmPrintOn | self should: [flow isActive]. self should: [flow isOpen]. self should: [flow binary]. confirmPrintOn _ (String new: 15) writeableStream. flow printOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self should: [flow numberOfBytesRead = 0]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 15:44'! checkRestOfSocket: socket port: aPort host: aHost | confirmPrintOn | self should: [socket isActive]. self should: [socket isOpen]. self shouldnt: [socket handleIsStale]. self should: [socket port = aPort]. confirmPrintOn _ (String new: 15) writeableStream. socket printOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self shouldnt: [socket dataAvailable]. self should: [socket isConnected]. confirmPrintOn _ (String new: 15) writeableStream. socket printInactivityExplanationOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self shouldnt: [socket timedOut]. self should: [socket peerAddress = (InternetSocketAddress forPort: aPort atHostWithIPAddress: (NetNameResolver addressForName: aHost))]. self should: [socket scribes]. self should: [socket socketError = 0]. self should: [socket statusString = 'connected']. self shouldnt: [socket timedOut]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/28/2000 14:53'! checkServerFlow: flow port: aPort host: aHost | confirmPrintOn | self should: [flow isActive]. self should: [flow isOpen]. self should: [flow binary]. confirmPrintOn _ (String new: 15) writeableStream. flow printOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self should: [flow numberOfBytesRead = 0]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/27/2000 12:10'! checkServerSocket: socket port: aPort host: aHost | confirmPrintOn | self should: [socket isActive]. self should: [socket isOpen]. self shouldnt: [socket handleIsStale]. self should: [socket port = aPort]. confirmPrintOn _ (String new: 15) writeableStream. socket printOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self shouldnt: [socket dataAvailable]. confirmPrintOn _ (String new: 15) writeableStream. socket printInactivityExplanationOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self shouldnt: [socket timedOut]. self shouldnt: [socket scribes]. self should: [socket socketError = 0]. self should: [socket statusString = 'waitingForConnection']. self shouldnt: [socket timedOut]. self should: [socket usesTCP]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 18:53'! checkServerStream: stream port: aPort host: aHost | confirmPrintOn | self should: [stream isBinary]. self should: [stream isExternal]. confirmPrintOn _ (String new: 15) writeableStream. stream printInactivityExplanationOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self should: [stream atEnd]. self should: [stream contents] raise: Error. self shouldnt: [stream dataAvailable]. self should: [stream isActive]. self should: [stream isOpen]. self should: [stream numberOfBytesRead = 0]. self should: [stream port = aPort]. self should: [stream readLimit = SmallInteger maxVal]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 15:45'! checkSocket: socket port: aPort host: aHost self checkRestOfSocket: socket port: aPort host: aHost. self should: [socket usesTCP]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 15:09'! checkSocketMayBeData: socket port: aPort host: aHost | confirmPrintOn | self should: [socket isActive]. self should: [socket isOpen]. self shouldnt: [socket handleIsStale]. self should: [socket port = aPort]. confirmPrintOn _ (String new: 15) writeableStream. socket printOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self should: [socket isConnected]. confirmPrintOn _ (String new: 15) writeableStream. socket printInactivityExplanationOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self shouldnt: [socket timedOut]. self should: [socket peerAddress = (InternetSocketAddress forPort: aPort atHostWithIPAddress: (NetNameResolver addressForName: aHost))]. self should: [socket scribes]. self should: [socket socketError = 0]. self should: [socket statusString = 'connected']. self shouldnt: [socket timedOut]. self should: [socket usesTCP]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 15:47'! checkStream: echo port: port self checkStream: echo port: port host: self echoHostName. echo resource usesTCP ifTrue: [self checkSocket: echo resource port: port host: self echoHostName] ifFalse: [self checkUDPSocket: echo resource port: port host: self echoHostName]. echo close. self shouldnt: [echo isActive]. self shouldnt: [echo isOpen]. self shouldnt: [echo resource isActive]. self shouldnt: [echo resource isOpen]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/26/2000 23:24'! checkStream: stream port: aPort host: aHost | confirmPrintOn | self should: [stream isBinary]. self should: [stream isExternal]. confirmPrintOn _ (String new: 15) writeableStream. stream printInactivityExplanationOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self should: [stream atEnd]. self should: [stream contents] raise: Error. self shouldnt: [stream dataAvailable]. self should: [stream isActive]. self should: [stream isOpen]. self should: [stream numberOfBytesRead = 0]. self should: [stream peerAddress = (InternetSocketAddress forPort: aPort atHostWithIPAddress: (NetNameResolver addressForName: aHost))]. self shouldnt: [stream peerClosed]. self should: [stream port = aPort]. self should: [stream readLimit = SmallInteger maxVal]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 15:08'! checkStreamMayBeData: stream port: aPort host: aHost | confirmPrintOn | self should: [stream isBinary]. self should: [stream isExternal]. confirmPrintOn _ (String new: 15) writeableStream. stream printInactivityExplanationOn: confirmPrintOn. self should: [confirmPrintOn contents size > 0]. self should: [stream isActive]. self should: [stream isOpen]. self should: [stream peerAddress = (InternetSocketAddress forPort: aPort atHostWithIPAddress: (NetNameResolver addressForName: aHost))]. self should: [stream port = aPort]. self should: [stream readLimit = SmallInteger maxVal]. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 17:06'! checkStreamThenWrite2: echo port: port | theData | self checkStream: echo port: port host: self echoHostName. echo resource usesTCP ifTrue: [self checkSocket: echo resource port: port host: self echoHostName] ifFalse: [self checkUDPSocket: echo resource port: port host: self echoHostName]. echo nextPutAll: 'abc'. (Delay forMilliseconds: 2000) wait. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ echo next. self should: [theData asCharacter = $a]. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ echo next: 2. self should: [theData = 'bc' asByteArray]. self should: [echo atEnd]. self shouldnt: [echo dataAvailable]. self should: [echo numberOfBytesRead = 3]. echo close. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 18:40'! checkStreamThenWrite2AndPeek: echo port: port | theData | self checkStream: echo port: port host: self echoHostName. echo resource usesTCP ifTrue: [self checkSocket: echo resource port: port host: self echoHostName] ifFalse: [self checkUDPSocket: echo resource port: port host: self echoHostName]. echo nextPutAll: 'abc'. (Delay forMilliseconds: 2000) wait. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ echo peek. self should: [theData asCharacter = $a]. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ echo peek: 3. self should: [theData = 'abc' asByteArray]. theData _ echo nextAvailable: 3. self should: [theData = 'abc' asByteArray]. self should: [echo atEnd]. self shouldnt: [echo dataAvailable]. self should: [echo numberOfBytesRead = 3]. echo close. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 16:02'! checkStreamThenWrite2AndPeekBeChar: echo port: port | theData | echo nextPutAll: 'abc'. (Delay forMilliseconds: 2000) wait. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ echo peek. self should: [theData = $a]. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ echo peek: 3. self should: [theData = 'abc' ]. theData _ echo nextAvailable: 3. self should: [theData = 'abc' ]. self should: [echo atEnd]. self shouldnt: [echo dataAvailable]. self should: [echo numberOfBytesRead = 3]. echo close. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 7/3/2000 11:27'! checkStreamThenWrite3: echo port: port | theData outGoing | self checkStream: echo port: port host: self echoHostName. echo resource usesTCP ifTrue: [self checkSocket: echo resource port: port host: self echoHostName] ifFalse: [self checkUDPSocket: echo resource port: port host: self echoHostName]. echo nextPut: 1. theData _ echo nextByte. self should: [theData = 1]. outGoing _ 16r31F2F3F4. echo nextInt32Put: outGoing. theData _ echo nextInt32. self should: [theData = outGoing]. outGoing _ 16r11121321. echo nextInt32Put: outGoing. theData _ echo nextInt32. self should: [theData = outGoing]. outGoing _ 20 factorial. echo nextLittleEndianNumber: outGoing size put: outGoing. theData _ echo nextLittleEndianNumber: outGoing size. self should: [theData = outGoing]. echo beCharacters. outGoing _ 16rF1F2F3F4. echo nextWordPut: outGoing. theData _ echo nextWord. self should: [theData = outGoing]. outGoing _ 16r11121321. echo nextWordPut: outGoing. theData _ echo nextWord. self should: [theData = outGoing]. outGoing _ 16r11121321. echo nextWordPut: outGoing. echo beBinary. theData _ echo nextNumber: 4. echo beCharacters. self should: [theData = outGoing]. outGoing _ 16r11121321. echo nextWordPut: outGoing. echo beBinary. theData _ echo nextWord16. self should: [theData = 16r1112]. theData _ echo nextWord16. self should: [theData = 16r1321]. echo close. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 7/3/2000 22:33'! checkStreamThenWrite4: echo port: port | theData outGoing offset | true ifTrue: [echo close. ^self]. echo lookBack: 6. self checkStream: echo port: port host: self echoHostName. echo resource usesTCP ifTrue: [self checkSocket: echo resource port: port host: self echoHostName] ifFalse: [self checkUDPSocket: echo resource port: port host: self echoHostName]. "echo cr. theData _ echo nextByte. self should: [theData = 13]. echo crlf. theData _ echo nextByte. self should: [theData = 13]. theData _ echo nextByte. self should: [theData = 9]. " echo beCharacters. echo nextPutAll: 'abc'. theData _ ByteArray new: 3 withAll: 0. echo next: 3 into: theData. self should: [theData asString = 'abc']. echo beBinary. echo nextPut: 1. theData _ echo next. self should: [theData = 1]. echo beCharacters. echo nextPutAll: 'abc'. theData _ echo next: 3. self should: [theData = 'abc']. echo beBinary. outGoing _ 16r31F2F3F4. echo nextPutMultiByte: outGoing. theData _ ByteArray new: 4. echo next: 4 into: theData. self should: [outGoing = (Integer byte1: (theData at: 1) byte2: (theData at: 2) byte3: (theData at: 3) byte4: (theData at: 4))]. echo beCharacters. echo nextPutString: 'abc'. theData _ echo next: 3. self should: [theData = 'abc']. echo nextPutString: 'abcdef'. theData _ echo upTo: $c. self should: [theData = 'ab']. theData _ echo nextAvailable. self should: [theData = 'cdef']. echo nextPutString: 'abcdef'. echo skip: 3. theData _ echo next: 3. self should: [theData = 'def']. echo skip: -6. theData _ echo next: 3. self should: [theData = 'abc']. echo nextPutString: 'aaaghi'. echo skipWhile: [:c | c = $a]. theData _ echo next: 3. self should: [theData = 'ghi']. echo nextPutString: 'aaaghi'. echo skipUntil: [:c | c = $g]. theData _ echo next: 3. self should: [theData = 'ghi']. echo nextPutString: 'bcadef'. offset _ ByteArray new: 6 withAll: $a. echo next: 5 into: offset startingAt: 2. self should: [offset = 'abcade']. theData _ echo next: 1 timeoutAfter: 2000. self should: [theData = 'f']. echo nextPutString: 'bcadef'. theData_ echo next: 6 timeoutAfter: 2000. self should: [theData = 'bcadef']. echo nextPutString: 'bcadef'. offset _ ByteArray new: 6 withAll: $a. echo next: 5 into: offset timeoutAfter: 2000. self should: [offset = 'bcade']. theData _ echo next: 1 timeoutAfter: 2000. self should: [theData = 'f']. echo close. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 7/3/2000 11:18'! checkStreamThenWrite: echo port: port | theData | self checkStream: echo port: port host: self echoHostName. echo resource usesTCP ifTrue: [self checkSocket: echo resource port: port host: self echoHostName] ifFalse: [self checkUDPSocket: echo resource port: port host: self echoHostName]. echo nextPut: 1. (Delay forMilliseconds: 2000) wait. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ echo next. self should: [theData = 1]. self should: [echo atEnd]. self shouldnt: [echo dataAvailable]. self should: [echo numberOfBytesRead = 1]. echo resetNumberOfBytesRead. self should: [echo numberOfBytesRead = 0]. echo close. ! ! !TestSockets methodsFor: 'checking' stamp: 'JMM 6/29/2000 15:46'! checkUDPSocket: socket port: aPort host: aHost self checkRestOfSocket: socket port: aPort host: aHost. self shouldnt: [socket usesTCP]. ! ! !TestSockets methodsFor: 'constants' stamp: 'JMM 6/29/2000 18:50'! echoHostName "^'192.168.1.3'" ^'seamonster.smalltalkconsulting.net' ! ! !TestSockets methodsFor: 'constants' stamp: 'JMM 6/29/2000 18:50'! echoPort ^7 "^54321"! ! !TestSockets methodsFor: 'constants' stamp: 'JMM 7/6/2000 02:37'! localHostName ^'otter.smalltalkconsulting.net.' " ^'ap5.smalltalkconsulting.net.'" ! ! !TestSockets methodsFor: 'setup' stamp: 'JMM 6/26/2000 17:19'! setUp NetNameResolver initializeNetworkIfFail: [self error: 'network initialization failed']. ! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 7/3/2000 11:24'! testConnectToEcho | port echo anAddress | port _ self echoPort. echo _ NetStream tcpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStream: echo port: port. anAddress _ echo addressForPort: port atHostNamed: self echoHostName. self should: [anAddress = (InternetSocketAddressResolver addressForPort: port atHostNamed: self echoHostName)]. ! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:13'! testConnectToEchoThenWrite | port echo | port _ self echoPort. echo _ NetStream tcpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite: echo port: port. ! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:13'! testConnectToEchoThenWrite2 | port echo | port _ self echoPort. echo _ NetStream tcpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite2: echo port: port ! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:13'! testConnectToEchoThenWrite2AndPeek | port echo | port _ self echoPort. echo _ NetStream tcpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite2AndPeek: echo port: port! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:13'! testConnectToEchoThenWrite2AndPeekBeChar | port echo | port _ self echoPort. echo _ NetStream tcpClientToPort: port atHostNamed: self echoHostName. echo beCharacters. self checkStreamThenWrite2AndPeekBeChar: echo port: port! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:13'! testConnectToEchoThenWrite3 | port echo | port _ self echoPort. echo _ NetStream tcpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite3: echo port: port! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 7/3/2000 14:37'! testConnectToEchoThenWrite4 | port echo | port _ self echoPort. echo _ NetStream tcpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite4: echo port: port! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:13'! testFlowClient | port echo theData | port _ self echoPort. echo _ TestClientForFlow new connectToPort: port atHostNamed: self echoHostName. self checkFlow: echo port: port host: self echoHostName. self checkStream: echo stream port: port host: self echoHostName. self checkSocket: echo stream resource port: port host: self echoHostName. echo nextPutAll: 'abc'. (Delay forMilliseconds: 1000) wait. theData _ echo stream next: 3. self should: [theData = 'abc' asByteArray]. self should: [echo numberOfBytesRead = 3]. echo close. ! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 7/4/2000 22:48'! testFlowServer | port server theData echo | server _ TestServerForFlow new. port _ TestServerForFlow defaultPort. self should: [TestServerForFlow localHostname = self localHostName]. self checkServerFlow: server port: port host: self echoHostName. server stream beBinary. self checkServerStream: server stream port: port host: self echoHostName. server stream beCharacters. self checkServerSocket: server stream resource port: port host: self echoHostName. self shouldnt: [server servesIndefinitely]. self should: [server numberOfClients = 0]. self shouldnt: [server serving]. echo _ [TestClientForFlow new connectToPort: port atHostNamed: self localHostName] on: ExceptionConnectionRefused do: [:ex | server close. ex return: nil]. self shouldnt: [echo isNil]. self checkFlow: echo port: port host: self localHostName. self checkStreamMayBeData: echo stream port: port host: self localHostName. self checkSocketMayBeData: echo stream resource port: port host: self localHostName. (Delay forSeconds: 2) wait. self should: [server numberOfClients = 1]. self shouldnt: [server serving]. theData _ echo stream next: (server dummyString size). self should: [theData = server dummyString asByteArray]. self should: [echo numberOfBytesRead = server dummyString size]. self should: [server numberOfBytesRead = 0]. server purgeDeadClients. echo close. self should: [server numberOfClients = 0]. server close. ! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 7/4/2000 20:57'! testServerConnection | port echo echoServer clientAtServer hostName | port _ 5568. hostName _ self localHostName. echoServer _ NetStream tcpServerAtPort: port queueSize: 1. echoServer beBinary. self checkServerStream: echoServer port: port host: hostName. self checkServerSocket: echoServer resource port: port host: hostName. [clientAtServer _ echoServer client] fork. echo _ NetStream tcpClientToPort: port atHostNamed: hostName. (Delay forMilliseconds: 2000) wait. echo beBinary. self checkStream: echo port: port host: hostName. self checkSocket: echo resource port: port host: hostName. echo close. clientAtServer ifNotNil: [clientAtServer close]. echoServer close.! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 19:02'! testServerConnectionSendData | port echo echoServer clientAtServer hostName theData theDataAtEchoServer | port _ 5569. hostName _ self localHostName. echoServer _ NetStream tcpServerAtPort: port queueSize: 1. echoServer beBinary. self checkServerStream: echoServer port: port host: hostName. self checkServerSocket: echoServer resource port: port host: hostName. [clientAtServer _ echoServer client. clientAtServer beCharacters] fork. echo _ NetStream tcpClientToPort: port atHostNamed: hostName. (Delay forMilliseconds: 2000) wait. echo beBinary. self checkStream: echo port: port host: hostName. self checkSocket: echo resource port: port host: hostName. echo beCharacters. echo nextPutString: 'abcdef'. theDataAtEchoServer _ clientAtServer next: 6. self should: [theDataAtEchoServer = 'abcdef']. clientAtServer nextPutAll: theDataAtEchoServer. theData _ echo next: 6. self should: [theData = 'abcdef']. echo close. clientAtServer ifNotNil: [clientAtServer close]. echoServer close.! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 19:02'! testServerConnectionSendDataTerminate | port echo echoServer clientAtServer hostName theData theDataAtEchoServer | port _ 5570. hostName _ self localHostName. echoServer _ NetStream tcpServerAtPort: port queueSize: 1. echoServer beBinary. self checkServerStream: echoServer port: port host: hostName. self checkServerSocket: echoServer resource port: port host: hostName. [clientAtServer _ echoServer client. clientAtServer beCharacters] fork. echo _ NetStream tcpClientToPort: port atHostNamed: hostName. (Delay forMilliseconds: 2000) wait. echo beBinary. self checkStream: echo port: port host: hostName. self checkSocket: echo resource port: port host: hostName. echo beCharacters. echo nextPutString: 'abcdef'. theDataAtEchoServer _ clientAtServer next: 6. self should: [theDataAtEchoServer = 'abcdef']. clientAtServer nextPutAll: theDataAtEchoServer. theData _ echo peek: 1. [(Delay forSeconds: 1) wait. clientAtServer close] fork. self should: [theData _ echo peek: 10] raise: ExceptionNetworkTimeout. clientAtServer close. echoServer close. echo close.! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 7/3/2000 22:57'! testServerConnectionSendDataTerminate2 | port echo echoServer clientAtServer hostName theData theDataAtEchoServer | port _ 5082. hostName _ self localHostName. echoServer _ NetStream tcpServerAtPort: port queueSize: 1. echoServer beBinary. self checkServerStream: echoServer port: port host: hostName. self checkServerSocket: echoServer resource port: port host: hostName. [clientAtServer _ echoServer client. clientAtServer beCharacters] fork. echo _ NetStream tcpClientToPort: port atHostNamed: hostName. (Delay forMilliseconds: 2000) wait. echo beBinary. self checkStream: echo port: port host: hostName. self checkSocket: echo resource port: port host: hostName. echo beCharacters. echo nextPutString: 'abcdef'. theDataAtEchoServer _ clientAtServer next: 6. self should: [theDataAtEchoServer = 'abcdef']. clientAtServer nextPutAll: theDataAtEchoServer. theData _ echo peek: 4. [(Delay forSeconds: 1) wait. clientAtServer close] fork. self should: [theData _ echo next: 10 timeoutAfter: 5000] raise: ExceptionNetworkTimeout. echoServer close. echo close.! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/30/2000 13:22'! testServerConnectionSendDataTerminate3 | port echo echoServer clientAtServer hostName theData theDataAtEchoServer | port _ 5081. hostName _ self localHostName. echoServer _ NetStream tcpServerAtPort: port queueSize: 1. echoServer beBinary. self checkServerStream: echoServer port: port host: hostName. self checkServerSocket: echoServer resource port: port host: hostName. [clientAtServer _ echoServer client. clientAtServer beCharacters] fork. echo _ NetStream tcpClientToPort: port atHostNamed: hostName. (Delay forMilliseconds: 2000) wait. echo beBinary. self checkStream: echo port: port host: hostName. self checkSocket: echo resource port: port host: hostName. echo beCharacters. echo nextPutString: 'abcdef'. theDataAtEchoServer _ clientAtServer next: 6. self should: [theDataAtEchoServer = 'abcdef']. clientAtServer nextPutAll: theDataAtEchoServer. theData _ echo next: 6. [clientAtServer close] fork. (Delay forSeconds:30) wait. self should: [theData _ echo nextPutString: 'abcdef'] raise: ExceptionFailedSocketWritingAttempt. echoServer close. echo close.! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:14'! testUDPConnectToEcho | port echo | port _ self echoPort. echo _ NetStream udpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStream: echo port: port ! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:14'! testUDPConnectToEchoThenWrite | port echo | port _ self echoPort. echo _ NetStream udpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite: echo port: port. ! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:14'! testUDPConnectToEchoThenWrite2 | port echo | port _ self echoPort. echo _ NetStream udpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite2: echo port: port ! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:14'! testUDPConnectToEchoThenWrite2AndPeek | port echo | port _ self echoPort. echo _ NetStream udpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite2AndPeek: echo port: port! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:14'! testUDPConnectToEchoThenWrite2AndPeekBeChar | port echo | port _ self echoPort. echo _ NetStream udpClientToPort: port atHostNamed: self echoHostName. echo beCharacters. self checkStreamThenWrite2AndPeekBeChar: echo port: port! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/29/2000 18:14'! testUDPConnectToEchoThenWrite3 | port echo | port _ self echoPort. echo _ NetStream udpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite3: echo port: port! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 7/3/2000 14:37'! testUDPConnectToEchoThenWrite4 | port echo | port _ self echoPort. echo _ NetStream udpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStreamThenWrite4: echo port: port! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 6/30/2000 14:05'! testUDPConnectToEchoThenWrite5 | port echo theData address | port _ self echoPort. echo _ NetStream udpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStream: echo port: port host: self echoHostName. self checkUDPSocket: echo resource port: port host: self echoHostName. echo nextPutAll: 'abc'. (Delay forMilliseconds: 2000) wait. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ ByteArray new: 1. address _ InternetSocketAddress new. echo nextPacketInto: theData addressInto: address. self should: [address hostname = (self echoHostName,'.')]. self should: [address port = port]. self should: [theData = 'a' asByteArray]. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. theData _ ByteArray new: 2. address _ InternetSocketAddress new. echo nextPacketInto: theData addressInto: address. self should: [address hostname = (self echoHostName,'.')]. self should: [address port = port]. self should: [theData = 'bc' asByteArray]. self should: [echo atEnd]. self shouldnt: [echo dataAvailable]. self should: [echo numberOfBytesRead = 3]. echo close.! ! !TestSockets methodsFor: 'testing' stamp: 'JMM 7/3/2000 11:34'! testUDPConnectToEchoThenWrite6 | port echo theData address count aByteArray | port _ self echoPort. echo _ NetStream udpClientToPort: port atHostNamed: self echoHostName. echo beBinary. self checkStream: echo port: port host: self echoHostName. self checkUDPSocket: echo resource port: port host: self echoHostName. count _ echo nextPutPacket: 'abc'. (Delay forMilliseconds: 2000) wait. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. self should: [count = 3]. theData _ echo nextAvailable: 3. self should: [theData = 'abc' asByteArray]. self should: [echo atEnd]. self shouldnt: [echo dataAvailable]. self should: [echo numberOfBytesRead = 3]. address _ InternetSocketAddressResolver addressForPort: port atHostNamed: self echoHostName. echo nextPutPacket: ('abc' asByteArray) toAddress: address. (Delay forMilliseconds: 2000) wait. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. self should: [count = 3]. theData _ echo nextAvailable: 3. self should: [theData = 'abc' asByteArray]. self should: [echo atEnd]. self shouldnt: [echo dataAvailable]. self should: [echo numberOfBytesRead = 6]. echo nextPutPacket: ('abc' asByteArray) toPort: port atHostNamed: self echoHostName. (Delay forMilliseconds: 2000) wait. self shouldnt: [echo atEnd]. self should: [echo dataAvailable]. self should: [count = 3]. theData _ echo nextAvailable: 3. self should: [theData = 'abc' asByteArray]. self should: [echo atEnd]. self shouldnt: [echo dataAvailable]. self should: [echo numberOfBytesRead = 9]. count _ echo nextPutPacket: 'abc'. address _ InternetSocketAddress new. aByteArray _ ByteArray new: 3 withAll: 66. echo nextPacketInto: aByteArray addressInto: address timeoutAfter: 2000. self should: [aByteArray = 'abc' asByteArray]. self should: [address = (InternetSocketAddressResolver addressForPort: port atHostNamed: self echoHostName)]. self should: [echo numberOfBytesRead = 12]. echo close.! ! !TestSockets class methodsFor: 'private' stamp: 'JMM 6/27/2000 11:55'! tempWorkArea | port echo | "Test Exceptions for peek" port _ 7. echo _ NetStream tcpClientToPort: port atHostNamed: self echoHostName. echo beCharacters. echo nextPutString: 'abc'. echo close. ! ! !TestSockets class methodsFor: 'instance creation' stamp: 'JMM 7/4/2000 21:29'! suite | testSelectors result | testSelectors _ self selectors asSortedCollection select: [:each | 'test*' match: each]. result _ TestSuite new. testSelectors do: [:each | result addTest: (self selector: each)]. ^ result! ! TestSockets removeSelector: #testConnectToEchoUDP! !TestSockets reorganize! ('checking' checkFlow:port:host: checkRestOfSocket:port:host: checkServerFlow:port:host: checkServerSocket:port:host: checkServerStream:port:host: checkSocket:port:host: checkSocketMayBeData:port:host: checkStream:port: checkStream:port:host: checkStreamMayBeData:port:host: checkStreamThenWrite2:port: checkStreamThenWrite2AndPeek:port: checkStreamThenWrite2AndPeekBeChar:port: checkStreamThenWrite3:port: checkStreamThenWrite4:port: checkStreamThenWrite:port: checkUDPSocket:port:host:) ('constants' echoHostName echoPort localHostName) ('setup' setUp) ('testing' testConnectToEcho testConnectToEchoThenWrite testConnectToEchoThenWrite2 testConnectToEchoThenWrite2AndPeek testConnectToEchoThenWrite2AndPeekBeChar testConnectToEchoThenWrite3 testConnectToEchoThenWrite4 testFlowClient testFlowServer testServerConnection testServerConnectionSendData testServerConnectionSendDataTerminate testServerConnectionSendDataTerminate2 testServerConnectionSendDataTerminate3 testUDPConnectToEcho testUDPConnectToEchoThenWrite testUDPConnectToEchoThenWrite2 testUDPConnectToEchoThenWrite2AndPeek testUDPConnectToEchoThenWrite2AndPeekBeChar testUDPConnectToEchoThenWrite3 testUDPConnectToEchoThenWrite4 testUDPConnectToEchoThenWrite5 testUDPConnectToEchoThenWrite6) ! TestServerForFlow removeSelector: #accept! TestInternetSocketAddress removeSelector: #checkButPort:! TestInternetSocketAddress removeSelector: #testAtPut! TestInternetSocketAddress removeSelector: #testStale! TestFlowSerial removeSelector: #testOpenWriteClose!