/* * These tests are of limited usefulness. In fact, you might even say that * they're not really tests at all. But I felt that it would be useful to have * some basic usage of most functions just to verify that things compile and * work generally */ #include #include #include #include #include using namespace boost::unit_test; #include #include #include #include #include #ifdef CAIRO_HAS_WIN32_FONT #include #include #endif // CAIRO_HAS_WIN32_FONT // Converts an enum class variable to int. template inline int to_int(T e) { return static_cast(e); } BOOST_AUTO_TEST_SUITE( Cairo_FontFace ) BOOST_AUTO_TEST_CASE(test_create_toy) { auto toy = Cairo::ToyFontFace::create("sans", Cairo::ToyFontFace::Slant::ITALIC, Cairo::ToyFontFace::Weight::NORMAL); BOOST_CHECK (toy); BOOST_CHECK_EQUAL (CAIRO_STATUS_SUCCESS, toy->get_status()); } BOOST_AUTO_TEST_CASE(test_toy_getters) { auto toy = Cairo::ToyFontFace::create("sans", Cairo::ToyFontFace::Slant::ITALIC, Cairo::ToyFontFace::Weight::NORMAL); BOOST_CHECK_EQUAL ("sans", toy->get_family()); BOOST_CHECK_EQUAL (to_int(Cairo::ToyFontFace::Slant::ITALIC), to_int(toy->get_slant())); BOOST_CHECK_EQUAL (to_int(Cairo::ToyFontFace::Weight::NORMAL), to_int(toy->get_weight())); BOOST_CHECK_EQUAL (Cairo::FONT_TYPE_TOY, toy->get_type()); } #if defined (CAIRO_HAS_FT_FONT) && defined (CAIRO_HAS_FC_FONT) BOOST_AUTO_TEST_CASE(test_ft_font_face) { // Does not throw an exception. Skip this test for now. /Kjell Ahlstedt 2020-04-21 //auto invalid = FcPatternCreate(); //Cairo::RefPtr invalid_face; //BOOST_CHECK_THROW(invalid_face = Cairo::FtFontFace::create(invalid), std::bad_alloc); // basically taken from the cairo test case -- we don't care what font we're // using so just create an empty pattern and do the minimal substitution to // get a valid pattern auto pattern = FcPatternCreate(); FcConfigSubstitute (nullptr, pattern, FcMatchPattern); FcDefaultSubstitute (pattern); FcResult result; auto resolved = FcFontMatch (nullptr, pattern, &result); auto face = Cairo::FtFontFace::create(resolved); BOOST_CHECK(face); // FIXME: test creating from a FT_Face } #endif // CAIRO_HAS_FT_FONT && CAIRO_HAS_FC_FONT #ifdef CAIRO_HAS_WIN32_FONT BOOST_AUTO_TEST_CASE(test_win32_font_face) { LOGFONTW lf; lf.lfHeight = 10; lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = FW_NORMAL; lf.lfItalic = FALSE; lf.lfUnderline = FALSE; lf.lfStrikeOut = FALSE; lf.lfCharSet = ANSI_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH; wcscpy(lf.lfFaceName, L"Courier New"); Cairo::RefPtr fc(Cairo::Win32FontFace::create(&lf)); BOOST_CHECK(fc); Cairo::RefPtr sfc(Cairo::ImageSurface::create(Cairo::Surface::Format::RGB24, 100, 100)); Cairo::RefPtr cr(Cairo::Context::create(sfc)); cr->translate(0.0, 50.0); cr->set_source_rgb(1.0, 1.0, 1.0); BOOST_CHECK_NO_THROW(cr->set_font_face(fc)); BOOST_CHECK_NO_THROW(cr->show_text("Hello, World!")); } #endif // CAIRO_HAS_WIN32_FONT BOOST_AUTO_TEST_SUITE_END()