openoffice-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1701357 [1/5] - /openoffice/trunk/main/sal/qa/osl/socket/
Date Sat, 05 Sep 2015 07:59:22 GMT
Author: damjan
Date: Sat Sep  5 07:59:22 2015
New Revision: 1701357

URL: http://svn.apache.org/r1701357
Log:
#i125003# migrate main/sal/qa/osl/socket from cppunit to Google Test,
get tests to compile and not to SIGSEGV or die from EPIPE,
and get as many tests to pass as possible.


Modified:
    openoffice/trunk/main/sal/qa/osl/socket/makefile.mk
    openoffice/trunk/main/sal/qa/osl/socket/osl_AcceptorSocket.cxx
    openoffice/trunk/main/sal/qa/osl/socket/osl_ConnectorSocket.cxx
    openoffice/trunk/main/sal/qa/osl/socket/osl_DatagramSocket.cxx
    openoffice/trunk/main/sal/qa/osl/socket/osl_Socket.cxx
    openoffice/trunk/main/sal/qa/osl/socket/osl_Socket2.cxx
    openoffice/trunk/main/sal/qa/osl/socket/osl_SocketAddr.cxx
    openoffice/trunk/main/sal/qa/osl/socket/osl_Socket_Const.h
    openoffice/trunk/main/sal/qa/osl/socket/osl_Socket_Const_orig.h
    openoffice/trunk/main/sal/qa/osl/socket/osl_Socket_tests.cxx
    openoffice/trunk/main/sal/qa/osl/socket/osl_StreamSocket.cxx
    openoffice/trunk/main/sal/qa/osl/socket/sockethelper.cxx
    openoffice/trunk/main/sal/qa/osl/socket/sockethelper.hxx

Modified: openoffice/trunk/main/sal/qa/osl/socket/makefile.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/osl/socket/makefile.mk?rev=1701357&r1=1701356&r2=1701357&view=diff
==============================================================================
--- openoffice/trunk/main/sal/qa/osl/socket/makefile.mk (original)
+++ openoffice/trunk/main/sal/qa/osl/socket/makefile.mk Sat Sep  5 07:59:22 2015
@@ -32,180 +32,174 @@ ENABLE_EXCEPTIONS=TRUE
 
 .INCLUDE :  settings.mk
 
+.IF "$(ENABLE_UNIT_TESTS)" != "YES"
+all:
+	@echo unit tests are disabled. Nothing to do.
+
+.ELSE
+
 CFLAGS+= $(LFS_CFLAGS)
 CXXFLAGS+= $(LFS_CFLAGS)
 
 # BEGIN ----------------------------------------------------------------
 # auto generated Target:Socket by codegen.pl
-SHL1OBJS=  \
+APP1OBJS=  \
 	$(SLO)$/osl_Socket.obj
 
-SHL1TARGET=osl_SocketOld
-SHL1STDLIBS= $(SALLIB) $CPPUNITLIB) $(TESTSHL2LIB)
+APP1TARGET=osl_SocketOld
+APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
 
 .IF "$(GUI)" == "WNT"
-SHL1STDLIBS+= $(WS2_32LIB)
+APP1STDLIBS+= $(WS2_32LIB)
 .ENDIF
 
-.IF "$(GUI)" == "UNX"
-SHL1STDLIBS+= -ldl -lnsl
+.IF ""$(OS)"=="SOLARIS"
+APP1STDLIBS+= -ldl -lnsl
 .ENDIF
 
-SHL1IMPLIB= i$(SHL1TARGET)
-# SHL1DEF=    $(MISC)$/$(SHL1TARGET).def
-DEF1NAME=$(SHL1TARGET)
-# DEF1EXPORTFILE= export.exp
-SHL1VERSIONMAP = $(PRJ)$/qa$/export.map
+APP1RPATH = NONE
+APP1TEST = enabled
 # auto generated Target:Socket
 # END ------------------------------------------------------------------
 
 # --- BEGIN --------------------------------------------------------
-SHL2OBJS=  \
+APP2OBJS=  \
 	$(SLO)$/osl_Socket_tests.obj
