' BSD Socket Extension Test Suite ' ' Exercise all known functionality of the extension and write ' a report file detailing the result. Screen Open 0,640,200,4,Hires _FILE_HANDLE=1 Dim _CONTEXT$(10) _CONTEXT_INDEX=0 Global _FILE_HANDLE,_CONTEXT$(),_CONTEXT_INDEX Procedure _ADD_TO_REPORT[MESSAGE$] _CONTEXT_STRING$="" For I=0 To _CONTEXT_INDEX-1 _CONTEXT_STRING$=_CONTEXT_STRING$+_CONTEXT$(I) If I<>(_CONTEXT_INDEX-1) _CONTEXT_STRING$=_CONTEXT_STRING$+"/" End If Next I _OUTPUT$="["+_CONTEXT_STRING$+"] "+MESSAGE$ Print #_FILE_HANDLE,_OUTPUT$ Print _OUTPUT$ ' ensure line is printed on screen to catch crashes Wait Vbl End Proc Procedure _BEGIN_CONTEXT[NAME$] _CONTEXT$(_CONTEXT_INDEX)=NAME$ _CONTEXT_INDEX=_CONTEXT_INDEX+1 End Proc Procedure _END_CONTEXT _CONTEXT_INDEX=_CONTEXT_INDEX-1 End Proc Open Out _FILE_HANDLE,"report.txt" _BEGIN_CONTEXT["Socket Library Open"] _BEGIN_CONTEXT["Open Library"] _LIBRARY_ADDRESS=Socket Library Open _ADD_TO_REPORT[Str$(_LIBRARY_ADDRESS)] _END_CONTEXT If _LIBRARY_ADDRESS=0 _ADD_TO_REPORT["bsdsocket.library not available, ending tests"] _END_CONTEXT Goto _FINISH_SUITE End If _BEGIN_CONTEXT["Double open"] _NEW_LIBRARY_ADDRESS=Socket Library Open _ADD_TO_REPORT[Str$(_NEW_LIBRARY_ADDRESS)] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Socket Create Inet Socket"] SOCKET=Socket Create Inet Socket _ADD_TO_REPORT[Str$(SOCKET)] _END_CONTEXT _BEGIN_CONTEXT["Socket Reuse Addr"] RESULT=Socket Reuse Addr(SOCKET) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["Socket Set Nonblocking"] _BEGIN_CONTEXT["False"] RESULT=Socket Set Nonblocking(SOCKET,False) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["True"] RESULT=Socket Set Nonblocking(SOCKET,True) _ADD_TO_REPORT[Str$(RESULT)] _ADD_TO_REPORT["Preserving this state for rest of tests"] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Dns Get Address By Name$"] _BEGIN_CONTEXT["Bad domain name"] IP$=Dns Get Address By Name$("u8dsf93jsdfoiodsoi.sdfjdsoifueru.sadfasdsdasd") Print IP$ _ADD_TO_REPORT[IP$] _END_CONTEXT _BEGIN_CONTEXT["localhost"] IP$=Dns Get Address By Name$("localhost") _ADD_TO_REPORT[IP$] _END_CONTEXT _BEGIN_CONTEXT["aminet.net"] IP$=Dns Get Address By Name$("aminet.net") Print IP$ _ADD_TO_REPORT[IP$] _ADD_TO_REPORT["Using this IP address for connection tests"] _END_CONTEXT _BEGIN_CONTEXT["Returned string can be manipulated"] _ADD_TO_REPORT["Cat"+IP$+"Dog"] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Socket Connect"] _BEGIN_CONTEXT["port too high"] RESULT=Socket Connect(SOCKET To IP$,999999) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["blank ip"] RESULT=Socket Connect(SOCKET To "",80) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["invalid ip -- requires reopening failed socket"] RESULT=Socket Connect(SOCKET To "999.999.999.999",80) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["Socket Close Socket"] RESULT=Socket Close Socket(SOCKET) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT ' re-set up this socket after a failed connection SOCKET=Socket Create Inet Socket _=Socket Set Nonblocking(SOCKET,True) _BEGIN_CONTEXT["aminet IP ("+IP$+") from above"] RESULT=Socket Connect(SOCKET To IP$,80) _ADD_TO_REPORT[Str$(RESULT)+" (ok to be -1, will Wait Async Writing next)"] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Socket Wait Async Writing"] _BEGIN_CONTEXT["With unconnected socket"] OTHER_SOCKET=Socket Create Inet Socket _=Socket Set Nonblocking(OTHER_SOCKET,True) _BEGIN_CONTEXT["2 second timeout"] RESULT=Socket Wait Async Writing(OTHER_SOCKET,2000) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["Zero timeout"] RESULT=Socket Wait Async Writing(OTHER_SOCKET,0) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Connected socket"] _BEGIN_CONTEXT["Two second timeout"] RESULT=Socket Wait Async Writing(SOCKET,2000) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["Zero timeout"] RESULT=Socket Wait Async Writing(SOCKET,0) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["Attempt to get actual connection"] For TRIES=0 To 10 RESULT=Socket Wait Async Writing(SOCKET,500) _ADD_TO_REPORT[Str$(RESULT)] If RESULT>0 Exit End If Next TRIES _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Socket Get Host"] _BEGIN_CONTEXT["socket id too high"] RESULT=Socket Get Host(999999) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["socket id is valid"] RESULT=Socket Get Host(SOCKET) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Socket Get Port"] _BEGIN_CONTEXT["socket id too high"] RESULT=Socket Get Port(999999) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["socket id is valid"] RESULT=Socket Get Port(SOCKET) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Socket Inet Ntoa$"] _BEGIN_CONTEXT["Use the socket host"] RESULT$=Socket Inet Ntoa$(Socket Get Host(SOCKET)) _ADD_TO_REPORT[RESULT$] _END_CONTEXT _BEGIN_CONTEXT["String can be manipulated"] _ADD_TO_REPORT["Cat"+RESULT$+"Dog"] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Socket Send and Socket Send$"] HTTP_REQUEST_HEADERS$="GET / HTTP/1.0"+Chr$(10)+"Host: amiga"+Chr$(10)+Chr$(10) _BEGIN_CONTEXT["Socket send$ first half"] FIRST_HALF$=Left$(HTTP_REQUEST_HEADERS$,10) RESULT=Socket Send$(SOCKET,FIRST_HALF$) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["Socket send second half"] SECOND_HALF_START=Varptr(HTTP_REQUEST_HEADERS$)+10 SECOND_HALF_LENGTH=Len(HTTP_REQUEST_HEADERS$)-10 RESULT=Socket Send(SOCKET,SECOND_HALF_START,SECOND_HALF_LENGTH) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Socket wait Async Reading"] _BEGIN_CONTEXT["With unconnected socket"] _BEGIN_CONTEXT["2 second timeout"] RESULT=Socket Wait Async Reading(OTHER_SOCKET,2000) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["Zero timeout"] RESULT=Socket Wait Async Reading(OTHER_SOCKET,0) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["With aminet socket"] _BEGIN_CONTEXT["2 second timeout"] RESULT=Socket Wait Async Reading(SOCKET,2000) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["Zero timeout"] RESULT=Socket Wait Async Reading(SOCKET,0) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _END_CONTEXT _END_CONTEXT 'Goto _FINISH_SUITE _BEGIN_CONTEXT["Socket Recv$ and Socket Recv"] _BEGIN_CONTEXT["Socket Recv$"] _BEGIN_CONTEXT["Read 20 characters"] RESULT$=Socket Recv$(SOCKET,20) _ADD_TO_REPORT[RESULT$] _END_CONTEXT _BEGIN_CONTEXT["String can be manipulated"] _ADD_TO_REPORT["Cat"+RESULT$+"Dog"] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Socket Read"] Reserve As Work 20,20 _BEGIN_CONTEXT["Read 20 bytes"] RESULT=Socket Recv(SOCKET To Start(20),20) _ADD_TO_REPORT[Str$(RESULT)] _END_CONTEXT _BEGIN_CONTEXT["Data was read"] BASE$="12345678901234567890" For I=0 To 19 Mid$(BASE$,I+1,1)=Chr$(Peek(Start(20)+I)) Next I _ADD_TO_REPORT[BASE$] _END_CONTEXT Erase 20 _END_CONTEXT _END_CONTEXT _FINISH_SUITE: _BEGIN_CONTEXT["Socket Library Close"] _BEGIN_CONTEXT["Close"] Socket Library Close _ADD_TO_REPORT["Success"] _END_CONTEXT _BEGIN_CONTEXT["Double close"] Socket Library Close _ADD_TO_REPORT["Success"] _END_CONTEXT _END_CONTEXT _BEGIN_CONTEXT["Call functions with library closed"] _=Socket Set Nonblocking(0,True) _ADD_TO_REPORT["Socket Set Nonblocking"] _=Socket Reuse Addr(0) _ADD_TO_REPORT["Socket Reuse Addr"] _=Socket Create Inet Socket _ADD_TO_REPORT["Socket Create Inet Socket"] _=Socket Connect(0 To "",0) _ADD_TO_REPORT["Socket Connect"] _=Socket Bind(0 To "",0) _ADD_TO_REPORT["Socket Bind"] _=Socket Listen(0) _ADD_TO_REPORT["Socket Listen"] _=Socket Accept(0) _ADD_TO_REPORT["Socket Accept"] _=Socket Wait Async Reading(0,0) _ADD_TO_REPORT["Socket Wait Async Reading"] _=Socket Wait Async Writing(0,0) _ADD_TO_REPORT["Socket Wait Async Writing"] _=Socket Set Timeout(0,0) _ADD_TO_REPORT["Socket Set Timeout"] _=Socket Close Socket(0) _ADD_TO_REPORT["Socket Close Socket"] _=Socket Send$(0,"") _ADD_TO_REPORT["Socket Send$"] _=Socket Send(0,0,0) _ADD_TO_REPORT["Socket Send"] _$=Socket Recv$(0,0) _ADD_TO_REPORT["Socket Recv$"] _=Socket Recv(0 To 0,0) _ADD_TO_REPORT["Socket Recv"] _=Socket Get Host(0) _ADD_TO_REPORT["Socket Get Host"] _=Socket Get Port(0) _ADD_TO_REPORT["Socket Get Port"] _$=Socket Inet Ntoa$(0) _ADD_TO_REPORT["Socket Inet Ntoa$"] _=Socket Errno _ADD_TO_REPORT["Socket Errno"] _=Socket Herrno _ADD_TO_REPORT["Socket Herrno"] _$=Dns Get Address By Name$("") _ADD_TO_REPORT["Dns Get Address By Name$"] _END_CONTEXT Close 1