You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by da...@apache.org on 2015/09/01 19:36:36 UTC
svn commit: r1700625 - in /openoffice/trunk/main/sal/qa/rtl/process:
makefile.mk rtl_Process.cxx
Author: damjan
Date: Tue Sep 1 17:36:36 2015
New Revision: 1700625
URL: http://svn.apache.org/r1700625
Log:
#i125003# migrate main/sal/qa/rtl/process from cppunit to Google Test.
Modified:
openoffice/trunk/main/sal/qa/rtl/process/makefile.mk
openoffice/trunk/main/sal/qa/rtl/process/rtl_Process.cxx
Modified: openoffice/trunk/main/sal/qa/rtl/process/makefile.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/rtl/process/makefile.mk?rev=1700625&r1=1700624&r2=1700625&view=diff
==============================================================================
--- openoffice/trunk/main/sal/qa/rtl/process/makefile.mk (original)
+++ openoffice/trunk/main/sal/qa/rtl/process/makefile.mk Tue Sep 1 17:36:36 2015
@@ -33,25 +33,26 @@ 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)
-CFLAGSCXX += $(CPPUNIT_CFLAGS)
-
# BEGIN ----------------------------------------------------------------
# auto generated Target:joblist by codegen.pl
-SHL1OBJS= \
+APP1OBJS= \
$(SLO)$/rtl_Process.obj
-SHL1TARGET= rtl_Process
-SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB)
-
-SHL1IMPLIB= i$(SHL1TARGET)
-# SHL1DEF= $(MISC)$/$(SHL1TARGET).def
+APP1TARGET= rtl_Process
+APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
+APP1RPATH = NONE
+APP1TEST = enabled
-DEF1NAME =$(SHL1TARGET)
-# DEF1EXPORTFILE= export.exp
-SHL1VERSIONMAP= $(PRJ)$/qa$/export.map
# END ------------------------------------------------------------------
OBJ3FILES=$(OBJ)$/child_process.obj
@@ -78,12 +79,8 @@ APP4OBJS=$(OBJ4FILES)
# .ENDIF
APP4STDLIBS=$(SALLIB)
-#------------------------------- All object files -------------------------------
-# do this here, so we get right dependencies
-SLOFILES=$(SHL1OBJS)
-
# --- Targets ------------------------------------------------------
.INCLUDE : target.mk
-.INCLUDE : _cppunit.mk
+.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES"
Modified: openoffice/trunk/main/sal/qa/rtl/process/rtl_Process.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/rtl/process/rtl_Process.cxx?rev=1700625&r1=1700624&r2=1700625&view=diff
==============================================================================
--- openoffice/trunk/main/sal/qa/rtl/process/rtl_Process.cxx (original)
+++ openoffice/trunk/main/sal/qa/rtl/process/rtl_Process.cxx Tue Sep 1 17:36:36 2015
@@ -29,7 +29,7 @@
#include <string.h>
#include <sal/types.h>
-#include <testshl/simpleheader.hxx>
+#include "gtest/gtest.h"
#include <rtl/ustring.hxx>
#include <rtl/string.hxx>
#include <rtl/process.h>
@@ -47,11 +47,11 @@ inline void printUString( const ::rtl::O
{
if ( msg != NULL )
{
- t_print("#%s #printUString_u# ", msg );
+ printf("#%s #printUString_u# ", msg );
}
rtl::OString aString;
aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
- t_print("%s\n", (char *)aString.getStr( ) );
+ printf("%s\n", (char *)aString.getStr( ) );
}
// -----------------------------------------------------------------------------
@@ -72,90 +72,76 @@ inline ::rtl::OUString getModulePath( vo
namespace rtl_Process
{
-class getAppCommandArg : public CppUnit::TestFixture
+class getAppCommandArg : public ::testing::Test
{
public:
// initialise your test code values here.
- void setUp()
+ void SetUp()
{
}
- void tearDown()
+ void TearDown()
{
}
+}; // class getAppCommandArg
- void getAppCommandArg_001()
- {
+TEST_F(getAppCommandArg, getAppCommandArg_001)
+{
#if defined(WNT) || defined(OS2)
- const rtl::OUString EXECUTABLE_NAME = rtl::OUString::createFromAscii("child_process.exe");
+ const rtl::OUString EXECUTABLE_NAME = rtl::OUString::createFromAscii("child_process.exe");
#else
- const rtl::OUString EXECUTABLE_NAME = rtl::OUString::createFromAscii("child_process");
+ const rtl::OUString EXECUTABLE_NAME = rtl::OUString::createFromAscii("child_process");
#endif
- rtl::OUString suCWD = getModulePath();
- // rtl::OUString suCWD2 = getExecutableDirectory();
+ rtl::OUString suCWD = getModulePath();
+ // rtl::OUString suCWD2 = getExecutableDirectory();
- printUString(suCWD, "path to the current module");
- // printUString(suCWD2, "suCWD2");
+ printUString(suCWD, "path to the current module");
+ // printUString(suCWD2, "suCWD2");
- oslProcess hProcess = NULL;
-
- const int nParameterCount = 4;
- rtl_uString* pParameters[ nParameterCount ];
-
- pParameters[0] = suParam0.pData;
- pParameters[1] = suParam1.pData;
- pParameters[2] = suParam2.pData;
- pParameters[3] = suParam3.pData;
-
- rtl::OUString suFileURL = suCWD;
- suFileURL += rtl::OUString::createFromAscii("/");
- suFileURL += EXECUTABLE_NAME;
-
- oslProcessError osl_error = osl_executeProcess(
- suFileURL.pData,
- pParameters,
- nParameterCount,
- osl_Process_WAIT,
- 0, /* osl_getCurrentSecurity() */
- suCWD.pData,
- NULL,
- 0,
- &hProcess );
-
- CPPUNIT_ASSERT_MESSAGE
- (
- "osl_createProcess failed",
- osl_error == osl_Process_E_None
- );
- //we could get return value only after the process terminated
- osl_joinProcess(hProcess);
- // CPPUNIT_ASSERT_MESSAGE
- // (
- // "osl_joinProcess returned with failure",
- // osl_Process_E_None == osl_error
- // );
- oslProcessInfo* pInfo = new oslProcessInfo;
- //please pay attention to initial the Size to sizeof(oslProcessInfo), or else
- //you will get unknow error when call osl_getProcessInfo
- pInfo->Size = sizeof(oslProcessInfo);
- osl_error = osl_getProcessInfo( hProcess, osl_Process_EXITCODE, pInfo );
- CPPUNIT_ASSERT_MESSAGE
- (
- "osl_getProcessInfo returned with failure",
- osl_Process_E_None == osl_error
- );
-
- t_print("the exit code is %d.\n", pInfo->Code );
- CPPUNIT_ASSERT_MESSAGE("rtl_getAppCommandArg or rtl_getAppCommandArgCount error.", pInfo->Code == 2);
- delete pInfo;
- }
+ oslProcess hProcess = NULL;
+ const int nParameterCount = 4;
+ rtl_uString* pParameters[ nParameterCount ];
+
+ pParameters[0] = suParam0.pData;
+ pParameters[1] = suParam1.pData;
+ pParameters[2] = suParam2.pData;
+ pParameters[3] = suParam3.pData;
+
+ rtl::OUString suFileURL = suCWD;
+ suFileURL += rtl::OUString::createFromAscii("/");
+ suFileURL += EXECUTABLE_NAME;
+
+ oslProcessError osl_error = osl_executeProcess(
+ suFileURL.pData,
+ pParameters,
+ nParameterCount,
+ osl_Process_WAIT,
+ 0, /* osl_getCurrentSecurity() */
+ suCWD.pData,
+ NULL,
+ 0,
+ &hProcess );
+
+ ASSERT_TRUE(osl_error == osl_Process_E_None) <<
+ "osl_createProcess failed";
+ //we could get return value only after the process terminated
+ osl_joinProcess(hProcess);
+ // ASSERT_TRUE(osl_Process_E_None == osl_error)
+ // << "osl_joinProcess returned with failure";
+ oslProcessInfo* pInfo = new oslProcessInfo;
+ //please pay attention to initial the Size to sizeof(oslProcessInfo), or else
+ //you will get unknow error when call osl_getProcessInfo
+ pInfo->Size = sizeof(oslProcessInfo);
+ osl_error = osl_getProcessInfo( hProcess, osl_Process_EXITCODE, pInfo );
+ ASSERT_TRUE(osl_Process_E_None == osl_error)
+ << "osl_getProcessInfo returned with failure";
+
+ printf("the exit code is %d.\n", pInfo->Code );
+ ASSERT_TRUE(pInfo->Code == 2) << "rtl_getAppCommandArg or rtl_getAppCommandArgCount error.";
+ delete pInfo;
+}
- CPPUNIT_TEST_SUITE(getAppCommandArg);
- CPPUNIT_TEST(getAppCommandArg_001);
- // CPPUNIT_TEST(getAppCommandArg_002);
- CPPUNIT_TEST_SUITE_END();
-}; // class getAppCommandArg
/************************************************************************
* For diagnostics( from sal/test/testuuid.cxx )
@@ -200,93 +186,83 @@ void printUuidtoBuffer( sal_uInt8 *pNode
}
}
-class getGlobalProcessId : public CppUnit::TestFixture
+class getGlobalProcessId : public ::testing::Test
{
public:
// initialise your test code values here.
- void setUp()
+ void SetUp()
{
}
- void tearDown()
+ void TearDown()
{
}
- //gets a 16-byte fixed size identifier which is guaranteed not to change during the current process.
- void getGlobalProcessId_001()
- {
- sal_uInt8 pTargetUUID1[16];
- sal_uInt8 pTargetUUID2[16];
- rtl_getGlobalProcessId( pTargetUUID1 );
- rtl_getGlobalProcessId( pTargetUUID2 );
- CPPUNIT_ASSERT_MESSAGE("getGlobalProcessId: got two same ProcessIds.", !memcmp( pTargetUUID1 , pTargetUUID2 , 16 ) );
- }
- //different processes different pids
- void getGlobalProcessId_002()
- {
+}; // class getGlobalProcessId
+
+//gets a 16-byte fixed size identifier which is guaranteed not to change during the current process.
+TEST_F(getGlobalProcessId, getGlobalProcessId_001)
+{
+ sal_uInt8 pTargetUUID1[16];
+ sal_uInt8 pTargetUUID2[16];
+ rtl_getGlobalProcessId( pTargetUUID1 );
+ rtl_getGlobalProcessId( pTargetUUID2 );
+ ASSERT_TRUE( !memcmp( pTargetUUID1 , pTargetUUID2 , 16 ) )
+ << "getGlobalProcessId: got two same ProcessIds.";
+}
+
+//different processes different pids
+TEST_F(getGlobalProcessId, getGlobalProcessId_002)
+{
#if defined(WNT) || defined(OS2)
- const rtl::OUString EXEC_NAME = rtl::OUString::createFromAscii("child_process_id.exe");
+ const rtl::OUString EXEC_NAME = rtl::OUString::createFromAscii("child_process_id.exe");
#else
- const rtl::OUString EXEC_NAME = rtl::OUString::createFromAscii("child_process_id");
+ const rtl::OUString EXEC_NAME = rtl::OUString::createFromAscii("child_process_id");
#endif
- sal_uInt8 pTargetUUID1[16];
- rtl_getGlobalProcessId( pTargetUUID1 );
- printUuid( pTargetUUID1 );
- sal_Char pUUID1[32];
- printUuidtoBuffer( pTargetUUID1, pUUID1 );
- printf("# UUID to String is %s\n", pUUID1);
-
- rtl::OUString suCWD = getModulePath();
- oslProcess hProcess = NULL;
- rtl::OUString suFileURL = suCWD;
- suFileURL += rtl::OUString::createFromAscii("/");
- suFileURL += EXEC_NAME;
- oslFileHandle* pChildOutputRead = new oslFileHandle();
- oslProcessError osl_error = osl_executeProcess_WithRedirectedIO(
- suFileURL.pData,
- NULL,
- 0,
- osl_Process_WAIT,
- 0,
- suCWD.pData,
- NULL,
- 0,
- &hProcess,
- NULL,
- pChildOutputRead,
- NULL);
-
- CPPUNIT_ASSERT_MESSAGE
- (
- "osl_createProcess failed",
- osl_error == osl_Process_E_None
- );
- //we could get return value only after the process terminated
- osl_joinProcess(hProcess);
-
- sal_Char pUUID2[33];
- pUUID2[32] = '\0';
- sal_uInt64 nRead = 0;
- osl_readFile( *pChildOutputRead, pUUID2, 32, &nRead );
- t_print("read buffer is %s, nRead is %d \n", pUUID2, nRead );
- OUString suUUID2 = OUString::createFromAscii( pUUID2 );
- CPPUNIT_ASSERT_MESSAGE("getGlobalProcessId: got two same ProcessIds.", suUUID2.equalsAsciiL( pUUID1, 32) == sal_False );
- }
-
- CPPUNIT_TEST_SUITE(getGlobalProcessId);
- CPPUNIT_TEST(getGlobalProcessId_001);
- CPPUNIT_TEST(getGlobalProcessId_002);
- CPPUNIT_TEST_SUITE_END();
-
-}; // class getGlobalProcessId
+ sal_uInt8 pTargetUUID1[16];
+ rtl_getGlobalProcessId( pTargetUUID1 );
+ printUuid( pTargetUUID1 );
+ sal_Char pUUID1[32];
+ printUuidtoBuffer( pTargetUUID1, pUUID1 );
+ printf("# UUID to String is %s\n", pUUID1);
+
+ rtl::OUString suCWD = getModulePath();
+ oslProcess hProcess = NULL;
+ rtl::OUString suFileURL = suCWD;
+ suFileURL += rtl::OUString::createFromAscii("/");
+ suFileURL += EXEC_NAME;
+ oslFileHandle* pChildOutputRead = new oslFileHandle();
+ oslProcessError osl_error = osl_executeProcess_WithRedirectedIO(
+ suFileURL.pData,
+ NULL,
+ 0,
+ osl_Process_WAIT,
+ 0,
+ suCWD.pData,
+ NULL,
+ 0,
+ &hProcess,
+ NULL,
+ pChildOutputRead,
+ NULL);
+
+ ASSERT_TRUE(osl_error == osl_Process_E_None)
+ << "osl_createProcess failed";
+ //we could get return value only after the process terminated
+ osl_joinProcess(hProcess);
+
+ sal_Char pUUID2[33];
+ pUUID2[32] = '\0';
+ sal_uInt64 nRead = 0;
+ osl_readFile( *pChildOutputRead, pUUID2, 32, &nRead );
+ printf("read buffer is %s, nRead is %lu \n", pUUID2, nRead );
+ OUString suUUID2 = OUString::createFromAscii( pUUID2 );
+ ASSERT_TRUE( suUUID2.equalsAsciiL( pUUID1, 32) == sal_False ) << "getGlobalProcessId: got two same ProcessIds.";
+}
} // namespace rtl_Process
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Process::getAppCommandArg, "rtl_Process");
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Process::getGlobalProcessId, "rtl_Process");
-
-
-// -----------------------------------------------------------------------------
-
-// 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();
+}