-SHL2TARGET= osl_Socket_tests
-SHL2STDLIBS= $(SALLIB) $CPPUNITLIB) $(TESTSHL2LIB)
-
-SHL2IMPLIB= i$(SHL2TARGET)
-DEF2NAME=    $(SHL2TARGET)
-SHL2VERSIONMAP = $(PRJ)$/qa$/export.map
-
+APP2TARGET= osl_Socket_tests
+APP2STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
+APP2RPATH = NONE
+APP2TEST = enabled
 # END --------------------------------------------------------------
 
 # BEGIN ----------------------------------------------------------------
 # auto generated Target:Socket by codegen.pl
-SHL3OBJS=  \
+APP3OBJS=  \
 	$(SLO)$/sockethelper.obj \
 	$(SLO)$/osl_StreamSocket.obj
 
-SHL3TARGET= osl_StreamSocket
-SHL3STDLIBS= $(SALLIB) $CPPUNITLIB) $(TESTSHL2LIB)
+APP3TARGET= osl_StreamSocket
+APP3STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
 
 .IF "$(GUI)" == "WNT"
-SHL3STDLIBS += $(WS2_32LIB)
+APP3STDLIBS += $(WS2_32LIB)
 .ENDIF
 
-.IF "$(GUI)" == "UNX"
-SHL3STDLIBS += -ldl -lnsl
+.IF "$(OS)"=="SOLARIS"
+APP3STDLIBS += -ldl -lnsl
 .ENDIF
 
-SHL3IMPLIB= i$(SHL3TARGET)
-DEF3NAME=    $(SHL3TARGET)
-SHL3VERSIONMAP = $(PRJ)$/qa$/export.map
+APP3RPATH = NONE
+APP3TEST = enabled
 # auto generated Target:Socket
 # END ------------------------------------------------------------------
 
 # BEGIN ----------------------------------------------------------------
 # auto generated Target:Socket by codegen.pl
-SHL4OBJS=  \
+APP4OBJS=  \
 	$(SLO)$/sockethelper.obj \
 	$(SLO)$/osl_DatagramSocket.obj
 
-SHL4TARGET= osl_DatagramSocket
-SHL4STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB)
+APP4TARGET= osl_DatagramSocket
+APP4STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
 
 .IF "$(GUI)" == "WNT"
-SHL4STDLIBS += $(WS2_32LIB)
+APP4STDLIBS += $(WS2_32LIB)
 .ENDIF
 
-.IF "$(GUI)" == "UNX"
-SHL4STDLIBS += -ldl -lnsl
+.IF "$(OS)"=="SOLARIS"
+APP4STDLIBS += -ldl -lnsl
 .ENDIF
 
-SHL4IMPLIB= i$(SHL4TARGET)
-DEF4NAME=    $(SHL4TARGET)
-SHL4VERSIONMAP = $(PRJ)$/qa$/export.map
+APP4RPATH = NONE
+APP4TEST = enabled
 # auto generated Target:Socket
 # END ------------------------------------------------------------------
 
 # BEGIN ----------------------------------------------------------------
 # auto generated Target:Socket by codegen.pl
-SHL5OBJS=  \
+APP5OBJS=  \
 	$(SLO)$/sockethelper.obj \
 	$(SLO)$/osl_SocketAddr.obj
 
-SHL5TARGET= osl_SocketAddr
-SHL5STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB)
+APP5TARGET= osl_SocketAddr
+APP5STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
 
 .IF "$(GUI)" == "WNT"
-SHL5STDLIBS += $(WS2_32LIB)
+APP5STDLIBS += $(WS2_32LIB)
 .ENDIF
 
-.IF "$(GUI)" == "UNX"
-SHL5STDLIBS += -ldl -lnsl
+.IF "$(OS)"=="SOLARIS"
+APP5STDLIBS += -ldl -lnsl
 .ENDIF
 
-SHL5IMPLIB= i$(SHL5TARGET)
-DEF5NAME=    $(SHL5TARGET)
-SHL5VERSIONMAP = $(PRJ)$/qa$/export.map
+APP5RPATH = NONE
+APP5TEST = enabled
 # auto generated Target:Socket
 # END ------------------------------------------------------------------
 
 # BEGIN ----------------------------------------------------------------
 # auto generated Target:Socket by codegen.pl
