1 /* $Id: test_filter2.cpp,v 1.23 2007-05-09 21:23:09 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 This file is part of Metaproxy.
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include <libxml/parser.h>
23 #include <libxml/tree.h>
27 #include "router_chain.hpp"
28 #include "package.hpp"
32 #define BOOST_AUTO_TEST_MAIN
33 #include <boost/test/auto_unit_test.hpp>
35 using namespace boost::unit_test;
37 namespace mp = metaproxy_1;
39 class FilterConstant: public mp::filter::Base {
41 FilterConstant() : m_constant(1234) { };
42 void process(mp::Package & package) const {
45 void configure(const xmlNode* ptr = 0);
46 int get_constant() const { return m_constant; };
53 void FilterConstant::configure(const xmlNode* ptr)
57 BOOST_CHECK_EQUAL (ptr->type, XML_ELEMENT_NODE);
58 BOOST_CHECK_EQUAL(std::string((const char *) ptr->name), "filter");
60 const struct _xmlAttr *attr;
62 for (attr = ptr->properties; attr; attr = attr->next)
64 BOOST_CHECK_EQUAL( std::string((const char *)attr->name), "type");
65 const xmlNode *val = attr->children;
66 BOOST_CHECK_EQUAL(val->type, XML_TEXT_NODE);
67 BOOST_CHECK_EQUAL(std::string((const char *)val->content), "constant");
69 const xmlNode *p = ptr->children;
70 for (; p; p = p->next)
72 if (p->type != XML_ELEMENT_NODE)
75 BOOST_CHECK_EQUAL (p->type, XML_ELEMENT_NODE);
76 BOOST_CHECK_EQUAL(std::string((const char *) p->name), "value");
78 const xmlNode *val = p->children;
83 BOOST_CHECK_EQUAL(val->type, XML_TEXT_NODE);
84 BOOST_CHECK_EQUAL(std::string((const char *)val->content), "2");
86 m_constant = atoi((const char *) val->content);
90 // This filter dose not have a configure function
92 class FilterDouble: public mp::filter::Base {
94 void process(mp::Package & package) const {
100 BOOST_AUTO_UNIT_TEST( testfilter2_1 )
107 mp::RouterChain router1;
109 // test filter set/get/exception
116 mp::Package pack(session, origin);
118 pack.router(router1).move();
120 //BOOST_CHECK_EQUAL(pack.data(), 2468);
125 mp::RouterChain router2;
132 mp::Package pack(session, origin);
134 pack.router(router2).move();
136 //BOOST_CHECK_EQUAL(pack.data(), 1234);
141 catch (std::exception &e) {
142 std::cout << e.what() << "\n";
151 BOOST_AUTO_UNIT_TEST( testfilter2_2 )
155 BOOST_CHECK_EQUAL(fc.get_constant(), 1234);
157 mp::filter::Base *base = &fc;
159 std::string some_xml = "<?xml version=\"1.0\"?>\n"
160 "<filter type=\"constant\">\n"
161 " <value>2</value>\n"
164 // std::cout << some_xml << std::endl;
166 xmlDocPtr doc = xmlParseMemory(some_xml.c_str(), some_xml.size());
172 xmlNodePtr root_element = xmlDocGetRootElement(doc);
174 base->configure(root_element);
179 BOOST_CHECK_EQUAL(fc.get_constant(), 2);
181 catch (std::exception &e) {
182 std::cout << e.what() << "\n";
194 * indent-tabs-mode: nil
195 * c-file-style: "stroustrup"
197 * vim: shiftwidth=4 tabstop=8 expandtab