timestamp.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Includes
00010 *****************************************************************************/
00011 
00012 #include <cstdlib>
00013 #include <gtest/gtest.h>
00014 #include "../../include/ecl/time/timestamp.hpp"
00015 
00016 /*****************************************************************************
00017 ** Platform Check
00018 *****************************************************************************/
00019 
00020 #ifdef ECL_HAS_TIMESTAMP
00021 
00022 /*****************************************************************************
00023 ** Using
00024 *****************************************************************************/
00025 
00026 using ecl::TimeStamp;
00027 
00028 TEST(TimeStampTests,construction) {
00029     TimeStamp time;
00030     SUCCEED();
00031     TimeStamp time_pair(3,123456789L);
00032     EXPECT_FLOAT_EQ(3.123456789,time_pair);
00033     TimeStamp time_double(3.00001);
00034     EXPECT_FLOAT_EQ(3.00001,time_double);
00035 }
00036 
00037 TEST(TimeStampTests,timestamps) {
00038     TimeStamp time;
00039     time.stamp();
00040     long t = time.sec();
00041     t = time.msec();
00042     t = time.usec();
00043     t = time.nsec();
00044     SUCCEED();
00045     time.stamp(3,1425);
00046     EXPECT_FLOAT_EQ(3.000001425,time);
00047     time.stamp(4.00000142);
00048     EXPECT_FLOAT_EQ(4.00000142,time);
00049 }
00050 
00051 TEST(TimeStampTests,copyConstruction) {
00052     TimeStamp time(3,100);
00053         TimeStamp time_copy(time);
00054         EXPECT_EQ(3,time_copy.sec());
00055         EXPECT_EQ(100,time_copy.nsec());
00056 }
00057 
00058 TEST(TimeStampTests,copyAssignment) {
00059     TimeStamp time(3,100);
00060         TimeStamp time_copy;
00061     time_copy = time;
00062         EXPECT_EQ(3,time_copy.sec());
00063         EXPECT_EQ(100,time_copy.nsec());
00064 }
00065 
00066 TEST(TimeStampTests,comparisonOperators) {
00067     TimeStamp time(3,100);
00068         TimeStamp time_copy(time);
00069         EXPECT_TRUE(time==time_copy);
00070         EXPECT_FALSE(time!=time_copy);
00071         EXPECT_TRUE(time<=time_copy);
00072         EXPECT_TRUE(time>=time_copy);
00073         EXPECT_FALSE(time<time_copy);
00074         EXPECT_FALSE(time>time_copy);
00075     time.stamp();
00076         EXPECT_FALSE(time==time_copy);
00077         EXPECT_TRUE(time!=time_copy);
00078         EXPECT_FALSE(time<=time_copy);
00079         EXPECT_TRUE(time>=time_copy);
00080         EXPECT_FALSE(time<time_copy);
00081         EXPECT_TRUE(time>time_copy);
00082 }
00083 
00084 TEST(TimeStampTests,mathematicalOperators) {
00085         TimeStamp time, time_copy;
00086     time.stamp(1,100100100L);
00087     time_copy.stamp(1,900100100L);
00088     time += time_copy;
00089     EXPECT_EQ(3,time.sec());
00090     EXPECT_EQ(200200,time.nsec());
00091     time.stamp(1,100100100L);
00092     time = time + time_copy;
00093     EXPECT_EQ(3,time.sec());
00094     EXPECT_EQ(200200,time.nsec());
00095     time.stamp(2,100100100L);
00096     time -= time_copy;
00097     EXPECT_EQ(0,time.sec());
00098     EXPECT_EQ(200000000,time.nsec());
00099     time.stamp(2,100100100L);
00100     time = time - time_copy;
00101     EXPECT_EQ(0,time.sec());
00102     EXPECT_EQ(200000000,time.nsec());
00103 }
00104 
00105 #endif /* ECL_HAS_TIMESTAMP */
00106 
00107 /*****************************************************************************
00108 ** Main program
00109 *****************************************************************************/
00110 
00111 int main(int argc, char **argv) {
00112 
00113 //      TimeStamp time;
00114 //      std::cout << time << std::endl;
00115 //      time.stamp();
00116 //      std::cout << time << std::endl;
00117     testing::InitGoogleTest(&argc,argv);
00118     return RUN_ALL_TESTS();
00119 }


ecl_time
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:35:32