testsuite/src/c++/TestTimestamp.cpp

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------
00002 Name:      TimeoutTest.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   Testing the Timeout Features
00006 -----------------------------------------------------------------------------*/
00007 #include "TestSuite.h"
00008 #include <iostream>
00009 
00010 using namespace std;
00011 using namespace org::xmlBlaster::util;
00012 
00021 namespace org { namespace xmlBlaster { namespace test {
00022 
00023 class TestTimestamp 
00024 {
00025    
00026 private:
00027    string ME;
00028    Timeout *timestampObject;
00029 public:
00030    TestTimestamp(string name) : ME(name) {
00031    }
00032 
00033    void setUp(int args=0, char *argc[]=0) {
00034       for (int i=0; i < args; i++) {
00035          cout << ME << " setUp invoked with argument " << argc[i] << endl;
00036       }
00037    }
00038 
00045    void testTimestamp() {
00046 
00047       TimestampFactory& factory = TimestampFactory::getInstance();
00048       Timestamp sum = 0;
00049       Timestamp previous = 0;
00050       int nmax = 1000;
00051       for (int i=0; i < nmax; i++) {
00052          Timestamp timestamp = factory.getTimestamp();
00053          if (timestamp <= previous) {
00054             cout << "error: the timestamp is lower or like a previous one" << endl;
00055             assert(0);
00056          }
00057          if (i != 0) sum += timestamp - previous;
00058          previous = timestamp;
00059       }
00060       double average = 1.0 * sum / (nmax-1);
00061       cout << ME << " testTimestamp: " + lexical_cast<string>(average) + " nanoseconds per request" << endl;
00062    }
00063 
00064    void tearDown() {
00065    }
00066 };
00067 
00068    
00069 }}} // namespace
00070 
00071 
00072 using namespace org::xmlBlaster::test;
00073 
00074 int main(int args, char *argc[]) {
00075 
00076    TestTimestamp *testObj = new TestTimestamp("TestTimestamp");
00077 
00078    testObj->setUp(args, argc);
00079    testObj->testTimestamp();
00080    testObj->tearDown();
00081    delete testObj;
00082    testObj = NULL;
00083    return 0;
00084 }
00085