enable passing working directory to cpp tests that hit the filesystem and expect files to be relative to the mapnik source folder

This commit is contained in:
Dane Springmeyer 2013-05-25 17:55:41 -07:00
parent 5184ef3e42
commit 3ff290ac07
3 changed files with 34 additions and 0 deletions

View file

@ -10,6 +10,8 @@ namespace sys = boost::system;
#include <vector>
#include <algorithm>
#include "utils.hpp"
int main(int argc, char** argv)
{
std::vector<std::string> args;
@ -21,6 +23,9 @@ int main(int argc, char** argv)
try
{
BOOST_TEST(set_working_dir(args));
std::string fontdir("fonts/");
BOOST_TEST( fs::exists( fontdir ) );

View file

@ -11,6 +11,8 @@ namespace sys = boost::system;
#include <vector>
#include <algorithm>
#include "utils.hpp"
int main(int argc, char** argv)
{
std::vector<std::string> args;
@ -24,6 +26,8 @@ int main(int argc, char** argv)
boost::optional<std::string> type;
try
{
BOOST_TEST(set_working_dir(args));
should_throw = "./tests/cpp_tests/data/blank.jpg";
BOOST_TEST( fs::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw);

25
tests/cpp_tests/utils.hpp Normal file
View file

@ -0,0 +1,25 @@
#include <vector>
#include <algorithm>
#include <string>
#include <boost/filesystem/convenience.hpp>
inline static bool set_working_dir(std::vector<std::string> args)
{
std::vector<std::string>::iterator itr = std::find(args.begin(), args.end(), "-d");
if (itr!=args.end())
{
int dist = std::distance(args.begin(),itr);
if (args.size() > dist+1)
{
std::string chdir = args.at(dist+1);
bool exists = boost::filesystem::exists( chdir );
if (exists)
{
boost::filesystem::current_path(chdir);
return true;
}
}
return false;
}
return true;
}