IODA Bundle
TestDistinct.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.h
12 ///
13 /// @author Piotr Kuchta, ECMWF, September 2010
14 
15 #include "eckit/filesystem/PathName.h"
16 #include "eckit/io/FileHandle.h"
17 
18 #include "odc/api/Odb.h"
19 #include "odc/Select.h"
20 
21 #include "TestCase.h"
22 
23 using namespace std;
24 using namespace eckit;
25 using namespace odc;
26 
27 ///
28 static void test()
29 {
30  std::string sql = "select distinct a from \"TestDistinct_a1to10twice.odb\";";
31 
32  Log::info() << "Executing: '" << sql << "'" << std::endl;
33 
34  odc::Select sel(sql);
35  odc::Select::iterator it2 = sel.begin();
36  odc::Select::iterator end2 = sel.end();
37 
38  int i = 0;
39  for (; it2 != end2; ++it2)
40  ASSERT((*it2)[0] == ++i);
41 
42  ASSERT((*it2)[0] == 10);
43 }
44 
45 static void setUp()
46 {
47  stringstream s;
48  s << "a:REAL" << std::endl;
49  for (size_t i = 1; i <= 10; ++i) s << i << std::endl;
50  for (size_t i = 1; i <= 10; ++i) s << i << std::endl;
51  FileHandle dh("TestDistinct_a1to10twice.odb");
52  dh.openForWrite(0);
53  AutoClose close(dh);
54  odc::api::odbFromCSV(s, dh);
55 }
56 
57 
58 static void tearDown(){}
59 
60 SIMPLE_TEST(Distinct)
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
static void tearDown()
Definition: TestDistinct.cc:58
static void test()
Definition: TestDistinct.cc:28
static void setUp()
Definition: TestDistinct.cc:45
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