Blame tests/test-font-face.cc

Packit 908522
// vim: ts=2 sw=2 et
Packit 908522
/*
Packit 908522
 * These tests are of limited usefulness.  In fact, you might even say that
Packit 908522
 * they're not really tests at all.  But I felt that it would be useful to have
Packit 908522
 * some basic usage of most functions just to verify that things compile and
Packit 908522
 * work generally
Packit 908522
 */
Packit 908522
Packit 908522
#include <cfloat>
Packit 908522
#include <stdexcept>
Packit 908522
#include <boost/test/unit_test.hpp>
Packit 908522
#include <boost/test/test_tools.hpp>
Packit 908522
#include <boost/test/floating_point_comparison.hpp>
Packit 908522
using namespace boost::unit_test;
Packit 908522
#include <cairomm/fontface.h>
Packit 908522
#include <cairomm/scaledfont.h>
Packit 908522
#include <cairomm/surface.h>
Packit 908522
#include <cairomm/context.h>
Packit 908522
Packit 908522
#include <cairo-features.h>
Packit 908522
#ifdef CAIRO_HAS_WIN32_FONT
Packit 908522
#include <windows.h>
Packit 908522
#include <cairomm/win32_font.h>
Packit 908522
#endif // CAIRO_HAS_WIN32_FONT
Packit 908522
Packit 908522
void
Packit 908522
test_create_toy ()
Packit 908522
{
Packit 908522
  auto toy =
Packit 908522
    Cairo::ToyFontFace::create("sans",
Packit 908522
                               Cairo::FONT_SLANT_ITALIC,
Packit 908522
                               Cairo::FONT_WEIGHT_NORMAL);
Packit 908522
  BOOST_CHECK (toy);
Packit 908522
  BOOST_CHECK_EQUAL (CAIRO_STATUS_SUCCESS, toy->get_status());
Packit 908522
}
Packit 908522
Packit 908522
void test_toy_getters ()
Packit 908522
{
Packit 908522
  auto toy =
Packit 908522
    Cairo::ToyFontFace::create("sans",
Packit 908522
                               Cairo::FONT_SLANT_ITALIC,
Packit 908522
                               Cairo::FONT_WEIGHT_NORMAL);
Packit 908522
  BOOST_CHECK_EQUAL ("sans", toy->get_family());
Packit 908522
  BOOST_CHECK_EQUAL (Cairo::FONT_SLANT_ITALIC, toy->get_slant());
Packit 908522
  BOOST_CHECK_EQUAL (Cairo::FONT_WEIGHT_NORMAL, toy->get_weight());
Packit 908522
  BOOST_CHECK_EQUAL (Cairo::FONT_TYPE_TOY, toy->get_type());
Packit 908522
}
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_FT_FONT
Packit 908522
void test_ft_font_face()
Packit 908522
{
Packit 908522
  auto invalid = FcPatternCreate();
Packit 908522
  Cairo::RefPtr<Cairo::FtFontFace> invalid_face;
Packit 908522
  BOOST_CHECK_THROW(invalid_face = Cairo::FtFontFace::create(invalid), std::bad_alloc);
Packit 908522
Packit 908522
  // basically taken from the cairo test case -- we don't care what font we're
Packit 908522
  // using so just create an empty pattern and do the minimal substitution to
Packit 908522
  // get a valid pattern
Packit 908522
  auto pattern = FcPatternCreate();
Packit 908522
  FcConfigSubstitute (NULL, pattern, FcMatchPattern);
Packit 908522
  FcDefaultSubstitute (pattern);
Packit 908522
  FcResult result;
Packit 908522
  auto resolved = FcFontMatch (NULL, pattern, &result);
Packit 908522
  auto face = Cairo::FtFontFace::create(resolved);
Packit 908522
  BOOST_CHECK(face);
Packit 908522
Packit 908522
  // FIXME: test creating from a FT_Face
Packit 908522
}
Packit 908522
#endif // CAIRO_HAS_FT_FONT
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_WIN32_FONT
Packit 908522
void test_win32_font_face()
Packit 908522
{
Packit 908522
  LOGFONTW lf;
Packit 908522
  lf.lfHeight = 10;
Packit 908522
  lf.lfWidth = 0;
Packit 908522
  lf.lfEscapement = 0;
Packit 908522
  lf.lfOrientation = 0;
Packit 908522
  lf.lfWeight = FW_NORMAL;
Packit 908522
  lf.lfItalic = FALSE;
Packit 908522
  lf.lfUnderline = FALSE;
Packit 908522
  lf.lfStrikeOut = FALSE;
Packit 908522
  lf.lfCharSet = ANSI_CHARSET;
Packit 908522
  lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
Packit 908522
  lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
Packit 908522
  lf.lfQuality = DEFAULT_QUALITY;
Packit 908522
  lf.lfPitchAndFamily = DEFAULT_PITCH;
Packit 908522
  wcscpy(lf.lfFaceName, L"Courier New");
Packit 908522
Packit 908522
  Cairo::RefPtr<Cairo::Win32FontFace> fc(Cairo::Win32FontFace::create(&lf);;
Packit 908522
  BOOST_CHECK(fc);
Packit 908522
  Cairo::RefPtr<Cairo::ImageSurface> sfc(Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, 100, 100));
Packit 908522
  Cairo::RefPtr<Cairo::Context> cr(Cairo::Context::create(sfc));
Packit 908522
  cr->translate(0.0, 50.0);
Packit 908522
  cr->set_source_rgb(1.0, 1.0, 1.0);
Packit 908522
  BOOST_CHECK_NO_THROW(cr->set_font_face(fc));
Packit 908522
  BOOST_CHECK_NO_THROW(cr->show_text("Hello, World!"));
Packit 908522
}
Packit 908522
#endif // CAIRO_HAS_WIN32_FONT
Packit 908522
Packit 908522
Packit 908522
test_suite*
Packit 908522
init_unit_test_suite(int argc, char* argv[])
Packit 908522
{
Packit 908522
  // compile even with -Werror
Packit 908522
  if (argc && argv) {}
Packit 908522
Packit 908522
  test_suite* test= BOOST_TEST_SUITE( "Cairo::FontFace Tests" );
Packit 908522
Packit 908522
  test->add (BOOST_TEST_CASE (&test_create_toy));
Packit 908522
  test->add (BOOST_TEST_CASE (&test_toy_getters));
Packit 908522
#ifdef CAIRO_HAS_FT_FONT
Packit 908522
  test->add (BOOST_TEST_CASE (&test_ft_font_face));
Packit 908522
#endif // CAIRO_HAS_FT_FONT
Packit 908522
#ifdef CAIRO_HAS_WIN32_FONT
Packit 908522
  test->add (BOOST_TEST_CASE (&test_win32_font_face));
Packit 908522
#endif // CAIRO_HAS_WIN32_FONT
Packit 908522
Packit 908522
  return test;
Packit 908522
}