My Project
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
24#include <mia/test/testhelpers.hh>
25
26#ifndef mia_template_filtertest_hh
27#define mia_template_filtertest_hh
28
30
38template <template <class> class Image>
40{
41 typedef typename Image<int>::dimsize_type dimsize_type;
42public:
43
44 TFiltertestFixture(): m_attr(new CStringAttribute("teststring"))
45 {
46 }
47
58 template <typename Filter, typename IN, typename OUT>
59 void run(const dimsize_type& in_size, const IN *init_data,
60 const dimsize_type& out_size, const OUT *test_data, const Filter& f)
61 {
62 Image<IN> image(in_size, init_data);
63 image.set_attribute("test_attr", m_attr);
64 auto result = f.filter(image);
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 // test output data
70 auto r = dynamic_cast<const Image<OUT>&>(*result);
71 BOOST_CHECK_EQUAL(r.get_size(), out_size);
72 BOOST_REQUIRE(r.get_size() == out_size);
73 const OUT *t = test_data;
74 auto i = r.begin_range(dimsize_type::_0, out_size);
75 auto e = r.end_range(dimsize_type::_0, out_size);
76
77 while (i != e) {
78 if (*i != *t)
79 cvfail() << i.pos() << "\n";
80
81 miatest::equal_or_close(*i, *t);
82 ++i;
83 ++t;
84 }
85 }
86private:
87 PAttribute m_attr;
88};
89
91
92#endif
std::shared_ptr< CAttribute > PAttribute
define the shared pointer wrapped attribute pointer
Class of an attribute that holds data of type T.
a Fixture to do general plug.in testing
void run(const dimsize_type &in_size, const IN *init_data, const dimsize_type &out_size, const OUT *test_data, const Filter &f)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
vstream & cvfail()
direct output to this stream adapter to print out failtures in tests beyond BOOST_FAIL
Definition msgstream.hh:301