1 /*-----------------------------------------------------------------------------
2 Name: TimeoutTest.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Testing the Timeout Features
6 -----------------------------------------------------------------------------*/
7 #include "TestSuite.h"
8 #include <iostream>
9
10 using namespace std;
11 using namespace org::xmlBlaster::util;
12
13 /**
14 * This client tests the synchronous method get() with its different qos
15 * variants.<p>
16 * This client may be invoked multiple time on the same xmlBlaster server,
17 * as it cleans up everything after his tests are done.
18 * <p>
19 */
20
21 namespace org { namespace xmlBlaster { namespace test {
22
23 class TestTimestamp
24 {
25
26 private:
27 string ME;
28 Timeout *timestampObject;
29 public:
30 TestTimestamp(string name) : ME(name) {
31 }
32
33 void setUp(int args=0, char *argc[]=0) {
34 for (int i=0; i < args; i++) {
35 cout << ME << " setUp invoked with argument " << argc[i] << endl;
36 }
37 }
38
39 /**
40 * The following should be tested:
41 * - all timestamps are different from eachother
42 * - timestamps are created in increasing order
43 *
44 */
45 void testTimestamp() {
46
47 TimestampFactory& factory = TimestampFactory::getInstance();
48 Timestamp sum = 0;
49 Timestamp previous = 0;
50 int nmax = 1000;
51 for (int i=0; i < nmax; i++) {
52 Timestamp timestamp = factory.getTimestamp();
53 if (timestamp <= previous) {
54 cout << "error: the timestamp is lower or like a previous one" << endl;
55 assert(0);
56 }
57 if (i != 0) sum += timestamp - previous;
58 previous = timestamp;
59 }
60 double average = 1.0 * sum / (nmax-1);
61 cout << ME << " testTimestamp: " + lexical_cast<string>(average) + " nanoseconds per request" << endl;
62 }
63
64 void tearDown() {
65 }
66 };
67
68
69 }}} // namespace
70
71
72 using namespace org::xmlBlaster::test;
73
74 int main(int args, char *argc[]) {
75
76 TestTimestamp *testObj = new TestTimestamp("TestTimestamp");
77
78 testObj->setUp(args, argc);
79 testObj->testTimestamp();
80 testObj->tearDown();
81 delete testObj;
82 testObj = NULL;
83 return 0;
84 }
syntax highlighted by Code2HTML, v. 0.9.1