diff --git a/SConstruct b/SConstruct index add1131ad..c23c5300b 100644 --- a/SConstruct +++ b/SConstruct @@ -1227,3 +1227,6 @@ if not HELP_REQUESTED: # Configure fonts and if requested install the bundled DejaVu fonts SConscript('fonts/SConscript') + + # build C++ tests + SConscript('tests/cpp_tests/SConscript') diff --git a/tests/cpp_tests/SConscript b/tests/cpp_tests/SConscript new file mode 100644 index 000000000..ab38ed4eb --- /dev/null +++ b/tests/cpp_tests/SConscript @@ -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) diff --git a/tests/cpp_tests/font_registration_test.cpp b/tests/cpp_tests/font_registration_test.cpp new file mode 100644 index 000000000..072c4dc30 --- /dev/null +++ b/tests/cpp_tests/font_registration_test.cpp @@ -0,0 +1,77 @@ +#include + +#include +namespace fs = boost::filesystem; +using fs::path; +namespace sys = boost::system; + +#include +#include +#include +#include +#include + + +// --------------------------------------------------------------------------// + +int main( int, char*[] ) +{ + + +// font registration() tests ----------------------------------------------// + + std::string fontdir("fonts/"); + + BOOST_TEST( fs::exists( fontdir ) ); + BOOST_TEST( fs::is_directory( fontdir ) ); + + std::vector 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(); +}