summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathon Jongsma <jonathon.jongsma@collabora.co.uk>2008-08-21 23:59:38 -0500
committerJonathon Jongsma <jonathon.jongsma@collabora.co.uk>2008-08-21 23:59:38 -0500
commit25cf269ed7c36dd1f72f557a1a6e7e36ae92573b (patch)
treeb379e53258c0f9782b92e9bafe5aefc0957781a6 /tests
parentb53bd1cf536a3042adb884150a577b196845fd72 (diff)
All Image Surface creation tests now pass (no exceptions thrown)
Diffstat (limited to 'tests')
-rw-r--r--tests/png-stream-test.pngbin0 -> 159 bytes
-rw-r--r--tests/test-surface.cc22
2 files changed, 17 insertions, 5 deletions
diff --git a/tests/png-stream-test.png b/tests/png-stream-test.png
new file mode 100644
index 0000000..2f25ed2
--- /dev/null
+++ b/tests/png-stream-test.png
Binary files differ
diff --git a/tests/test-surface.cc b/tests/test-surface.cc
index 3b3e7d0..ef11ed2 100644
--- a/tests/test-surface.cc
+++ b/tests/test-surface.cc
@@ -1,3 +1,4 @@
+#include <fstream>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/floating_point_comparison.hpp>
@@ -46,27 +47,38 @@ void test_svg_constructor_slot()
BOOST_CHECK(test_slot_called > 0);
}
+static std::ifstream png_file;
unsigned int test_read_func_called = 0;
-static ErrorStatus test_read_func(unsigned char* /*data*/, unsigned int /*len*/)
+static ErrorStatus test_read_func(unsigned char* data, unsigned int len)
{
++test_read_func_called;
- return CAIRO_STATUS_SUCCESS;
+ if (png_file.read(reinterpret_cast<char*>(data), len))
+ return CAIRO_STATUS_SUCCESS;
+ return CAIRO_STATUS_READ_ERROR;
}
unsigned int c_test_read_func_called = 0;
-static cairo_status_t c_test_read_func(void* /*closure*/, unsigned char* /*data*/, unsigned int /*len*/)
+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;
+ if (png_file.read(reinterpret_cast<char*>(data), len))
+ return CAIRO_STATUS_SUCCESS;
+ return CAIRO_STATUS_READ_ERROR;
}
void test_create_from_png()
{
- // FIXME: these cause a std::bad_alloc exception for some reason
RefPtr<ImageSurface> surface;
+ // try the sigc::slot version
+ png_file.open("png-stream-test.png");
surface = ImageSurface::create_from_png_stream(sigc::ptr_fun(&test_read_func));
+ png_file.close();
BOOST_CHECK(test_read_func_called > 0);
+
+ // now try the raw C function (deprecated) version
+ png_file.open("png-stream-test.png");
surface = ImageSurface::create_from_png(&c_test_read_func, NULL);
+ png_file.close();
BOOST_CHECK(c_test_read_func_called > 0);
}