1 /* $Id: test_filter2.cpp,v 1.25 2008-02-20 15:07:53 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 #define BOOST_TEST_DYN_LINK
34 #include <boost/test/auto_unit_test.hpp>
36 using namespace boost::unit_test;
38 namespace mp = metaproxy_1;
40 class FilterConstant: public mp::filter::Base {
42 FilterConstant() : m_constant(1234) { };
43 void process(mp::Package & package) const {
46 void configure(const xmlNode* ptr, bool test_only);
47 int get_constant() const { return m_constant; };
54 void FilterConstant::configure(const xmlNode* ptr, bool test_only)
58 BOOST_CHECK_EQUAL (ptr->type, XML_ELEMENT_NODE);
59 BOOST_CHECK_EQUAL(std::string((const char *) ptr->name), "filter");
61 const struct _xmlAttr *attr;
63 for (attr = ptr->properties; attr; attr = attr->next)
65 BOOST_CHECK_EQUAL( std::string((const char *)attr->name), "type");
66 const xmlNode *val = attr->children;
67 BOOST_CHECK_EQUAL(val->type, XML_TEXT_NODE);
68 BOOST_CHECK_EQUAL(std::string((const char *)val->content), "constant");
70 const xmlNode *p = ptr->children;
71 for (; p; p = p->next)
73 if (p->type != XML_ELEMENT_NODE)
76 BOOST_CHECK_EQUAL (p->type, XML_ELEMENT_NODE);
77 BOOST_CHECK_EQUAL(std::string((const char *) p->name), "value");
79 const xmlNode *val = p->children;
84 BOOST_CHECK_EQUAL(val->type, XML_TEXT_NODE);
85 BOOST_CHECK_EQUAL(std::string((const char *)val->content), "2");
87 m_constant = atoi((const char *) val->content);
91 // This filter dose not have a configure function
93 class FilterDouble: public mp::filter::Base {
95 void process(mp::Package & package) const {
101 BOOST_AUTO_TEST_CASE( testfilter2_1 )
108 mp::RouterChain router1;
110 // test filter set/get/exception
117 mp::Package pack(session, origin);
119 pack.router(router1).move();
121 //BOOST_CHECK_EQUAL(pack.data(), 2468);
126 mp::RouterChain router2;
133 mp::Package pack(session, origin);
135 pack.router(router2).move();
137 //BOOST_CHECK_EQUAL(pack.data(), 1234);
142 catch (std::exception &e) {
143 std::cout << e.what() << "\n";
152 BOOST_AUTO_TEST_CASE( testfilter2_2 )
156 BOOST_CHECK_EQUAL(fc.get_constant(), 1234);
158 mp::filter::Base *base = &fc;
160 std::string some_xml = "<?xml version=\"1.0\"?>\n"
161 "<filter type=\"constant\">\n"
162 " <value>2</value>\n"
165 // std::cout << some_xml << std::endl;
167 xmlDocPtr doc = xmlParseMemory(some_xml.c_str(), some_xml.size());
173 xmlNodePtr root_element = xmlDocGetRootElement(doc);
175 base->configure(root_element, true);
180 BOOST_CHECK_EQUAL(fc.get_constant(), 2);
182 catch (std::exception &e) {
183 std::cout << e.what() << "\n";
195 * indent-tabs-mode: nil
196 * c-file-style: "stroustrup"
198 * vim: shiftwidth=4 tabstop=8 expandtab