summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@gnome.org>2007-03-24 03:05:33 +0000
committerJonathon Jongsma <jjongsma@gnome.org>2007-03-24 03:05:33 +0000
commit2d59e18935e5ea28814cc522c431c0caabe3cd84 (patch)
tree0e203313c1fb867c10c5b70bac5f793d5b2ce517
parentea07f5b2076a75ac15e9b3f99c4f8285a857c0d1 (diff)
2007-03-23 Jonathon Jongsma <jjongsma@gnome.org>
* Makefile.am: * autogen.sh: * configure.in: * m4/ax_boost_base.m4: * m4/ax_boost_unit_test_framework.m4: Add some basic test infrastructure. It's disabled by default, and must be explicitly enabled by passing --enable-tests to configure (or by setting the CAIROMM_DEVEL environment variable to "on"). It uses the boost unit test framework, but this should not be required unless you've explicitly enabled tests. If tests are enabled, you can easily run them with 'make check' * tests/Makefile.am: * tests/test-context.cc: added the beginning of a test for Cairo::Context. Most of these tests are really very interesting. Basically what I'm trying to do is a) test some basic behaviors, and b) excercise the functionality a little bit. One of the tests currently fails due to a RefPtr::cast_dynamic failure, so I have to see what's going on there.
-rw-r--r--ChangeLog19
-rw-r--r--Makefile.am3
-rwxr-xr-xautogen.sh5
-rw-r--r--configure.in23
-rw-r--r--m4/ax_boost_base.m4198
-rw-r--r--m4/ax_boost_unit_test_framework.m4138
-rw-r--r--tests/Makefile.am19
-rw-r--r--tests/test-context.cc256
8 files changed, 657 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index d880c9a..a0f71c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2007-03-23 Jonathon Jongsma <jjongsma@gnome.org>
+
+ * Makefile.am:
+ * autogen.sh:
+ * configure.in:
+ * m4/ax_boost_base.m4:
+ * m4/ax_boost_unit_test_framework.m4: Add some basic test infrastructure.
+ It's disabled by default, and must be explicitly enabled by passing
+ --enable-tests to configure (or by setting the CAIROMM_DEVEL environment
+ variable to "on"). It uses the boost unit test framework, but this should
+ not be required unless you've explicitly enabled tests. If tests are
+ enabled, you can easily run them with 'make check'
+ * tests/Makefile.am:
+ * tests/test-context.cc: added the beginning of a test for Cairo::Context.
+ Most of these tests are really very interesting. Basically what I'm trying
+ to do is a) test some basic behaviors, and b) excercise the functionality a
+ little bit. One of the tests currently fails due to a RefPtr::cast_dynamic
+ failure, so I have to see what's going on there.
+
2007-03-22 Murray Cumming <murrayc@murrayc@murrayc.com>
* cairomm/enums.h: Restored FORMAT_RGB16_565 and marked it as deprecated.
diff --git a/Makefile.am b/Makefile.am
index 9387b03..3fc2fd5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,8 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = cairomm examples MSVC $(DOCS_SUBDIR)
+SUBDIRS = cairomm examples MSVC $(DOCS_SUBDIR) tests
#docs examples
+ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = MAINTAINERS cairomm-1.0.pc.in
diff --git a/autogen.sh b/autogen.sh
index 83c25b2..0652978 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,7 +1,7 @@
#! /bin/sh
set -e
-# $Id: autogen.sh,v 1.3 2006-03-13 01:43:04 jjongsma Exp $
+# $Id: autogen.sh,v 1.4 2007-03-24 03:05:33 jjongsma Exp $
#
# Copyright (c) 2002 Daniel Elstner <daniel.elstner@gmx.net>
#
@@ -35,6 +35,7 @@ LIBTOOLIZE=${LIBTOOLIZE:-libtoolize}
AUTOCONF=${AUTOCONF:-autoconf}
AUTOMAKE=${AUTOMAKE:-automake}
+ACLOCAL_FLAGS="-I m4"
ACLOCAL=`echo $AUTOMAKE | sed s/automake/aclocal/`
rm -f config.cache acconfig.h
@@ -44,7 +45,7 @@ do_cmd() {
$@
}
-do_cmd $ACLOCAL
+do_cmd $ACLOCAL $ACLOCAL_FLAGS
do_cmd $LIBTOOLIZE --force
do_cmd $AUTOCONF
do_cmd $AUTOMAKE --add-missing --gnu
diff --git a/configure.in b/configure.in
index 2a55412..f0d935d 100644
--- a/configure.in
+++ b/configure.in
@@ -28,7 +28,6 @@ AC_SUBST(GENERIC_LIBRARY_VERSION)
VERSION=$GENERIC_VERSION
-
AM_INIT_AUTOMAKE(cairomm, $GENERIC_VERSION)
AC_PROG_CXX
@@ -103,6 +102,26 @@ AC_CHECK_HEADERS(string list map, , exit)
PKG_CHECK_MODULES(CAIROMM, cairo >= 1.3.10)
+AC_ARG_ENABLE(tests,
+ AC_HELP_STRING([--enable-tests=yes|no],
+ [enable automated tests (default is no)]),
+ ENABLE_TESTS=$enableval,
+ ENABLE_TESTS=no)
+if test x$CAIROMM_DEVEL = xon ; then
+ ENABLE_TESTS=yes
+fi
+
+if test x$ENABLE_TESTS = xyes ; then
+AX_BOOST_BASE([1.33.1])
+AX_BOOST_UNIT_TEST_FRAMEWORK
+AC_MSG_NOTICE(support of automated tests enabled)
+else
+ AC_MSG_NOTICE(disabled support of automated tests)
+fi
+AM_CONDITIONAL(AUTOTESTS, test x$ENABLE_TESTS = xyes)
+
+
+
dnl Check whether to build the documentation directory
DOCS_SUBDIR="" dnl set DOCS_SUBDIR initially blank
@@ -143,6 +162,8 @@ AC_CONFIG_FILES(
examples/svg-surface/Makefile
examples/text-rotate/Makefile
+ tests/Makefile
+
cairomm-1.0.pc
)
diff --git a/m4/ax_boost_base.m4 b/m4/ax_boost_base.m4
new file mode 100644
index 0000000..575a51e
--- /dev/null
+++ b/m4/ax_boost_base.m4
@@ -0,0 +1,198 @@
+##### http://autoconf-archive.cryp.to/ax_boost_base.html
+#
+# SYNOPSIS
+#
+# AX_BOOST_BASE([MINIMUM-VERSION])
+#
+# DESCRIPTION
+#
+# Test for the Boost C++ libraries of a particular version (or newer)
+#
+# If no path to the installed boost library is given the macro
+# searchs under /usr, /usr/local, and /opt, and evaluates the
+# $BOOST_ROOT environment variable. Further documentation is
+# available at <http://randspringer.de/boost/index.html>.
+#
+# This macro calls:
+#
+# AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
+#
+# And sets:
+#
+# HAVE_BOOST
+#
+# LAST MODIFICATION
+#
+# 2006-12-28
+#
+# COPYLEFT
+#
+# Copyright (c) 2006 Thomas Porschberg <thomas@randspringer.de>
+#
+# Copying and distribution of this file, with or without
+# modification, are permitted in any medium without royalty provided
+# the copyright notice and this notice are preserved.
+
+AC_DEFUN([AX_BOOST_BASE],
+[
+AC_ARG_WITH([boost],
+ AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is No) - it is possible to specify the root directory for boost (optional)]),
+ [
+ if test "$withval" = "no"; then
+ want_boost="no"
+ elif test "$withval" = "yes"; then
+ want_boost="yes"
+ ac_boost_path=""
+ else
+ want_boost="yes"
+ ac_boost_path="$withval"
+ fi
+ ],
+ [want_boost="yes"])
+
+if test "x$want_boost" = "xyes"; then
+ boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
+ boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
+ boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
+ boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
+ boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+ if test "x$boost_lib_version_req_sub_minor" = "x" ; then
+ boost_lib_version_req_sub_minor="0"
+ fi
+ WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
+ AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
+ succeeded=no
+
+ dnl first we check the system location for boost libraries
+ dnl this location ist chosen if boost libraries are installed with the --layout=system option
+ dnl or if you install boost with RPM
+ if test "$ac_boost_path" != ""; then
+ BOOST_LDFLAGS="-L$ac_boost_path/lib"
+ BOOST_CPPFLAGS="-I$ac_boost_path/include"
+ else
+ for ac_boost_path_tmp in /usr /usr/local /opt ; do
+ if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
+ BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
+ BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
+ break;
+ fi
+ done
+ fi
+
+ CPPFLAGS_SAVED="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+
+ LDFLAGS_SAVED="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ AC_LANG_PUSH(C++)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ @%:@include <boost/version.hpp>
+ ]], [[
+ #if BOOST_VERSION >= $WANT_BOOST_VERSION
+ // Everything is okay
+ #else
+ # error Boost version is too old
+ #endif
+ ]])],[
+ AC_MSG_RESULT(yes)
+ succeeded=yes
+ found_system=yes
+ ],[
+ ])
+ AC_LANG_POP([C++])
+
+
+
+ dnl if we found no boost with system layout we search for boost libraries
+ dnl built and installed without the --layout=system option or for a staged(not installed) version
+ if test "x$succeeded" != "xyes"; then
+ _version=0
+ if test "$ac_boost_path" != ""; then
+ BOOST_LDFLAGS="-L$ac_boost_path/lib"
+ if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
+ for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
+ _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
+ V_CHECK=`expr $_version_tmp \> $_version`
+ if test "$V_CHECK" = "1" ; then
+ _version=$_version_tmp
+ fi
+ VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
+ BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
+ done
+ fi
+ else
+ for ac_boost_path in /usr /usr/local /opt ; do
+ if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
+ for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
+ _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
+ V_CHECK=`expr $_version_tmp \> $_version`
+ if test "$V_CHECK" = "1" ; then
+ _version=$_version_tmp
+ best_path=$ac_boost_path
+ fi
+ done
+ fi
+ done
+
+ VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
+ BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
+ BOOST_LDFLAGS="-L$best_path/lib"
+
+ if test "x$BOOST_ROOT" != "x"; then
+ if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then
+ version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
+ stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
+ stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
+ V_CHECK=`expr $stage_version_shorten \>\= $_version`
+ if test "$V_CHECK" = "1" ; then
+ AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
+ BOOST_CPPFLAGS="-I$BOOST_ROOT"
+ BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
+ fi
+ fi
+ fi
+ fi
+
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ AC_LANG_PUSH(C++)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ @%:@include <boost/version.hpp>
+ ]], [[
+ #if BOOST_VERSION >= $WANT_BOOST_VERSION
+ // Everything is okay
+ #else
+ # error Boost version is too old
+ #endif
+ ]])],[
+ AC_MSG_RESULT(yes)
+ succeeded=yes
+ found_system=yes
+ ],[
+ ])
+ AC_LANG_POP([C++])
+ fi
+
+ if test "$succeeded" != "yes" ; then
+ if test "$_version" = "0" ; then
+ AC_MSG_ERROR([[We could not detect the boost libraries (version $boost_lib_version_req_shorten or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.]])
+ else
+ AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
+ fi
+ else
+ AC_SUBST(BOOST_CPPFLAGS)
+ AC_SUBST(BOOST_LDFLAGS)
+ AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
+ fi
+
+ CPPFLAGS="$CPPFLAGS_SAVED"
+ LDFLAGS="$LDFLAGS_SAVED"
+fi
+
+])
diff --git a/m4/ax_boost_unit_test_framework.m4 b/m4/ax_boost_unit_test_framework.m4
new file mode 100644
index 0000000..11e5d8d
--- /dev/null
+++ b/m4/ax_boost_unit_test_framework.m4
@@ -0,0 +1,138 @@
+##### http://autoconf-archive.cryp.to/ax_boost_unit_test_framework.html
+#
+# SYNOPSIS
+#
+# AX_BOOST_UNIT_TEST_FRAMEWORK
+#
+# DESCRIPTION
+#
+# Test for Unit_Test_Framework library from the Boost C++ libraries.
+# The macro requires a preceding call to AX_BOOST_BASE. Further
+# documentation is available at
+# <http://randspringer.de/boost/index.html>.
+#
+# This macro calls:
+#
+# AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
+#
+# And sets:
+#
+# HAVE_BOOST_UNIT_TEST_FRAMEWORK
+#
+# LAST MODIFICATION
+#
+# 2006-12-28
+#
+# COPYLEFT
+#
+# Copyright (c) 2006 Thomas Porschberg <thomas@randspringer.de>
+#
+# Copying and distribution of this file, with or without
+# modification, are permitted in any medium without royalty provided
+# the copyright notice and this notice are preserved.
+
+AC_DEFUN([AX_BOOST_UNIT_TEST_FRAMEWORK],
+[
+ AC_ARG_WITH([boost-unit-test-framework],
+ AS_HELP_STRING([--with-boost-unit-test-framework@<:@=special-lib@:>@],
+ [use the Unit_Test_Framework library from boost - it is possible to specify a certain library for the linker
+ e.g. --with-boost-unit-test-framework=boost_unit_test_framework-gcc ]),
+ [
+ if test "$withval" = "no"; then
+ want_boost="no"
+ elif test "$withval" = "yes"; then
+ want_boost="yes"
+ ax_boost_user_unit_test_framework_lib=""
+ else
+ want_boost="yes"
+ ax_boost_user_unit_test_framework_lib="$withval"
+ fi
+ ],
+ [want_boost="yes"]
+ )
+
+ if test "x$want_boost" = "xyes"; then
+ AC_REQUIRE([AC_PROG_CC])
+ CPPFLAGS_SAVED="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+
+ LDFLAGS_SAVED="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ AC_CACHE_CHECK(whether the Boost::Unit_Test_Framework library is available,
+ ax_cv_boost_unit_test_framework,
+ [AC_LANG_PUSH([C++])
+ AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/test/unit_test.hpp>]],
+ [[using boost::unit_test::test_suite;
+ test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" ); return 0;]]),
+ ax_cv_boost_unit_test_framework=yes, ax_cv_boost_unit_test_framework=no)
+ AC_LANG_POP([C++])
+ ])
+ if test "x$ax_cv_boost_unit_test_framework" = "xyes"; then
+ AC_DEFINE(HAVE_BOOST_UNIT_TEST_FRAMEWORK,,[define if the Boost::Unit_Test_Framework library is available])
+ BN=boost_unit_test_framework
+ if test "x$ax_boost_user_unit_test_framework_lib" = "x"; then
+ saved_ldflags="${LDFLAGS}"
+ for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
+ lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
+ $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
+ LDFLAGS="${LDFLAGS} -l$ax_lib"
+ AC_CACHE_CHECK(Boost::UnitTestFramework library linkage,
+ ax_cv_boost_unit_test_framework_link,
+ [AC_LANG_PUSH([C++])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/test/unit_test.hpp>
+ using boost::unit_test::test_suite;
+ test_suite* init_unit_test_suite( int argc, char * argv[] ) {
+ test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" );
+ return test;
+ }
+ ]],
+ [[ return 0;]])],
+ link_unit_test_framework="yes",link_unit_test_framework="no")
+ AC_LANG_POP([C++])
+ ])
+ LDFLAGS="${saved_ldflags}"
+
+ if test "x$link_unit_test_framework" = "xyes"; then
+ BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
+ AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
+ break
+ fi
+ done
+ else
+ saved_ldflags="${LDFLAGS}"
+ for ax_lib in $ax_boost_user_unit_test_framework_lib $BN-$ax_boost_user_unit_test_framework_lib; do
+ LDFLAGS="${LDFLAGS} -l$ax_lib"
+ AC_CACHE_CHECK(Boost::UnitTestFramework library linkage,
+ ax_cv_boost_unit_test_framework_link,
+ [AC_LANG_PUSH([C++])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/test/unit_test.hpp>
+ using boost::unit_test::test_suite;
+ test_suite* init_unit_test_suite( int argc, char * argv[] ) {
+ test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" );
+ return test;
+ }
+ ]],
+ [[ return 0;]])],
+ link_unit_test_framework="yes",link_unit_test_framework="no")
+ AC_LANG_POP([C++])
+ ])
+ LDFLAGS="${saved_ldflags}"
+ if test "x$link_unit_test_framework" = "xyes"; then
+ BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
+ AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
+ break
+ fi
+ done
+ fi
+ if test "x$link_unit_test_framework" = "xno"; then
+ AC_MSG_ERROR(Could not link against $ax_lib !)
+ fi
+ fi
+
+ CPPFLAGS="$CPPFLAGS_SAVED"
+ LDFLAGS="$LDFLAGS_SAVED"
+ fi
+])
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..366ccfe
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,19 @@
+if AUTOTESTS
+
+# build automated 'tests'
+noinst_PROGRAMS = test-context
+test_context_SOURCES=test-context.cc
+TESTS=test-context
+
+else
+
+#don't build anything
+TESTS=
+
+endif
+
+#Where to find the header files needed by the source files:
+INCLUDES = -I$(top_srcdir) @CAIROMM_CFLAGS@
+
+#The libraries that the executable needs to link against:
+LIBS = $(top_builddir)/cairomm/libcairomm-1.0.la @LIBS@ @CAIROMM_LIBS@ @BOOST_UNIT_TEST_FRAMEWORK_LIB@
diff --git a/tests/test-context.cc b/tests/test-context.cc
new file mode 100644
index 0000000..bd0ce2a
--- /dev/null
+++ b/tests/test-context.cc
@@ -0,0 +1,256 @@
+// vim: ts=2 sw=2 et
+/*
+ * 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 <boost/test/unit_test.hpp>
+#include <boost/test/test_tools.hpp>
+using namespace boost::unit_test;
+#include <cairomm/context.h>
+
+#define CREATE_CONTEXT(varname) \
+ Cairo::RefPtr<Cairo::Surface> surf = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 10, 10); \
+ Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surf);
+
+void
+test_dashes ()
+{
+ CREATE_CONTEXT(cr);
+ std::valarray<double> dash_array(4);
+ dash_array[0] = 0.1;
+ dash_array[1] = 0.2;
+ dash_array[2] = 0.04;
+ dash_array[3] = 0.31;
+ cr->set_dash(dash_array, 0.54);
+
+ std::vector<double> get_array;
+ double get_offset;
+ cr->get_dash (get_array, get_offset);
+ BOOST_CHECK (get_array[0] == dash_array[0]);
+ BOOST_CHECK (get_array[1] == dash_array[1]);
+ BOOST_CHECK (get_array[2] == dash_array[2]);
+ BOOST_CHECK (get_array[3] == dash_array[3]);
+ BOOST_CHECK (get_offset == 0.54);
+
+ cr->unset_dash ();
+ cr->get_dash (get_array, get_offset);
+ BOOST_CHECK (get_array.empty ());
+}
+
+void
+test_save_restore ()
+{
+ CREATE_CONTEXT(cr);
+ cr->set_line_width (1.0);
+ cr->save ();
+ cr->set_line_width (4.0);
+ BOOST_CHECK (cr->get_line_width () == 4.0);
+ cr->restore ();
+ BOOST_CHECK (cr->get_line_width () == 1.0);
+}
+
+void
+test_operator ()
+{
+ CREATE_CONTEXT(cr);
+ cr->set_operator (Cairo::OPERATOR_ATOP);
+ BOOST_CHECK (cr->get_operator () == Cairo::OPERATOR_ATOP);
+ cr->set_operator (Cairo::OPERATOR_CLEAR);
+ BOOST_CHECK (cr->get_operator () == Cairo::OPERATOR_CLEAR);
+}
+
+void
+test_source ()
+{
+ CREATE_CONTEXT(cr);
+ Cairo::RefPtr<Cairo::Pattern> solid_pattern =
+ Cairo::SolidPattern::create_rgb (1.0, 0.5, 0.25);
+ Cairo::RefPtr<Cairo::Pattern> gradient_pattern =
+ Cairo::LinearGradient::create (0.0, 0.0, 1.0, 1.0);
+
+ // there doesn't seem to be any way to compare the retrieved pattern to the
+ // one that was set... for now, just excercise the function calls.
+ cr->set_source (solid_pattern);
+ //BOOST_CHECK (cr->get_source () == solid_pattern);
+
+ cr->set_source (gradient_pattern);
+ //BOOST_CHECK (cr->get_source () == gradient_pattern);
+
+ cr->set_source_rgb (1.0, 0.5, 0.25);
+ Cairo::RefPtr<Cairo::SolidPattern> solid =
+ Cairo::RefPtr<Cairo::SolidPattern>::cast_dynamic(cr->get_source ());
+ BOOST_REQUIRE (solid);
+ double rx, gx, bx, ax;
+ solid->get_rgba (rx, gx, bx, ax);
+ BOOST_CHECK (rx == 1.0);
+ BOOST_CHECK (gx == 0.5);
+ BOOST_CHECK (bx == 0.25);
+ cr->set_source_rgba (0.1, 0.3, 0.5, 0.7);
+ solid =
+ Cairo::RefPtr<Cairo::SolidPattern>::cast_dynamic(cr->get_source ());
+ BOOST_REQUIRE (solid);
+ solid->get_rgba (rx, gx, bx, ax);
+ BOOST_CHECK (rx == 0.1);
+ BOOST_CHECK (gx == 0.3);
+ BOOST_CHECK (bx == 0.5);
+ BOOST_CHECK (ax == 0.7);
+}
+
+void
+test_tolerance ()
+{
+ CREATE_CONTEXT(cr);
+ cr->set_tolerance (3.0);
+ BOOST_CHECK (cr->get_tolerance () == 3.0);
+}
+
+void
+test_antialias ()
+{
+ CREATE_CONTEXT(cr);
+ cr->set_antialias (Cairo::ANTIALIAS_GRAY);
+ BOOST_CHECK (cr->get_antialias () == Cairo::ANTIALIAS_GRAY);
+
+ cr->set_antialias (Cairo::ANTIALIAS_SUBPIXEL);
+ BOOST_CHECK (cr->get_antialias () == Cairo::ANTIALIAS_SUBPIXEL);
+}
+
+void
+test_fill_rule ()
+{
+ CREATE_CONTEXT(cr);
+ cr->set_fill_rule (Cairo::FILL_RULE_EVEN_ODD);
+ BOOST_CHECK (cr->get_fill_rule () == Cairo::FILL_RULE_EVEN_ODD);
+ cr->set_fill_rule (Cairo::FILL_RULE_WINDING);
+ BOOST_CHECK (cr->get_fill_rule () == Cairo::FILL_RULE_WINDING);
+}
+
+void
+test_line_width ()
+{
+ CREATE_CONTEXT(cr);
+ cr->set_line_width (1.0);
+ BOOST_CHECK (cr->get_line_width () == 1.0);
+ cr->set_line_width (4.0);
+ BOOST_CHECK (cr->get_line_width () == 4.0);
+}
+
+void
+test_line_cap ()
+{
+ CREATE_CONTEXT(cr);
+ cr->set_line_cap (Cairo::LINE_CAP_BUTT);
+ BOOST_CHECK (cr->get_line_cap () == Cairo::LINE_CAP_BUTT);
+ cr->set_line_cap (Cairo::LINE_CAP_ROUND);
+ BOOST_CHECK (cr->get_line_cap () == Cairo::LINE_CAP_ROUND);
+}
+
+void
+test_line_join ()
+{
+ CREATE_CONTEXT(cr);
+ cr->set_line_join (Cairo::LINE_JOIN_BEVEL);
+ BOOST_CHECK (cr->get_line_join () == Cairo::LINE_JOIN_BEVEL);
+ cr->set_line_join (Cairo::LINE_JOIN_MITER);
+ BOOST_CHECK (cr->get_line_join () == Cairo::LINE_JOIN_MITER);
+}
+
+void
+test_miter_limit ()
+{
+ CREATE_CONTEXT (cr);
+ cr->set_miter_limit (1.3);
+ BOOST_CHECK (cr->get_miter_limit () == 1.3);
+ cr->set_miter_limit (4.12);
+ BOOST_CHECK (cr->get_miter_limit () == 4.12);
+}
+
+void
+test_matrix ()
+{
+ CREATE_CONTEXT (cr);
+ //cr->transform();
+ //cr->set_matrix();
+ //cr->set_identity_matrix ();
+}
+
+void
+test_user_device ()
+{
+ // scale / transform a context, and then verify that user-to-device and
+ // device-to-user things work.
+}
+
+void
+test_draw ()
+{
+ CREATE_CONTEXT (cr);
+ // just call a bunch of drawing functions to excercise them a bit. There's no
+ // rhyme or reason to this, don't expect it to draw anything interesting.
+ cr->begin_new_path ();
+ cr->move_to (1.0, 1.0);
+ cr->line_to (2.0, 2.0);
+ cr->curve_to (0.5, 0.5, 0.5, 0.5, 1.0, 1.0);
+ cr->arc (1.5, 0.5, 0.5, 0, 2 * M_PI);
+ cr->stroke ();
+ cr->arc_negative (1.5, 0.5, 0.5, 0, 2 * M_PI);
+ cr->rel_move_to (0.1, 0.1);
+ cr->rel_line_to (0.5, -0.5);
+ cr->rel_curve_to (0.5, 0.5, 0.5, 0.5, 1.0, 1.0);
+ cr->rectangle (0.0, 0.0, 1.0, 1.0);
+ cr->close_path ();
+ cr->paint ();
+}
+
+void
+test_clip ()
+{
+ CREATE_CONTEXT (cr);
+ cr->rectangle (0.0, 0.0, 1.0, 1.0);
+ cr->clip ();
+ double x1, y1, x2, y2;
+ cr->get_clip_extents (x1, y1, x2, y2);
+ BOOST_CHECK (x1 == 0.0);
+ BOOST_CHECK (y1 == 0.0);
+ BOOST_CHECK (x2 == 1.0);
+ BOOST_CHECK (y2 == 1.0);
+}
+
+void
+test_current_point ()
+{
+ CREATE_CONTEXT (cr);
+ cr->move_to (2.0, 3.0);
+ double x, y;
+ cr->get_current_point (x, y);
+ BOOST_CHECK (x == 2.0);
+ BOOST_CHECK (y == 3.0);
+}
+
+test_suite*
+init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite* test= BOOST_TEST_SUITE( "Cairo::Context Tests" );
+
+ test->add (BOOST_TEST_CASE (&test_dashes));
+ test->add (BOOST_TEST_CASE (&test_save_restore));
+ test->add (BOOST_TEST_CASE (&test_operator));
+ test->add (BOOST_TEST_CASE (&test_source));
+ test->add (BOOST_TEST_CASE (&test_tolerance));
+ test->add (BOOST_TEST_CASE (&test_antialias));
+ test->add (BOOST_TEST_CASE (&test_fill_rule));
+ test->add (BOOST_TEST_CASE (&test_line_width));
+ test->add (BOOST_TEST_CASE (&test_line_cap));
+ test->add (BOOST_TEST_CASE (&test_line_join));
+ test->add (BOOST_TEST_CASE (&test_miter_limit));
+ //test->add (BOOST_TEST_CASE (&test_matrix));
+ //test->add (BOOST_TEST_CASE (&test_user_device));
+ test->add (BOOST_TEST_CASE (&test_draw));
+ test->add (BOOST_TEST_CASE (&test_clip));
+ test->add (BOOST_TEST_CASE (&test_current_point));
+
+ return test;
+}