Fix test cases.
This commit is contained in:
parent
51a50fdf92
commit
192495ce21
3 changed files with 40 additions and 25 deletions
|
@ -45,7 +45,7 @@ namespace mapnik { namespace svg {
|
|||
~svg_parser();
|
||||
void parse(std::string const& filename);
|
||||
void parse_from_string(std::string const& svg);
|
||||
template <typename T> void parse_from_stream(boost::iostreams::stream<T> const& svg_stream);
|
||||
template <typename T> void parse_from_stream(boost::iostreams::stream<T> &svg_stream);
|
||||
svg_converter_type & path_;
|
||||
bool is_defs_;
|
||||
std::map<std::string, gradient> gradient_map_;
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
|
||||
namespace mapnik { namespace svg {
|
||||
|
||||
bool parse_reader(svg_parser & parser,xmlTextReaderPtr reader);
|
||||
void process_node(svg_parser & parser,xmlTextReaderPtr reader);
|
||||
void start_element(svg_parser & parser,xmlTextReaderPtr reader);
|
||||
void end_element(svg_parser & parser,xmlTextReaderPtr reader);
|
||||
|
@ -1091,34 +1092,37 @@ void svg_parser::parse_from_string(std::string const& svg)
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int _xmlInputReadCallback(boost::iostreams::stream<T> * stream, char * buffer, int len) {
|
||||
stream->read(buffer,len);
|
||||
return stream->gcount();
|
||||
int _xmlInputReadCallback(void * stream, char * buffer, int len) {
|
||||
std::istream *s = reinterpret_cast<std::istream *>(stream);
|
||||
s->read(buffer,len);
|
||||
return s->gcount();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int _xmlInputCloseCallback(boost::iostreams::stream<T> * stream)
|
||||
int _xmlInputCloseCallback(void * stream)
|
||||
{
|
||||
if(stream->close())
|
||||
{
|
||||
boost::iostreams::stream<T> *s = reinterpret_cast<boost::iostreams::stream<T> *>(stream);
|
||||
try {
|
||||
s->close();
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void svg_parser::parse_from_stream(boost::iostreams::stream<T> const& svg_stream)
|
||||
void svg_parser::parse_from_stream(boost::iostreams::stream<T> &svg_stream)
|
||||
{
|
||||
xmlTextReaderPtr reader = xmlReaderForIO(_xmlInputReadCallback<T>,
|
||||
xmlTextReaderPtr reader = xmlReaderForIO(_xmlInputReadCallback,
|
||||
_xmlInputCloseCallback<T>,
|
||||
reinterpret_cast<const void *>(&svg_stream),
|
||||
reinterpret_cast<void *>(&svg_stream),
|
||||
nullptr,
|
||||
nullptr,
|
||||
(XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA | XML_PARSE_NOERROR | XML_PARSE_NOWARNING));
|
||||
if (reader == nullptr)
|
||||
{
|
||||
MAPNIK_LOG_ERROR(svg_parser) << "Unable to parse SVG";
|
||||
MAPNIK_LOG_ERROR(svg_parser) << "Unable to parse SVG XML";
|
||||
}
|
||||
else if (!parse_reader(*this,reader))
|
||||
{
|
||||
|
@ -1126,9 +1130,7 @@ void svg_parser::parse_from_stream(boost::iostreams::stream<T> const& svg_stream
|
|||
}
|
||||
}
|
||||
|
||||
template void svg_parser::parse_from_stream(boost::iostreams::stream<boost::iostreams::file_source> const& svg_stream);
|
||||
template void svg_parser::parse_from_stream(boost::iostreams::stream<boost::iostreams::array_source> const& svg_stream);
|
||||
|
||||
|
||||
template void svg_parser::parse_from_stream(boost::iostreams::stream<boost::iostreams::file_source> & svg_stream);
|
||||
template void svg_parser::parse_from_stream(boost::iostreams::stream<boost::iostreams::array_source> & svg_stream);
|
||||
|
||||
}}
|
||||
|
|
|
@ -26,19 +26,29 @@ SECTION("svg_invalid")
|
|||
{
|
||||
std::string imagedata = "<svg/svg>";
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(imagedata.c_str(), imagedata.length()));
|
||||
CHECK_FALSE(reader.get());
|
||||
CHECK(reader.get());
|
||||
unsigned width = reader->width();
|
||||
unsigned height = reader->height();
|
||||
|
||||
CHECK(width == 0);
|
||||
CHECK(height == 0);
|
||||
}
|
||||
|
||||
SECTION("svg_empty")
|
||||
{
|
||||
std::string imagedata = "<svg></svg>";
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(imagedata.c_str(), imagedata.length()));
|
||||
CHECK_FALSE(reader.get());
|
||||
CHECK(reader.get());
|
||||
unsigned width = reader->width();
|
||||
unsigned height = reader->height();
|
||||
|
||||
CHECK(width == 0);
|
||||
CHECK(height == 0);
|
||||
}
|
||||
|
||||
SECTION("svg_blank")
|
||||
{
|
||||
std::string imagedata = "<svg width='100' height='100'><g id='a'><ellipse fill='#FFFFFF' stroke='#000000' stroke-width='4' cx='50' cy='50' rx='25' ry='25'></g></svg>";
|
||||
std::string imagedata = "<svg width='100' height='100'><g id='a'><ellipse fill='#FFFFFF' stroke='#000000' stroke-width='4' cx='50' cy='50' rx='25' ry='25'/></g></svg>";
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(imagedata.c_str(), imagedata.length()));
|
||||
CHECK(reader.get());
|
||||
unsigned width = reader->width();
|
||||
|
@ -51,6 +61,9 @@ SECTION("svg_blank")
|
|||
|
||||
mapnik::image_rgba8 raw = im.get<mapnik::image_rgba8>();
|
||||
|
||||
std::string pngdata = mapnik::save_to_string<mapnik::image_rgba8>(raw,"png");
|
||||
CHECK(pngdata.length() == 1270 )
|
||||
|
||||
} // END SECTION
|
||||
|
||||
} // END TEST CASE
|
||||
|
|
Loading…
Reference in a new issue