1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2009 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
19 #include <libxml/parser.h>
20 #include <libxml/tree.h>
24 #include "router_chain.hpp"
25 #include "package.hpp"
29 #define BOOST_AUTO_TEST_MAIN
30 #define BOOST_TEST_DYN_LINK
31 #include <boost/test/auto_unit_test.hpp>
33 using namespace boost::unit_test;
35 namespace mp = metaproxy_1;
37 class FilterConstant: public mp::filter::Base {
39 FilterConstant() : m_constant(1234) { };
40 void process(mp::Package & package) const {
43 void configure(const xmlNode* ptr, bool test_only);
44 int get_constant() const { return m_constant; };
51 void FilterConstant::configure(const xmlNode* ptr, bool test_only)
55 BOOST_CHECK_EQUAL (ptr->type, XML_ELEMENT_NODE);
56 BOOST_CHECK_EQUAL(std::string((const char *) ptr->name), "filter");
58 const struct _xmlAttr *attr;
60 for (attr = ptr->properties; attr; attr = attr->next)
62 BOOST_CHECK_EQUAL( std::string((const char *)attr->name), "type");
63 const xmlNode *val = attr->children;
64 BOOST_CHECK_EQUAL(val->type, XML_TEXT_NODE);
65 BOOST_CHECK_EQUAL(std::string((const char *)val->content), "constant");
67 const xmlNode *p = ptr->children;
68 for (; p; p = p->next)
70 if (p->type != XML_ELEMENT_NODE)
73 BOOST_CHECK_EQUAL (p->type, XML_ELEMENT_NODE);
74 BOOST_CHECK_EQUAL(std::string((const char *) p->name), "value");
76 const xmlNode *val = p->children;
81 BOOST_CHECK_EQUAL(val->type, XML_TEXT_NODE);
82 BOOST_CHECK_EQUAL(std::string((const char *)val->content), "2");
84 m_constant = atoi((const char *) val->content);
88 // This filter dose not have a configure function
90 class FilterDouble: public mp::filter::Base {
92 void process(mp::Package & package) const {
98 BOOST_AUTO_TEST_CASE( testfilter2_1 )
105 mp::RouterChain router1;
107 // test filter set/get/exception
114 mp::Package pack(session, origin);
116 pack.router(router1).move();
118 //BOOST_CHECK_EQUAL(pack.data(), 2468);
123 mp::RouterChain router2;
130 mp::Package pack(session, origin);
132 pack.router(router2).move();
134 //BOOST_CHECK_EQUAL(pack.data(), 1234);
139 catch (std::exception &e) {
140 std::cout << e.what() << "\n";
149 BOOST_AUTO_TEST_CASE( testfilter2_2 )
153 BOOST_CHECK_EQUAL(fc.get_constant(), 1234);
155 mp::filter::Base *base = &fc;
157 std::string some_xml = "<?xml version=\"1.0\"?>\n"
158 "<filter type=\"constant\">\n"
159 " <value>2</value>\n"
162 // std::cout << some_xml << std::endl;
164 xmlDocPtr doc = xmlParseMemory(some_xml.c_str(), some_xml.size());
170 xmlNodePtr root_element = xmlDocGetRootElement(doc);
172 base->configure(root_element, true);
177 BOOST_CHECK_EQUAL(fc.get_constant(), 2);
179 catch (std::exception &e) {
180 std::cout << e.what() << "\n";
192 * c-file-style: "Stroustrup"
193 * indent-tabs-mode: nil
195 * vim: shiftwidth=4 tabstop=8 expandtab