1 /* $Id: test_filter_factory.cpp,v 1.13 2006-06-10 14:29:12 adam Exp $
2 Copyright (c) 2005-2006, Index Data.
4 See the LICENSE file for details
12 #include "package.hpp"
13 #include "factory_filter.hpp"
16 #define BOOST_AUTO_TEST_MAIN
17 #include <boost/test/auto_unit_test.hpp>
19 using namespace boost::unit_test;
20 namespace mp = metaproxy_1;
23 class XFilter: public mp::filter::Base {
25 void process(mp::Package & package) const;
28 void XFilter::process(mp::Package & package) const
33 static mp::filter::Base* xfilter_creator(){
38 class YFilter: public mp::filter::Base {
40 void process(mp::Package & package) const;
43 void YFilter::process(mp::Package & package) const
48 static mp::filter::Base* yfilter_creator(){
52 BOOST_AUTO_UNIT_TEST( test_filter_factory_1 )
56 mp::FactoryFilter ffactory;
61 const std::string xfid = "XFilter";
62 const std::string yfid = "YFilter";
64 BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
65 BOOST_CHECK(ffactory.drop_creator(xfid));
66 BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
67 BOOST_CHECK(ffactory.add_creator(yfid, yfilter_creator));
69 mp::filter::Base* xfilter = 0;
70 xfilter = ffactory.create(xfid);
71 mp::filter::Base* yfilter = 0;
72 yfilter = ffactory.create(yfid);
74 BOOST_CHECK(0 != xfilter);
75 BOOST_CHECK(0 != yfilter);
78 xfilter->process(pack);
79 BOOST_CHECK_EQUAL(pack.data(), 1);
81 yfilter->process(pack);
82 BOOST_CHECK_EQUAL(pack.data(), 2);
92 BOOST_AUTO_UNIT_TEST( test_filter_factory_2 )
95 mp::FactoryFilter ffactory;
97 const std::string id = "dl";
100 BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
103 BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
105 mp::filter::Base* filter = 0;
106 filter = ffactory.create(id);
108 BOOST_CHECK(0 != filter);
111 filter->process(pack);
112 BOOST_CHECK_EQUAL(pack.data(), 42); // magic from filter_dl ..
125 * indent-tabs-mode: nil
126 * c-file-style: "stroustrup"
128 * vim: shiftwidth=4 tabstop=8 expandtab