PhoenixClockMock  2.0.0
Tool to manipulate mock of clock (split, merge and get info)
main.cpp
Go to the documentation of this file.
1 
2 /***************************************
3  Auteur : Pierre Aubert
4  Mail : pierre.aubert@lapp.in2p3.fr
5  Licence : CeCILL-C
6 ****************************************/
7 
8 #include <unistd.h>
9 #include <iomanip>
10 #include <iostream>
11 #include "data_stream_assert.h"
12 #include "PClockNs.h"
13 
15 void testPClockNs(){
16  PClockNs clockNs;
17  clockNs.setOffsetTimeNs(0l);
18  data_stream_assert(clockNs.getOffsetTimeNs() == 0l);
19  std::cout << "testPClockNs : " << clockNs.getFullTimeNs() << std::endl;
20  std::cout << "testPClockNs : " << clockNs.getDateNs() << std::endl;
21  std::cout << "testPClockNs : " << clockNs.getDateCompactNs() << std::endl;
22  data_stream_assert(clockNs.getFullTimeNs() != 0l);
23  data_stream_assert(clockNs.getDateNs() != "");
24 
25  PClockNs otherClock(clockNs), thirdClock;
26  thirdClock = clockNs;
27  data_stream_assert(otherClock.getOffsetTimeNs() == 0l);
28  data_stream_assert(thirdClock.getOffsetTimeNs() == 0l);
29 }
30 
33  PClockNs clockNs;
34  for(size_t i(0lu); i < 100lu; ++i){
35  std::time_t currentTime = clockNs.getFullTimeNs();
36  std::cerr << "i = " << std::setfill('0') << std::setw(3) << i << ", time = " << currentTime << ", date = '"<<phoenix_dateNs(currentTime)<<"'" << std::endl;
37  usleep(100);
38  }
39 }
40 
41 int main(int argc, char** argv){
42  testPClockNs();
44  return 0;
45 }
46 
47 
std::string phoenix_dateNs(std::time_t currentDateNs, const char *format)
Convert a given date in nanosecond into a text date.
Definition: PClockNs.cpp:15
int main(int argc, char **argv)
Definition: main.cpp:56
void testPClockNs()
Test the PClockNs.
Definition: main.cpp:15
void testPClockNsCoherence()
Test the coherence of the PClockNs.
Definition: main.cpp:32
Nanosecond clock.
Definition: PClockNs.h:16
std::string getDateCompactNs() const
Get the date at nanosecond precision (even if it is not precise at the nanosecond scale,...
Definition: PClockNs.cpp:103
std::time_t getOffsetTimeNs() const
Get the offset in nanoseconds of the current clock.
Definition: PClockNs.cpp:78
std::time_t getFullTimeNs() const
Get the full time in nanoseconds.
Definition: PClockNs.cpp:85
void setOffsetTimeNs(std::time_t offsetTimeNs)
Set the offset in nanoseconds of the current clock.
Definition: PClockNs.cpp:71
std::string getDateNs() const
Get the date at nanosecond precision (even if it is not precise at the nanosecond scale,...
Definition: PClockNs.cpp:96
#define data_stream_assert(isOk)