add directory for C++ tests, and first C++ test against the font engine functions

This commit is contained in:
Dane Springmeyer 2010-07-15 23:09:33 +00:00
parent b4851dcb78
commit b0d568dff1
3 changed files with 100 additions and 0 deletions

View file

@ -1227,3 +1227,6 @@ if not HELP_REQUESTED:
# Configure fonts and if requested install the bundled DejaVu fonts # Configure fonts and if requested install the bundled DejaVu fonts
SConscript('fonts/SConscript') SConscript('fonts/SConscript')
# build C++ tests
SConscript('tests/cpp_tests/SConscript')

View file

@ -0,0 +1,20 @@
import os
import glob
Import ('env')
headers = env['CPPPATH']
boost_filesystem = 'boost_filesystem%s' % env['BOOST_APPEND']
boost_system = 'boost_system%s' % env['BOOST_APPEND']
libraries = [boost_system, boost_filesystem, 'mapnik2']
if env['PLATFORM'] == 'Darwin':
libraries.append(env['ICU_LIB_NAME'])
if env['HAS_BOOST_SYSTEM']:
libraries.append(boost_system)
for cpp_test in glob.glob('*_test.cpp'):
env.Program(cpp_test.replace('.cpp',''), [cpp_test], CPPPATH=headers, LIBS=libraries)

View file

@ -0,0 +1,77 @@
#include <boost/config/warning_disable.hpp>
#include <boost/filesystem/convenience.hpp>
namespace fs = boost::filesystem;
using fs::path;
namespace sys = boost::system;
#include <boost/detail/lightweight_test.hpp>
#include <boost/bind.hpp>
#include <fstream>
#include <iostream>
#include <mapnik/font_engine_freetype.hpp>
// --------------------------------------------------------------------------//
int main( int, char*[] )
{
// font registration() tests ----------------------------------------------//
std::string fontdir("fonts/");
BOOST_TEST( fs::exists( fontdir ) );
BOOST_TEST( fs::is_directory( fontdir ) );
std::vector<std::string> face_names;
std::string foo("foo");
// fake directories
BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo , true ) );
face_names = mapnik::freetype_engine::face_names();
BOOST_TEST( face_names.size() == 0 );
BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo) );
face_names = mapnik::freetype_engine::face_names();
BOOST_TEST( face_names.size() == 0 );
// directories without fonts
std::string src("src");
// a legitimate directory will return true even it is does not
// successfully register a font...
BOOST_TEST( mapnik::freetype_engine::register_fonts(src , true ) );
face_names = mapnik::freetype_engine::face_names();
BOOST_TEST( face_names.size() == 0 );
std::clog << "number of registered fonts: " << face_names.size() << std::endl;
// register unifont
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir) );
face_names = mapnik::freetype_engine::face_names();
std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() > 0 );
BOOST_TEST( face_names.size() == 1 );
// re-register unifont, should not have any affect
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, false) );
face_names = mapnik::freetype_engine::face_names();
std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 1 );
// register a single dejavu font
std::string dejavu_bold_oblique("tests/data/fonts/DejaVuSansMono-BoldOblique.ttf");
BOOST_TEST( mapnik::freetype_engine::register_font(dejavu_bold_oblique) );
face_names = mapnik::freetype_engine::face_names();
std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 2 );
// recurse to find all dejavu fonts
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, true) );
face_names = mapnik::freetype_engine::face_names();
std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 21 );
return ::boost::report_errors();
}