[Libreoffice-commits] core.git: sal/qa
Stephan Bergmann
sbergman at redhat.com
Mon Nov 2 03:08:58 PST 2015
sal/qa/osl/socket/export.exp | 1
sal/qa/osl/socket/osl_AcceptorSocket.cxx | 243 -
sal/qa/osl/socket/osl_ConnectorSocket.cxx | 247 -
sal/qa/osl/socket/osl_ConnectorSocket.xsce | 18
sal/qa/osl/socket/osl_DatagramSocket.cxx | 300 --
sal/qa/osl/socket/osl_Socket.cxx | 3585 -----------------------------
sal/qa/osl/socket/osl_Socket.xsce | 22
sal/qa/osl/socket/osl_Socket2.cxx | 1391 -----------
sal/qa/osl/socket/osl_Socket2.xsce | 19
sal/qa/osl/socket/osl_SocketAddr.cxx | 855 ------
sal/qa/osl/socket/osl_SocketOld.xsce | 31
sal/qa/osl/socket/osl_Socket_Const.h | 110
sal/qa/osl/socket/osl_Socket_Const_orig.h | 148 -
sal/qa/osl/socket/osl_Socket_tests.cxx | 75
sal/qa/osl/socket/osl_Socket_tests.xsce | 18
sal/qa/osl/socket/osl_StreamSocket.cxx | 1364 -----------
sal/qa/osl/socket/osl_StreamSocket.xsce | 21
sal/qa/osl/socket/sockethelper.cxx | 326 --
sal/qa/osl/socket/sockethelper.hxx | 158 -
19 files changed, 8932 deletions(-)
New commits:
commit dbf80fac45a513688ac8acfcf2dbbc0a726258e9
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Mon Nov 2 12:08:08 2015 +0100
Remove long-unused sal/qa/osl/socket/ test code for good
Change-Id: I2614e6c9f6d0a31866cb9821910da7f3e31377c6
diff --git a/sal/qa/osl/socket/export.exp b/sal/qa/osl/socket/export.exp
deleted file mode 100755
index a13529d..0000000
--- a/sal/qa/osl/socket/export.exp
+++ /dev/null
@@ -1 +0,0 @@
-registerAllTestFunction
diff --git a/sal/qa/osl/socket/osl_AcceptorSocket.cxx b/sal/qa/osl/socket/osl_AcceptorSocket.cxx
deleted file mode 100644
index 85d5d4c..0000000
--- a/sal/qa/osl/socket/osl_AcceptorSocket.cxx
+++ /dev/null
@@ -1,243 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-/** test coder preface:
- 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform
- if you are not including ws2_32.lib in makefile.mk, the including format will be like this:
-
- .IF "$(OS)" == "WNT"
- SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib
- SHL1STDLIBS += ws2_32.lib
- .ENDIF
-
- likewise on Solaris platform.
- .IF "$(OS)" != "WNT"
- SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a
- SHL1STDLIBS += -lsocket -ldl -lnsl
- .ENDIF
-
- 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4
- category.
-
- 3. some fragment of Socket source implementation are lack of comment so it is hard for testers
- guess what the exact functionality or usage of a member. Hope the Socket section's comment
- will be added.
-
- 4. following functions are declared but not implemented:
- inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const;
- */
-
-// include files
-
-#include <sal/types.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
-
-#include "osl_Socket_Const.h"
-#include "sockethelper.hxx"
-
-using namespace osl;
-using ::rtl::OUString;
-
-#define IP_PORT_FTP 21
-#define IP_PORT_MYPORT9 8897
-#define IP_PORT_MYPORT4 8885
-#define IP_PORT_MYPORT3 8884
-
-// helper functions
-
-// just used to test socket::close() when accepting
-class AcceptorThread : public Thread
-{
- ::osl::AcceptorSocket asAcceptorSocket;
- ::rtl::OUString aHostIP;
- sal_Bool bOK;
-protected:
- void SAL_CALL run( )
- {
- ::osl::SocketAddr saLocalSocketAddr( aHostIP, IP_PORT_MYPORT9 );
- ::osl::StreamSocket ssStreamConnection;
-
- asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //integer not sal_Bool : sal_True);
- sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
- if ( sal_True != bOK1 )
- {
- t_print("# AcceptorSocket bind address failed.\n" ) ;
- return;
- }
- sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
- if ( sal_True != bOK2 )
- {
- t_print("# AcceptorSocket listen address failed.\n" ) ;
- return;
- }
-
- asAcceptorSocket.enableNonBlockingMode( sal_False );
-
- oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection );
- if (eResult != osl_Socket_Ok )
- {
- bOK = sal_True;
- t_print("AcceptorThread: acceptConnection failed! \n");
- }
- }
-public:
- AcceptorThread(::osl::AcceptorSocket & asSocket, ::rtl::OUString const& aBindIP )
- : asAcceptorSocket( asSocket ), aHostIP( aBindIP )
- {
- bOK = sal_False;
- }
-
- sal_Bool isOK() { return bOK; }
-
- ~AcceptorThread( )
- {
- if ( isRunning( ) )
- {
- asAcceptorSocket.shutdown();
- t_print("# error: Acceptor thread not terminated.\n" );
- }
- }
-};
-
-namespace osl_AcceptorSocket
-{
-
- /** testing the methods:
- inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
- oslProtocol Protocol = osl_Socket_ProtocolIp,
- oslSocketType Type = osl_Socket_TypeStream);
- */
-
- class ctors : public CppUnit::TestFixture
- {
- public:
-
- void ctors_001()
- {
- /// Socket constructor.
- ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream );
-
- CPPUNIT_ASSERT_MESSAGE( "test for ctors_001 constructor function: check if the acceptor socket was created successfully.",
- osl_Socket_TypeStream == asSocket.getType( ) );
- }
-
- CPPUNIT_TEST_SUITE( ctors );
- CPPUNIT_TEST( ctors_001 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class ctors
-
- /** testing the method:
- inline sal_Bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
- inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
- inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
- */
-
- class listen_accept : public CppUnit::TestFixture
- {
- public:
- TimeValue *pTimeout;
- ::osl::AcceptorSocket asAcceptorSocket;
- ::osl::ConnectorSocket csConnectorSocket;
-
- // initialization
- void setUp( )
- {
- pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) );
- pTimeout->Seconds = 3;
- pTimeout->Nanosec = 0;
- asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1);
- // sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp );
- }
-
- void tearDown( )
- {
- free( pTimeout );
- // sHandle = NULL;
- asAcceptorSocket.close( );
- csConnectorSocket.close( );
- }
-
- void listen_accept_001()
- {
- ::osl::SocketAddr saLocalSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT3 );
- ::osl::SocketAddr saTargetSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT3 );
- ::osl::StreamSocket ssConnection;
-
- /// launch server socket
- sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
- CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 );
- sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
- CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 );
- asAcceptorSocket.enableNonBlockingMode( sal_True );
-
- /// launch client socket
- csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server...
-
- oslSocketResult eResult = asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection...
-
- CPPUNIT_ASSERT_MESSAGE( "test for listen_accept function: try to create a connection with remote host, using listen and accept.",
- ( osl_Socket_Ok == eResult ) );
- }
-
- void listen_accept_002()
- {
- ::osl::SocketAddr saLocalSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT4 );
- ::osl::SocketAddr saTargetSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT4 );
- ::osl::SocketAddr saPeerSocketAddr( rtl::OUString("129.158.217.202"), IP_PORT_FTP );
- ::osl::StreamSocket ssConnection;
-
- /// launch server socket
- sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
- CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 );
- sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
- CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 );
- asAcceptorSocket.enableNonBlockingMode( sal_True );
-
- /// launch client socket
- csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server...
-
- oslSocketResult eResult = asAcceptorSocket.acceptConnection(ssConnection, saPeerSocketAddr); /// waiting for incoming connection...
-
- CPPUNIT_ASSERT_MESSAGE( "test for listen_accept function: try to create a connection with remote host, using listen and accept, accept with peer address.",
- ( sal_True == bOK2 ) &&
- ( osl_Socket_Ok == eResult ) &&
- ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) ) );
- }
-
- CPPUNIT_TEST_SUITE( listen_accept );
- CPPUNIT_TEST( listen_accept_001 );
- CPPUNIT_TEST( listen_accept_002 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class listen_accept
-
-CPPUNIT_TEST_SUITE_REGISTRATION(osl_AcceptorSocket::ctors);
-//CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_AcceptorSocket::operator_assign, "osl_AcceptorSocket");
-CPPUNIT_TEST_SUITE_REGISTRATION(osl_AcceptorSocket::listen_accept);
-
-} // namespace osl_AcceptorSocket
-
-// this macro creates an empty function, which will called by the RegisterAllFunctions()
-// to let the user the possibility to also register some functions by hand.
-CPPUNIT_PLUGIN_IMPLEMENT();
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/qa/osl/socket/osl_ConnectorSocket.cxx b/sal/qa/osl/socket/osl_ConnectorSocket.cxx
deleted file mode 100644
index 261cfc2..0000000
--- a/sal/qa/osl/socket/osl_ConnectorSocket.cxx
+++ /dev/null
@@ -1,247 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-/** test coder preface:
- 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform
- if you are not including ws2_32.lib in makefile.mk, the including format will be like this:
-
- .IF "$(OS)" == "WNT"
- SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib
- SHL1STDLIBS += ws2_32.lib
- .ENDIF
-
- likewise on Solaris platform.
- .IF "$(OS)" != "WNT"
- SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a
- SHL1STDLIBS += -lsocket -ldl -lnsl
- .ENDIF
-
- 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4
- category.
-
- 3. some fragment of Socket source implementation are lack of comment so it is hard for testers
- guess what the exact functionality or usage of a member. Hope the Socket section's comment
- will be added.
-
- 4. following functions are declared but not implemented:
- inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const;
- */
-
-// include files
-
-#include <sal/types.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
-
-#include "osl_Socket_Const.h"
-#include "sockethelper.hxx"
-
-using namespace osl;
-using ::rtl::OUString;
-
-#define IP_PORT_MYPORT2 8883
-#define IP_PORT_FTP 21
-#define IP_PORT_MYPORT3 8884
-
-// helper functions
-
-class CloseSocketThread : public Thread
-{
- ::osl::Socket &m_sSocket;
-protected:
- void SAL_CALL run( )
- {
- thread_sleep( 1 );
- m_sSocket.close( );
- }
-public:
- CloseSocketThread(::osl::Socket & sSocket )
- : m_sSocket( sSocket )
- {
- }
-
- ~CloseSocketThread( )
- {
- if ( isRunning( ) )
- {
- t_print("# error: CloseSocketThread not terminated.\n" );
- }
- }
-};
-
-namespace osl_ConnectorSocket
-{
-
- /** testing the method:
- ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
- oslProtocol Protocol = osl_Socket_ProtocolIp,
- oslSocketType Type = osl_Socket_TypeStream);
- */
-
- class ctors : public CppUnit::TestFixture
- {
- public:
- void ctors_001()
- {
- /// Socket constructor.
- ::osl::ConnectorSocket csSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream );
-
- CPPUNIT_ASSERT_MESSAGE( "test for ctors_001 constructor function: check if the connector socket was created successfully.",
- osl_Socket_TypeStream == csSocket.getType( ) );
- }
-
- CPPUNIT_TEST_SUITE( ctors );
- CPPUNIT_TEST( ctors_001 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class ctors
-
- /** testing the method:
- oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = 0);
- */
-
- class connect : public CppUnit::TestFixture
- {
- public:
- TimeValue *pTimeout;
- ::osl::AcceptorSocket asAcceptorSocket;
- ::osl::ConnectorSocket csConnectorSocket;
-
- // initialization
- void setUp( )
- {
- pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) );
- pTimeout->Seconds = 3;
- pTimeout->Nanosec = 0;
- // sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp );
- }
-
- void tearDown( )
- {
- free( pTimeout );
- // sHandle = NULL;
- asAcceptorSocket.close( );
- csConnectorSocket.close( );
- }
-
- void connect_001()
- {
- ::osl::SocketAddr saLocalSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT2 );
- ::osl::SocketAddr saTargetSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT2 );
- ::osl::SocketAddr saPeerSocketAddr( rtl::OUString("129.158.217.202"), IP_PORT_FTP );
- ::osl::StreamSocket ssConnection;
-
- /// launch server socket
- asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True);
- sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
- CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 );
- sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
- CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 );
-
- //asAcceptorSocket.enableNonBlockingMode( sal_True );
- //oslSocketResult eResultAccept = asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection...
- //CPPUNIT_ASSERT_MESSAGE( "accept failed.", osl_Socket_Ok == eResultAccept );
- /// launch client socket
- oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server...
- CPPUNIT_ASSERT_MESSAGE( "connect failed.", osl_Socket_Ok == eResult );
-
- /// get peer information
- csConnectorSocket.getPeerAddr( saPeerSocketAddr );/// connected.
-
- CPPUNIT_ASSERT_MESSAGE( "test for connect function: try to create a connection with remote host. and check the setup address.",
- ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) ) &&
- ( osl_Socket_Ok == eResult ));
- }
- //non-blocking mode connect?
- void connect_002()
- {
- ::osl::SocketAddr saLocalSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT3 );
- ::osl::SocketAddr saTargetSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT3 );
- ::osl::SocketAddr saPeerSocketAddr( rtl::OUString("129.158.217.202"), IP_PORT_FTP );
-
- asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True);
- asAcceptorSocket.enableNonBlockingMode( sal_True );
- sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
- CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 );
- sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
- CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 );
-
- csConnectorSocket.enableNonBlockingMode( sal_True );
-
- oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server...
- CPPUNIT_ASSERT_MESSAGE( "connect failed.", osl_Socket_InProgress == eResult || osl_Socket_Ok == eResult );
-
- /// get peer information
- csConnectorSocket.getPeerAddr( saPeerSocketAddr );
-
- CPPUNIT_ASSERT_MESSAGE( "test for connect function: try to create a connection with remote host. and check the setup address.",
- sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) ) ;
- }
- // really an error or just delayed
- // how to design scenarios that will return osl_Socket_Interrupted, osl_Socket_TimedOut
- void connect_003()
- {
- ::osl::SocketAddr saTargetSocketAddr1( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT3 );
- ::osl::SocketAddr saTargetSocketAddr2( rtl::OUString("123.345.67.89"), IP_PORT_MYPORT3 );
-
- csConnectorSocket.enableNonBlockingMode( sal_False );
-
- oslSocketResult eResult1 = csConnectorSocket.connect( saTargetSocketAddr1, pTimeout );
- oslSocketResult eResult2 = csConnectorSocket.connect( saTargetSocketAddr2, pTimeout );
- CloseSocketThread myCloseThread( csConnectorSocket );
- oslSocketResult eResult3 = csConnectorSocket.connect( saTargetSocketAddr2, pTimeout );
- myCloseThread.join();
- CPPUNIT_ASSERT_MESSAGE( "connect should failed.", osl_Socket_Error == eResult1 &&
- osl_Socket_Error == eResult2 && osl_Socket_Error == eResult3 );
-
- }
-
- // really an error in non-blocking mode
- void connect_004()
- {
- ::osl::SocketAddr saTargetSocketAddr( rtl::OUString("123.345.67.89"), IP_PORT_MYPORT3 );
-
- csConnectorSocket.enableNonBlockingMode( sal_True );
-
- oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server...
- CPPUNIT_ASSERT_MESSAGE( "connect should failed.", osl_Socket_Error == eResult );
- }
- /** here need a case: immediate connection, say in non-blocking mode connect return osl_Socket_Ok
- */
-
- CPPUNIT_TEST_SUITE( connect );
- CPPUNIT_TEST( connect_001 );
- CPPUNIT_TEST( connect_002 );
- CPPUNIT_TEST( connect_003 );
- CPPUNIT_TEST( connect_004 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class connect
-
-CPPUNIT_TEST_SUITE_REGISTRATION(osl_ConnectorSocket::ctors);
-CPPUNIT_TEST_SUITE_REGISTRATION(osl_ConnectorSocket::connect);
-
-} // namespace osl_ConnectorSocket
-
-// this macro creates an empty function, which will called by the RegisterAllFunctions()
-// to let the user the possibility to also register some functions by hand.
-CPPUNIT_PLUGIN_IMPLEMENT();
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/qa/osl/socket/osl_ConnectorSocket.xsce b/sal/qa/osl/socket/osl_ConnectorSocket.xsce
deleted file mode 100644
index 6eafd2d..0000000
--- a/sal/qa/osl/socket/osl_ConnectorSocket.xsce
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# This file is part of the LibreOffice project.
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#
-# This file incorporates work covered by the following license notice:
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed
-# with this work for additional information regarding copyright
-# ownership. The ASF licenses this file to you under the Apache
-# License, Version 2.0 (the "License"); you may not use this file
-# except in compliance with the License. You may obtain a copy of
-# the License at http://www.apache.org/licenses/LICENSE-2.0 .
-#
-osl_ConnectorSocket.connect.connect_003 wntmsci
diff --git a/sal/qa/osl/socket/osl_DatagramSocket.cxx b/sal/qa/osl/socket/osl_DatagramSocket.cxx
deleted file mode 100644
index 3fb83cf..0000000
--- a/sal/qa/osl/socket/osl_DatagramSocket.cxx
+++ /dev/null
@@ -1,300 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-/** test coder preface:
- 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform
- if you are not including ws2_32.lib in makefile.mk, the including format will be like this:
-
- .IF "$(OS)" == "WNT"
- SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib
- SHL1STDLIBS += ws2_32.lib
- .ENDIF
-
- likewise on Solaris platform.
- .IF "$(OS)" != "WNT"
- SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a
- SHL1STDLIBS += -lsocket -ldl -lnsl
- .ENDIF
-
- 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4
- category.
-
- 3. some fragment of Socket source implementation are lack of comment so it is hard for testers
- guess what the exact functionality or usage of a member. Hope the Socket section's comment
- will be added.
-
- 4. following functions are declared but not implemented:
- inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const;
- */
-
-#include <sal/types.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
-
-#include "sockethelper.hxx"
-
-using namespace osl;
-
-using ::rtl::OUString;
-
-#define IP_PORT_MYPORT9 8897
-#define IP_PORT_MYPORT10 8898
-
-const char * pTestString1 = "test socket";
-const char * pTestString2 = " Passed#OK";
-
-// helper functions
-
-class CloseSocketThread : public Thread
-{
- ::osl::Socket m_sSocket;
-protected:
- void SAL_CALL run( )
- {
- thread_sleep( 1 );
- m_sSocket.close( );
- }
-public:
- CloseSocketThread(::osl::Socket & sSocket )
- : m_sSocket( sSocket )
- {
- }
-
- ~CloseSocketThread( )
- {
- if ( isRunning( ) )
- {
- t_print("# error: CloseSocketThread not terminated.\n" );
- }
- }
-};
-
-// tests cases begins here
-
-namespace osl_DatagramSocket
-{
-
- /** testing the methods:
- inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet,
- oslProtocol Protocol= osl_Socket_ProtocolIp,
- oslSocketType Type= osl_Socket_TypeDgram);
- */
-
- class ctors : public CppUnit::TestFixture
- {
- public:
-
- void ctors_001()
- {
- /// Socket constructor.
- ::osl::DatagramSocket dsSocket;
-
- CPPUNIT_ASSERT_MESSAGE( "test for ctors_001 constructor function: check if the datagram socket was created successfully.",
- osl_Socket_TypeDgram == dsSocket.getType( ) );
- }
-
- CPPUNIT_TEST_SUITE( ctors );
- CPPUNIT_TEST( ctors_001 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class ctors
-
-/**thread do sendTo, refer to http://www.coding-zone.co.uk/cpp/articles/140101networkprogrammingv.shtml
-*/
-class TalkerThread : public Thread
-{
-protected:
- ::osl::SocketAddr saTargetSocketAddr;
- ::osl::DatagramSocket dsSocket;
-
- void SAL_CALL run( )
- {
- dsSocket.sendTo( saTargetSocketAddr, pTestString1, strlen( pTestString1 ) + 1 ); // "test socket"
- dsSocket.shutdown();
- }
-
- void SAL_CALL onTerminated( )
- {
- }
-
-public:
- TalkerThread( ):
- saTargetSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT9 )
- {
- }
-
- ~TalkerThread( )
- {
- if ( isRunning( ) )
- t_print("# error: TalkerThread not terminated normally.\n" );
- }
-};
-
-/**thread do listen, refer to http://www.coding-zone.co.uk/cpp/articles/140101networkprogrammingv.shtml
-*/
-class ListenerThread : public Thread
-{
-protected:
- ::osl::SocketAddr saTargetSocketAddr;
- ::osl::DatagramSocket dsSocket;
-
- void SAL_CALL run( )
- {
- ::osl::SocketAddr saLocalSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT10 );
- dsSocket.setOption( osl_Socket_OptionReuseAddr, 1 );
- if ( dsSocket.bind( saLocalSocketAddr ) == sal_False )
- {
- t_print("DatagramSocket bind failed \n");
- return;
- }
- //blocking mode: default
-#if !SILENT_TEST
- sal_Int32 nRecv =
-#endif
- dsSocket.recvFrom( pRecvBuffer, 30, &saTargetSocketAddr); //strlen( pTestString2 ) + 1
- t_print("After recvFrom, nRecv is %d\n", (int) nRecv);
- }
-
- void SAL_CALL onTerminated( )
- {
- }
-
-public:
- sal_Char pRecvBuffer[30];
- ListenerThread( ):
- saTargetSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT10 )
- {
- pRecvBuffer[0] = '\0';
- }
-
- ~ListenerThread( )
- {
- if ( isRunning( ) )
- t_print("# error: ListenerThread not terminated normally.\n" );
- }
-
-};
-
- /** testing the methods:
- inline sal_Int32 DatagramSocket::recvFrom(void* pBuffer, sal_uInt32 BufferSize,
- SocketAddr* pSenderAddr, oslSocketMsgFlag Flag )
- inline sal_Int32 DatagramSocket::sendTo( const SocketAddr& ReceiverAddr,
- const void* pBuffer, sal_uInt32 BufferSize, oslSocketMsgFlag Flag )
- */
-
- class sendTo_recvFrom : public CppUnit::TestFixture
- {
- public:
-
- void sr_001()
- {
- ::osl::SocketAddr saLocalSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT9 );
- ::osl::DatagramSocket dsSocket;
- dsSocket.setOption( osl_Socket_OptionReuseAddr, 1 );
- dsSocket.bind( saLocalSocketAddr );
-
- sal_Char pReadBuffer[30];
- TalkerThread myTalkThread;
- myTalkThread.create();
- sal_Int32 nRecv = dsSocket.recvFrom( pReadBuffer, 30, &saLocalSocketAddr);
- myTalkThread.join();
- //t_print("#received buffer is %s# \n", pReadBuffer);
-
- sal_Bool bOk = ( strcmp(pReadBuffer, pTestString1) == 0 );
-
- CPPUNIT_ASSERT_MESSAGE( "test for sendTo/recvFrom function: create a talker thread and recvFrom in the main thread, check if the datagram socket can communicate successfully.",
- nRecv > 0 && bOk == sal_True );
- }
-
- void sr_002()
- {
- ::osl::SocketAddr saListenSocketAddr( rtl::OUString("127.0.0.1"), IP_PORT_MYPORT10 );
- ::osl::DatagramSocket dsSocket;
-
- //listener thread construct a DatagramSocket, recvFrom waiting for data, then main thread sendto data
- ListenerThread myListenThread;
- myListenThread.create();
- //to grantee the recvFrom is before sendTo
- thread_sleep( 1 );
-
- sal_Int32 nSend = dsSocket.sendTo( saListenSocketAddr, pTestString2, strlen( pTestString2 ) + 1 );
-
- CPPUNIT_ASSERT_MESSAGE( "DatagramSocket sendTo failed: nSend <= 0.", nSend > 0);
-
- myListenThread.join();
- //t_print("#received buffer is %s# \n", myListenThread.pRecvBuffer);
-
- sal_Bool bOk = ( strcmp( myListenThread.pRecvBuffer, pTestString2) == 0 );
-
- CPPUNIT_ASSERT_MESSAGE( "test for sendTo/recvFrom function: create a listener thread and sendTo in the main thread, check if the datagram socket can communicate successfully.",
- bOk == sal_True );
- }
-
- //sendTo error, return -1; recvFrom error, return -1
- void sr_003()
- {
- ::osl::SocketAddr saListenSocketAddr( rtl::OUString("123.345.67.89"), IP_PORT_MYPORT10 );
- ::osl::DatagramSocket dsSocket;
- // Transport endpoint is not connected
- sal_Int32 nSend = dsSocket.sendTo( saListenSocketAddr, pTestString2, strlen( pTestString2 ) + 1 );
- CPPUNIT_ASSERT_MESSAGE( "DatagramSocket sendTo should fail: nSend <= 0.",
- nSend == -1 );
- }
-
- void sr_004()
- {
- ::osl::SocketAddr saListenSocketAddr1( rtl::OUString("123.345.67.89"), IP_PORT_MYPORT10 );
- ::osl::SocketAddr saListenSocketAddr2( rtl::OUString("129.158.217.202"), IP_PORT_MYPORT10 );
- ::osl::DatagramSocket dsSocket;
-
- dsSocket.enableNonBlockingMode( sal_True );
-
- sal_Char pReadBuffer[30];
- //sal_Int32 nRecv1 = dsSocket.recvFrom( pReadBuffer, 30, &saListenSocketAddr1 );
-
- // will block ?
- CloseSocketThread myThread( dsSocket );
- myThread.create();
- sal_Int32 nRecv2 = dsSocket.recvFrom( pReadBuffer, 30, &saListenSocketAddr1 );
- myThread.join();
- //t_print("#nRecv1 is %d nRecv2 is %d\n", nRecv1, nRecv2 );
- CPPUNIT_ASSERT_MESSAGE( "DatagramSocket sendTo should fail: nSend <= 0.",
- nRecv2 == -1 );
- }
-
- CPPUNIT_TEST_SUITE( sendTo_recvFrom );
- CPPUNIT_TEST( sr_001 );
- CPPUNIT_TEST( sr_002 );
- CPPUNIT_TEST( sr_003 );
- CPPUNIT_TEST( sr_004 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class sendTo_recvFrom
-
-CPPUNIT_TEST_SUITE_REGISTRATION(osl_DatagramSocket::ctors);
-CPPUNIT_TEST_SUITE_REGISTRATION(osl_DatagramSocket::sendTo_recvFrom);
-
-} // namespace osl_DatagramSocket
-
-// this macro creates an empty function, which will called by the RegisterAllFunctions()
-// to let the user the possibility to also register some functions by hand.
-CPPUNIT_PLUGIN_IMPLEMENT();
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/qa/osl/socket/osl_Socket.cxx b/sal/qa/osl/socket/osl_Socket.cxx
deleted file mode 100644
index 2c9e1ff..0000000
--- a/sal/qa/osl/socket/osl_Socket.cxx
+++ /dev/null
@@ -1,3585 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-/** test coder preface:
- 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform
- if you are not including ws2_32.lib in makefile.mk, the including format will be like this:
-
- .IF "$(OS)" == "WNT"
- SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib
- SHL1STDLIBS += ws2_32.lib
- .ENDIF
-
- likewise on Solaris platform.
- .IF "$(OS)" != "WNT"
- SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a
- SHL1STDLIBS += -lsocket -ldl -lnsl
- .ENDIF
-
- 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4
- category.
-
- 3. some fragment of Socket source implementation are lack of comment so it is hard for testers
- guess what the exact functionality or usage of a member. Hope the Socket section's comment
- will be added.
-
- 4. following functions are declared but not implemented:
- inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const;
- */
-
-// include files
-
-#include <sal/types.h>
-#include <osl_Socket_Const_orig.h>
-
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
-
-/** test output if SILENT_TEST is 0
-*/
-#if OSL_DEBUG_LEVEL > 0
-# define SILENT_TEST 0
-#else
-# define SILENT_TEST 1
-#endif
-
-#if SILENT_TEST
-# define t_print(...) { }
-#else
-# define t_print printf
-#endif
-
-/** convert UString and OUString to std::string
-*/
-#define STD_STRING(s) (std::string((const char *)s.getStr()))
-
-using namespace osl;
-
-using ::rtl::OUString;
-using ::rtl::OUStringToOString;
-using ::rtl::OString;
-
-// helper functions
-
-/** compare two OUString.
-*/
-inline sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 )
-{
- sal_Bool bOk = ustr1.equalsIgnoreAsciiCase( ustr2 );
-
- return bOk;
-}
-
-/** compare a OUString and an ASCII string.
-*/
-inline sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr )
-{
- ::rtl::OUString ustr2 = rtl::OUString::createFromAscii( astr );
- sal_Bool bOk = ustr.equalsIgnoreAsciiCase( ustr2 );
-
- return bOk;
-}
-
-/** compare two socket address.
-*/
-inline sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2 )
-{
- return ( ( sal_True == compareUString( addr1.getHostname( 0 ), addr2.getHostname( 0 ) ) ) && ( addr2.getPort( ) == addr2.getPort( ) ) );
-}
-
-inline char * oustring2char( const ::rtl::OUString & str )
-{
- rtl::OString aString;
- aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
- return (char *)aString.getStr( );
-}
-
-/** print a UNI_CODE String. And also print some comments of the string.
-*/
-inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = "" )
-{
-#if SILENT_TEST
- (void)str;
- (void)msg;
-#else
- t_print("#%s #printUString_u# ", msg );
- t_print("%s\n", oustring2char( str ) );
-#endif
-}
-
-/** get the local host name.
- mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name,
- if no entry in /etc/hosts, it returns "localhost" + domain name
-*/
-inline ::rtl::OUString getHost()
-{
- struct hostent *hptr;
-
- hptr = gethostbyname( "localhost" );
- CPPUNIT_ASSERT_MESSAGE( "#In getHostname function, error on gethostbyname()", hptr != NULL );
- ::rtl::OUString aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) hptr->h_name );
-
- return aUString;
-}
-
-/** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu
-*/
-inline ::rtl::OUString getThisHostname()
-{
- ::rtl::OUString aUString;
-#ifdef WNT
- struct hostent *hptr;
- hptr = gethostbyname( "localhost" );
- CPPUNIT_ASSERT_MESSAGE( "#In getHostname function, error on gethostbyname()", hptr != NULL );
- aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) hptr->h_name );
-#else
- char hostname[255];
- CPPUNIT_ASSERT_MESSAGE( "#Error: gethostname failed.", gethostname(hostname, 255) == 0 );
-
- struct hostent *hptr;
- //first search /ets/hosts, then search from dns
- hptr = gethostbyname( hostname);
- if ( hptr != NULL )
- {
- strcpy( hostname, hptr->h_name );
- }
-
- t_print("hostname is %s \n", hostname );
- aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) hostname );
-#endif
- return aUString;
-}
-
-/** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("")
-*/
-inline ::rtl::OUString getIPbyName( rtl::OString const& str_name )
-{
- ::rtl::OUString aUString;
- struct hostent *hptr;
- //first search /ets/hosts, then search from dns
- hptr = gethostbyname( str_name.getStr());
- if ( hptr != NULL )
- {
- struct in_addr ** addrptr;
- addrptr = (struct in_addr **) hptr->h_addr_list ;
- //if there are more than one IPs on the same machine, we select one
- for (; *addrptr; addrptr++)
- {
- t_print("#Local IP Address: %s\n", inet_ntoa(**addrptr));
- aUString = ::rtl::OUString::createFromAscii( (sal_Char *) (inet_ntoa(**addrptr)) );
- }
- }
- return aUString;
-}
-
-/** get local ethernet IP
-*/
-inline ::rtl::OUString getLocalIP( )
-{
- char hostname[255];
- gethostname(hostname, 255);
-
- return getIPbyName( hostname );
-}
-
-/** construct error message
-*/
-inline ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = "")
-{
- ::rtl::OUString aUString;
- if ( returnVal.equals( rightVal ) )
- return aUString;
- aUString += ::rtl::OUString::createFromAscii(msg);
- aUString += ::rtl::OUString(": the returned value is '");
- aUString += returnVal;
- aUString += ::rtl::OUString("', but the value should be '");
- aUString += rightVal;
- aUString += ::rtl::OUString("'.");
- return aUString;
-}
-
-/** wait _nSec seconds.
-*/
-void thread_sleep( sal_Int32 _nSec )
-{
- /// print statement in thread process must use fflush() to force display.
- t_print("# wait %d seconds. ", (int) _nSec );
- fflush(stdout);
-
-#ifdef WNT //Windows
- Sleep( _nSec * 100 );
-#endif
-#if ( defined UNX ) //Unix
- usleep(_nSec * 100000);
-#endif
- t_print("# done\n" );
-}
-
-/** print Boolean value.
-*/
-inline void printBool( sal_Bool bOk )
-{
-#if SILENT_TEST
- (void)bOk;
-#else
- t_print("#printBool# " );
- t_print ("%s", (sal_True == bOk) ? "YES!\n" : "NO!\n");
-#endif
-}
-
-/** print content of a ByteSequence.
-*/
-inline void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen )
-{
-#if SILENT_TEST
- (void)bsByteSeq;
- (void)nLen;
-#else
- t_print("#ByteSequence is: " );
- for ( int i = 0; i < nLen; i++ ){
- if ( bsByteSeq[i] < 0 )
- t_print("%d ", 256 + bsByteSeq[i] );
- else
- t_print("%d ", bsByteSeq[i] );
- }
- t_print(" .\n" );
-#endif
-}
-
-/** convert an IP which is stored as a UString format to a ByteSequence array for later use.
-*/
-inline ::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr )
-{
-
- rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );
- const sal_Char *pChar = aString.getStr( ) ;
- sal_Char tmpBuffer[4];
- sal_Int32 nCharCounter = 0;
- ::rtl::ByteSequence bsByteSequence( IP_VER );
- sal_Int32 nByteSeqCounter = 0;
-
- for ( int i = 0; i < aString.getLength( ) + 1 ; i++ )
- {
- if ( ( *pChar != '.' ) && ( i !=aString.getLength( ) ) )
- tmpBuffer[nCharCounter++] = *pChar;
- else
- {
- tmpBuffer[nCharCounter] = '\0';
- nCharCounter = 0;
- bsByteSequence[nByteSeqCounter++] = static_cast<sal_Int8>( atoi( tmpBuffer ) );
- }
- pChar++;
- }
- return bsByteSequence;
-}
-
-/** print a socket result name.
-*/
-inline void printSocketResult( oslSocketResult eResult )
-{
- t_print("#printSocketResult# " );
- if (!eResult)
- switch (eResult)
- {
- case osl_Socket_Ok:
- t_print("client connected\n");
- break;
- case osl_Socket_Error:
- t_print("got an error ... exiting\r\n\r\n" );
- break;
- case osl_Socket_TimedOut:
- t_print("timeout\n");
- break;
-
- case osl_Socket_FORCE_EQUAL_SIZE:
- t_print("FORCE EQUAL SIZE\n");
- break;
- case osl_Socket_InProgress:
- t_print("In Progress\n");
- break;
- case osl_Socket_Interrupted:
- t_print("Interrupted\n");
- break;
- }
-}
-
-/** Client Socket Thread, served as a temp little client to communicate with server.
-*/
-class ClientSocketThread : public Thread
-{
-protected:
- oslThreadIdentifier m_id;
- ::osl::SocketAddr saTargetSocketAddr;
- ::osl::ConnectorSocket csConnectorSocket;
-
- void SAL_CALL run( )
- {
- TimeValue *pTimeout;
- pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) );
- pTimeout->Seconds = 5;
- pTimeout->Nanosec = 0;
-
- /// if the thread should terminate, schedule return false
- //while ( schedule( ) == sal_True )
- //{
- if ( osl_Socket_Ok == csConnectorSocket.connect( saTargetSocketAddr, pTimeout ))
- {
- csConnectorSocket.send( pTestString1, 11 ); // "test socket"
- csConnectorSocket.send( pTestString2, 10);
- }
- else
- t_print("# ClientSocketThread: connect failed! \n");
- // terminate();
- //}
- csConnectorSocket.close();
- free( pTimeout );
- }
-
- void SAL_CALL onTerminated( )
- {
- //t_print("# normally terminate this thread %d!\n", m_id );
- }
-
-public:
- ClientSocketThread( ):
- saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT9 ),
- csConnectorSocket( )
- {
- m_id = getIdentifier( );
- //t_print("# successfully create this client thread %d!\n", m_id );
- }
-
- ~ClientSocketThread( )
- {
- if ( isRunning( ) )
- t_print("# error: client thread not terminated.\n" );
- }
-
-};
-
-/** Server Socket Thread, served as a temp little server to communicate with client.
-*/
-class ServerSocketThread : public Thread
-{
-protected:
- oslThreadIdentifier m_id;
-
- void SAL_CALL run( )
- {
- ::osl::AcceptorSocket asAcceptorSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream );
- ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT9 );
- ::osl::StreamSocket ssStreamConnection;
-
- //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket
- asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //integer not sal_Bool : sal_True);
- while ( schedule( ) == sal_True )
- {
- sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
- if ( sal_True != bOK1 )
- {
- t_print("# ServerSocketThread: AcceptorSocket bind address failed.\n" ) ;
- break;
- }
- sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
- if ( sal_True != bOK2 )
- {
- t_print("# ServerSocketThread: AcceptorSocket listen address failed.\n" ) ;
- break;
- }
-
- asAcceptorSocket.enableNonBlockingMode( sal_False );
-
- oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection );
- if (eResult != osl_Socket_Ok )
- {
- t_print("ServerSocketThread: acceptConnection failed! \n");
- break;
- }
- sal_Int32 nReadNumber1 = ssStreamConnection.recv( pReadBuffer, 11 );
- sal_Int32 nReadNumber2 = ssStreamConnection.recv( pReadBuffer + nReadNumber1, 11 );
- pReadBuffer[nReadNumber1 + nReadNumber2] = '\0';
- //t_print("# read buffer content: %s\n", pReadBuffer );
- break;
- }
- ssStreamConnection.close();
- asAcceptorSocket.close();
-
- }
-
- void SAL_CALL onTerminated( )
- {
- //t_print("# normally terminate this server thread %d!\n", m_id );
- }
-
-public:
- // public to check if data transmition is OK
- sal_Char pReadBuffer[30];
- ServerSocketThread( )
- {
- m_id = getIdentifier( );
- //t_print("# successfully create this server thread %d!\n", m_id );
- }
-
- ~ServerSocketThread( )
- {
- if ( isRunning( ) )
- t_print("# error: server thread not terminated.\n" );
- }
-};
-
-// Helper functions, to create buffers, check buffers
-class ValueCheckProvider
-{
- bool m_bFoundFailure;
- char *m_pBuffer;
- sal_Int32 m_nBufferSize;
-
-public:
- ValueCheckProvider()
- :
- m_bFoundFailure(false),
- m_pBuffer(NULL),
- m_nBufferSize(0)
- {
- }
-
- bool isFailure() {return m_bFoundFailure;}
-
- const char* getBuffer() {return m_pBuffer;}
- char* getWriteBuffer() {return m_pBuffer;}
-
- sal_Int32 getBufferSize() {return m_nBufferSize;}
-
- bool checkValues(sal_Int32 _nLength, int _nValue)
- {
- m_bFoundFailure = false;
- for(sal_Int32 i=0;i<_nLength;i++)
- {
- if (m_pBuffer[i] != _nValue)
- {
- m_bFoundFailure = true;
- }
- }
- return m_bFoundFailure;
- }
-
- void createBuffer(sal_Int32 _nLength, int _nValue)
- {
- m_nBufferSize = _nLength;
- m_pBuffer = (char*) malloc(m_nBufferSize);
- if (m_pBuffer)
- {
- memset(m_pBuffer, _nValue, m_nBufferSize);
- }
- }
-
- void freeBuffer()
- {
- if (m_pBuffer) free(m_pBuffer);
- }
-
-};
-
-/** Client Socket Thread, served as a temp little client to communicate with server.
-*/
-
-class ReadSocketThread : public Thread
-{
- int m_nValue;
- ValueCheckProvider m_aValues;
-
-protected:
- oslThreadIdentifier m_id;
- ::osl::SocketAddr saTargetSocketAddr;
- ::osl::ConnectorSocket csConnectorSocket;
-
- void SAL_CALL run( )
- {
- TimeValue *pTimeout;
- pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) );
- pTimeout->Seconds = 5;
- pTimeout->Nanosec = 0;
-
- /// if the thread should terminate, schedule return false
- //while ( schedule( ) == sal_True )
- //{
- if ( osl_Socket_Ok == csConnectorSocket.connect( saTargetSocketAddr, pTimeout ))
- {
- sal_Int32 nReadCount = csConnectorSocket.read( m_aValues.getWriteBuffer(), m_aValues.getBufferSize() );
- m_aValues.checkValues(nReadCount, m_nValue);
- }
- else
- {
- t_print("# ReadSocketThread: connect failed! \n");
- }
- // terminate();
- //}
- //remove this line for deadlock on solaris( margritte.germany )
- csConnectorSocket.close();
- free( pTimeout );
- }
-
- void SAL_CALL onTerminated( )
- {
- //t_print("# normally terminate this thread %d!\n", m_id );
- }
-
-public:
- sal_Int32 getCount() {return m_aValues.getBufferSize();}
- bool isOk() {return m_aValues.isFailure() == true ? false : true;}
-
- ReadSocketThread(sal_Int32 _nBufferSize, int _nValue )
- :
- m_nValue( _nValue ),
- saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT10 ),
- csConnectorSocket( )
- {
- m_id = getIdentifier( );
- //t_print("# successfully create this client thread %d!\n", m_id );
- m_aValues.createBuffer(_nBufferSize, 0);
- }
-
- ~ReadSocketThread( )
- {
- if ( isRunning( ) )
- t_print("# error: client thread not terminated.\n" );
- m_aValues.freeBuffer();
- }
-
-};
-
-/** Server Socket Thread, write a file which is large
-*/
-class WriteSocketThread : public Thread
-{
- ValueCheckProvider m_aValues;
-
-protected:
- oslThreadIdentifier m_id;
-
- void SAL_CALL run( )
- {
- ::osl::AcceptorSocket asAcceptorSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream );
- ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT10 );
- ::osl::StreamSocket ssStreamConnection;
-
- //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket
- asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True);
-
- /// if the thread should terminate, schedule return false
- while ( schedule( ) == sal_True )
- {
- sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
- if ( sal_True != bOK1 )
- {
- t_print("# WriteSocketThread: AcceptorSocket bind address failed. \n" ) ;
- break;
- }
- sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
- if ( sal_True != bOK2 )
- {
- t_print("# WriteSocketThread: AcceptorSocket listen address failed. \n" ) ;
- break;
- }
- // blocking mode, if read/recv failed, block until success
- asAcceptorSocket.enableNonBlockingMode( sal_False);
-
- oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection );
- if (eResult != osl_Socket_Ok )
- {
- t_print("WriteSocketThread: acceptConnection failed! \n");
- break;
- }
-
- ssStreamConnection.write( m_aValues.getBuffer(), m_aValues.getBufferSize() );
- break;
- }
- ssStreamConnection.close();
- asAcceptorSocket.close();
- }
-
- void SAL_CALL onTerminated( )
- {
- //t_print("# normally terminate this server thread %d!\n", m_id );
- }
-
-public:
- // public to check if data transmition is OK
- WriteSocketThread(sal_Int32 _nBufferSize, int _nValue )
- {
- m_id = getIdentifier( );
- //t_print("# successfully create this server thread %d!\n", m_id );
-
- m_aValues.createBuffer(_nBufferSize, _nValue);
- }
-
- ~WriteSocketThread( )
- {
- if ( isRunning( ) )
- t_print("# error: server thread not terminated.\n" );
- m_aValues.freeBuffer();
- }
-
-};
-
-// just used to test socket::close() when accepting
-class AcceptorThread : public Thread
-{
- ::osl::AcceptorSocket asAcceptorSocket;
- ::rtl::OUString aHostIP;
- sal_Bool bOK;
-protected:
- void SAL_CALL run( )
- {
- ::osl::SocketAddr saLocalSocketAddr( aHostIP, IP_PORT_MYPORT9 );
- ::osl::StreamSocket ssStreamConnection;
-
- asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //integer not sal_Bool : sal_True);
- sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
- if ( sal_True != bOK1 )
- {
- t_print("# AcceptorSocket bind address failed.\n" ) ;
- return;
- }
- sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
- if ( sal_True != bOK2 )
- {
- t_print("# AcceptorSocket listen address failed.\n" ) ;
- return;
- }
-
- asAcceptorSocket.enableNonBlockingMode( sal_False );
-
- oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection );
- if (eResult != osl_Socket_Ok )
- {
- bOK = sal_True;
- t_print("AcceptorThread: acceptConnection failed! \n");
- }
- }
-public:
- AcceptorThread(::osl::AcceptorSocket & asSocket, ::rtl::OUString & aBindIP )
- : asAcceptorSocket( asSocket ), aHostIP( aBindIP )
- {
- bOK = sal_False;
- }
-
- sal_Bool isOK() { return bOK; }
-
- ~AcceptorThread( )
- {
- if ( isRunning( ) )
- {
- asAcceptorSocket.shutdown();
- t_print("# error: Acceptor thread not terminated.\n" );
- }
- }
-};
-
-class CloseSocketThread : public Thread
-{
- ::osl::Socket m_sSocket;
-protected:
- void SAL_CALL run( )
- {
- thread_sleep( 1 );
- m_sSocket.close( );
- }
-public:
- CloseSocketThread(::osl::Socket & sSocket )
- : m_sSocket( sSocket )
- {
- }
-
- ~CloseSocketThread( )
- {
- if ( isRunning( ) )
- {
- t_print("# error: CloseSocketThread not terminated.\n" );
- }
- }
-};
-
-// tests cases begins here
-
-namespace osl_SocketAddr
-{
-
- /** testing the methods:
- inline SocketAddr();
- inline SocketAddr(const SocketAddr& Addr);
- inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy );
- inline SocketAddr(oslSocketAddr Addr);
- inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort );
- */
-
- class ctors : public CppUnit::TestFixture
- {
- public:
-
- void ctors_none()
- {
- /// SocketAddr constructor.
- ::osl::SocketAddr saSocketAddr;
-
- // oslSocketResult aResult;
- // rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult);
-
- // rtl::OUString suHost2 = getThisHostname();
-
- CPPUNIT_ASSERT_MESSAGE("test for none parameter constructor function: check if the socket address was created successfully",
- sal_True == saSocketAddr.is( ) );
- }
-
- void ctors_none_000()
- {
- /// SocketAddr constructor.
- ::osl::SocketAddr saSocketAddr;
-
- oslSocketResult aResult;
- rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult);
- rtl::OUString suHost2 = getThisHostname();
-
- sal_Bool bOk = compareUString(suHost, suHost2);
-
- rtl::OUString suError ("Host names should be the same. From SocketAddr.getLocalHostname() it is'");
- suError += suHost;
- suError += rtl::OUString("', from getThisHostname() it is '");
- suError += suHost2;
- suError += rtl::OUString("'.");
-
- CPPUNIT_ASSERT_MESSAGE(STD_STRING(suError), sal_True == bOk);
- }
-
- void ctors_copy()
- {
- /// SocketAddr copy constructor.
- ::osl::SocketAddr saSocketAddr( aHostName1, IP_PORT_HTTP1 );
- ::osl::SocketAddr saCopySocketAddr( saSocketAddr );
-
- sal_Int32 nPort = saCopySocketAddr.getPort( );
-
- CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy constructor function: copy constructor, do an action of copy construction then check the port with original set.",
- ( sal_True == saCopySocketAddr.is( ) ) && ( nPort == IP_PORT_HTTP1 ) );
- }
-
- void ctors_copy_no_001()
- {
-
- ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( aHostName1, IP_PORT_HTTP1 );
- CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL);
-
- oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( );
-
- ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY );
-
- pSocketAddrCopy->setPort( IP_PORT_HTTP2 );
- CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.",
- pSocketAddr->getPort( ) == IP_PORT_HTTP2 );
-
- delete pSocketAddrCopy;
- // LLA: don't do this also: delete pSocketAddr;
- }
-
- void ctors_copy_no_002()
- {
- ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( aHostName1, IP_PORT_HTTP1 );
- CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL);
- oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( );
- ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY );
-
- CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.",
- pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( ) );
-
- delete pSocketAddrCopy;
- }
-
- void ctors_copy_handle_001()
- {
- ::osl::SocketAddr saSocketAddr( aHostName1, IP_PORT_HTTP1 );
- ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) );
-
- CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy handle constructor function: copy another Socket's handle, get its port to check copy effect.",
- saSocketAddrCopy.getPort( ) == IP_PORT_HTTP1 );
- }
-
- void ctors_copy_handle_002()
- {
- ::osl::SocketAddr saSocketAddr( aHostName1, IP_PORT_HTTP1 );
- ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) );
- saSocketAddrCopy.setPort( IP_PORT_HTTP2 );
-
- CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy handle constructor function: copy another Socket's handle, the original one should not be changed.",
- saSocketAddr.getPort( ) != IP_PORT_HTTP2 );
- }
-
- void ctors_hostname_port_001()
- {
- /// tcpip-specific constructor.
- ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP );
- printUString(saSocketAddr.getHostname( ), "ctors_hostname_port_001:getHostname");
-
- CPPUNIT_ASSERT_MESSAGE("test for SocketAddr tcpip specificy constructor function: do a constructor using tcpip spec, check the result.",
- saSocketAddr.is( ) == sal_True &&
- ( saSocketAddr.getPort( ) == IP_PORT_FTP )/*&&
- ( sal_True == compareUString( saSocketAddr.getHostname( ), aHostName1 ) ) */);
- }
-
- //same as is_002
- void ctors_hostname_port_002()
- {
- /// tcpip-specific constructor.
- ::osl::SocketAddr saSocketAddr( aHostIpInval1, IP_PORT_MYPORT2 );
-
- CPPUNIT_ASSERT_MESSAGE("test for SocketAddr tcpip specificy constructor function: using an invalid IP address, the socketaddr ctors should fail", sal_False == saSocketAddr.is( ));
- }
- CPPUNIT_TEST_SUITE( ctors );
- CPPUNIT_TEST( ctors_none );
- CPPUNIT_TEST( ctors_none_000 );
- CPPUNIT_TEST( ctors_copy );
- CPPUNIT_TEST( ctors_copy_no_001 );
- CPPUNIT_TEST( ctors_copy_no_002 );
- CPPUNIT_TEST( ctors_copy_handle_001 );
- CPPUNIT_TEST( ctors_copy_handle_002 );
- CPPUNIT_TEST( ctors_hostname_port_001 );
- CPPUNIT_TEST( ctors_hostname_port_002 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class ctors
-
- /** testing the method:
- inline sal_Bool is() const;
- */
-
- class is : public CppUnit::TestFixture
- {
- public:
- void is_001()
- {
- ::osl::SocketAddr saSocketAddr;
-
- CPPUNIT_ASSERT_MESSAGE("test for is() function: create an unknown type socket, it should be True when call is.",
- sal_True == saSocketAddr.is( ) );
- }
- // refer to setPort_003()
- void is_002()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_INVAL );
-
- CPPUNIT_ASSERT_MESSAGE("test for is() function: create a tcp-ip socket using invalid port number",
- sal_True == saSocketAddr.is( ) );
- }
-
- void is_003()
- {
- ::osl::SocketAddr saSocketAddr( aHostIpInval1, IP_PORT_MYPORT );
-
- CPPUNIT_ASSERT_MESSAGE("test for is() function: create a tcp-ip socket using invalid Ip number",
- sal_True != saSocketAddr.is( ) );
- }
-
- CPPUNIT_TEST_SUITE( is );
- CPPUNIT_TEST( is_001 );
- CPPUNIT_TEST( is_002 );
- CPPUNIT_TEST( is_003 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class is
-
- /** testing the method:
- inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const;
- */
-
- class getHostname : public CppUnit::TestFixture
- {
- public:
- void setUp()
- {
- }
-
- void tearDown()
- {
- }
-
- void getHostname_000()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp4, IP_PORT_FTP );
-
- }
-
- /** it will search the Ip in current machine's /etc/hosts at first, if find, then return the
- mapped hostname, otherwise, it will search via DNS server, and often return hostname+ Domain name
- like "sceri.PRC.Sun.COM"
- The process is same as Socket::getLocalHost(), but getLocalHost can only return hostname of the current machine.
- */
- void getHostname_001()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp4, IP_PORT_FTP );
- rtl::OUString suResult = saSocketAddr.getHostname( 0 );
- rtl::OUString suError = outputError(suResult, aHostName4, "test for getHostname(0)");
- sal_Bool bOK = compareUString( suResult, aHostName4 );
- // search the returned hostname in /etc/hosts, if find, and the IP in the row is same as IP
- // in the Addr, it's right also.
- if ( bOK == sal_False)
- {
- if ( compareUString( getIPbyName( oustring2char( suResult ) ), aHostIp4 ) == sal_True )
- bOK = sal_True;
- }
- CPPUNIT_ASSERT_MESSAGE( STD_STRING(suError), sal_True == bOK);
- }
-
-// LLA: now we have to control, if this behaviour is right.
-// LLA: this function does not work in company (Linux, Windows) but at home
- void getHostname_002()
- {
- rtl::OUString suHostname ("cn-1.germany.sun.com");
- rtl::OUString aHostIP = getIPbyName( oustring2char( suHostname ) );
-
- ::osl::SocketAddr saSocketAddr( aHostName1, IP_PORT_FTP );
- sal_Bool bOK = saSocketAddr.setHostname( suHostname );
- CPPUNIT_ASSERT_MESSAGE("#SocketAddr.setHostname failed", sal_True == bOK );
- oslSocketResult aResult;
- rtl::OUString suResult = saSocketAddr.getHostname( &aResult );
- CPPUNIT_ASSERT_MESSAGE("SocketAddr.getHostname failed.", aResult == osl_Socket_Ok);
-
- rtl::OUString suError = outputError(suResult, suHostname, "test for getHostname(0)");
- bOK = compareUString( suResult, suHostname );
- if ( bOK == sal_False)
- {
- rtl::OString aString = ::rtl::OUStringToOString( suResult, RTL_TEXTENCODING_ASCII_US );
- if ( compareUString( getIPbyName( aString) , aHostIp6 ) == sal_True )
- {
- bOK = sal_True;
- }
- }
-
- CPPUNIT_ASSERT_MESSAGE( STD_STRING(suError), sal_True == bOK );
- }
-
- CPPUNIT_TEST_SUITE( getHostname );
- CPPUNIT_TEST( getHostname_001 );
- CPPUNIT_TEST( getHostname_002 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class getHostname
-
- /** testing the method:
- inline sal_Int32 SAL_CALL getPort() const;
- */
-
- class getPort : public CppUnit::TestFixture
- {
- public:
- void getPort_001()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP );
-
- CPPUNIT_ASSERT_MESSAGE( "test for getPort() function: get a normal port number.",
- IP_PORT_FTP == saSocketAddr.getPort( ) );
- }
-
- void getPort_002()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp2, IP_PORT_INVAL );
-
- //t_print("#getPort_002: Port number is %d \n", saSocketAddr.getPort( ));
-
- CPPUNIT_ASSERT_MESSAGE( "test for getPort( ) function: give an invalid port to a SocketAddr, get the port to see if it can detect. it did not pass in (W32).",
- saSocketAddr.getPort( )>=1 && saSocketAddr.getPort( ) <= 65535 );
- }
- //two cases will return OSL_INVALID_PORT: 1. not valid SocketAddr
- //2. SocketAddr family is not osl_Socket_FamilyInet, but case 2 could not be constructed
- void getPort_003()
- {
- ::osl::SocketAddr saSocketAddr( aHostIpInval1, IP_PORT_MYPORT );
-
- CPPUNIT_ASSERT_MESSAGE( "test for getPort( ) function: give an invalid IP to a SocketAddr, get the port to see returned value. ",
- saSocketAddr.getPort( ) == OSL_INVALID_PORT );
- }
-
- CPPUNIT_TEST_SUITE( getPort );
- CPPUNIT_TEST( getPort_001 );
- CPPUNIT_TEST( getPort_002 );
- CPPUNIT_TEST( getPort_003 );
- CPPUNIT_TEST_SUITE_END( );
-
- }; // class getPort
-
- /** testing the method:
- inline sal_Bool SAL_CALL setPort( sal_Int32 nPort );
- rfc1413.txt: TCP port numbers are from 1-65535
- rfc1700.txt: 0/tcp Reserved ; 0/udp Reserved
- */
-
- class setPort : public CppUnit::TestFixture
- {
- public:
- void setPort_001()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP );
- sal_Bool bOK = saSocketAddr.setPort( IP_PORT_TELNET );
-
- CPPUNIT_ASSERT_MESSAGE( "test for setPort() function: modify a port number setting, and check it.",
- ( sal_True == bOK ) &&
- ( IP_PORT_TELNET == saSocketAddr.getPort( ) ) );
- }
-
- /** 0 to 1024 is known as the reserved port range (traditionally only root can assign programs to ports in
- this range) and the ephemeral port range from 1025 to 65535.
- As many of you programmers will know, when you specify the source port of 0 when you connect to a host,
- the OS automatically reassigns the port number to high numbered ephemeral port. The same happens if you
- try to bind a listening socket to port 0.
- http://www.securiteam.com/securityreviews/5XP0Q2AAKS.html
- another: http://www.muq.org/~cynbe/muq/mufref_564.html
- */
- void setPort_002()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP );
- sal_Bool bOK = saSocketAddr.setPort( IP_PORT_ZERO );
-
- oslSocket sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp );
- ::osl::Socket sSocket(sHandle);
- sSocket.setOption( osl_Socket_OptionReuseAddr, 1 );//sal_True);
- sal_Bool bOK1 = sSocket.bind( saSocketAddr );
- CPPUNIT_ASSERT_MESSAGE( "bind SocketAddr failed", bOK1 == sal_True );
-
- sal_Int32 newPort = sSocket.getLocalPort();
- //t_print("#new port is %d\n", newPort );
-
- CPPUNIT_ASSERT_MESSAGE( "test for setPort() function: port number should be in 1 ~ 65535, set port 0, it should be converted to a port number between 1024~65535.",
- ( 1024 <= newPort ) && ( 65535 >= newPort ) && ( bOK == sal_True ) );
-
- }
-
- void setPort_003()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP);
- sal_Bool bOK = saSocketAddr.setPort( IP_PORT_INVAL );
- //on Linux, getPort return 34463
- //t_print("#Port number is %d \n", saSocketAddr.getPort( ));
-
- CPPUNIT_ASSERT_MESSAGE( "test for setPort( ) function: set an address with invalid port. it should return error or convert it to a valid port.",
- ( ( 1 <= saSocketAddr.getPort( ) ) && ( 65535 >= saSocketAddr.getPort( ) ) &&( bOK == sal_True ) ) ||
- bOK == sal_False);
- }
-
- /* this is not a inet-addr => can't set port */
- void setPort_004()
- {
- ::osl::SocketAddr saSocketAddr( aHostIpInval1, IP_PORT_FTP);
- sal_Bool bOK = saSocketAddr.setPort( IP_PORT_MYPORT );
-
- CPPUNIT_ASSERT_MESSAGE( "test for setPort( ) function: set an invalid address with valid port. it should return error.",
- bOK == sal_False);
- }
-
- CPPUNIT_TEST_SUITE( setPort );
- CPPUNIT_TEST( setPort_001 );
- CPPUNIT_TEST( setPort_002 );
- CPPUNIT_TEST( setPort_003 );
- CPPUNIT_TEST( setPort_004 );
- CPPUNIT_TEST_SUITE_END( );
-
- }; // class setPort
-
- /** tester comment:
-
- In the following two functions, it use ::rtl::ByteSequence as an intermediate storage for address,
- the ByteSequence object can hold sal_Int8 arrays, which is raged [-127, 127], in case of IP addr
- that is greater than 127, say 129.158.217.202, it will stored as -127, -98, -39, -54, it is unique
- in the range of sal_Int8, but lack of readability.
- so may be a sal_uInt8 array is better.
- */
-
- /** testing the method:
- inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address );
- */
-
- class setAddr : public CppUnit::TestFixture
- {
- public:
- void setAddr_001()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp2, IP_PORT_FTP );
- saSocketAddr.setAddr( UStringIPToByteSequence( aHostIp1 ) );
- ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 );
- sal_Bool bOK = sal_False;
-
- if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) && ( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) )
- bOK = sal_True;
-
- CPPUNIT_ASSERT_MESSAGE( "test for setAddr() function: construct Addr with \"129.158.217.202\", set it to \"127.0.0.1\", and check the correctness ",
- sal_True == bOK );
- }
-
- CPPUNIT_TEST_SUITE( setAddr );
- CPPUNIT_TEST( setAddr_001 );
- CPPUNIT_TEST_SUITE_END( );
-
- }; // class setAddr
-
- /** testing the method:
- inline ::rtl::ByteSequence SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const;
- */
-
- class getAddr : public CppUnit::TestFixture
- {
- public:
- void getAddr_001()
- {
- oslSocketResult SocketResult;
- ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP );
- ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( &SocketResult );
-
- sal_Bool bOK = sal_False;
-
- if ( ( osl_Socket_Ok == SocketResult ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) )
- bOK = sal_True;
-
- CPPUNIT_ASSERT_MESSAGE( "test for getAddr() function: construct a socketaddr with IP assigned, get the address to check correctness.Caught unknown exception on (Win32)",
- sal_True == bOK && SocketResult == osl_Socket_Ok);
- }
-
- CPPUNIT_TEST_SUITE( getAddr );
- CPPUNIT_TEST( getAddr_001 );
- CPPUNIT_TEST_SUITE_END( );
-
- }; // class getAddr
-
- /** testing the methods:
- inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
- inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
- inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
- inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const;
- inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; /// not implemented.
- */
-
- class operator_equal : public CppUnit::TestFixture
- {
- public:
- void operator_equal_001()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_TELNET);
- ::osl::SocketAddr saSocketAddrEqual( aHostIp2, IP_PORT_FTP );
-
- saSocketAddrEqual = saSocketAddr;
- sal_Bool bOK = sal_False;
- ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 );
-
- if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) )
- bOK = sal_True;
-
- CPPUNIT_ASSERT_MESSAGE( "test for operator_equal() function: use operator= to assign Ip1 to Ip2, check its modification.",
- sal_True == bOK );
- }
-
- void operator_equal_002()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp3, IP_PORT_TELNET);
- ::osl::SocketAddr saSocketAddrEqual( aHostIp2, IP_PORT_FTP );
-
- saSocketAddrEqual = saSocketAddr;
- CPPUNIT_ASSERT_MESSAGE( "after assign, the assigned SocketAddr is not same as the original Addr",
- IP_PORT_TELNET == saSocketAddrEqual.getPort( ) );
- saSocketAddrEqual.setPort( IP_PORT_MYPORT3 );
- saSocketAddr.setPort( IP_PORT_HTTP2 );
-
- CPPUNIT_ASSERT_MESSAGE( "test for operator_equal() function: perform an equal action, then try to change the original address's port. it should not be changed ( handle released), it did not pass in (W32), this is under discussion.",
- IP_PORT_MYPORT3 == saSocketAddrEqual.getPort( ) );
- }
-
- void operator_equal_const_001()
- {
- const ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_TELNET);
- ::osl::SocketAddr saSocketAddrEqual( aHostIp2, IP_PORT_FTP );
-
- saSocketAddrEqual = saSocketAddr;
- sal_Bool bOK = sal_False;
- ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 );
-
- if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) )
- bOK = sal_True;
-
- CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_const() function: use operator= const to assign Ip1 to Ip2, verify the change on the second one.",
- sal_True == bOK );
- }
-
- void operator_equal_const_002()
- {
- const ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_TELNET);
- ::osl::SocketAddr saSocketAddrEqual( aHostIp2, IP_PORT_FTP );
-
- saSocketAddrEqual = saSocketAddr;
- saSocketAddrEqual.setPort( IP_PORT_HTTP1 );
-
- CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_const() function: change the second instance, the first one should not be altered, since it does not released the handle.",
- IP_PORT_HTTP1 != saSocketAddr.getPort( ) );
- }
-
- void operator_equal_assign_001()
- {
- ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( aHostIp1, IP_PORT_TELNET );
- CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL);
- ::osl::SocketAddr* pSocketAddrAssign = new ::osl::SocketAddr( aHostIp2, IP_PORT_FTP );
- oslSocketAddr poslSocketAddr = pSocketAddr->getHandle( );
- //if( m_handle ) osl_destroySocketAddr( m_handle ); so pSocketAddrAssign had been destroyed and then point to pSocketAddr
- pSocketAddrAssign->assign(poslSocketAddr, SAL_NO_COPY);
-
- CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.",
- pSocketAddrAssign->getPort( ) == IP_PORT_TELNET );
-
- delete pSocketAddrAssign;
- }
-
- void operator_is_equal_001()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_TELNET);
- ::osl::SocketAddr saSocketAddrequal( aHostIp1, IP_PORT_TELNET );
-
- CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_equal() function: check two identical Address.",
- sal_True == ( saSocketAddrequal == saSocketAddr.getHandle( ) ) );
- }
-
- void operator_is_equal_002()
- {
- ::osl::SocketAddr saSocketAddr( aHostIp2, IP_PORT_FTP);
- ::osl::SocketAddr saSocketAddrequal( aHostIp1, IP_PORT_TELNET );
-
- CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_equal() function: check two different Address.",
- sal_False == ( saSocketAddrequal == saSocketAddr.getHandle( ) ) );
- }
-
- CPPUNIT_TEST_SUITE( operator_equal );
- CPPUNIT_TEST( operator_equal_001 );
- CPPUNIT_TEST( operator_equal_002 );
- CPPUNIT_TEST( operator_equal_const_001 );
- CPPUNIT_TEST( operator_equal_const_002 );
- CPPUNIT_TEST( operator_equal_assign_001 );
- CPPUNIT_TEST( operator_is_equal_001 );
- CPPUNIT_TEST( operator_is_equal_002 );
- CPPUNIT_TEST_SUITE_END( );
-
- }; // class operator_equal
-
- /** testing the method:
- inline oslSocketAddr SAL_CALL getHandle() const;
- */
-
- class getSocketAddrHandle : public CppUnit::TestFixture
- {
- public:
-
- void getSocketAddrHandle_001()
- {
- ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( aHostName1, IP_PORT_HTTP1 );
- CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL);
- oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( );
- ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY );
-
- CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.",
- pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( ) );
-
- delete pSocketAddrCopy;
- }
-
- void getSocketAddrHandle_002()
- {
- ::osl::SocketAddr saSocketAddr( aHostName3, IP_PORT_MYPORT4 );
- oslSocketAddr poslSocketAddr = saSocketAddr.getHandle( );
-
- sal_Bool bOK = ( saSocketAddr == poslSocketAddr );
- //t_print("getSocketAddrHandle_002\n");
- CPPUNIT_ASSERT_MESSAGE( "test for getHandle() function: use getHandle() function as an intermediate way to create identical address.",
- sal_True == bOK );
- }
-
- CPPUNIT_TEST_SUITE( getSocketAddrHandle );
- CPPUNIT_TEST( getSocketAddrHandle_001 );
- CPPUNIT_TEST( getSocketAddrHandle_002 );
- CPPUNIT_TEST_SUITE_END( );
-
- }; // class getSocketAddrHandle
-
- /** testing the method:
- static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0);
- */
-
- class getLocalHostname : public CppUnit::TestFixture
- {
- public:
- /* the process of getLocalHostname: 1.gethostname (same as /bin/hostname) returned name A
- 2. search A in /etc/hosts, if there is an alias name is A, return the name in the same row
- */
-
- void getLocalHostname_000()
- {
- // _osl_getFullQualifiedDomainName( );
- oslSocketResult aResult = osl_Socket_Error;
- rtl::OUString suHostname = osl::SocketAddr::getLocalHostname(&aResult);
- CPPUNIT_ASSERT_MESSAGE("getLocalHostname failed", aResult == osl_Socket_Ok);
- }
-
- void getLocalHostname_001()
- {
- oslSocketResult *pResult = NULL;
- //printSocketResult(*pResult);
- ::rtl::OUString suResult = ::osl::SocketAddr::getLocalHostname( pResult );
-
- // LLA: IMHO localhost, or hostname by itself should be ok.
- rtl::OUString suThisHost = getThisHostname( );
- bool bOk = false;
- if ( suThisHost == "localhost" )
- {
- bOk = true;
- }
- else
- {
- if (suThisHost.equals(suResult))
- {
- bOk = true;
- }
- }
-
- ::rtl::OUString suError;
- suError = outputError(suResult, getThisHostname( ), "test for getLocalHostname() function");
-
- CPPUNIT_ASSERT_MESSAGE( STD_STRING(suError), bOk == true );
- }
-
- CPPUNIT_TEST_SUITE( getLocalHostname );
- CPPUNIT_TEST( getLocalHostname_000 );
- CPPUNIT_TEST( getLocalHostname_001 );
- CPPUNIT_TEST_SUITE_END( );
-
- }; // class getLocalHostname
-
- /** testing the method:
- static inline void SAL_CALL resolveHostname( const ::rtl::OUString & strHostName , SocketAddr & Addr );
- */
-
- class resolveHostname : public CppUnit::TestFixture
- {
- public:
- void resolveHostname_001()
- {
- ::osl::SocketAddr saSocketAddr;
- ::osl::SocketAddr::resolveHostname( aHostIp1, saSocketAddr );
- ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 );
- sal_Bool bOK = sal_False;
-
- if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) )
- bOK = sal_True;
-
- CPPUNIT_ASSERT_MESSAGE( "test for resolveHostname() function: try to resolve localhost to 127.0.0.1.",
- sal_True == bOK );
- }
-
- CPPUNIT_TEST_SUITE( resolveHostname );
- CPPUNIT_TEST( resolveHostname_001 );
- CPPUNIT_TEST_SUITE_END( );
-
- }; // class resolveHostname
-
- /** testing the method:
- static inline sal_Int32 SAL_CALL getServicePort(
- const ::rtl::OUString& strServiceName,
- const ::rtl::OUString & strProtocolName= ::rtl::OUString("tcp") );
- */
-
- class gettheServicePort : public CppUnit::TestFixture
- {
- public:
- void gettheServicePort_001()
- {
- CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get ftp service port on TCP protocol.",
- IP_PORT_FTP== ::osl::SocketAddr::getServicePort( aServiceFTP, aProtocolTCP ) );
- }
-
- void gettheServicePort_002()
- {
- CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get telnet service port on TCP protocol.",
- IP_PORT_TELNET== ::osl::SocketAddr::getServicePort( aServiceTELNET, aProtocolTCP ) );
- }
-
- void gettheServicePort_003()
- {
- //Solaris has no service called "https", please see /etc/services
- CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get netbios-ssn service port on UDP protocol.",
- IP_PORT_NETBIOS_DGM == ::osl::SocketAddr::getServicePort( aServiceNETBIOS, aProtocolUDP ) );
- }
-
- void gettheServicePort_004()
- {
- CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get a service port which is not exist.",
- OSL_INVALID_PORT == ::osl::SocketAddr::getServicePort( ::rtl::OUString("notexist"), aProtocolUDP ) );
- }
-
- CPPUNIT_TEST_SUITE( gettheServicePort );
- CPPUNIT_TEST( gettheServicePort_001 );
- CPPUNIT_TEST( gettheServicePort_002 );
- CPPUNIT_TEST( gettheServicePort_003 );
- CPPUNIT_TEST( gettheServicePort_004 );
- CPPUNIT_TEST_SUITE_END( );
-
- }; // class gettheServicePort
-
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::ctors, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::is, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getHostname, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getPort, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::setPort, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::setAddr, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getAddr, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::operator_equal, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getSocketAddrHandle, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getLocalHostname, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::resolveHostname, "osl_SocketAddr");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::gettheServicePort, "osl_SocketAddr");
-
-} // namespace osl_SocketAddr
-
-namespace osl_Socket
-{
-
- /** testing the methods:
- inline Socket( );
- inline Socket( const Socket & socket );
- inline Socket( oslSocket socketHandle );
- inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
- */
-
- /** test writer's comment:
-
- class Socket can not be initialized by its protected constructor, though the protected
- constructor is the most convenient way to create a new socket.
- it only allow the method of C function osl_createSocket like:
- ::osl::Socket sSocket( osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream,
- osl_Socket_ProtocolIp ) );
- the use of C method lost some of the transparent of tester using C++ wrapper.
- */
-
- class ctors : public CppUnit::TestFixture
- {
- public:
- oslSocket sHandle;
- // initialization
- void setUp( )
- {
- sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp );
- }
-
- void tearDown( )
- {
- sHandle = NULL;
- }
-
- void ctors_none()
- {
- /// Socket constructor.
- // ::osl::Socket sSocket;
-
- CPPUNIT_ASSERT_MESSAGE( "test for ctors_none constructor function: check if the socket was created successfully, if no exception occurred",
- 1 == 1 );
- }
-
- void ctors_acquire()
- {
- /// Socket constructor.
- ::osl::Socket sSocket( sHandle );
-
- CPPUNIT_ASSERT_MESSAGE( "test for ctors_acquire constructor function: check if the socket was created successfully",
- osl_Socket_TypeStream == sSocket.getType( ) );
- }
-
- void ctors_no_acquire()
- {
- /// Socket constructor.
- ::osl::Socket sSocket( sHandle, SAL_NO_ACQUIRE );
-
- CPPUNIT_ASSERT_MESSAGE(" test for ctors_no_acquire constructor function: check if the socket was created successfully",
- osl_Socket_TypeStream == sSocket.getType( ) );
- }
-
- void ctors_copy_ctor()
- {
- ::osl::Socket sSocket( sHandle );
- /// Socket copy constructor.
- ::osl::Socket copySocket( sSocket );
-
- CPPUNIT_ASSERT_MESSAGE(" test for ctors_copy_ctor constructor function: create new Socket instance using copy constructor",
- osl_Socket_TypeStream == copySocket.getType( ) );
- }
-
- void ctors_TypeRaw()
- {
-#ifdef WNT
- oslSocket sHandleRaw = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeRaw, osl_Socket_ProtocolIp );
-// LLA: ? ::osl::Socket sSocket( sHandleRaw );
- CPPUNIT_ASSERT_MESSAGE( " type osl_Socket_TypeRaw socket create failed on UNX ", sHandleRaw != NULL);
-#else
- oslSocket sHandleRaw = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeRaw, osl_Socket_ProtocolIp );
- CPPUNIT_ASSERT_MESSAGE( " can't create socket with type osl_Socket_TypeRaw within UNX is ok.", sHandleRaw == NULL);
-#endif
- }
-
- void ctors_family_Ipx()
- {
- oslSocket sHandleIpx = osl_createSocket( osl_Socket_FamilyIpx, osl_Socket_TypeStream, osl_Socket_ProtocolIp );
- CPPUNIT_ASSERT_MESSAGE( " family osl_Socket_FamilyIpx socket create failed! ", sHandleIpx != NULL);
- ::osl::Socket sSocket( sHandleIpx ); //, SAL_NO_ACQUIRE );
- t_print("#Type is %d \n", sSocket.getType( ) );
-
- CPPUNIT_ASSERT_MESSAGE(" test for create new Socket instance that family is osl_Socket_FamilyIpx",
- osl_Socket_TypeStream == sSocket.getType( ) );
- }
-
- CPPUNIT_TEST_SUITE( ctors );
- CPPUNIT_TEST( ctors_none );
- CPPUNIT_TEST( ctors_acquire );
- CPPUNIT_TEST( ctors_no_acquire );
- CPPUNIT_TEST( ctors_copy_ctor );
- CPPUNIT_TEST( ctors_TypeRaw );
- CPPUNIT_TEST( ctors_family_Ipx );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class ctors
-
- /** testing the methods:
- inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
- inline Socket& SAL_CALL operator= (const Socket& sock);
- inline sal_Bool SAL_CALL operator==( const Socket& rSocket ) const ;
- inline sal_Bool SAL_CALL operator==( const oslSocket socketHandle ) const;
- */
-
- class operators : public CppUnit::TestFixture
- {
- public:
- oslSocket sHandle;
- // initialization
- void setUp( )
- {
- sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp );
- }
-
- void tearDown( )
- {
- sHandle = NULL;
- }
-
- /** test writer's comment:
-
- the assignment operator does not support direct assinment like:
- ::osl::Socket sSocket = sHandle.
- */
- void operators_assignment_handle()
- {
- ::osl::Socket sSocket(sHandle);
- ::osl::Socket assignSocket = sSocket.getHandle();
-
- CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment_handle function: test the assignment operator.",
- osl_Socket_TypeStream == assignSocket.getType( ) );
- }
-
- void operators_assignment()
- {
- ::osl::Socket sSocket( sHandle );
- ::osl::Socket assignSocket = sSocket;
-
- CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment function: assignment operator",
- osl_Socket_TypeStream == assignSocket.getType( ) );
- }
-
- void operators_equal_handle_001()
- {
- /// Socket constructor.
- ::osl::Socket sSocket( sHandle );
- ::osl::Socket equalSocket = sSocket;
-
- CPPUNIT_ASSERT_MESSAGE(" test for operators_equal_handle_001 function: check equal.",
- equalSocket == sHandle );
- }
-
- void operators_equal_handle_002()
- {
- /// Socket constructor.
- ::osl::Socket equalSocket( osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ) );
-
- CPPUNIT_ASSERT_MESSAGE(" test for operators_equal_handle_001 function: check unequal.",
- !( equalSocket == sHandle ) );
- }
-
- void operators_equal_001()
- {
- ::osl::Socket sSocket( sHandle );
- /// Socket copy constructor.
- ::osl::Socket equalSocket( sSocket );
-
- CPPUNIT_ASSERT_MESSAGE(" test for operators_equal function: check equal.",
- equalSocket == sSocket );
- }
-
- void operators_equal_002()
- {
- ::osl::Socket sSocket( sHandle );
- /// Socket copy constructor.
- ::osl::Socket equalSocket( osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ) );
-
- CPPUNIT_ASSERT_MESSAGE(" test for operators_equal_002 function: check unequal.",
- !( equalSocket == sSocket ) );
- }
-
- CPPUNIT_TEST_SUITE( operators );
- CPPUNIT_TEST( operators_assignment_handle );
- CPPUNIT_TEST( operators_assignment );
- CPPUNIT_TEST( operators_equal_handle_001 );
- CPPUNIT_TEST( operators_equal_handle_002 );
- CPPUNIT_TEST( operators_equal_001 );
- CPPUNIT_TEST( operators_equal_002 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class operators
-
- /** testing the methods:
- inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
- inline void SAL_CALL close();
- */
-
- class close : public CppUnit::TestFixture
- {
- public:
- oslSocket sHandle;
- // initialization
- void setUp( )
- {
- sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp );
- }
-
- void tearDown( )
- {
- sHandle = NULL;
- }
-
- void close_001()
- {
- ::osl::Socket sSocket(sHandle);
- sSocket.close();
-
- CPPUNIT_ASSERT_MESSAGE( "test for close_001 function: this function is reserved for test.",
- sSocket.getHandle() == sHandle );
- }
-
- void close_002()
- {
-//#if defined(LINUX)
- ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream );
- AcceptorThread myAcceptorThread( asSocket, aHostIp1 );
- myAcceptorThread.create();
-
- thread_sleep( 1 );
- //when accepting, close the socket, the thread will not block for accepting
- //man close:Any locks held on the file it was associated with, and owned by the process, are removed
- asSocket.close();
- //thread_sleep( 2 );
- myAcceptorThread.join();
-
- CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.",
- myAcceptorThread.isOK() == sal_True );
-//#endif
- }
-
- // to cover "if ( pSockAddrIn->sin_addr.s_addr == htonl(INADDR_ANY) )" in osl_closeSocket( )
- void close_003()
- {
- ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream );
- AcceptorThread myAcceptorThread( asSocket, aHostIpZero );
- myAcceptorThread.create();
-
- thread_sleep( 1 );
- asSocket.close();
- myAcceptorThread.join();
-
- CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.",
- myAcceptorThread.isOK() == sal_True );
- }
-
- CPPUNIT_TEST_SUITE( close );
- CPPUNIT_TEST( close_001 );
- CPPUNIT_TEST( close_002 );
- CPPUNIT_TEST( close_003 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class close
-
- /** testing the method:
- inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
- */
-
- class getLocalAddr : public CppUnit::TestFixture
- {
- public:
- oslSocket sHandle;
- // initialization
- void setUp( )
- {
- sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp );
- }
-
- void tearDown( )
- {
- sHandle = NULL;
- }
-
- // get the Address of the local end of the socket
- void getLocalAddr_001()
- {
- ::osl::Socket sSocket(sHandle);
- ::osl::SocketAddr saBindSocketAddr( aHostIp1, IP_PORT_MYPORT8 );
- ::osl::SocketAddr saLocalSocketAddr;
-
- sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True);
-
- sal_Bool bOK1 = sSocket.bind( saBindSocketAddr );
- ::rtl::OUString suError1 = ::rtl::OUString("Socket bind fail:") + sSocket.getErrorAsString();
- CPPUNIT_ASSERT_MESSAGE( STD_STRING(suError1), sal_True == bOK1 );
-
- sSocket.getLocalAddr( saLocalSocketAddr );
-
- sal_Bool bOK = compareUString( saLocalSocketAddr.getHostname( 0 ), sSocket.getLocalHost() ) ;
-
- CPPUNIT_ASSERT_MESSAGE( "test for getLocalAddr function: first create a new socket, then a socket address, bind them, and check the address.",
- sal_True == bOK );
- }
-
- CPPUNIT_TEST_SUITE( getLocalAddr );
- CPPUNIT_TEST( getLocalAddr_001 );
- CPPUNIT_TEST_SUITE_END();
-
- }; // class getLocalAddr
-
- /** testing the method:
- inline sal_Int32 SAL_CALL getLocalPort() const;
- */
-
- class getLocalPort : public CppUnit::TestFixture
- {
- public:
- oslSocket sHandle;
- // initialization
- void setUp( )
- {
- sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp );
- }
-
- void tearDown( )
- {
- sHandle = NULL;
- }
-
- void getLocalPort_001()
- {
- ::osl::Socket sSocket(sHandle);
- ::osl::SocketAddr saBindSocketAddr( aHostIp1, IP_PORT_MYPORT7 ); // aHostIp1 localhost
- ::osl::SocketAddr saLocalSocketAddr;
-
- sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True);
-
- sal_Bool bOK1 = sSocket.bind( saBindSocketAddr );
- ::rtl::OUString suError1 = ::rtl::OUString("Socket bind fail:") + sSocket.getErrorAsString();
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list