summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathon Jongsma <jonathon.jongsma@collabora.co.uk>2008-08-19 12:28:02 -0500
committerJonathon Jongsma <jonathon.jongsma@collabora.co.uk>2008-08-19 12:28:02 -0500
commitb53bd1cf536a3042adb884150a577b196845fd72 (patch)
tree44f13661aff7366c85ef66e6f5947fdf28b81ead /tests
parent326e392bdcf84f9d7c27105e95c6d1963255c3b2 (diff)
Add sigc::slot versions of all of the functions that take a cairo_write_func_t or cairo_read_func_t
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/test-surface.cc89
2 files changed, 91 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 03e58a0..9b534a5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,10 +1,11 @@
if AUTOTESTS
# build automated 'tests'
-TESTS=test-context test-font-face
+TESTS=test-context test-font-face test-surface
noinst_PROGRAMS = $(TESTS)
test_context_SOURCES=test-context.cc
test_font_face_SOURCES=test-font-face.cc
+test_surface_SOURCES=test-surface.cc
else
diff --git a/tests/test-surface.cc b/tests/test-surface.cc
new file mode 100644
index 0000000..3b3e7d0
--- /dev/null
+++ b/tests/test-surface.cc
@@ -0,0 +1,89 @@
+#include <boost/test/unit_test.hpp>
+#include <boost/test/test_tools.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+using namespace boost::unit_test;
+#include <cairomm/surface.h>
+using namespace Cairo;
+
+static unsigned int test_slot_called = 0;
+ErrorStatus test_slot(const unsigned char* /*data*/, unsigned int /*len*/)
+{
+ test_slot_called++;
+ return CAIRO_STATUS_SUCCESS;
+}
+
+void test_write_to_png_stream()
+{
+ RefPtr<ImageSurface> surface = ImageSurface::create(FORMAT_ARGB32, 1, 1);
+ surface->write_to_png_stream(sigc::ptr_fun(test_slot));
+ BOOST_CHECK(test_slot_called > 0);
+}
+
+void test_pdf_constructor_slot()
+{
+ test_slot_called = 0;
+ RefPtr<PdfSurface> pdf = PdfSurface::create(sigc::ptr_fun(&test_slot), 1, 1);
+ pdf->show_page();
+ pdf->finish();
+ BOOST_CHECK(test_slot_called > 0);
+}
+
+void test_ps_constructor_slot()
+{
+ test_slot_called = 0;
+ RefPtr<PsSurface> ps = PsSurface::create(sigc::ptr_fun(&test_slot), 1, 1);
+ ps->show_page();
+ ps->finish();
+ BOOST_CHECK(test_slot_called > 0);
+}
+
+void test_svg_constructor_slot()
+{
+ test_slot_called = 0;
+ RefPtr<SvgSurface> svg = SvgSurface::create(sigc::ptr_fun(&test_slot), 1, 1);
+ svg->show_page();
+ svg->finish();
+ BOOST_CHECK(test_slot_called > 0);
+}
+
+unsigned int test_read_func_called = 0;
+static ErrorStatus test_read_func(unsigned char* /*data*/, unsigned int /*len*/)
+{
+ ++test_read_func_called;
+ return CAIRO_STATUS_SUCCESS;
+}
+
+unsigned int c_test_read_func_called = 0;
+static cairo_status_t c_test_read_func(void* /*closure*/, unsigned char* /*data*/, unsigned int /*len*/)
+{
+ ++c_test_read_func_called;
+ return CAIRO_STATUS_SUCCESS;
+}
+
+void test_create_from_png()
+{
+ // FIXME: these cause a std::bad_alloc exception for some reason
+ RefPtr<ImageSurface> surface;
+ surface = ImageSurface::create_from_png_stream(sigc::ptr_fun(&test_read_func));
+ BOOST_CHECK(test_read_func_called > 0);
+ surface = ImageSurface::create_from_png(&c_test_read_func, NULL);
+ BOOST_CHECK(c_test_read_func_called > 0);
+}
+
+
+test_suite*
+init_unit_test_suite(int argc, char* argv[])
+{
+ // compile even with -Werror
+ if (argc && argv) {}
+
+ test_suite* test= BOOST_TEST_SUITE( "Cairo::Surface Tests" );
+
+ test->add (BOOST_TEST_CASE (&test_write_to_png_stream));
+ test->add (BOOST_TEST_CASE (&test_pdf_constructor_slot));
+ test->add (BOOST_TEST_CASE (&test_ps_constructor_slot));
+ test->add (BOOST_TEST_CASE (&test_svg_constructor_slot));
+ test->add (BOOST_TEST_CASE (&test_create_from_png));
+
+ return test;
+}