TsTimeInstant.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 // Unit-Test TerraLib
21 #include "TsTimeInstant.h"
22 
23 //STL
24 #include <iostream>
25 
26 static boost::gregorian::date d(2010,8,9);
27 static boost::posix_time::ptime bt;
28 
29 static te::dt::Date ds(2010,01,01); //date start
30 static te::dt::Date de(2010,12,31); //date end
31 static te::dt::TimeDuration td(20,30,50,11);
32 static te::dt::TimeDuration td1(23,59,59);
33 static te::dt::TimeInstant TT(ds,td);
34 
36 
38 {
39 }
40 
42 {
43 }
44 
46 {
47 //#ifdef TE_COMPILE_ALL
48 
50  std::cout << std::endl;
51  std::cout << " print tt: " << tt.toString() << std::endl;
52  tt = TT;
53  std::cout << " print tt after assign: " << tt.toString() << std::endl;
54  CPPUNIT_ASSERT( tt.toString() =="20100101T203050.000011");
55 
56 //#endif
57 }
58 
60 {
61 //#ifdef TE_COMPILE_ALL
62 
64  CPPUNIT_ASSERT(tt.getDate().getYear() == 2010 && tt.getDate().getMonth() == 1 && tt.getDate().getDay() == 1 );
65  CPPUNIT_ASSERT(tt.getTime().getHours() == 20 && tt.getTime().getMinutes() == 30 && tt.getTime().getSeconds() == 50 && tt.getTime().getFractionalSeconds() == 11) ;
66 
67 //#endif
68 }
69 
71 {
72 //#ifdef TE_COMPILE_ALL
73 
75  CPPUNIT_ASSERT(tt.getDate().getYear() == 2010 && tt.getDate().getMonth() == 1 && tt.getDate().getDay() == 1 );
76  CPPUNIT_ASSERT(tt.getTime().getHours() == 20 && tt.getTime().getMinutes() == 30 && tt.getTime().getSeconds() == 50 && tt.getTime().getFractionalSeconds() == 11) ;
77 
79  CPPUNIT_ASSERT(bt.getDate().getYear() == 2010 && bt.getDate().getMonth() == 1 && bt.getDate().getDay() == 1 );
80  CPPUNIT_ASSERT(bt.getTime().getHours() == 20 && bt.getTime().getMinutes() == 30 && bt.getTime().getSeconds() == 50 && bt.getTime().getFractionalSeconds() == 11) ;
81 
82 //#endif
83 }
84 
86 {
87 //#ifdef TE_COMPILE_ALL
88 
89  //boost::posix_time::ptime b = TT.getTimeInstant();
91 
92  CPPUNIT_ASSERT(tt.getDate().getYear() == 2010 && tt.getDate().getMonth() == 1 && tt.getDate().getDay() == 1 );
93  CPPUNIT_ASSERT(tt.getTime().getHours() == 20 && tt.getTime().getMinutes() == 30 && tt.getTime().getSeconds() == 50 && tt.getTime().getFractionalSeconds() == 11) ;
94 
95 //#endif
96 }
97 
99 {
100 //#ifdef TE_COMPILE_ALL
101 
103  CPPUNIT_ASSERT(tt.getDate().getYear() == 2010 && tt.getDate().getMonth() == 1 && tt.getDate().getDay() == 1 );
104 
105  //#endif
106 }
107 
109 {
110 //#ifdef TE_COMPILE_ALL
111 
113  CPPUNIT_ASSERT(tt.getTime().getHours() == 20 && tt.getTime().getMinutes() == 30 && tt.getTime().getSeconds() == 50 && tt.getTime().getFractionalSeconds() == 11) ;
115  CPPUNIT_ASSERT(tt1.getTime().getHours() == 23 && tt1.getTime().getMinutes() == 59 && tt1.getTime().getSeconds() == 59 && tt1.getTime().getFractionalSeconds() == 0) ;
116 
117  //#endif
118 }
119 
121 {
122 //#ifdef TE_COMPILE_ALL
123 // Test all operators...
124 
127  tt1 = tt;
128 
130  te::dt::TimeDuration m59(20,30,59,11);
131  te::dt::TimeInstant tt3(de,m59); //plus 9 seconds in tt2
132 
133  std::cout << std::endl;
134  std::cout << " tt1: " << tt1.toString() << std::endl;
135  std::cout << " tt2: " << tt2.toString() << std::endl;
136  std::cout << " tt3: " << tt3.toString() << std::endl;
137 
138  CPPUNIT_ASSERT(tt1.operator==(tt));
139  long res;
140  res = tt2 - tt1;
141  CPPUNIT_ASSERT(tt2.operator-(tt1) != 0);
142 
143  CPPUNIT_ASSERT(tt3.operator-(tt2) == 9);
144 
145  CPPUNIT_ASSERT(tt1 < tt2);
146  CPPUNIT_ASSERT(tt1.operator<(tt2));
147 
148  CPPUNIT_ASSERT(tt2 > tt1);
149  CPPUNIT_ASSERT(tt2.operator>(tt1));
150 
151  CPPUNIT_ASSERT(tt2 != tt1);
152  CPPUNIT_ASSERT(tt2.operator!=(tt1));
153 
154  CPPUNIT_ASSERT( tt1.toString() =="20100101T203050.000011");
155  CPPUNIT_ASSERT( tt2.toString() =="20101231T203050.000011");
156  CPPUNIT_ASSERT( tt3.toString() =="20101231T203059.000011");
157 
158 //#endif
159 }
160 
162 {
163 //#ifdef TE_COMPILE_ALL
164 
166  tt = TT;
167  te::dt::TimeInstant tclone = *static_cast<te::dt::TimeInstant*>(tt.clone());
168  CPPUNIT_ASSERT(tt.operator==(tclone));
169 
170 //#endif
171 }
172 
174 {
175 //#ifdef TE_COMPILE_ALL
176 
178  tt = TT;
179  te::dt::TimeInstant tclone = *static_cast<te::dt::TimeInstant*>(tt.clone());
180  CPPUNIT_ASSERT(tt.operator==(tclone));
181  std::string show = tclone.toString();
182  CPPUNIT_ASSERT( tclone.toString() =="20100101T203050.000011");
183 
184 //#endif
185 }
static te::dt::TimeDuration td(20, 30, 50, 11)
static boost::posix_time::ptime bt
void tcTimeInstant()
Test Case: Empty Constructor.
Test suite for the TimeInstant class.
long getSeconds() const
It returns the seconds of a minute - from 0 to 59.
Definition: TimeDuration.h:105
static te::dt::TimeDuration td1(23, 59, 59)
boost::gregorian::greg_year getYear() const
It returns the gregorian year.
Definition: Date.h:111
boost::gregorian::greg_day getDay() const
It returns the gregorian day - from 1 to 31.
Definition: Date.h:97
static te::dt::TimeInstant TT(ds, td)
std::string toString() const
It returns the time instant in the ISO textual format (YYYYMMDDTHHMMSS,fffffffff) where T is the date...
Definition: TimeInstant.cpp:92
void tcTimeInstant2()
Test Case: Constructor from a date and time offset.
void tcCheckOperators()
Test Case: Check operators (==, >,<, !=, -).
const boost::posix_time::ptime & getTimeInstant() const
It returns the boost time instant type.
Definition: TimeInstant.h:92
A class to represent time instant.
Definition: TimeInstant.h:55
AbstractData * clone() const
It returns a clone of this object.
Definition: TimeInstant.cpp:87
Date getDate() const
It returns the date associated to time instant.
Definition: TimeInstant.h:106
A base class for date data types.
Definition: Date.h:53
Test suite for the TimeInstant Class.
Definition: TsTimeInstant.h:60
CPPUNIT_TEST_SUITE_REGISTRATION(TsTimeInstant)
boost::int64_t getFractionalSeconds() const
It returns the fractional seconds.
Definition: TimeDuration.h:112
void tcToString()
It returns the time instant in the ISO textual format (YYYYMMDDTHHMMSS,fffffffff) where T is the date...
static te::dt::Date ds(2010, 01, 01)
void tcGetDate()
Test Case: It returns the date associated to time instant.
void tcTimeInstant3()
Test Case: Constructor from a boost time instant type.
static te::dt::Date de(2010, 12, 31)
A class to represent time duration with nano-second/micro-second resolution.
Definition: TimeDuration.h:51
TimeDuration getTime() const
It returns the time duration associated to time instant.
Definition: TimeInstant.cpp:49
long getMinutes() const
It returns the minutes of a hour - from 0 to 59.
Definition: TimeDuration.h:98
void tcGetTime()
Test Case:It returns the time duration associated to time instant.
void tcGetTimeInstant()
Test Case: It returns the boost time instant type.
boost::gregorian::greg_month getMonth() const
It returns the gregorian month - from 1 to 12.
Definition: Date.h:104
long getHours() const
It returns the hours of a day - from 0 to 23.
Definition: TimeDuration.h:91
void tcClone()
Test Case: Clone this object and return AbstractData.
static boost::gregorian::date d(2010, 8, 9)