1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2011 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <metaproxy/filter.hpp>
24 #include <metaproxy/package.hpp>
25 #include "factory_filter.hpp"
28 #define BOOST_AUTO_TEST_MAIN
29 #define BOOST_TEST_DYN_LINK
30 #include <boost/test/auto_unit_test.hpp>
32 using namespace boost::unit_test;
33 namespace mp = metaproxy_1;
36 class XFilter: public mp::filter::Base {
38 void process(mp::Package & package) const;
39 void configure(const xmlNode* ptr, bool test_only, const char *path) {};
42 void XFilter::process(mp::Package & package) const
47 static mp::filter::Base* xfilter_creator(){
52 class YFilter: public mp::filter::Base {
54 void process(mp::Package & package) const;
55 void configure(const xmlNode* ptr, bool test_only, const char *path) {};
58 void YFilter::process(mp::Package & package) const
63 static mp::filter::Base* yfilter_creator(){
67 BOOST_AUTO_TEST_CASE( test_filter_factory_1 )
71 mp::FactoryFilter ffactory;
76 const std::string xfid = "XFilter";
77 const std::string yfid = "YFilter";
79 BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
80 BOOST_CHECK(ffactory.drop_creator(xfid));
81 BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
82 BOOST_CHECK(ffactory.add_creator(yfid, yfilter_creator));
84 mp::filter::Base* xfilter = 0;
85 xfilter = ffactory.create(xfid);
86 mp::filter::Base* yfilter = 0;
87 yfilter = ffactory.create(yfid);
89 BOOST_CHECK(0 != xfilter);
90 BOOST_CHECK(0 != yfilter);
93 xfilter->process(pack);
94 //BOOST_CHECK_EQUAL(pack.data(), 1);
96 yfilter->process(pack);
97 //BOOST_CHECK_EQUAL(pack.data(), 2);
107 BOOST_AUTO_TEST_CASE( test_filter_factory_2 )
110 mp::FactoryFilter ffactory;
112 const std::string id = "dl";
115 BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
118 BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
120 mp::filter::Base* filter = 0;
121 filter = ffactory.create(id);
123 BOOST_CHECK(0 != filter);
126 filter->process(pack);
127 //BOOST_CHECK_EQUAL(pack.data(), 42); // magic from filter_dl ..
140 * c-file-style: "Stroustrup"
141 * indent-tabs-mode: nil
143 * vim: shiftwidth=4 tabstop=8 expandtab