source: Sophya/trunk/SophyaProg/Tests/ttimestamp.cc@ 3334

Last change on this file since 3334 was 2832, checked in by ansari, 20 years ago

Programmes test TimeStamp completes (format YYYY-MM-DDThh:mm:ss) et programme test DataTable (champ DateTime et I/O ascii - Reza 8 Nov 2005

File size: 4.9 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <stdio.h>
4#include <stdlib.h>
5#include "math.h"
6#include <iostream>
7#include <string>
8#include <vector>
9
10#include <typeinfo>
11#include "timing.h"
12#include "timestamp.h"
13#include "histinit.h"
14#include "pexceptions.h"
15#include "ppfwrapstlv.h"
16
17/* Programme test de la classe TimeStamp */
18/* SOPHYA - R. Ansari (LAL) - Mars 2005 */
19
20int main(int narg, char* arg[])
21{
22 cout << " ---- Programme ttimestamp.cc - Test classe TimeStamp --- " << endl;
23 int rc = 0;
24 try {
25 SophyaInit();
26// PPRegister(FIO_SphereECP<r_8>);
27// DObjRegister(FIO_SphereECP<r_8>, SphereECP<r_8>);
28
29 InitTim();
30 cout << " Sizeof(TimeStamp=) " << sizeof(TimeStamp) << endl;
31 TimeStamp ts;
32 cout << "ts: Now : " << ts << "(->double: " << (double)ts << " )" << endl;
33 TimeStamp ts2("26/8/1974","14:22:35.65");
34 cout << "ts2: 26/8/1974 14:22:35.65 : " << ts2
35 << " double->TimeStamp: " << TimeStamp(ts2.ToDays()) << endl;
36 TimeStamp ts3("08/05/1905","00:00:00");
37 cout << "ts3: 8/05/1905 , 00:00:00 : " << ts3 << " (double): "
38 << (double)ts3 << " double->TimeStamp: " << TimeStamp(ts3.ToDays()) << endl;
39 TimeStamp ts4("01/01/1901","03:00:20");
40 cout << "ts3: 01/01/1901 , 03:00:20 : " << ts4 << " (double): "
41 << (double)ts4 << " double->TimeStamp: " << TimeStamp(ts4.ToDays()) << endl;
42
43 TimeStamp ts5("01/12/1899","00:00:00");
44 cout << "ts5: 01/12/1899 , 00:00:00 : " << ts5 << " (double): "
45 << (double)ts5 << " double->TimeStamp: " << TimeStamp(ts5.ToDays()) << endl;
46 TimeStamp ts6("01/12/1899","15:30:00");
47 cout << "ts6: 01/12/1899 , 15:30:00 : " << ts6 << " (double): "
48 << (double)ts6 << " double->TimeStamp: " << TimeStamp(ts6.ToDays()) << endl;
49
50 cout << " ts.ToString(bool, bool) test : " << endl;
51 cout << " ts.ToString()= " << ts.ToString() << endl;
52 cout << " ts.ToString(FmtDateOnly)= " << ts.ToString(TimeStamp::FmtDateOnly) << endl;
53 cout << " ts.ToString(FmtTimeOnly)= " << ts.ToString(TimeStamp::FmtTimeOnly) << endl;
54 cout << " ts.ToString(FmtDateTime)= " << ts.ToString(TimeStamp::FmtDateTime) << endl;
55
56 TimeStamp ts12("1974-08-26T14:22:35.65");
57 cout << "ts12: 1974-08-26T14:22:35.65 : " << ts12
58 << " double->TimeStamp: " << TimeStamp(ts12.ToDays()) << endl;
59 TimeStamp ts13("1905-05-08T00:00:00");
60 cout << "ts13: 1905-05-08T00:00:00 " << ts13 << " (double): "
61 << (double)ts13 << " double->TimeStamp: " << TimeStamp(ts13.ToDays()) << endl;
62
63 double diff;
64 diff = ts12.ToDays()-ts2.ToDays();
65 if (fabs(diff) > 1.e-6) {
66 cout << "ttimestamp/Erreur Diff t12-t2 : Rc+=1 " << endl;
67 rc += 1;
68 }
69 diff = ts13.ToDays()-ts3.ToDays();
70 if (fabs(diff) > 1.e-6) {
71 cout << "ttimestamp/Erreur Diff t13-t3 : Rc+=2 " << endl;
72 rc += 2;
73 }
74 TimeStamp tsa("1901-1-1T14:0:0");
75 diff = tsa.ToDays()-38./24.;
76 if (fabs(diff) > 1.e-6) {
77 cout << "ttimestamp/Erreur Diff tsa-38/24. : Rc+=4 " << endl;
78 rc += 4;
79 }
80 tsa.Set("1901-02-07T18:00:00");
81 diff = tsa.ToDays()-38.75;
82 if (fabs(diff) > 1.e-6) {
83 cout << "ttimestamp/Erreur Diff tsa-38.75 : Rc+=8 " << endl;
84 rc += 8;
85 }
86 tsa.Set("2004-08-24T18:00:00");
87 TimeStamp tsb("2004-09-03T21:00:00");
88 diff = tsb.ToDays()-tsa.ToDays();
89 if (fabs(diff-10.125) > 1.e-6) {
90 cout << "ttimestamp/Erreur Diff tsb-tsa : Rc+=16 " << endl;
91 rc += 16;
92 }
93 if (rc == 0)
94 cout << "ttimestamp/Info CheckDiffs OK (Rc=" << rc << ")" << endl;
95 else
96 cout << "ttimestamp/Erreur Pb Diffs (Rc=" << rc << ")" << endl;
97
98 cout << "ttimestamp/Info: Test PPF , vector<TimeStamp> " << endl;
99 vector<TimeStamp> vts, vtsr;
100 vts.push_back(ts);
101 vts.push_back(ts2);
102 vts.push_back(ts3);
103 {
104 POutPersist so("tts.ppf");
105 so << vts;
106 }
107 cout << "ttimestamp/Info: Reading from tts.ppf " << endl;
108 PInPersist si("tts.ppf");
109
110 si >> vtsr;
111 for(int kk=0; kk<vtsr.size(); kk++) {
112 cout << " vtsr[" << kk << "] : " << vtsr[kk] << endl;
113 diff = vtsr[kk].ToDays()-vts[kk].ToDays();
114 if (fabs(diff) > 1.e-6) {
115 cout << "ttimestamp/Erreur Diff vtsr[kk]-vts[kk] : Rc+=32 " << endl;
116 rc += 32;
117 }
118 }
119 if (rc >= 32)
120 cout << "ttimestamp/Info Pb Diffs vector<TimeStamp>/PPF (Rc="
121 << rc << ")" << endl;
122 else
123 cout << "ttimestamp/Erreur Diffs vector<TimeStamp>/PPF OK" << endl;
124 }
125 catch (PThrowable & exc) {
126 cerr << " ttimestamp.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
127 << " - Msg= " << exc.Msg() << endl;
128 rc = 99;
129 }
130 catch (std::exception & e) {
131 cerr << " ttimestamp.cc: Catched std::xception "
132 << " - what()= " << e.what() << endl;
133 rc = 98;
134 }
135 catch (...) {
136 cerr << " ttimestamp.cc: some other exception (...) was caught ! " << endl;
137 rc = 97;
138 }
139 PrtTim("End ttimestamp " );
140 cout << " ---- Programme ttimestamp.cc- FIN (Rc=" << rc << ") --- " << endl;
141 return rc;
142}
Note: See TracBrowser for help on using the repository browser.