metric_generator.h
Go to the documentation of this file.
1 
8 #pragma once
13 
14 namespace illumina{ namespace interop { namespace unittest
15 {
16  template<class Gen>
20  template<class Gen>
24  template<class Gen>
28  template<class Gen>
36  template<class Gen>
37  class hardcoded_metric_generator : public abstract_generator< typename Gen::metric_set_t >
38  {
39  typedef typename Gen::metric_set_t metric_set_t;
40  typedef typename Gen::metric_t metric_t;
41  typedef typename abstract_generator<metric_set_t>::parent_type parent_t;
42  public:
45  {
46  hardcoded_metric_registry_t::instance()(metric_t(), Gen::VERSION);
47  }
53  ::testing::AssertionResult generate(metric_set_t& expected, metric_set_t& actual, bool*)const
54  {
55  actual.clear();
56  Gen::create_expected(expected);
57  std::string binary_data;//std::vector< ::uint8_t > binary_data;
58  Gen::create_binary_data(binary_data);
59  io::read_interop_from_string(binary_data, actual);
60  return ::testing::AssertionSuccess();
61  }
66  parent_t clone()const{return new hardcoded_metric_generator<Gen>;}
71  void write(std::ostream& out)const
72  {
73  out << "hardcoded_metric_generator<" << Gen::name() << ">";
74  }
75 
76  };
81  template<class Gen>
82  class write_read_metric_generator : public abstract_generator< typename Gen::metric_set_t >
83  {
84  typedef typename Gen::metric_set_t metric_set_t;
85  typedef typename Gen::metric_t metric_t;
86  typedef typename abstract_generator<metric_set_t>::parent_type parent_t;
87  public:
89  write_read_metric_generator() : abstract_generator< typename Gen::metric_set_t >(1)
90  {
91  write_read_metric_registry_t::instance()(metric_t(), Gen::VERSION);
92  }
98  ::testing::AssertionResult generate(metric_set_t& expected, metric_set_t& actual, bool*)const
99  {
100  actual.clear();
101  Gen::create_expected(expected);
102  std::ostringstream fout;
103  illumina::interop::io::write_metrics(fout, expected);
104 
105  //-------------------------------------------------
106  //For unit test creation!
107  //print_actual(std::cout, fout.str());
108  //-------------------------------------------------
109 
110  io::read_interop_from_string(fout.str(), actual);
111  return ::testing::AssertionSuccess();
112  }
117  parent_t clone()const{return new write_read_metric_generator<Gen>;}
122  void write(std::ostream& out)const
123  {
124  out << "write_read_metric_generator<" << Gen::name() << ">";
125  }
126 
127  private:
128  static void print_actual(std::ostream& out, const std::string& data)
129  {
130  for(size_t i=0;i<data.size();++i)
131  {
132  out << "," << int(data[i]);
133  if( i%20 == 0) out << std::endl;
134  }
135  out << std::endl;
136  out << std::endl;
137  out << std::endl;
138  }
139  };
144  template<class Gen>
145  class by_cycle_metric_generator : public abstract_generator< typename Gen::metric_set_t >
146  {
147  typedef typename Gen::metric_set_t metric_set_t;
148  typedef typename Gen::metric_t metric_t;
149  typedef typename abstract_generator<metric_set_t>::parent_type parent_t;
150  public:
153  {
154  by_cycle_metric_registry_t::instance()(metric_t(), Gen::VERSION);
155  }
161  ::testing::AssertionResult generate(metric_set_t& expected, metric_set_t& actual, bool*)const
162  {
163  typedef typename metric_set_t::metric_type metric_t;
164  typedef typename metric_t::uint_t uint_t;
165  typedef typename metric_set_t::metric_comparison_t metric_comparison_t;
166 
167  std::string expected_data;
168  {
169  // Write out expected metrics
170  std::ostringstream fout;
171  Gen::create_expected(expected);
172  io::write_metrics(fout, expected);
173  expected_data = fout.str();
174  }
175  std::string expected_binary_data2;
176  {
177  // Insert additional metrics and write them to another buffer
178  std::ostringstream fout;
179  metric_set_t expected_metric_set2(expected, Gen::VERSION);
180  uint_t max_tile_id=0;
181 
182  metric_t tmp = expected[0];
183  const size_t n = expected.size();
184  for(size_t i=0;i<n;++i)
185  max_tile_id = std::max(metric_comparison_t::to_tile(expected[i]), max_tile_id);
186  for(uint_t i=0;i<n;++i)
187  {
188  tmp.set_base(metric_comparison_t::to_lane(tmp), max_tile_id+1+i);
189  expected.insert(tmp);
190  expected_metric_set2.insert(tmp);
191  }
192  io::write_metrics(fout, expected_metric_set2, Gen::VERSION);
193  expected_binary_data2 = fout.str();
194  }
196  reinterpret_cast< ::uint8_t*>(const_cast<char*>(expected_data.c_str()))
197  , static_cast<size_t>(expected_data.size())
198  , actual);
200  reinterpret_cast< ::uint8_t*>(const_cast<char*>(expected_binary_data2.c_str()))
201  , static_cast<size_t>(expected_binary_data2.size())
202  , actual);
203  actual.rebuild_index();
204 
205  return ::testing::AssertionSuccess();
206  }
211  parent_t clone()const{return new by_cycle_metric_generator<Gen>;}
216  void write(std::ostream& out)const
217  {
218  out << "by_cycle_metric_generator<" << Gen::name() << ">";
219  }
220  };
225  template<class MetricSet>
227  {
229  typedef typename parent_t::base_t base_type;
230  typedef MetricSet metric_set_t;
231  enum{INCOMPLETE=250, NOT_FOUND=251};
232  public:
234  public:
237  regression_test_metric_generator() : parent_t("InterOp", 2)
238  {
239  }
244  regression_test_metric_generator(const std::string& run_folder) :
245  parent_t(run_folder, "InterOp", 2)
246  {
247  }
248 
249  protected:
256  bool read_expected(const std::string& baseline_file, metric_set_t& expected)const
257  {
258  expected.clear();
259  try
260  {
261  illumina::interop::io::read_interop(baseline_file, expected);
262  }
263  // Should never have an incomplete file in baseline, set sentinel to detect
264  catch(const io::incomplete_file_exception&){expected.set_version(INCOMPLETE);return true;}
265  // Ensure missing file is expected
266  catch(const io::file_not_found_exception&){expected.set_version(NOT_FOUND); return false;}
267  return true;
268  }
274  bool generate_actual(const std::string& run_folder, metric_set_t& actual)const
275  {
276  actual.clear();
277  try
278  {
279  illumina::interop::io::read_interop(run_folder, actual);
280  }
281  // Ensure missing file is expected
282  catch(const io::incomplete_file_exception&){if(actual.empty()) actual.set_version(NOT_FOUND);}
283  // Ensure file is missing
284  catch(const io::file_not_found_exception&){actual.set_version(NOT_FOUND);}
285  return !actual.empty();
286  }
292  bool write_actual(const std::string& baseline_file, const metric_set_t& actual)const
293  {
294  return illumina::interop::io::write_interop(baseline_file, actual);
295  }
301  base_type clone(const std::string& run_folder)const
302  {
303  return new regression_test_metric_generator<MetricSet>(run_folder);
304  }
309  base_type clone()const
310  {
312  }
317  void write(std::ostream& out)const
318  {
319  out << "regression_test_metric_generator< "<< metric_set_t::prefix() << metric_set_t::suffix() << "> - "
321  }
326  std::string baseline()const
327  {
329  }
330  };
331 
336  template<class Gen>
337  class clear_metric_generator : public abstract_generator< typename Gen::metric_set_t >
338  {
339  typedef typename Gen::metric_set_t metric_set_t;
340  typedef typename Gen::metric_t metric_t;
341  typedef typename abstract_generator<metric_set_t>::parent_type parent_t;
342  public:
345  {
346  clear_metric_registry_t::instance()(metric_t(), Gen::VERSION);
347  }
352  ::testing::AssertionResult generate(metric_set_t&, metric_set_t& actual, bool*)const
353  {
354  actual.clear();
355  std::string binary_data;
356  Gen::create_binary_data(binary_data);
357  io::read_interop_from_string(binary_data, actual);
358  actual.clear();
359  return ::testing::AssertionSuccess();
360  }
365  parent_t clone()const{return new clear_metric_generator<Gen>;}
370  void write(std::ostream& out)const
371  {
372  out << "clear_metric_generator<" << Gen::name() << ">";
373  }
374 
375  };
376 
377 }}}
378 
::testing::AssertionResult generate(metric_set_t &expected, metric_set_t &actual, bool *) const
Definition: metric_generator.h:98
metric_type
Definition: enums.h:284
void write(std::ostream &out) const
Definition: metric_generator.h:216
Definition: enum_description.h:15
bool write_actual(const std::string &baseline_file, const metric_set_t &actual) const
Definition: metric_generator.h:292
registry_factory< hardcoded_metric_generator > hardcoded_metric_registry_t
Definition: metric_generator.h:17
bool generate_actual(const std::string &run_folder, metric_set_t &actual) const
Definition: metric_generator.h:274
void write(std::ostream &out) const
Definition: metric_generator.h:122
std::string basename(std::string const &source)
Definition: filesystem.cpp:95
write_read_metric_generator()
Definition: metric_generator.h:89
Definition: generic_fixture.h:23
void write(std::ostream &out) const
Definition: metric_generator.h:317
Definition: format_registry.h:81
std::string baseline() const
Definition: metric_generator.h:326
base_type clone(const std::string &run_folder) const
Definition: metric_generator.h:301
bool read_expected(const std::string &baseline_file, metric_set_t &expected) const
Definition: metric_generator.h:256
registry_factory< by_cycle_metric_generator > by_cycle_metric_registry_t
Definition: metric_generator.h:25
parent_t clone() const
Definition: metric_generator.h:365
Definition: stream_exceptions.h:45
by_cycle_metric_generator()
Definition: metric_generator.h:152
static format_registry & instance()
Definition: format_registry.h:87
void read_interop(const std::string &run_directory, MetricSet &metrics, const bool use_out=true) INTEROP_THROW_SPEC((io
Definition: metric_file_stream.h:165
virtual std::string baseline() const
Definition: abstract_regression_test_generator.h:114
hardcoded_metric_generator()
Definition: metric_generator.h:44
::testing::AssertionResult generate(metric_set_t &, metric_set_t &actual, bool *) const
Definition: metric_generator.h:352
regression_test_metric_generator()
Definition: metric_generator.h:237
abstract_regression_test_generator< MetricSet >::parent_type parent_type
Definition: metric_generator.h:233
Definition: generic_fixture.h:19
::testing::AssertionResult generate(metric_set_t &expected, metric_set_t &actual, bool *) const
Definition: metric_generator.h:53
parent_t clone() const
Definition: metric_generator.h:211
abstract_generator< MetricSet >::parent_type base_t
Definition: abstract_regression_test_generator.h:26
clear_metric_generator()
Definition: metric_generator.h:344
::testing::AssertionResult generate(metric_set_t &expected, metric_set_t &actual, bool *) const
Definition: metric_generator.h:161
base_type clone() const
Definition: metric_generator.h:309
bool write_interop(const std::string &run_directory, const MetricSet &metrics, const bool use_out=true, const ::int16_t version=-1) INTEROP_THROW_SPEC((io
Definition: metric_file_stream.h:203
void write(std::ostream &out) const
Definition: metric_generator.h:71
std::string m_run_folder
Definition: abstract_regression_test_generator.h:148
Definition: stream_exceptions.h:73
void write(std::ostream &out) const
Definition: metric_generator.h:370
void read_interop_from_string(const std::string &buffer, MetricSet &metrics, const bool rebuild=true) INTEROP_THROW_SPEC((interop
Definition: metric_file_stream.h:86
Definition: abstract_regression_test_generator.h:22
regression_test_metric_generator(const std::string &run_folder)
Definition: metric_generator.h:244
registry_factory< write_read_metric_generator > write_read_metric_registry_t
Definition: metric_generator.h:21
std::string dirname(std::string source)
Definition: filesystem.cpp:109
registry_factory< clear_metric_generator > clear_metric_registry_t
Definition: metric_generator.h:29
parent_t clone() const
Definition: metric_generator.h:66
parent_t clone() const
Definition: metric_generator.h:117
void read_interop_from_buffer(::uint8_t *buffer, const size_t buffer_size, MetricSet &metrics) INTEROP_THROW_SPEC((interop
Definition: metric_file_stream.h:66