-SHL6OBJS=  \
+APP6OBJS=  \
 	$(SLO)$/sockethelper.obj \
 	$(SLO)$/osl_Socket2.obj
 
-SHL6TARGET= osl_Socket2
-SHL6STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB)
+APP6TARGET= osl_Socket2
+APP6STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
 
 .IF "$(GUI)" == "WNT"
-SHL6STDLIBS += $(WS2_32LIB)
+APP6STDLIBS += $(WS2_32LIB)
 .ENDIF
 
-.IF "$(GUI)" == "UNX"
-SHL6STDLIBS += -ldl -lnsl
+.IF "$(OS)"=="SOLARIS"
+APP6STDLIBS += -ldl -lnsl
 .ENDIF
 
-SHL6IMPLIB= i$(SHL6TARGET)
-DEF6NAME=    $(SHL6TARGET)
-SHL6VERSIONMAP = $(PRJ)$/qa$/export.map
+APP6RPATH = NONE
+APP6TEST = enabled
 # auto generated Target:Socket
 # END ------------------------------------------------------------------
 
 # BEGIN ----------------------------------------------------------------
 # auto generated Target:Socket by codegen.pl
-SHL7OBJS=  \
+APP7OBJS=  \
 	$(SLO)$/sockethelper.obj \
 	$(SLO)$/osl_ConnectorSocket.obj
 
-SHL7TARGET= osl_ConnectorSocket
-SHL7STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB)
+APP7TARGET= osl_ConnectorSocket
+APP7STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
 
 .IF "$(GUI)" == "WNT"
-SHL7STDLIBS += $(WS2_32LIB)
+APP7STDLIBS += $(WS2_32LIB)
 .ENDIF
 
-.IF "$(GUI)" == "UNX"
-SHL7STDLIBS += -ldl -lnsl
+.IF "$(OS)"=="SOLARIS"
+APP7STDLIBS += -ldl -lnsl
 .ENDIF
 
-SHL7IMPLIB= i$(SHL7TARGET)
-DEF7NAME=    $(SHL7TARGET)
-SHL7VERSIONMAP = $(PRJ)$/qa$/export.map
+APP7RPATH = NONE
+APP7TEST = enabled
 # auto generated Target:Socket
 # END ------------------------------------------------------------------
 
 # BEGIN ----------------------------------------------------------------
 # auto generated Target:Socket by codegen.pl
-SHL8OBJS=  \
+APP8OBJS=  \
 	$(SLO)$/sockethelper.obj \
 	$(SLO)$/osl_AcceptorSocket.obj
 
-SHL8TARGET= osl_AcceptorSocket
-SHL8STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB)
+APP8TARGET= osl_AcceptorSocket
+APP8STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
 
 .IF "$(GUI)" == "WNT"
-SHL8STDLIBS += $(WS2_32LIB)
+APP8STDLIBS += $(WS2_32LIB)
 .ENDIF
 
-.IF "$(GUI)" == "UNX"
-SHL8STDLIBS += -ldl -lnsl
+.IF "$(OS)"=="SOLARIS"
+APP8STDLIBS += -ldl -lnsl
 .ENDIF
 
-SHL8IMPLIB= i$(SHL8TARGET)
-DEF8NAME=    $(SHL8TARGET)
-SHL8VERSIONMAP = $(PRJ)$/qa$/export.map
+APP8PATH = NONE
+APP8TEST = enabled
 # auto generated Target:Socket
 # END ------------------------------------------------------------------
 
@@ -216,4 +210,5 @@ SHL8VERSIONMAP = $(PRJ)$/qa$/export.map
 # --- Targets ------------------------------------------------------
 
 .INCLUDE :  target.mk
-.INCLUDE : _cppunit.mk
+
+.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES"
\ No newline at end of file

Modified: openoffice/trunk/main/sal/qa/osl/socket/osl_AcceptorSocket.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/osl/socket/osl_AcceptorSocket.cxx?rev=1701357&r1=1701356&r2=1701357&view=diff
==============================================================================
--- openoffice/trunk/main/sal/qa/osl/socket/osl_AcceptorSocket.cxx (original)
+++ openoffice/trunk/main/sal/qa/osl/socket/osl_AcceptorSocket.cxx Sat Sep  5 07:59:22 2015
@@ -54,7 +54,7 @@
 // include files
 //------------------------------------------------------------------------
 
