IODA Bundle
TestAggregateFunctions2.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 TestAggregateFunctions2.h
12 ///
13 /// @author Piotr Kuchta, ECMWF, September 2010
14 
15 #include "eckit/io/StdFileHandle.h"
16 #include "eckit/io/FileHandle.h"
17 
18 #include "odc/api/Odb.h"
19 #include "odc/Select.h"
20 #include "odc/Writer.h"
21 
22 #include "TestCase.h"
23 
24 using namespace std;
25 using namespace eckit;
26 using namespace odc;
27 
28 static void test()
29 {
30  string sql = "select count(*) from \"TestAggregateFunctions2.odb\";";
31 
32  Log::info() << "Executing: '" << sql << "'" << std::endl;
33 
34  odc::Select oda(sql);
35  odc::Select::iterator it = oda.begin();
36 
37  ASSERT(it->columns().size() == 1);
38  ASSERT((*it)[0] == 10);
39 
40  odc::Select sel(sql);
41  odc::Select::iterator it2 = sel.begin();
42  odc::Select::iterator end2 = sel.end();
43 
44  FILE *fout = fopen("TestAggregateFunctions2.odb", "w");
45  StdFileHandle fhout(fout);
46  odc::Writer<> writer(fhout);
47  odc::Writer<>::iterator outit = writer.begin();
48 
49  //outit->pass1(it2, end2);
50  size_t i = 0;
51  for (; it2 != end2; ++it2)
52  {
53  ++i;
54  ASSERT( (*it2)[0] == 10);
55  }
56  ASSERT( i == 1);
57 }
58 
59 static void setUp()
60 {
61  stringstream s;
62  s << "a:REAL" << std::endl;
63  for (size_t i = 1; i <= 10; ++i)
64  s << i << std::endl;
65  FileHandle dh("TestAggregateFunctions2.odb");
66  dh.openForWrite(0);
67  AutoClose close(dh);
68  odc::api::odbFromCSV(s, dh);
69 }
70 
71 
72 static void tearDown(){}
73 
74 SIMPLE_TEST(AggregateFunctions2)
void oda
static void tearDown()
static void test()
static void setUp()
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
const core::MetaData & columns() const
Definition: IteratorProxy.h:94
const iterator end()
Definition: Select.cc:77
iterator begin()
Definition: Select.cc:81
size_t odbFromCSV(DataHandle &dh_in, DataHandle &dh_out, const std::string &delimiter)
odbFromCSV returns number of lines imported
Definition: Odb.cc:375
Definition: ColumnInfo.h:23
Definition: encode.cc:30