template/filtertest.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #include <type_traits>
22 
23 #include <mia/core/attributes.hh>
24 #include <mia/test/testhelpers.hh>
25 
26 #ifndef mia_template_filtertest_hh
27 #define mia_template_filtertest_hh
28 
30 
38 template <template <class> class Image>
40  typedef typename Image<int>::dimsize_type dimsize_type;
41 public:
42 
43  TFiltertestFixture():m_attr(new CStringAttribute("teststring"))
44  {
45  }
46 
57  template <typename Filter, typename IN, typename OUT>
58  void run(const dimsize_type& in_size, const IN *init_data,
59  const dimsize_type& out_size, const OUT *test_data, const Filter& f) {
60  Image<IN> image(in_size, init_data);
61  image.set_attribute("test_attr", m_attr);
62 
63  auto result = f.filter(image);
64 
65  // test attribute transfer
66  auto result_attr = result->get_attribute("test_attr");
67  BOOST_REQUIRE(result_attr);
68  BOOST_CHECK_EQUAL(*result_attr, *m_attr);
69 
70 
71  // test output data
72  auto r = dynamic_cast<const Image<OUT>&>(*result);
73 
74  BOOST_CHECK_EQUAL(r.get_size(), out_size);
75  BOOST_REQUIRE(r.get_size()== out_size);
76 
77  const OUT *t = test_data;
78  auto i = r.begin_range(dimsize_type::_0, out_size);
79  auto e = r.end_range(dimsize_type::_0, out_size);
80  while (i != e) {
81  if (*i != *t)
82  cvfail() << i.pos() << "\n";
83  miatest::equal_or_close(*i, *t);
84  ++i; ++t;
85  }
86  }
87 private:
88  PAttribute m_attr;
89 };
90 
92 
93 #endif
a Fixture to do general plug.in testing
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
std::shared_ptr< CAttribute > PAttribute
define the shared pointer wrapped attribute pointer
Definition: attributes.hh:100
vstream & cvfail()
direct output to this stream adapter to print out failtures in tests beyond BOOST_FAIL ...
Definition: msgstream.hh:291
void run(const dimsize_type &in_size, const IN *init_data, const dimsize_type &out_size, const OUT *test_data, const Filter &f)
Class of an attribute that holds data of type T.
Definition: attributes.hh:116
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36