-#include <testshl/simpleheader.hxx>
+#include "gtest/gtest.h"
 
 #include "osl_Socket_Const.h"
 #include "sockethelper.hxx"
@@ -87,13 +87,13 @@ protected:
 		sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
 		if  ( sal_True != bOK1 )
 		{
-			t_print("# AcceptorSocket bind address failed.\n" ) ;
+			printf("# AcceptorSocket bind address failed.\n" ) ;
 			return;
 		}
 		sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
 		if  ( sal_True != bOK2 )
 		{
-			t_print("# AcceptorSocket listen address failed.\n" ) ;
+			printf("# AcceptorSocket listen address failed.\n" ) ;
 			return;
 		}
 
@@ -103,7 +103,7 @@ protected:
 		if (eResult != osl_Socket_Ok )
 		{
 			bOK = sal_True;
-			t_print("AcceptorThread: acceptConnection failed! \n");
+			printf("AcceptorThread: acceptConnection failed! \n");
 		}
 	}
 public:
@@ -120,7 +120,7 @@ public:
 		if ( isRunning( ) )
 		{
 			asAcceptorSocket.shutdown();
-			t_print("# error: Acceptor thread not terminated.\n" );
+			printf("# error: Acceptor thread not terminated.\n" );
 		}
 	}
 };
@@ -134,64 +134,51 @@ namespace osl_AcceptorSocket
 							  oslSocketType	Type = osl_Socket_TypeStream);
 	*/
 
-	class ctors : public CppUnit::TestFixture
+	class ctors : public ::testing::Test
 	{
 	public:
+	}; // class ctors
 
-		void ctors_001()
-		{
-			/// Socket constructor.
-			::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream
);
+    TEST_F(ctors, 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
+        ASSERT_TRUE(osl_Socket_TypeStream ==  asSocket.getType( )) << "test for ctors_001
constructor function: check if the acceptor socket was created successfully.";
+    }
 
 #if 0  /* OBSOLETE */
-	class operator_assign : public CppUnit::TestFixture
+	class operator_assign : public ::testing::Test
 	{
 	public:
+	}; // class operator_assign
 
-		void assign_001()
-		{
+    TEST_F(assign, assign_001)
+    {
 #if defined(LINUX)
-			::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream
);
-			::osl::AcceptorSocket asSocketAssign( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream
);
-			asSocket.setOption( osl_Socket_OptionReuseAddr, 1);
-			::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT4
);
-			asSocket.bind( saSocketAddr );
-
-			AcceptorThread myAcceptorThread( asSocketAssign, rtl::OUString::createFromAscii("127.0.0.1")
);
-			myAcceptorThread.create();
-
-			thread_sleep( 1 );
-			//when accepting, assign another socket to the socket, the thread will not be closed,
so is blocking
-			asSocketAssign = asSocket;
-
-			t_print("#asSocketAssign port number is %d\n", asSocketAssign.getLocalPort() );
+        ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream
);
+        ::osl::AcceptorSocket asSocketAssign( osl_Socket_FamilyInet, osl_Socket_ProtocolIp,
osl_Socket_TypeStream );
+        asSocket.setOption( osl_Socket_OptionReuseAddr, 1);
+        ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT4
);
+        asSocket.bind( saSocketAddr );
 
-			asSocketAssign.shutdown();
-			myAcceptorThread.join();
+        AcceptorThread myAcceptorThread( asSocketAssign, rtl::OUString::createFromAscii("127.0.0.1")
);
+        myAcceptorThread.create();
 
-			CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting
status.",
-								myAcceptorThread.isOK()	== sal_True );
+        thread_sleep( 1 );
+        //when accepting, assign another socket to the socket, the thread will not be closed,
so is blocking
+        asSocketAssign = asSocket;
 
+        printf("#asSocketAssign port number is %d\n", asSocketAssign.getLocalPort() );
 
-#endif /* LINUX */
-		}
+        asSocketAssign.shutdown();
+        myAcceptorThread.join();
 
+        ASSERT_TRUE(myAcceptorThread.isOK() == sal_True) << "test for close when is
accepting: the socket will quit accepting status.";
 
