<commit_before>#include <boost/version.hpp>
#include <boost/detail/lightweight_test.hpp>

#include <iostream>
#include <mapnik/map.hpp>
#include <mapnik/load_map.hpp>
#include <mapnik/agg_renderer.hpp>
#if defined(HAVE_CAIRO)
#include <mapnik/cairo_renderer.hpp>
#include <mapnik/cairo_context.hpp>
#endif
#include <mapnik/graphics.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/image_data.hpp>
#include <mapnik/image_reader.hpp>
#include <mapnik/scale_denominator.hpp>
#include <mapnik/feature_style_processor.hpp>
#include <boost/foreach.hpp>
#include <vector>
#include <algorithm>

bool compare_images(std::string const& src_fn,std::string const& dest_fn)
{
    using namespace mapnik;
    std::auto_ptr<mapnik::image_reader> reader1(mapnik::get_image_reader(dest_fn,"png"));
    if (!reader1.get())
    {
        throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
    }
    boost::shared_ptr<image_32> image_ptr1 = boost::make_shared<image_32>(reader1->width(),reader1->height());
    reader1->read(0,0,image_ptr1->data());

    std::auto_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(src_fn,"png"));
    if (!reader2.get())
    {
        throw mapnik::image_reader_exception("Failed to load: " + src_fn);
    }
    boost::shared_ptr<image_32> image_ptr2 = boost::make_shared<image_32>(reader2->width(),reader2->height());
    reader2->read(0,0,image_ptr2->data());

    image_data_32 const& dest = image_ptr1->data();
    image_data_32 const& src = image_ptr2->data();

    unsigned int width = src.width();
    unsigned int height = src.height();
    if ((width != dest.width()) || height != dest.height()) return false;
    for (unsigned int y = 0; y < height; ++y)
    {
        const unsigned int* row_from = src.getRow(y);
        const unsigned int* row_to = dest.getRow(y);
        for (unsigned int x = 0; x < width; ++x)
        {
            if (row_from[x] != row_to[x]) return false;
        }
    }
    return true;
}

int main(int argc, char** argv)
{
    std::vector<std::string> args;
    for (int i=1;i<argc;++i)
    {
        args.push_back(argv[i]);
    }
    bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();

    std::string expected("./tests/cpp_tests/support/map-request-marker-text-line-expected.png");
    std::string expected_cairo("./tests/cpp_tests/support/map-request-marker-text-line-expected-cairo.png");
    try {
        mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
        mapnik::freetype_engine::register_fonts("./fonts", true );
        mapnik::Map m(256,256);
        mapnik::load_map(m,"./tests/data/good_maps/marker-text-line.xml",false);
        m.zoom_all();
        mapnik::image_32 im(m.width(),m.height());
        double scale_factor = 1.2;

        // render normally with apply() and just map and image
        mapnik::agg_renderer<mapnik::image_32> renderer1(m,im,scale_factor);
        renderer1.apply();
        std::string actual1("/tmp/map-request-marker-text-line-actual1.png");
        //mapnik::save_to_file(im,expected);
        mapnik::save_to_file(im,actual1);
        BOOST_TEST(compare_images(actual1,expected));

        // reset image
        im.clear();

        // set up a mapnik::request object
        mapnik::request req(m.width(),m.height(),m.get_current_extent());
        req.set_buffer_size(m.buffer_size());

        // render using apply() and mapnik::request<commit_msg>set working dir of map_request.cpp<commit_after>#include <boost/version.hpp>
#include <boost/detail/lightweight_test.hpp>

#include <iostream>
#include <mapnik/map.hpp>
#include <mapnik/load_map.hpp>
#include <mapnik/agg_renderer.hpp>
#if defined(HAVE_CAIRO)
#include <mapnik/cairo_renderer.hpp>
#include <mapnik/cairo_context.hpp>
#endif
#include <mapnik/graphics.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/image_data.hpp>
#include <mapnik/image_reader.hpp>
#include <mapnik/scale_denominator.hpp>
#include <mapnik/feature_style_processor.hpp>
#include <boost/foreach.hpp>
#include <vector>
#include <algorithm>

#include "utils.hpp"

bool compare_images(std::string const& src_fn,std::string const& dest_fn)
{
    using namespace mapnik;
    std::auto_ptr<mapnik::image_reader> reader1(mapnik::get_image_reader(dest_fn,"png"));
    if (!reader1.get())
    {
        throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
    }
    boost::shared_ptr<image_32> image_ptr1 = boost::make_shared<image_32>(reader1->width(),reader1->height());
    reader1->read(0,0,image_ptr1->data());

    std::auto_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(src_fn,"png"));
    if (!reader2.get())
    {
        throw mapnik::image_reader_exception("Failed to load: " + src_fn);
    }
    boost::shared_ptr<image_32> image_ptr2 = boost::make_shared<image_32>(reader2->width(),reader2->height());
    reader2->read(0,0,image_ptr2->data());

    image_data_32 const& dest = image_ptr1->data();
    image_data_32 const& src = image_ptr2->data();

    unsigned int width = src.width();
    unsigned int height = src.height();
    if ((width != dest.width()) || height != dest.height()) return false;
    for (unsigned int y = 0; y < height; ++y)
    {
        const unsigned int* row_from = src.getRow(y);
        const unsigned int* row_to = dest.getRow(y);
        for (unsigned int x = 0; x < width; ++x)
        {
            if (row_from[x] != row_to[x]) return false;
        }
    }
    return true;
}

int main(int argc, char** argv)
{
    std::vector<std::string> args;
    for (int i=1;i<argc;++i)
    {
        args.push_back(argv[i]);
    }
    bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();

    std::string expected("./tests/cpp_tests/support/map-request-marker-text-line-expected.png");
    std::string expected_cairo("./tests/cpp_tests/support/map-request-marker-text-line-expected-cairo.png");
    try {

        BOOST_TEST(set_working_dir(args));

        mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
        mapnik::freetype_engine::register_fonts("./fonts", true );
        mapnik::Map m(256,256);
        mapnik::load_map(m,"./tests/data/good_maps/marker-text-line.xml",false);
        m.zoom_all();
        mapnik::image_32 im(m.width(),m.height());
        double scale_factor = 1.2;

        // render normally with apply() and just map and image
        mapnik::agg_renderer<mapnik::image_32> renderer1(m,im,scale_factor);
        renderer1.apply();
        std::string actual1("/tmp/map-request-marker-text-line-actual1.png");
        //mapnik::save_to_file(im,expected);
        mapnik::save_to_file(im,actual1);
        BOOST_TEST(compare_images(actual1,expected));

        // reset image
        im.clear();

        // set up a mapnik::request object
        mapnik::request req(m.width(),m.height(),m.get_current_extent());
        req.set_buffer_size(m.buffer_size());

        // render using apply() and mapnik::request
{'fraction_non_alphanumeric': 0.16232127838519764, 'fraction_numerical': 0.01485842444631343, 'mean_word_length': 3.8307379823967502, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4995149', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2423, 'n_words': 402}