Kaydet (Commit) 5d85807f authored tarafından Damjan Jovanovic's avatar Damjan Jovanovic

#i125003# migrate main/sal/qa/rtl/doublelock from cppunit to Google Test. Also fix

an include file problem that stopped it from compiling.
üst 3f7cee35
......@@ -31,11 +31,16 @@ 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:testjob by codegen.pl
......@@ -43,24 +48,19 @@ CFLAGSCXX += $(CPPUNIT_CFLAGS)
CFLAGS+=/Ob1
.ENDIF
SHL1OBJS= \
APP1OBJS= \
$(SLO)$/rtl_doublelocking.obj
SHL1TARGET= rtl_doublelocking
SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB)
SHL1IMPLIB= i$(SHL1TARGET)
DEF1NAME =$(SHL1TARGET)
SHL1VERSIONMAP = $(PRJ)$/qa$/export.map
APP1TARGET= rtl_doublelocking
APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
APP1RPATH = NONE
APP1TEST = enabled
# END ------------------------------------------------------------------
#------------------------------- 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"
......@@ -28,9 +28,8 @@
//------------------------------------------------------------------------
#include <sal/types.h>
#ifndef _RTL_USTRING_HXX_
#include <rtl/string.hxx>
#endif
#include <rtl/ustring.h>
#include <rtl/ustring.hxx>
#ifndef _OSL_THREAD_HXX
#include <osl/thread.hxx>
......@@ -39,7 +38,7 @@
#include <rtl/instance.hxx>
#include <testshl/simpleheader.hxx>
#include "gtest/gtest.h"
// -----------------------------------------------------------------------------
#define CONST_TEST_STRING "gregorian"
......@@ -56,9 +55,9 @@ inline void printOUString( ::rtl::OUString const & _suStr )
{
rtl::OString aString;
t_print( "OUString: " );
printf( "OUString: " );
aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US );
t_print( "'%s'\n", aString.getStr( ) );
printf( "'%s'\n", aString.getStr( ) );
}
// -----------------------------------------------------------------------------
......@@ -73,7 +72,7 @@ namespace ThreadHelper
{
// if (nVerbose == VERBOSE)
// {
// t_print("wait %d tenth seconds. ", _nTenthSec );
// printf("wait %d tenth seconds. ", _nTenthSec );
// fflush(stdout);
// }
#ifdef WNT //Windows
......@@ -87,7 +86,7 @@ namespace ThreadHelper
#endif
// if (nVerbose == VERBOSE)
// {
// t_print("done\n");
// printf("done\n");
// }
}
}
......@@ -150,7 +149,7 @@ public:
{
if (isRunning())
{
t_print("error: not terminated.\n");
printf("error: not terminated.\n");
}
}
};
......@@ -162,95 +161,85 @@ namespace rtl_DoubleLocking
/** Test of the osl::Thread::create method
*/
class getValue : public CppUnit::TestFixture
class getValue : public ::testing::Test
{
public:
// initialise your test code values here.
void setUp()
void SetUp()
{
}
void tearDown()
void TearDown()
{
}
}; // class create
TEST_F(getValue, getValue_001)
{
rtl::OUString aStr = Gregorian::get();
printOUString(aStr);
void getValue_001()
{
rtl::OUString aStr = Gregorian::get();
printOUString(aStr);
CPPUNIT_ASSERT_MESSAGE(
"Gregorian::get() failed, wrong value expected.",
aStr.getLength() != 0
);
}
/** check 2 threads.
ASSERT_TRUE(aStr.getLength() != 0)
<< "Gregorian::get() failed, wrong value expected.";
}
ALGORITHM:
Here the function should show, that 2 different threads,
which only increase a value, should run at the same time with same prio.
The test fails, if the difference between the two values is more than 5%
but IMHO this isn't a failure, it's only a feature of the OS.
*/
/** check 2 threads.
void getValue_002()
{
// initial 5 threads with different priorities
OGetThread* pThread = new OGetThread();
OGetThread* p2Thread = new OGetThread();
ALGORITHM:
Here the function should show, that 2 different threads,
which only increase a value, should run at the same time with same prio.
The test fails, if the difference between the two values is more than 5%
but IMHO this isn't a failure, it's only a feature of the OS.
*/
TEST_F(getValue, getValue_002)
{
// initial 5 threads with different priorities
OGetThread* pThread = new OGetThread();
OGetThread* p2Thread = new OGetThread();
//Create them and start running at the same time
pThread->create();
p2Thread->create();
//Create them and start running at the same time
pThread->create();
p2Thread->create();
ThreadHelper::thread_sleep_tenth_sec(50);
ThreadHelper::thread_sleep_tenth_sec(50);
pThread->terminate();
p2Thread->terminate();
pThread->terminate();
p2Thread->terminate();
sal_Int32 nValueOK = 0;
nValueOK = pThread->getOK();
sal_Int32 nValueOK = 0;
nValueOK = pThread->getOK();
sal_Int32 nValueOK2 = 0;
nValueOK2 = p2Thread->getOK();
sal_Int32 nValueOK2 = 0;
nValueOK2 = p2Thread->getOK();
t_print("Value in Thread #1 is %d\n", nValueOK);
t_print("Value in Thread #2 is %d\n", nValueOK2);
printf("Value in Thread #1 is %d\n", nValueOK);
printf("Value in Thread #2 is %d\n", nValueOK2);
sal_Int32 nValueFails = 0;
nValueFails = pThread->getFails();
sal_Int32 nValueFails = 0;
nValueFails = pThread->getFails();
sal_Int32 nValueFails2 = 0;
nValueFails2 = p2Thread->getFails();
sal_Int32 nValueFails2 = 0;
nValueFails2 = p2Thread->getFails();
t_print("Fails in Thread #1 is %d\n", nValueFails);
t_print("Fails in Thread #2 is %d\n", nValueFails2);
printf("Fails in Thread #1 is %d\n", nValueFails);
printf("Fails in Thread #2 is %d\n", nValueFails2);
// ThreadHelper::thread_sleep_tenth_sec(1);
pThread->join();
p2Thread->join();
// ThreadHelper::thread_sleep_tenth_sec(1);
pThread->join();
p2Thread->join();
delete pThread;
delete p2Thread;
delete pThread;
delete p2Thread;
CPPUNIT_ASSERT_MESSAGE(
"getValue() failed, wrong value expected.",
nValueOK != 0 && nValueFails == 0 && nValueFails2 == 0
);
}
ASSERT_TRUE(nValueOK != 0 && nValueFails == 0 && nValueFails2 == 0)
<< "getValue() failed, wrong value expected.";
}
CPPUNIT_TEST_SUITE(getValue);
CPPUNIT_TEST(getValue_001);
CPPUNIT_TEST(getValue_002);
CPPUNIT_TEST_SUITE_END();
}; // class create
// -----------------------------------------------------------------------------
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_DoubleLocking::getValue, "rtl_DoubleLocking");
} // namespace rtl_DoubleLocking
// 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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment