File: test_face_ptr_creation.cpp

package info (click to toggle)
mapnik 3.0.12%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,084 kB
  • ctags: 18,454
  • sloc: cpp: 142,516; python: 1,416; sh: 769; makefile: 170; xml: 140; lisp: 13
file content (69 lines) | stat: -rw-r--r-- 3,067 bytes parent folder | download | duplicates (4)
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
#include "bench_framework.hpp"
#include <mapnik/font_engine_freetype.hpp>
#include <boost/format.hpp>

class test : public benchmark::test_case
{
public:
    test(mapnik::parameters const& params)
     : test_case(params) {}
    bool validate() const
    {
        std::size_t count = 0;
        std::size_t expected_count = mapnik::freetype_engine::face_names().size();
        mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
        mapnik::freetype_engine::font_memory_cache_type font_cache;
        mapnik::font_library library;
        for (std::string const& name : mapnik::freetype_engine::face_names())
        {
            mapnik::face_ptr f = mapnik::freetype_engine::create_face(name,
                                                                      library,
                                                                      font_file_mapping,
                                                                      font_cache,
                                                                      mapnik::freetype_engine::get_mapping(),
                                                                      mapnik::freetype_engine::get_cache());
            if (f) ++count;
        }
        return count == expected_count;
    }
    bool operator()() const
    {
        std::size_t expected_count = mapnik::freetype_engine::face_names().size();
        for (unsigned i=0;i<iterations_;++i)
        {
            std::size_t count = 0;
            mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
            mapnik::freetype_engine::font_memory_cache_type font_cache;
            mapnik::font_library library;
            for (std::string const& name : mapnik::freetype_engine::face_names())
            {
                mapnik::face_ptr f = mapnik::freetype_engine::create_face(name,
                                                                          library,
                                                                          font_file_mapping,
                                                                          font_cache,
                                                                          mapnik::freetype_engine::get_mapping(),
                                                                          mapnik::freetype_engine::get_cache());
                if (f) ++count;
            }
            if (count != expected_count) {
                std::clog << "warning: face creation not working as expected\n";
            }
        }
        return true;
    }
};

int main(int argc, char** argv)
{
    mapnik::parameters params;
    benchmark::handle_args(argc,argv,params);
    bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
    if (!success) {
       std::clog << "warning, did not register any new fonts!\n";
       return -1;
    } 
    std::size_t face_count = mapnik::freetype_engine::face_names().size();
    test test_runner(params);
    return run(test_runner,(boost::format("font_engine: creating %ld faces") % (face_count)).str());
}