Windows: use Boost 1.59, msvc 14.0
[metaproxy-moved-to-github.git] / src / test_xmlutil.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) Index Data
3
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
7 version.
8
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
12 for more details.
13
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
17 */
18
19 #include "config.hpp"
20 #include <iostream>
21 #include <stdexcept>
22
23 #include <metaproxy/xmlutil.hpp>
24
25 #define BOOST_AUTO_TEST_MAIN
26 #define BOOST_TEST_DYN_LINK
27 #include <boost/test/auto_unit_test.hpp>
28
29 #include <yaz/zgdu.h>
30 #include <yaz/otherinfo.h>
31 #include <yaz/oid_db.h>
32
33 using namespace boost::unit_test;
34 namespace mp = metaproxy_1;
35 namespace mp_xml = metaproxy_1::xml;
36
37 BOOST_AUTO_TEST_CASE( url_recipe )
38 {
39     try
40     {
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"
55             "</pz:record>\n";
56         xmlDoc *doc = xmlParseMemory(xml_text, strlen(xml_text));
57         BOOST_CHECK(doc);
58         if (doc)
59         {
60             std::string res;
61
62             res = mp_xml::url_recipe_handle(doc, "abc");
63             BOOST_CHECK(!res.compare("abc"));
64
65             res = mp_xml::url_recipe_handle(doc, "${has-fulltext[no/yes]}");
66             BOOST_CHECK(!res.compare("yes"));
67
68             res = mp_xml::url_recipe_handle(doc, "<${has-fulltext[no/yes]}>");
69             BOOST_CHECK(!res.compare("<yes>"));
70
71             res = mp_xml::url_recipe_handle(doc, "${has-fulltext[no]}");
72             BOOST_CHECK(!res.compare(""));
73
74             res = mp_xml::url_recipe_handle(doc, "${has-fulltext[no/]}");
75             BOOST_CHECK(!res.compare(""));
76
77             res = mp_xml::url_recipe_handle(doc, "${has-fulltext[n/]}");
78             BOOST_CHECK(!res.compare("o"));
79
80             res = mp_xml::url_recipe_handle(doc, "${has-fulltext}");
81             BOOST_CHECK(!res.compare("no"));
82
83             res = mp_xml::url_recipe_handle(doc, "%{has-fulltext}");
84             BOOST_CHECK(!res.compare("no"));
85
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"));
89
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"));
93
94
95             res = mp_xml::url_recipe_handle(doc, "${md-id[2/1]}");
96             BOOST_CHECK(!res.compare("   11124466 "));
97
98             res = mp_xml::url_recipe_handle(doc, "${md-id[2/1/g]}");
99             BOOST_CHECK(!res.compare("   11114466 "));
100
101             xmlFreeDoc(doc);
102         }
103     }
104     catch ( std::runtime_error &e) {
105         std::cout << "std::runtime error: " << e.what() << std::endl;
106         BOOST_CHECK(false);
107     }
108     catch ( ... ) {
109         std::cout << "unknown exception" << std::endl;
110         BOOST_CHECK(false);
111     }
112 }
113
114
115 /*
116  * Local variables:
117  * c-basic-offset: 4
118  * c-file-style: "Stroustrup"
119  * indent-tabs-mode: nil
120  * End:
121  * vim: shiftwidth=4 tabstop=8 expandtab
122  */
123