1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2013 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
23 #include <metaproxy/xmlutil.hpp>
25 #define BOOST_AUTO_TEST_MAIN
26 #define BOOST_TEST_DYN_LINK
27 #include <boost/test/auto_unit_test.hpp>
30 #include <yaz/otherinfo.h>
31 #include <yaz/oid_db.h>
33 using namespace boost::unit_test;
34 namespace mp = metaproxy_1;
35 namespace mp_xml = metaproxy_1::xml;
37 BOOST_AUTO_TEST_CASE( url_recipe )
41 const char *xml_text =
42 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
43 "<pz:record xmlns:pz=\"http://www.indexdata.com/pazpar2/1.0\""
44 " xmlns:tmarc=\"http://www.indexdata.com/turbomarc\">\n"
45 "<pz:metadata type=\"id\"> 11224466 </pz:metadata>\n"
46 "<pz:metadata type=\"oclc-number\"/>\n"
47 "<pz:metadata type=\"lccn\"> 11224466 </pz:metadata>\n"
48 "<pz:metadata type=\"author\">Jack Collins</pz:metadata>\n"
49 "<pz:metadata type=\"author-title\"/>\n"
50 "<pz:metadata type=\"author-date\"/>\n"
51 "<pz:metadata type=\"date\"/>\n"
52 "<pz:metadata type=\"title\">How to program a computer</pz:metadata>\n"
53 "<pz:metadata type=\"publication-place\">Penguin</pz:metadata>\n"
54 "<pz:metadata type=\"has-fulltext\">no</pz:metadata>\n"
56 xmlDoc *doc = xmlParseMemory(xml_text, strlen(xml_text));
62 res = mp_xml::url_recipe_handle(doc, "abc");
63 BOOST_CHECK(!res.compare("abc"));
65 res = mp_xml::url_recipe_handle(doc, "${has-fulltext[no/yes]}");
66 BOOST_CHECK(!res.compare("yes"));
68 res = mp_xml::url_recipe_handle(doc, "<${has-fulltext[no/yes]}>");
69 BOOST_CHECK(!res.compare("<yes>"));
71 res = mp_xml::url_recipe_handle(doc, "${has-fulltext[no]}");
72 BOOST_CHECK(!res.compare(""));
74 res = mp_xml::url_recipe_handle(doc, "${has-fulltext[no/]}");
75 BOOST_CHECK(!res.compare(""));
77 res = mp_xml::url_recipe_handle(doc, "${has-fulltext[n/]}");
78 BOOST_CHECK(!res.compare("o"));
80 res = mp_xml::url_recipe_handle(doc, "${has-fulltext}");
81 BOOST_CHECK(!res.compare("no"));
83 res = mp_xml::url_recipe_handle(doc, "%{has-fulltext}");
84 BOOST_CHECK(!res.compare("no"));
86 res = mp_xml::url_recipe_handle(
87 doc, "http://sever.com?title=${md-title[\\s+/+/g]}");
88 BOOST_CHECK(!res.compare("http://sever.com?title=How+to+program+a+computer"));
90 res = mp_xml::url_recipe_handle(
91 doc, "http://sever.com?title=%{md-title}");
92 BOOST_CHECK(!res.compare("http://sever.com?title=How%20to%20program%20a%20computer"));
95 res = mp_xml::url_recipe_handle(doc, "${md-id[2/1]}");
96 BOOST_CHECK(!res.compare(" 11124466 "));
98 res = mp_xml::url_recipe_handle(doc, "${md-id[2/1/g]}");
99 BOOST_CHECK(!res.compare(" 11114466 "));
104 catch ( std::runtime_error &e) {
105 std::cout << "std::runtime error: " << e.what() << std::endl;
109 std::cout << "unknown exception" << std::endl;
118 * c-file-style: "Stroustrup"
119 * indent-tabs-mode: nil
121 * vim: shiftwidth=4 tabstop=8 expandtab