File: xml_parser_trim.cpp

package info (click to toggle)
mapnik 4.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 18,548 kB
  • sloc: cpp: 163,861; python: 1,190; sh: 690; xml: 161; makefile: 123; perl: 28; lisp: 13
file content (43 lines) | stat: -rw-r--r-- 1,656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#include "catch.hpp"

#include <mapnik/xml_tree.hpp>
#include <mapnik/xml_loader.hpp>
#include <mapnik/attribute.hpp> // needed due to fwd declare in value_types.hpp

TEST_CASE("xml parser")
{
    SECTION("trims whitespace")
    {
        // simple and non-valid mapnik XML reduced from the empty_parameter2.xml
        // test case. this is to check that the xml parsing routine is trimming
        // whitespace from text nodes as part of the parsing operation.
        std::string const xml("<Map>"
                              "  <Layer>"
                              "    <Datasource>"
                              "      <Parameter name=\"empty\"><![CDATA[ ]]></Parameter>"
                              "    </Datasource>"
                              "  </Layer>"
                              "</Map>");

        mapnik::xml_tree tree;
        tree.set_filename("xml_datasource_parameter_trim.cpp");
        REQUIRE_NOTHROW(read_xml_string(xml, tree.root(), ""));

        REQUIRE(tree.root().has_child("Map"));
        mapnik::xml_node const& map = tree.root().get_child("Map");

        REQUIRE(map.has_child("Layer"));
        mapnik::xml_node const& layer = map.get_child("Layer");

        REQUIRE(layer.has_child("Datasource"));
        mapnik::xml_node const& datasource = layer.get_child("Datasource");

        REQUIRE(datasource.has_child("Parameter"));
        mapnik::xml_node const& parameter = datasource.get_child("Parameter");

        // parser should call mapnik::util::trim on the text content and
        // this should result in an empty text string in the parameter.
        REQUIRE(parameter.get_text() == "");
    }
}