Go to the documentation of this file.00001 #include <boost/test/unit_test.hpp>
00002 #include "../xmlparse/xmlparse.h"
00003 #include <iostream>
00004 #include "../util.h"
00005
00006 BOOST_AUTO_TEST_SUITE(xml)
00007
00008 BOOST_AUTO_TEST_CASE(basic)
00009 {
00010 std::string input(" <osm version=\"adsf\"> <node id=\"1234556\" lat=\"34.252\" lon=\"21.512\"> <tag k=\"key\" v=\"val\" /> </node>");
00011 input += "<node id=\"35312\" lat=\"234\" lon=\"23\" />";
00012 input += "<way id=\"5432\"><nd ref=\"555\" /><tag k=\"wkey\" v=\"wval\" /> </way>";
00013 input += "<relation id=\"1253\"> <member type=\"node\" ref=\"2521\" role=\"role\" />";
00014 input += "<member type=\"way\" ref=\"2522\" role=\"role\" />";
00015 input += "<member type=\"relation\" ref=\"2523\" role=\"role\" /> <tag k=\"rkey\" v=\"rval\" /> </relation></osm>";
00016 osmxml::XmlParser p;
00017 std::vector<osm::Node> correctn;
00018 osm::Node n1(1234556, 34.252, 21.512);
00019 n1.tags.insert(osm::Tag("key", "val"));
00020 correctn.push_back(n1);
00021 n1 = osm::Node(35312, 234, 23);
00022 correctn.push_back(n1);
00023 std::vector<osm::Way> correctw;
00024 osm::Way w1(5432);
00025 w1.tags.insert(osm::Tag("wkey", "wval"));
00026 w1.nodes.push_back(555);
00027 correctw.push_back(w1);
00028 std::vector<osm::Relation> correctr;
00029 osm::Relation r1(1253);
00030 r1.tags.insert(osm::Tag("rkey", "rval"));
00031 r1.add_node("role", osm::Node(2521));
00032 r1.add_way("role", osm::Way(2522));
00033 r1.add_rel("role", osm::Relation(2523));
00034 correctr.push_back(r1);
00035 std::vector<osm::Node> nodes;
00036 std::vector<osm::Way> ways;
00037 std::vector<osm::Relation> rels;
00038 p.node_handler = [&nodes](osm::Node const & nd)
00039 {
00040 nodes.push_back(nd);
00041 };
00042 p.way_handler = [&ways](osm::Way const & w)
00043 {
00044 ways.push_back(w);
00045 };
00046 p.relation_handler = [&rels](osm::Relation const & r)
00047 {
00048 rels.push_back(r);
00049 };
00050 try
00051 {
00052 p.parse_memory(input);
00053 BOOST_CHECK(correctn == nodes);
00054 BOOST_CHECK(correctw == ways);
00055 BOOST_CHECK(correctr == rels);
00056 }
00057 catch (xml_schema::parsing& e)
00058 {
00059 BOOST_CHECK_MESSAGE(false, util::to_str(e));
00060 }
00061
00062 }
00063
00064 BOOST_AUTO_TEST_CASE(isthrowing)
00065 {
00066 osmxml::XmlParser p;
00067 try
00068 {
00069 p.parse_memory("<assdf></asdf>");
00070 }
00071 catch (std::exception& ex)
00072 {
00073 return;
00074 }
00075 BOOST_ERROR("Expected parsing exception");
00076
00077 }
00078
00079 BOOST_AUTO_TEST_SUITE_END()