File: font_registration_test.cpp

package info (click to toggle)
mapnik 2.0.0%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 35,496 kB
  • sloc: cpp: 91,793; python: 6,051; xml: 3,528; sh: 848; makefile: 70; lisp: 10
file content (77 lines) | stat: -rw-r--r-- 2,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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();
}