Added the getmilliSeconds() function for the WIN32 environnement.

_WIN32 & MinGW compiler uses std::clock()
_CYGWIN_ & linux compilers uses gettimeofday() implementation

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@780 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
clitte_bbt 2006-11-20 23:41:15 +00:00
parent 7dbb105cab
commit f6e7714eca

View file

@ -37,13 +37,23 @@
#include <loki/CachedFactory.h> #include <loki/CachedFactory.h>
#if defined(_WIN32) || defined(__CYGWIN__) typedef long milliSec;
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h> #include <windows.h>
milliSec getmilliSeconds()
{
return std::clock()*1000/CLOCKS_PER_SEC;
}
#else #else
#include <unistd.h> #include <unistd.h>
void Sleep(unsigned int t) { usleep( 1000 * static_cast<unsigned long>(t));} void Sleep(unsigned int t) { usleep( 1000 * static_cast<unsigned long>(t));}
/**
* Returns the number of milliseconds elapsed from the epoch.
* This counter might overrun and come back to 0.
* This might give a false result in the following tests.
*/
#include <sys/time.h> #include <sys/time.h>
typedef long milliSec;
milliSec getmilliSeconds() milliSec getmilliSeconds()
{ {
struct timeval time; struct timeval time;
@ -54,7 +64,6 @@
} }
#endif #endif
using std::cout; using std::cout;
using std::cerr; using std::cerr;
using std::endl; using std::endl;
@ -314,7 +323,7 @@ bool testRateLimitedFetchPolicy(bool waitBetweenFetch)
bool exceptionOccured = false; bool exceptionOccured = false;
const int number(5); const int number(5);
const int sleepTime(60); const int sleepTime(70);
AbstractProduct *products[number]; AbstractProduct *products[number];
for(int i=0;i<number;i++) products[i]=NULL; // initializing for(int i=0;i<number;i++) products[i]=NULL; // initializing
try{ try{
@ -342,7 +351,7 @@ bool fullTestRateLimitedFetchPolicy()
cout << " || => Setting rate limit to 2 fetch within 100 ms." << endl; cout << " || => Setting rate limit to 2 fetch within 100 ms." << endl;
cout << " || => generating 5 objects " << endl; cout << " || => generating 5 objects " << endl;
bool test1 = dispResult("Fast creation", testRateLimitedFetchPolicy(false)==true); bool test1 = dispResult("Fast creation", testRateLimitedFetchPolicy(false)==true);
cout << " || => generating 5 objects with 60ms between each Fetch" << endl; cout << " || => generating 5 objects with 70ms between each Fetch" << endl;
bool test2 = dispResult("Slow creation", testRateLimitedFetchPolicy(true)==false); bool test2 = dispResult("Slow creation", testRateLimitedFetchPolicy(true)==false);
return test1 && test2; return test1 && test2;
} }