IODA Bundle
TestInt16_MissingCodec.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, Jan 2010
14 
15 #include "eckit/log/Timer.h"
16 #include "odc/core/MetaData.h"
17 #include "odc/Reader.h"
18 
19 #include "odc/Writer.h"
20 #include "MockReader.h"
21 #include "TestCase.h"
22 
23 using namespace std;
24 using namespace eckit;
25 using namespace odc;
26 
27 
29 {
30 public:
32  : noMore_(false), refCount_(0), columns_(1), nRows_(0), min_(23), data_(0)
33  {
34  core::Column* col = columns_[0] = new core::Column(columns_);
35  ASSERT(col);
36 
37  col->name("column_name");
39  col->hasMissing(true);
40  next();
41  }
42 
43  core::MetaData& columns() { return columns_; }
44 
45  bool isNewDataset() { return false; }
46  double* data() { return &data_; }
47  double& data(size_t) { return data_; }
48 
49  //MockReaderIterator3& operator++() { next(); return *this; }
50 
51  const MockReaderIterator3& end() { return *reinterpret_cast<MockReaderIterator3*>(0); }
52 
53  bool next()
54  {
55  if (noMore_) return noMore_;
56  switch (nRows_++)
57  {
58  case 0:
59  data_ = min_ + 0;
60  break;
61  case 1:
62  data_ = min_ + (0xffff - 1) / 2;
63  break;
64  case 2:
65  data_ = min_ + (0xffff - 1);
66  break;
67  case 3:
68  data_ = columns_[0]->coder().missingValue();
69  break;
70  default:
71  return !(noMore_ = true);
72  break;
73  }
74  return true;
75  }
76 
77  bool noMore_;
78  int refCount_;
79 
80 private:
82  unsigned int nRows_;
83  double min_;
84  double data_;
85 };
86 
87 static void setUp()
88 {
89  Timer t("Writing test_int16_missing.odb");
90  odc::Writer<> oda("test_int16_missing.odb");
91 
93  M reader;
94  M::iterator b = reader.begin();
95  const M::iterator e = reader.end();
96 
97  odc::Writer<>::iterator outit = oda.begin();
98  outit->pass1(b, e);
99 }
100 
101 static void test()
102 {
103  odc::Reader oda("test_int16_missing.odb");
104  odc::Reader::iterator it = oda.begin();
105  odc::Reader::iterator end = oda.end();
106 
108  M reader;
109  M::iterator originalIt = reader.begin();
110  const M::iterator originalItEnd = reader.end();
111 
112  Log::info() << it->columns() << std::endl;
113 
114  for ( ; it != end; ++it, ++originalIt)
115  {
116  Log::info() << "it[0] = " << (*it)[0] << ", originalIt.data()[0]=" << (*originalIt)[0] << std::endl;
117  ASSERT((*it)[0] == (*originalIt)[0]);
118  }
119 
120  core::Codec& coder ( it->columns()[0]->coder() );
121 
122  string name = coder.name();
123 
124  Log::debug() << "test: codec name is '" << name << "'" << std::endl;
125 
126  ASSERT(name == "int16_missing");
127 
128  Log::debug() << "test: OK" << std::endl;
129 }
130 
131 
132 static void tearDown(){}
133 
134 SIMPLE_TEST(Int16_MissingCodec)
void oda
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
static void tearDown()
static void test()
static void setUp()
core::MetaData & columns()
const MockReaderIterator3 & end()
unsigned long pass1(T b, const T e)
const core::MetaData & columns() const
Definition: IteratorProxy.h:94
const std::string & name() const
Definition: Codec.h:40
void hasMissing(bool h)
Delegations to Codec:
Definition: Column.h:71
void name(const std::string name)
Definition: Column.h:57
static api::ColumnType type(const std::string &)
Definition: Column.cc:74
Definition: ColumnInfo.h:23
Definition: encode.cc:30