IODA Bundle
TestAtTableInTheOutput.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 TestAtTableInTheOutput.h
12 ///
13 /// @author Piotr Kuchta, ECMWF, Feb 2009
14 
15 #include "odc/Comparator.h"
16 #include "odc/core/MetaData.h"
17 #include "odc/Select.h"
18 #include "odc/Reader.h"
19 
20 #include "odc/Writer.h"
21 #include "TestCase.h"
22 
23 using namespace std;
24 using namespace eckit;
25 using namespace odc;
26 
27 static void setUp()
28 {
29  odc::Writer<> f("TestAtTableInTheOutput_A.odb");
30  odc::Writer<>::iterator it = f.begin();
31 
32  it->setNumberOfColumns(4);
33  it->setColumn(0, "lat@hdr", odc::api::REAL);
34  it->setColumn(1, "lon@hdr", odc::api::REAL);
35  it->setColumn(2, "obsvalue", odc::api::REAL);
36 
37  eckit::sql::BitfieldDef bfDef;
38  bfDef.first.push_back("x");
39  bfDef.second.push_back(1);
40  bfDef.first.push_back("y");
41  bfDef.second.push_back(2);
42 
43  it->setBitfieldColumn(3, "bf", odc::api::BITFIELD, bfDef);
44 
45  it->writeHeader();
46 
47  for (size_t i = 1; i <= 2; i++)
48  {
49  (*it)[0] = i; // col 0
50  (*it)[1] = i; // col 1
51  (*it)[2] = i; // col 2
52  ++it;
53  }
54 }
55 
56 static void selectIntoSecondFile()
57 {
58  const string fileName = "TestAtTableInTheOutput_A.odb";
59  string sql = "select lat,lon,obsvalue,bf into \"TestAtTableInTheOutput_B.odb\"";
60  sql += " from \"" + fileName + "\" ;";
61 
62  odc::Select f(sql); //, fileName);
63  odc::Select::iterator it = f.begin();
64 
65  //string c0 = it.columns()[0]->name();
66  //string c1 = it.columns()[1]->name();
67  //string c2 = it.columns()[2]->name();
68 
69  ++it; // this is needed to push the second row to the INTO file
70 
71  //Log::info() << "c0=" << c0 << ", c1=" << c1 << ", c2=" << c2 << std::endl;
72  ///ASSERT("");
73 }
74 
75 static void compareFiles()
76 {
77  odc::Reader oda1("TestAtTableInTheOutput_A.odb");
78  odc::Reader oda2("TestAtTableInTheOutput_B.odb");
79 
80  odc::Reader::iterator it1(oda1.begin());
81  odc::Reader::iterator end1(oda1.end());
82  odc::Reader::iterator it2(oda2.begin());
83  odc::Reader::iterator end2(oda2.end());
84 
85  odc::Comparator().compare(it1, end1, it2, end2, "TestAtTableInTheOutput_A.odb", "TestAtTableInTheOutput_B.odb");
86 }
87 
88 
89 static void test()
90 {
92  compareFiles();
93 }
94 
95 
96 
97 static void tearDown(){}
98 
99 SIMPLE_TEST(AtTableInTheOutput)
static void tearDown()
static void compareFiles()
static void test()
static void selectIntoSecondFile()
static void setUp()
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
bool compare(T1 &it1, const T1 &end1, T2 &it2, const T2 &end2, const std::string &desc1, const std::string &desc2)
Definition: Comparator.h:108
const iterator end() const
Definition: Reader.cc:81
iterator begin()
Definition: Reader.cc:74
void writeHeader()
void setNumberOfColumns(size_t n)
Definition: IteratorProxy.h:95
int setColumn(size_t index, const std::string &name, api::ColumnType type)
int setBitfieldColumn(size_t index, const std::string &name, api::ColumnType type, eckit::sql::BitfieldDef b)
@ BITFIELD
Definition: ColumnType.h:27
Definition: ColumnInfo.h:23
Definition: encode.cc:30