1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2012 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 std::cout << "res=" << res << std::endl;
67 BOOST_CHECK(!res.compare("yes"));
69 res = mp_xml::url_recipe_handle(doc, "${has-fulltext[no]}");
70 std::cout << "res=" << res << std::endl;
71 BOOST_CHECK(!res.compare(""));
73 res = mp_xml::url_recipe_handle(doc, "${has-fulltext[no/]}");
74 std::cout << "res=" << res << std::endl;
75 BOOST_CHECK(!res.compare(""));
77 res = mp_xml::url_recipe_handle(doc, "${has-fulltext[n/]}");
78 std::cout << "res=" << res << std::endl;
79 BOOST_CHECK(!res.compare("o"));
81 res = mp_xml::url_recipe_handle(doc, "${has-fulltext}");
82 std::cout << "res=" << res << std::endl;
83 BOOST_CHECK(!res.compare("no"));
85 res = mp_xml::url_recipe_handle(
86 doc, "http://sever.com?title=${md-title[\\s+/+/g]}");
87 std::cout << "res=" << res << std::endl;
88 BOOST_CHECK(!res.compare("http://sever.com?title=How+to+program+a+computer"));
90 res = mp_xml::url_recipe_handle(doc, "${md-id[2/1]}");
91 std::cout << "res=" << res << std::endl;
92 BOOST_CHECK(!res.compare(" 11124466 "));
94 res = mp_xml::url_recipe_handle(doc, "${md-id[2/1/g]}");
95 std::cout << "res=" << res << std::endl;
96 BOOST_CHECK(!res.compare(" 11114466 "));
102 catch ( std::runtime_error &e) {
103 std::cout << "std::runtime error: " << e.what() << std::endl;
107 std::cout << "unknown exception" << std::endl;
116 * c-file-style: "Stroustrup"
117 * indent-tabs-mode: nil
119 * vim: shiftwidth=4 tabstop=8 expandtab