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(); try { BOOST_TEST(set_working_dir(args)); // create a renderable map with a fontset and a text symbolizer // and do not register any fonts, to ensure the error thrown is reasonable mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>(); ctx->push("name"); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1)); mapnik::transcoder tr("utf-8"); UnicodeString ustr = tr.transcode("hello world!"); feature->put("name",ustr); mapnik::geometry_type * pt = new mapnik::geometry_type(mapnik::Point); pt->move_to(128,128); feature->add_geometry(pt); mapnik::datasource_ptr memory_ds = boost::make_shared<mapnik::memory_datasource>(); mapnik::memory_datasource *cache = dynamic_cast<mapnik::memory_datasource *>(memory_ds.get()); cache->push(feature); mapnik::Map m(256,256); mapnik::font_set fontset("fontset"); // NOTE: this is a valid font, but will fail because none are registered fontset.add_face_name("DejaVu Sans Book"); m.insert_fontset("fontset", fontset); mapnik::layer lyr("myLayerName"); lyr.set_datasource(memory_ds); lyr.add_style("style"); m.addLayer(lyr); mapnik::feature_type_style the_style; mapnik::rule the_rule; mapnik::text_symbolizer text_sym(mapnik::parse_expression("[name]"),10,mapnik::color(0,0,0)); text_sym.set_fontset(fontset); the_rule.append(text_sym); the_style.add_rule(the_rule); m.insert_style("style",the_style ); m.zoom_to_box(mapnik::box2d<double>(-256,-256, 256,256)); mapnik::image_32 buf(m.width(),m.height()); mapnik::agg_renderer<mapnik::image_32> ren(m,buf); ren.apply(); } catch (std::exception const& ex) { BOOST_TEST_EQ(std::string(ex.what()),std::string("myLayerName: No valid font face could be loaded for font set: 'fontset'")); } if (!::boost::detail::test_errors()) { if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; else std::clog << "C++ fontset runtime: \x1b[1;32m✓ \x1b[0m\n"; #if BOOST_VERSION >= 104600 ::boost::detail::report_errors_remind().called_report_errors_function = true; #endif } else { return ::boost::report_errors(); } }
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(); try { BOOST_TEST(set_working_dir(args)); std::string filename("tests/cpp_tests/data/cases.txt"); std::ifstream stream(filename.c_str(),std::ios_base::in | std::ios_base::binary); if (!stream.is_open()) throw std::runtime_error("could not open: '" + filename + "'"); std::string csv_line; while(std::getline(stream,csv_line,'\n')) { if (csv_line.empty() || csv_line[0] == '#') continue; std::vector<std::string> parts; boost::split(parts, csv_line, boost::is_any_of(";")); // first part is clipping box mapnik::box2d<double> bbox; if (!bbox.from_string(parts[0])) { throw std::runtime_error(std::string("could not parse bbox '") + parts[0] + "'"); } // second part is input geometry mapnik::geometry_type geom; parse_geom(geom,parts[1]); //std::clog << dump_path(geom) << "\n"; // third part is expected, clipped geometry BOOST_TEST_EQ(clip_line(bbox,geom),mapnik::util::trim_copy(parts[2])); } stream.close(); } catch (std::exception const& ex) { std::cerr << ex.what() << "\n"; } if (!::boost::detail::test_errors()) { if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; else std::clog << "C++ clipping: \x1b[1;32m✓ \x1b[0m\n"; ::boost::detail::report_errors_remind().called_report_errors_function = true; } else { return ::boost::report_errors(); } }
BOOL CMcviewDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) { // TODO: Add your message handler code here and/or call default mcview_ext_cmd_t * cmd; cmd = (mcview_ext_cmd_t * )pCopyDataStruct->lpData; if(pCopyDataStruct->cbData == sizeof(*cmd)){ set_working_dir(cmd->projDir); theApp.m_path = cmd->projDir; theView.LoadFile(cmd->fileName); } return CDialog::OnCopyData(pWnd, pCopyDataStruct); }
static void _setupProxy() { char path[_MAX_PATH]; GetModuleFileName(_Module.m_hInst, path, sizeof(path)); extract_file_path(path); set_working_dir(path); init_proxy( 0, PROXY_SILENT | PROXY_ENABLE_BGLOADER | PROXY_ENABLE_DISPATCHER ); initHisProxy(); extern void hookEvents(); hookEvents(); }
int main(int argc, char **argv) { int o; printf("\nCSF[%d] starting...\n", (int)getpid()); realpath(argv[0], exec_path); if (set_working_dir(exec_path) != 0) { PRINT("Can not set the working directory."); return (2); } set_conf_file(CONF_FILE); while(-1 != (o = getopt(argc, argv, "f:hv"))) { switch(o) { case 'f': set_conf_file(optarg); break; case 'v': output_config(); return 0; case 'h': show_help(); return 0; default: break; } } /* init each modules */ if (csf_init() < 0) { PRINT("CSF init failed. Exited."); return (2); } set_signals(); save_pid(argv[0]); /* starts the server */ server_init(&main_conf); WLOG_ERR("Fatal Error, SERVER DOWN!"); logger_deinit(); PRINT("Fatal Error, SERVER DOWN!"); return (2); }
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(); try { BOOST_TEST(set_working_dir(args)); // create a renderable map with a fontset and a text symbolizer // and do not register any fonts, to ensure the error thrown is reasonable mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>(); ctx->push("name"); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1)); mapnik::transcoder tr("utf-8"); mapnik::value_unicode_string ustr = tr.transcode("hello world!"); feature->put("name",ustr); auto pt = std::make_unique<mapnik::geometry_type>(mapnik::geometry_type::types::Point); pt->move_to(128,128); feature->add_geometry(pt.release()); mapnik::parameters params; params["type"]="memory"; auto ds = std::make_shared<mapnik::memory_datasource>(params); ds->push(feature); mapnik::Map m(256,256); mapnik::font_set fontset("fontset"); // NOTE: this is a valid font, but will fail because none are registered fontset.add_face_name("DejaVu Sans Book"); m.insert_fontset("fontset", fontset); mapnik::layer lyr("layer"); lyr.set_datasource(ds); lyr.add_style("style"); m.add_layer(lyr); mapnik::feature_type_style the_style; mapnik::rule r; mapnik::text_symbolizer text_sym; mapnik::text_placements_ptr placement_finder = std::make_shared<mapnik::text_placements_dummy>(); placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book"; placement_finder->defaults.format_defaults.text_size = 10.0; placement_finder->defaults.format_defaults.fill = mapnik::color(0,0,0); placement_finder->defaults.format_defaults.fontset = fontset; placement_finder->defaults.set_format_tree(std::make_shared<mapnik::formatting::text_node>(mapnik::parse_expression("[name]"))); mapnik::put<mapnik::text_placements_ptr>(text_sym, mapnik::keys::text_placements_, placement_finder); r.append(std::move(text_sym)); the_style.add_rule(std::move(r)); m.insert_style("style", std::move(the_style) ); m.zoom_to_box(mapnik::box2d<double>(-256,-256, 256,256)); mapnik::image_rgba8 buf(m.width(),m.height()); mapnik::agg_renderer<mapnik::image_rgba8> ren(m,buf); ren.apply(); } catch (std::exception const& ex) { BOOST_TEST_EQ(std::string(ex.what()),std::string("Unable to find specified font face 'DejaVu Sans Book' in font set: 'fontset'")); } u_cleanup(); if (!::boost::detail::test_errors()) { if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; else std::clog << "C++ fontset runtime: \x1b[1;32m✓ \x1b[0m\n"; ::boost::detail::report_errors_remind().called_report_errors_function = true; } else { return ::boost::report_errors(); } }
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 should_throw; boost::optional<std::string> type; try { BOOST_TEST(set_working_dir(args)); #if defined(HAVE_JPEG) should_throw = "./tests/cpp_tests/data/blank.jpg"; BOOST_TEST( mapnik::util::exists( should_throw ) ); type = mapnik::type_from_filename(should_throw); BOOST_TEST( type ); try { std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)); BOOST_TEST( false ); } catch (std::exception const&) { BOOST_TEST( true ); } #endif #if defined(HAVE_PNG) should_throw = "./tests/cpp_tests/data/blank.png"; BOOST_TEST( mapnik::util::exists( should_throw ) ); type = mapnik::type_from_filename(should_throw); BOOST_TEST( type ); try { std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)); BOOST_TEST( false ); } catch (std::exception const&) { BOOST_TEST( true ); } should_throw = "./tests/data/images/xcode-CgBI.png"; BOOST_TEST( mapnik::util::exists( should_throw ) ); type = mapnik::type_from_filename(should_throw); BOOST_TEST( type ); try { std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)); BOOST_TEST( false ); } catch (std::exception const&) { BOOST_TEST( true ); } #endif #if defined(HAVE_TIFF) should_throw = "./tests/cpp_tests/data/blank.tiff"; BOOST_TEST( mapnik::util::exists( should_throw ) ); type = mapnik::type_from_filename(should_throw); BOOST_TEST( type ); try { std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)); BOOST_TEST( false ); } catch (std::exception const&) { BOOST_TEST( true ); } #endif #if defined(HAVE_WEBP) should_throw = "./tests/cpp_tests/data/blank.webp"; BOOST_TEST( mapnik::util::exists( should_throw ) ); type = mapnik::type_from_filename(should_throw); BOOST_TEST( type ); try { std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)); BOOST_TEST( false ); } catch (std::exception const&) { BOOST_TEST( true ); } #endif } catch (std::exception const & ex) { std::clog << "C++ image i/o problem: " << ex.what() << "\n"; BOOST_TEST(false); } if (!::boost::detail::test_errors()) { if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; else std::clog << "C++ image i/o: \x1b[1;32m✓ \x1b[0m\n"; #if BOOST_VERSION >= 104600 ::boost::detail::report_errors_remind().called_report_errors_function = true; #endif } else { return ::boost::report_errors(); } }
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(); try { BOOST_TEST(set_working_dir(args)); mapnik::projection srs("foo"); // to avoid unused variable warning srs.params(); BOOST_TEST(false); } catch (...) { BOOST_TEST(true); } mapnik::Map map(256,256); mapnik::rule r; r.set_filter(mapnik::parse_expression("[foo]='bar'")); r.append(mapnik::markers_symbolizer()); mapnik::feature_type_style style; style.add_rule(r); map.insert_style("style",style); std::string csv_plugin("./plugins/input/csv.input"); if (mapnik::util::exists(csv_plugin)) { try { mapnik::datasource_cache::instance().register_datasource(csv_plugin); mapnik::parameters p; p["type"]="csv"; p["inline"]="x,y\n0,0"; mapnik::datasource_ptr ds = mapnik::datasource_cache::instance().create(p); mapnik::layer l("layer"); l.set_datasource(ds); l.add_style("style"); mapnik::Map m = map; m.addLayer(l); m.zoom_all(); mapnik::image_32 im(m.width(),m.height()); mapnik::agg_renderer<mapnik::image_32> ren(m,im); //std::clog << mapnik::save_map_to_string(m) << "\n"; BOOST_TEST(true); // should throw here with "CSV Plugin: no attribute 'foo'. Valid attributes are: x,y." ren.apply(); BOOST_TEST(false); } catch (...) { BOOST_TEST(true); } } std::string shape_plugin("./plugins/input/shape.input"); if (mapnik::util::exists(shape_plugin)) { try { mapnik::datasource_cache::instance().register_datasource(shape_plugin); mapnik::parameters p2; p2["type"]="shape"; p2["file"]="foo"; mapnik::datasource_cache::instance().create(p2); BOOST_TEST(false); } catch (...) { BOOST_TEST(true); } } if (!::boost::detail::test_errors()) { if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; else std::clog << "C++ exceptions: \x1b[1;32m✓ \x1b[0m\n"; #if BOOST_VERSION >= 104600 ::boost::detail::report_errors_remind().called_report_errors_function = true; #endif } else { return ::boost::report_errors(); } }
int main(int argc, char *argv[]) { float *data; float *dest; unsigned char *data_ub; /* ubyte data */ int w, h, n; /* with, height, n-components*/ int i, size; set_working_dir(argv); /* read and convert image */ { float uctof = 1.0f / 255.0f; /* read */ data_ub = stbi_load(ABS_TOP_SRCDIR "/examples/image/dataset/lena.tga", &w, &h, &n, 0); if (! data_ub) { printf("unable to read image\n"); return EXIT_FAILURE; } /* allocate memory */ size = w * h; data = malloc(size * sizeof(float)); dest = malloc(size * sizeof(float)); /* convert to float */ if (n == 1) /* already greyscale */ for (i = 0; i < size; i++) data[i] = (float)data_ub[i] * uctof; else if(n >= 3) /* convert to greyscale */ for (i = 0; i < size; i++) data[i] = (data_ub[i*n]*0.2f + data_ub[i*n + 1]*0.7f + data_ub[i*n + 2]*0.1f) * uctof; } /* gaussian */ { p_gauss3x3_f32(data, dest, h, w); float_to_ubyte(data_ub, dest, size); stbi_write_tga("../dataset/lena_gaussian.tga", w, h, 1, data_ub); } /* harris */ { float *tmp = malloc(size * 3 * sizeof(float)); p_harris3x3_f32(data, dest, tmp, h, w); free(tmp); float_to_ubyte(data_ub, dest, size); stbi_write_tga("../dataset/lena_harris.tga", w-4, h-4, 1, data_ub); } /* sobel */ { p_sobel3x3_f32(data, dest, h, w); float_to_ubyte(data_ub, dest, size); stbi_write_tga("../dataset/lena_sobel.tga", w, h, 1, data_ub); } /* scharr */ { p_scharr3x3_f32(data, dest, h, w); float_to_ubyte(data_ub, dest, size); stbi_write_tga("../dataset/lena_scharr.tga", w, h, 1, data_ub); } /* prewitt */ { p_prewitt3x3_f32(data, dest, h, w); float_to_ubyte(data_ub, dest, size); stbi_write_tga("../dataset/lena_prewitt.tga", w, h, 1, data_ub); } /* box */ { p_box3x3_f32(data, dest, h, w); float_to_ubyte(data_ub, dest, size); stbi_write_tga("../dataset/lena_box.tga", w-2, h-2, 1, data_ub); } /* median */ { p_median3x3_f32(data, dest, h, w); float_to_ubyte(data_ub, dest, size); stbi_write_tga("../dataset/lena_median.tga", w-2, h-2, 1, data_ub); } free(dest); free(data); stbi_image_free(data_ub); return EXIT_SUCCESS; }
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(); try { BOOST_TEST(set_working_dir(args)); std::string fontdir("fonts/"); BOOST_TEST( mapnik::util::exists( fontdir ) ); BOOST_TEST( mapnik::util::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"); // an empty directory will not return true // we need to register at least one font and not fail on any // to return true BOOST_TEST( mapnik::freetype_engine::register_font(src) == false ); BOOST_TEST( mapnik::freetype_engine::register_fonts(src, true) == false ); BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 ); // bogus, emtpy file that looks like font BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/fake.ttf") == false ); BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/fake.ttf") == false ); BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 ); BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/intentionally-broken.ttf") == false ); BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/intentionally-broken.ttf") == false ); BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 ); // register unifont, since we know it sits in the root fonts/ dir 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() == 22 ); } catch (std::exception const & ex) { std::clog << "C++ fonts registration problem: " << ex.what() << "\n"; BOOST_TEST(false); } if (!::boost::detail::test_errors()) { if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; else std::clog << "C++ fonts registration: \x1b[1;32m✓ \x1b[0m\n"; #if BOOST_VERSION >= 104600 ::boost::detail::report_errors_remind().called_report_errors_function = true; #endif } else { return ::boost::report_errors(); } }