IODA Bundle
TestFunctionDateAndTime.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// \file UnitTest.cc
12 ///
13 /// @author ECMWF, July 2010
14 
15 const double EPS = 1e-6;
16 
17 #include <cmath>
18 
19 #include "eckit/log/Timer.h"
20 #include "odc/Select.h"
21 
22 #include "odc/Writer.h"
23 #include "TestCase.h"
24 
25 using namespace std;
26 using namespace eckit;
27 using namespace odc;
28 
29 
30 static void setUp()
31 {
32  Timer t("Test DateAndTime function");
33  odc::Writer<> oda("test_date_and_time.odb");
34 
35  odc::Writer<>::iterator row = oda.begin();
36  row->setNumberOfColumns(2);
37 
38  row->setColumn(0, "date", odc::api::INTEGER);
39  row->setColumn(1, "time", odc::api::INTEGER);
40 
41  row->writeHeader();
42 
43  (*row)[0] = 20090706.0;
44  (*row)[1] = 210109.0;
45 
46  ++row;
47 }
48 
49 static void tearDown()
50 {
51  PathName("test_date_and_time.odb").unlink();
52 }
53 
54 static void test()
55 {
56  const string sql = "select julian(date,time), year(date),month(date),day(date),hour(time),minute(time),second(time), timestamp(date,time) from \"test_date_and_time.odb\";";
57 
58  Log::info() << "Executing: '" << sql << "'" << std::endl;
59 
60  odc::Select oda(sql);
61  odc::Select::iterator it = oda.begin();
62 
63  ASSERT(fabs((*it)[0] - 2455019.) < EPS); //
64  ASSERT((*it)[1] == 2009); //
65  ASSERT((*it)[2] == 7); //
66  ASSERT((*it)[3] == 6); //
67  ASSERT((*it)[4] == 21); //
68  ASSERT((*it)[5] == 1); //
69  ASSERT((*it)[6] == 9); //
70  ASSERT((*it)[7] == 20090706210109ll); //
71 
72 }
73 
74 
75 
76 SIMPLE_TEST(FunctionDateAndTime)
void oda
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
static void tearDown()
static void test()
static void setUp()
const double EPS
void writeHeader()
void setNumberOfColumns(size_t n)
Definition: IteratorProxy.h:95
int setColumn(size_t index, const std::string &name, api::ColumnType type)
Definition: ColumnInfo.h:23
Definition: encode.cc:30