Add memory_datasource test + fix returning of invalid_featureset for emptyset

This commit is contained in:
Dane Springmeyer 2016-09-02 15:09:45 -07:00
parent 73715afdb8
commit fa44f0e247
2 changed files with 54 additions and 0 deletions

View file

@ -117,12 +117,20 @@ datasource::datasource_t memory_datasource::type() const
featureset_ptr memory_datasource::features(const query& q) const featureset_ptr memory_datasource::features(const query& q) const
{ {
if (features_.empty())
{
return mapnik::make_invalid_featureset();
}
return std::make_shared<memory_featureset>(q.get_bbox(),*this,bbox_check_); return std::make_shared<memory_featureset>(q.get_bbox(),*this,bbox_check_);
} }
featureset_ptr memory_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr memory_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (features_.empty())
{
return mapnik::make_invalid_featureset();
}
box2d<double> box = box2d<double>(pt.x, pt.y, pt.x, pt.y); box2d<double> box = box2d<double>(pt.x, pt.y, pt.x, pt.y);
box.pad(tol); box.pad(tol);
MAPNIK_LOG_DEBUG(memory_datasource) << "memory_datasource: Box=" << box << ", Point x=" << pt.x << ",y=" << pt.y; MAPNIK_LOG_DEBUG(memory_datasource) << "memory_datasource: Box=" << box << ", Point x=" << pt.x << ",y=" << pt.y;

View file

@ -0,0 +1,46 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#include "catch.hpp"
#include "ds_test_util.hpp"
#include <mapnik/unicode.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/memory_datasource.hpp>
#include <mapnik/datasource_cache.hpp>
TEST_CASE("memory datasource") {
SECTION("empty featureset")
{
mapnik::parameters params;
mapnik::datasource_ptr ds = std::make_shared<mapnik::memory_datasource>(params);
CHECK(ds != nullptr);
auto fs = all_features(ds);
REQUIRE(!mapnik::is_valid(fs));
while (auto f = fs->next())
{
CHECK(false); // shouldn't get here
}
}
}