-		CPPUNIT_TEST_SUITE( operator_assign  );
-		CPPUNIT_TEST( assign_001 );
-		CPPUNIT_TEST_SUITE_END();
 
-	}; // class operator_assign
+#endif /* LINUX */
+    }
 #endif /* OBSOLETE */
 
 	/** testing the method:
@@ -200,7 +187,7 @@ namespace osl_AcceptorSocket
 		inline oslSocketResult SAL_CALL acceptConnection( StreamSocket&	Connection, SocketAddr
& PeerAddr);
 	*/
 
-	class listen_accept : public CppUnit::TestFixture
+	class listen_accept : public ::testing::Test
 	{
 	public:
 		TimeValue *pTimeout;
@@ -209,7 +196,7 @@ namespace osl_AcceptorSocket
 
 
 		// initialization
-		void setUp( )
+		void SetUp( )
 		{
 			pTimeout  = ( TimeValue* )malloc( sizeof( TimeValue ) );
 			pTimeout->Seconds = 3;
@@ -218,81 +205,67 @@ namespace osl_AcceptorSocket
 		//	sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp
);
 		}
 
-		void tearDown( )
+		void TearDown( )
 		{
 			free( pTimeout );
 		//	sHandle = NULL;
 			asAcceptorSocket.close( );
 			csConnectorSocket.close( );
 		}
-
-
-		void listen_accept_001()
-		{
-			::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT3
);
-			::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("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::createFromAscii("127.0.0.1"), IP_PORT_MYPORT4
);
-			::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT4
);
-			::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("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_NAMED_REGISTRATION(osl_AcceptorSocket::ctors, "osl_AcceptorSocket");
-//CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_AcceptorSocket::operator_assign, "osl_AcceptorSocket");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_AcceptorSocket::listen_accept, "osl_AcceptorSocket");
+    TEST_F(listen_accept, listen_accept_001)
+    {
+        ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"),
IP_PORT_MYPORT3 );
+        ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"),
IP_PORT_MYPORT3 );
+        ::osl::StreamSocket ssConnection;
+
+        /// launch server socket
+        sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
+        ASSERT_TRUE(sal_True == bOK1) << "AcceptorSocket bind address failed.";
+        sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
+        ASSERT_TRUE(sal_True == bOK2) << "AcceptorSocket listen failed.";
+        asAcceptorSocket.enableNonBlockingMode( sal_True );
+
+        /// launch client socket
+        csConnectorSocket.connect( saTargetSocketAddr, pTimeout );   /// connecting to server...
+
+        oslSocketResult eResult = asAcceptorSocket.acceptConnection(ssConnection); /// waiting
for incoming connection...
+
+        ASSERT_TRUE( ( osl_Socket_Ok == eResult ) )
+            << "test for listen_accept function: try to create a connection with remote
host, using listen and accept.";
+    }
+
+    TEST_F(listen_accept, listen_accept_002)
+    {
+        ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"),
IP_PORT_MYPORT4 );
+        ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"),
IP_PORT_MYPORT4 );
+        ::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"),
IP_PORT_FTP );
+        ::osl::StreamSocket ssConnection;
+
+        /// launch server socket
+        sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr );
+        ASSERT_TRUE(sal_True == bOK1) << "AcceptorSocket bind address failed.";
+        sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
+        ASSERT_TRUE(sal_True == bOK2) << "AcceptorSocket listen failed.";
+        asAcceptorSocket.enableNonBlockingMode( sal_True );
+
+        /// launch client socket
+        csConnectorSocket.connect( saTargetSocketAddr, pTimeout );   /// connecting to server...
+
+        oslSocketResult eResult = asAcceptorSocket.acceptConnection(ssConnection, saPeerSocketAddr);
/// waiting for incoming connection...
+
+        ASSERT_TRUE(
+                                ( sal_True == bOK2 ) &&
+                                ( osl_Socket_Ok == eResult ) &&
+                                ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr
) ) )
+            << "test for listen_accept function: try to create a connection with remote
host, using listen and accept, accept with peer address.";
+    }
 
 } // 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.
-NOADDITIONAL;
+int main(int argc, char **argv)
+{
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}

