added TimeConversion::sleep() function
This commit is contained in:
parent
5f03d18970
commit
d7d84661c4
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -71,7 +71,7 @@ using namespace LiveSupport;
|
|||
* A helper object holding static time conversion functions.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
class TimeConversion
|
||||
{
|
||||
|
@ -102,6 +102,14 @@ class TimeConversion
|
|||
*/
|
||||
static Ptr<ptime>::Ref
|
||||
now(void) throw ();
|
||||
|
||||
/**
|
||||
* Sleep for the specified time duration, with microsecond precision.
|
||||
*
|
||||
* @param duration sleep for this duration.
|
||||
*/
|
||||
static void
|
||||
sleep(Ptr<time_duration>::Ref duration) throw ();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversion.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -89,3 +89,14 @@ TimeConversion :: now(void)
|
|||
return timevalToPtime(&timeval);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Sleep for the specified duration.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TimeConversion :: sleep(Ptr<time_duration>::Ref duration)
|
||||
throw ()
|
||||
{
|
||||
usleep(duration->total_microseconds());
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversionTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -140,3 +140,24 @@ TimeConversionTest :: nowTest(void)
|
|||
CPPUNIT_ASSERT(ptime->time_of_day().seconds() == tm.tm_sec);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test the sleep function
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TimeConversionTest :: sleepTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<ptime>::Ref start;
|
||||
Ptr<ptime>::Ref end;
|
||||
Ptr<time_duration>::Ref duration;
|
||||
|
||||
duration.reset(new time_duration(seconds(2)));
|
||||
|
||||
start = TimeConversion::now();
|
||||
TimeConversion::sleep(duration);
|
||||
end = TimeConversion::now();
|
||||
|
||||
CPPUNIT_ASSERT((*end - *start) >= *duration);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversionTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -58,7 +58,7 @@ namespace Core {
|
|||
* Unit test for the TimeConversion class.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
* @version $Revision: 1.2 $
|
||||
* @see TimeConversion
|
||||
*/
|
||||
class TimeConversionTest : public CPPUNIT_NS::TestFixture
|
||||
|
@ -66,6 +66,7 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture
|
|||
CPPUNIT_TEST_SUITE(TimeConversionTest);
|
||||
CPPUNIT_TEST(timevalToPtimeTest);
|
||||
CPPUNIT_TEST(nowTest);
|
||||
CPPUNIT_TEST(sleepTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
protected:
|
||||
|
@ -86,6 +87,14 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture
|
|||
void
|
||||
nowTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* Test the sleep function.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
sleepTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in New Issue