1 /* $Id: test_filter_factory.cpp,v 1.11 2006-01-19 09:41:01 adam Exp $
2 Copyright (c) 2005, Index Data.
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;
22 class XFilter: public yp2::filter::Base {
24 void process(yp2::Package & package) const;
27 void XFilter::process(yp2::Package & package) const
32 static yp2::filter::Base* xfilter_creator(){
37 class YFilter: public yp2::filter::Base {
39 void process(yp2::Package & package) const;
42 void YFilter::process(yp2::Package & package) const
47 static yp2::filter::Base* yfilter_creator(){
51 BOOST_AUTO_UNIT_TEST( test_filter_factory_1 )
55 yp2::FactoryFilter ffactory;
60 const std::string xfid = "XFilter";
61 const std::string yfid = "YFilter";
63 BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
64 BOOST_CHECK(ffactory.drop_creator(xfid));
65 BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
66 BOOST_CHECK(ffactory.add_creator(yfid, yfilter_creator));
68 yp2::filter::Base* xfilter = 0;
69 xfilter = ffactory.create(xfid);
70 yp2::filter::Base* yfilter = 0;
71 yfilter = ffactory.create(yfid);
73 BOOST_CHECK(0 != xfilter);
74 BOOST_CHECK(0 != yfilter);
77 xfilter->process(pack);
78 BOOST_CHECK_EQUAL(pack.data(), 1);
80 yfilter->process(pack);
81 BOOST_CHECK_EQUAL(pack.data(), 2);
91 BOOST_AUTO_UNIT_TEST( test_filter_factory_2 )
94 yp2::FactoryFilter ffactory;
96 const std::string id = "dl";
99 BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
102 BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
104 yp2::filter::Base* filter = 0;
105 filter = ffactory.create(id);
107 BOOST_CHECK(0 != filter);
110 filter->process(pack);
111 BOOST_CHECK_EQUAL(pack.data(), 42); // magic from filter_dl ..
124 * indent-tabs-mode: nil
125 * c-file-style: "stroustrup"
127 * vim: shiftwidth=4 tabstop=8 expandtab