Modified: openoffice/trunk/main/sal/qa/osl/socket/osl_ConnectorSocket.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/osl/socket/osl_ConnectorSocket.cxx?rev=1701357&r1=1701356&r2=1701357&view=diff
==============================================================================
--- openoffice/trunk/main/sal/qa/osl/socket/osl_ConnectorSocket.cxx (original)
+++ openoffice/trunk/main/sal/qa/osl/socket/osl_ConnectorSocket.cxx Sat Sep  5 07:59:22 2015
@@ -54,7 +54,7 @@
 // include files
 //------------------------------------------------------------------------
 
-#include <testshl/simpleheader.hxx>
+#include "gtest/gtest.h"
 
 #include "osl_Socket_Const.h"
 #include "sockethelper.hxx"
@@ -89,7 +89,7 @@ public:
 	{
 		if ( isRunning( ) )
 		{
-			t_print("# error: CloseSocketThread not terminated.\n" );
+			printf("# error: CloseSocketThread not terminated.\n" );
 		}
 	}
 };
@@ -103,29 +103,25 @@ namespace osl_ConnectorSocket
 						oslSocketType	Type = osl_Socket_TypeStream);
 	*/
 
-	class ctors : public CppUnit::TestFixture
+	class ctors : public ::testing::Test
 	{
 	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
 
+    TEST_F(ctors, ctors_001)
+    {
+        /// Socket constructor.
+        ::osl::ConnectorSocket csSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream
);
+
+        ASSERT_TRUE( osl_Socket_TypeStream ==  csSocket.getType( ) )
+            << "test for ctors_001 constructor function: check if the connector socket
was created successfully.";
+    }
+
 	/** testing the method:
 		oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout
= 0);
 	*/
 
-	class connect : public CppUnit::TestFixture
+	class connect : public ::testing::Test
 	{
 	public:
 		TimeValue *pTimeout;
@@ -134,7 +130,7 @@ namespace osl_ConnectorSocket
 
 
 		// initialization
-		void setUp( )
+		void SetUp( )
 		{
 			pTimeout  = ( TimeValue* )malloc( sizeof( TimeValue ) );
 			pTimeout->Seconds = 3;
@@ -142,119 +138,105 @@ namespace osl_ConnectorSocket
 		//	sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp
);
 		}
 
-		void tearDown( )
+		void TearDown( )
 		{
 			free( pTimeout );
 		//	sHandle = NULL;
 			asAcceptorSocket.close( );
 			csConnectorSocket.close( );
 		}
