Merge branch 'master' into spirit-x3
This commit is contained in:
commit
c5fc27920e
3 changed files with 43 additions and 5 deletions
|
@ -88,7 +88,7 @@ datasource_ptr datasource_cache::create(parameters const& params)
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
std::lock_guard<std::recursive_mutex> lock(instance_mutex_);
|
std::lock_guard<std::recursive_mutex> lock(instance_mutex_);
|
||||||
#endif
|
#endif
|
||||||
itr=plugins_.find(*type);
|
itr = plugins_.find(*type);
|
||||||
if (itr == plugins_.end())
|
if (itr == plugins_.end())
|
||||||
{
|
{
|
||||||
std::string s("Could not create datasource for type: '");
|
std::string s("Could not create datasource for type: '");
|
||||||
|
@ -105,7 +105,7 @@ datasource_ptr datasource_cache::create(parameters const& params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! itr->second->valid())
|
if (!itr->second->valid())
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string("Cannot load library: ") +
|
throw std::runtime_error(std::string("Cannot load library: ") +
|
||||||
itr->second->get_error());
|
itr->second->get_error());
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <mapnik/datasource_cache.hpp>
|
#include <mapnik/datasource_cache.hpp>
|
||||||
#include <mapnik/util/fs.hpp>
|
#include <mapnik/util/fs.hpp>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <fstream>
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#include <mapnik/warning_ignore.hpp>
|
#include <mapnik/warning_ignore.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
@ -57,6 +58,7 @@ std::size_t count_shapefile_features(std::string const& filename)
|
||||||
++feature_count;
|
++feature_count;
|
||||||
feature = features->next();
|
feature = features->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
return feature_count;
|
return feature_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,12 +86,49 @@ int create_shapefile_index(std::string const& filename, bool index_parts, bool s
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("invalid shapeindex")
|
||||||
|
{
|
||||||
|
std::string shape_plugin("./plugins/input/shape.input");
|
||||||
|
if (mapnik::util::exists(shape_plugin))
|
||||||
|
{
|
||||||
|
SECTION("Invalid index")
|
||||||
|
{
|
||||||
|
std::string path = "test/data/shp/boundaries.shp";
|
||||||
|
std::string index_path = path.substr(0, path.rfind(".")) + ".index";
|
||||||
|
// remove *.index if present
|
||||||
|
if (mapnik::util::exists(index_path))
|
||||||
|
{
|
||||||
|
mapnik::util::remove(index_path);
|
||||||
|
}
|
||||||
|
// count features
|
||||||
|
|
||||||
|
std::size_t feature_count = count_shapefile_features(path);
|
||||||
|
|
||||||
|
// create invalid index
|
||||||
|
std::ofstream index(index_path.c_str(), std::ios::binary);
|
||||||
|
std::string buf("mapnik-invalid-index.................");
|
||||||
|
index.write(buf.c_str(), buf.size());
|
||||||
|
index.close();
|
||||||
|
|
||||||
|
// count features
|
||||||
|
std::size_t feature_count_indexed = count_shapefile_features(path);
|
||||||
|
// ensure number of features are the same
|
||||||
|
REQUIRE(feature_count == feature_count_indexed);
|
||||||
|
// remove *.index if present
|
||||||
|
if (mapnik::util::exists(index_path))
|
||||||
|
{
|
||||||
|
mapnik::util::remove(index_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("shapeindex")
|
TEST_CASE("shapeindex")
|
||||||
{
|
{
|
||||||
std::string shape_plugin("./plugins/input/shape.input");
|
std::string shape_plugin("./plugins/input/shape.input");
|
||||||
if (mapnik::util::exists(shape_plugin))
|
if (mapnik::util::exists(shape_plugin))
|
||||||
{
|
{
|
||||||
SECTION("Shapefile index")
|
SECTION("Index")
|
||||||
{
|
{
|
||||||
for (auto const& path : mapnik::util::list_directory("test/data/shp/"))
|
for (auto const& path : mapnik::util::list_directory("test/data/shp/"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -255,8 +255,7 @@ int main (int argc,char** argv)
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
std::clog << " number shapes=" << count << std::endl;
|
std::clog << " number shapes=" << count << std::endl;
|
||||||
std::fstream file((shapename+".index").c_str(),
|
std::ofstream file((shapename+".index").c_str(), std::ios::trunc | std::ios::binary);
|
||||||
std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
|
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
std::clog << "cannot open index file for writing file \""
|
std::clog << "cannot open index file for writing file \""
|
||||||
|
|
Loading…
Reference in a new issue