-
-
-		void connect_001()
-		{
-			::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT2
);
-			::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT2
);
-			::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("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::createFromAscii("127.0.0.1"), IP_PORT_MYPORT3
);
-			::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT3
);
-			::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("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::createFromAscii("127.0.0.1"), IP_PORT_MYPORT3
);
-			::osl::SocketAddr saTargetSocketAddr2( rtl::OUString::createFromAscii("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::createFromAscii("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_NAMED_REGISTRATION(osl_ConnectorSocket::ctors, "osl_ConnectorSocket");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ConnectorSocket::connect, "osl_ConnectorSocket");
+    TEST_F(connect, connect_001)
+    {
+        ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"),
IP_PORT_MYPORT2 );
+        ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"),
IP_PORT_MYPORT2 );
+        ::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("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 );
+        ASSERT_TRUE(sal_True == bOK1) << "AcceptorSocket bind address failed.";
+        sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
+        ASSERT_TRUE(sal_True == bOK2) << "AcceptorSocket listen failed.";
+
+        //asAcceptorSocket.enableNonBlockingMode( sal_True );
+        //oslSocketResult eResultAccept = asAcceptorSocket.acceptConnection(ssConnection);
/// waiting for incoming connection...
+        //ASSERT_TRUE(osl_Socket_Ok == eResultAccept) << "accept failed.";
+        /// launch client socket
+        oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout
);   /// connecting to server...
+        ASSERT_TRUE(osl_Socket_Ok == eResult) << "connect failed.";
+
+        /// get peer information
+        csConnectorSocket.getPeerAddr( saPeerSocketAddr );/// connected.
+
+        ASSERT_TRUE(
+                                ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr
) ) &&
+                                ( osl_Socket_Ok == eResult ))
+            << "test for connect function: try to create a connection with remote host.
and check the setup address.";
+    }
+    //non-blocking mode connect?
+    TEST_F(connect, connect_002)
+    {
+        ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"),
IP_PORT_MYPORT3 );
+        ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"),
IP_PORT_MYPORT3 );
+        ::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("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 );
+        ASSERT_TRUE(sal_True == bOK1) << "AcceptorSocket bind address failed.";
+        sal_Bool bOK2 = asAcceptorSocket.listen( 1 );
+        ASSERT_TRUE(sal_True == bOK2) << "AcceptorSocket listen failed.";
+
+        csConnectorSocket.enableNonBlockingMode( sal_True );
+
+        oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout
);   /// connecting to server...
+        ASSERT_TRUE(osl_Socket_InProgress == eResult ||  osl_Socket_Ok == eResult) <<
"connect failed.";
+
+        /// get peer information
+        csConnectorSocket.getPeerAddr( saPeerSocketAddr );
+
+        ASSERT_TRUE( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr 
)  )
+            << "test for connect function: try to create a connection with remote host.
and check the setup address.";
+    }
+    // really an error or just delayed
+    // how to design scenarios that will return osl_Socket_Interrupted, osl_Socket_TimedOut
+    TEST_F(connect, connect_003)
+    {
+        ::osl::SocketAddr saTargetSocketAddr1( rtl::OUString::createFromAscii("127.0.0.1"),
IP_PORT_MYPORT3 );
+        ::osl::SocketAddr saTargetSocketAddr2( rtl::OUString::createFromAscii("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();
+        ASSERT_TRUE(osl_Socket_Error == eResult1 &&
+            osl_Socket_Error == eResult2 &&  osl_Socket_Error == eResult3) <<
"connect should failed.";
+
+    }
+
+    // really an error in non-blocking mode
+    TEST_F(connect, connect_004)
+    {
+        ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"),
IP_PORT_MYPORT3 );
+
+        csConnectorSocket.enableNonBlockingMode( sal_True );
+
+        oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout
);   /// connecting to server...
+        ASSERT_TRUE(osl_Socket_Error == eResult) << "connect should failed.";
+    }
+    /** here need a case: immediate connection, say in non-blocking mode connect return osl_Socket_Ok
+    */
 
 } // 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.
-NOADDITIONAL;
+int main(int argc, char **argv)
+{
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}

Modified: openoffice/trunk/main/sal/qa/osl/socket/osl_DatagramSocket.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/osl/socket/osl_DatagramSocket.cxx?rev=1701357&r1=1701356&r2=1701357&view=diff
==============================================================================
--- openoffice/trunk/main/sal/qa/osl/socket/osl_DatagramSocket.cxx (original)
+++ openoffice/trunk/main/sal/qa/osl/socket/osl_DatagramSocket.cxx Sat Sep  5 07:59:22 2015
@@ -54,7 +54,7 @@
 // include files
 //------------------------------------------------------------------------
 
-#include <testshl/simpleheader.hxx>
+#include "gtest/gtest.h"
 
 //#include "osl_Socket_Const.h"
 #include "sockethelper.hxx"
@@ -91,7 +91,7 @@ public:
 	{
 		if ( isRunning( ) )
 		{
-			t_print("# error: CloseSocketThread not terminated.\n" );
+			printf("# error: CloseSocketThread not terminated.\n" );
 		}
 	}
 };
@@ -109,26 +109,20 @@ namespace osl_DatagramSocket
 							  oslSocketType	Type= osl_Socket_TypeDgram);
 	*/
 
-	class ctors : public CppUnit::TestFixture
+	class ctors : public ::testing::Test
 	{
 	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
 
+    TEST_F(ctors, ctors_001)
+    {
+        /// Socket constructor.
+        ::osl::DatagramSocket dsSocket;
+
+        ASSERT_TRUE(osl_Socket_TypeDgram ==  dsSocket.getType( ))
+            << "test for ctors_001 constructor function: check if the datagram socket
was created successfully.";
+    }
+
 /**thread do sendTo, refer to http://www.coding-zone.co.uk/cpp/articles/140101networkprogrammingv.shtml
 */
 class TalkerThread : public Thread
@@ -156,7 +150,7 @@ public:
 	~TalkerThread( )
 	{
 		if ( isRunning( ) )
-			t_print("# error: TalkerThread not terminated normally.\n" );
+			printf("# error: TalkerThread not terminated normally.\n" );
 	}
 };
 
@@ -174,12 +168,12 @@ protected:
 		dsSocket.setOption( osl_Socket_OptionReuseAddr, 1 );
 		if ( dsSocket.bind( saLocalSocketAddr ) == sal_False )
 		{
-			t_print("DatagramSocket bind failed \n");
+			printf("DatagramSocket bind failed \n");
 			return;
 		}
 		//blocking mode: default
 		sal_Int32 nRecv = dsSocket.recvFrom( pRecvBuffer, 30, &saTargetSocketAddr); //strlen(
pTestString2 ) + 1
-		t_print("After recvFrom, nRecv is %d\n", nRecv);
+		printf("After recvFrom, nRecv is %d\n", nRecv);
 	}
 
 	void SAL_CALL onTerminated( )
@@ -197,7 +191,7 @@ public:
 	~ListenerThread( )
 	{
 		if ( isRunning( ) )
-			t_print("# error: ListenerThread not terminated normally.\n" );
+			printf("# error: ListenerThread not terminated normally.\n" );
 	}
 
 };
@@ -209,104 +203,89 @@ public:
 			  const void* pBuffer, sal_uInt32 BufferSize, oslSocketMsgFlag Flag )
 	*/
 
-	class sendTo_recvFrom : public CppUnit::TestFixture
+	class sendTo_recvFrom : public ::testing::Test
 	{
 	public:
-
-		void sr_001()
-		{
-			::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("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::createFromAscii("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::createFromAscii("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::createFromAscii("123.345.67.89"),
IP_PORT_MYPORT10 );
-			::osl::SocketAddr saListenSocketAddr2( rtl::OUString::createFromAscii("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_NAMED_REGISTRATION(osl_DatagramSocket::ctors, "osl_DatagramSocket");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DatagramSocket::sendTo_recvFrom, "osl_DatagramSocket");
+    TEST_F(sendTo_recvFrom, sr_001)
+    {
+        ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("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();
+        //printf("#received buffer is %s# \n", pReadBuffer);
+
+        sal_Bool bOk = ( strcmp(pReadBuffer, pTestString1) == 0 );
+
+        ASSERT_TRUE(nRecv > 0 && bOk == sal_True )
+            << "test for sendTo/recvFrom function: create a talker thread and recvFrom
in the main thread, check if the datagram socket can communicate successfully.";
+    }
+
+    TEST_F(sendTo_recvFrom, sr_002)
+    {
+        ::osl::SocketAddr saListenSocketAddr( rtl::OUString::createFromAscii("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 );
+
+        ASSERT_TRUE(nSend > 0) << "DatagramSocket sendTo failed: nSend <= 0.";
+
+        myListenThread.join();
+        //printf("#received buffer is %s# \n", myListenThread.pRecvBuffer);
+
+        sal_Bool bOk = ( strcmp( myListenThread.pRecvBuffer, pTestString2) == 0 );
+
+        ASSERT_TRUE( bOk == sal_True )
+            << "test for sendTo/recvFrom function: create a listener thread and sendTo
in the main thread, check if the datagram socket can communicate successfully.";
+    }
+
+    //sendTo error, return -1; recvFrom error, return -1
+    TEST_F(sendTo_recvFrom, sr_003)
+    {
+        ::osl::SocketAddr saListenSocketAddr( rtl::OUString::createFromAscii("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 );
+        ASSERT_TRUE(nSend == -1) << "DatagramSocket sendTo should fail: nSend <=
0.";
+    }
+
+    TEST_F(sendTo_recvFrom, sr_004)
+    {
+        ::osl::SocketAddr saListenSocketAddr1( rtl::OUString::createFromAscii("123.345.67.89"),
IP_PORT_MYPORT10 );
+        ::osl::SocketAddr saListenSocketAddr2( rtl::OUString::createFromAscii("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();
+        //printf("#nRecv1 is %d nRecv2 is %d\n", nRecv1, nRecv2 );
+        ASSERT_TRUE(nRecv2 == -1) << "DatagramSocket sendTo should fail: nSend <=
0.";
+    }
 
 } // 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.
-NOADDITIONAL;
+int main(int argc, char **argv)
+{
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}



Mime
View raw message