summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@gnome.org>2007-07-04 23:18:41 -0500
committerJonathon Jongsma <jjongsma@gnome.org>2007-07-04 23:29:04 -0500
commitdc5bc937ae5e48efe594a8a8767adbf5b339fecf (patch)
tree8d8b5926e849dd9c6f98e2f17336f51771afa2f5
parent7bbaa8760044e8578d8c79e8a0939e5017a3ff5a (diff)
Added some tests for matrix transformations and user-to-device coordinate mappings
The matrix transformation 'test' does nothing more than call the functions to excercise them a bit Also used BOOST_CHECK_EQUAL in most places instead of BOOST_CHECK to get more meaningful failure messages.
-rw-r--r--ChangeLog11
-rw-r--r--tests/test-context.cc108
2 files changed, 75 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index eba347d..6fa231e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2007-07-04 Jonathon Jongsma <jjongsma@gnome.org>
+ * tests/test-context.cc: add some tests for matrix transformations and
+ user-to-device coordinate mappings. The matrix transformation 'test' does
+ nothing more than call the functions to excercise them a bit, but it's
+ causing an unexpected exception to be triggered when calling
+ Context::set_matrix(). The odd thing is that exception.what() results in
+ 'success' being printed. This requires further investigation
+ Also used BOOST_CHECK_EQUAL in most places instead of BOOST_CHECK to get
+ more meaningful failure messages.
+
+2007-07-04 Jonathon Jongsma <jjongsma@gnome.org>
+
* cairomm/private.cc: add missing 'break;' on the I/O error case statement
2007-07-04 Jonathon Jongsma <jjongsma@gnome.org>
diff --git a/tests/test-context.cc b/tests/test-context.cc
index 11088b1..5efd0a7 100644
--- a/tests/test-context.cc
+++ b/tests/test-context.cc
@@ -6,8 +6,10 @@
* work generally
*/
+#include <cfloat>
#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/context.h>
@@ -29,11 +31,11 @@ test_dashes ()
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);
+ BOOST_CHECK_EQUAL (dash_array[0], get_array[0]);
+ BOOST_CHECK_EQUAL (dash_array[1], get_array[1]);
+ BOOST_CHECK_EQUAL (dash_array[2], get_array[2]);
+ BOOST_CHECK_EQUAL (dash_array[3], get_array[3]);
+ BOOST_CHECK_EQUAL (0.54, get_offset);
cr->unset_dash ();
cr->get_dash (get_array, get_offset);
@@ -44,12 +46,12 @@ void
test_save_restore ()
{
CREATE_CONTEXT(cr);
- cr->set_line_width (1.0);
+ cr->set_line_width (2.3);
cr->save ();
cr->set_line_width (4.0);
- BOOST_CHECK (cr->get_line_width () == 4.0);
+ BOOST_CHECK_EQUAL (4.0, cr->get_line_width ());
cr->restore ();
- BOOST_CHECK (cr->get_line_width () == 1.0);
+ BOOST_CHECK_EQUAL (2.3, cr->get_line_width ());
}
void
@@ -57,9 +59,9 @@ test_operator ()
{
CREATE_CONTEXT(cr);
cr->set_operator (Cairo::OPERATOR_ATOP);
- BOOST_CHECK (cr->get_operator () == Cairo::OPERATOR_ATOP);
+ BOOST_CHECK_EQUAL (Cairo::OPERATOR_ATOP, cr->get_operator ());
cr->set_operator (Cairo::OPERATOR_CLEAR);
- BOOST_CHECK (cr->get_operator () == Cairo::OPERATOR_CLEAR);
+ BOOST_CHECK_EQUAL (Cairo::OPERATOR_CLEAR, cr->get_operator ());
}
void
@@ -71,8 +73,6 @@ test_source ()
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);
{
Cairo::RefPtr<Cairo::SolidPattern> retrieved_solid =
@@ -80,9 +80,9 @@ test_source ()
BOOST_REQUIRE (retrieved_solid);
double r, g, b, a;
retrieved_solid->get_rgba (r, g, b, a);
- BOOST_CHECK (r == 1.0);
- BOOST_CHECK (g == 0.5);
- BOOST_CHECK (b == 0.25);
+ BOOST_CHECK_EQUAL (1.0, r);
+ BOOST_CHECK_EQUAL (0.5, g);
+ BOOST_CHECK_EQUAL (0.25, b);
}
cr->set_source (gradient_pattern);
@@ -92,10 +92,10 @@ test_source ()
BOOST_REQUIRE (retrieved_linear);
double x0, x1, y0, y1;
retrieved_linear->get_linear_points (x0, y0, x1, y1);
- BOOST_CHECK (x0 == 0.0);
- BOOST_CHECK (y0 == 0.0);
- BOOST_CHECK (x1 == 1.0);
- BOOST_CHECK (y1 == 1.0);
+ BOOST_CHECK_EQUAL (0.0, x0);
+ BOOST_CHECK_EQUAL (0.0, y0);
+ BOOST_CHECK_EQUAL (1.0, x1);
+ BOOST_CHECK_EQUAL (1.0, y1);
}
cr->set_source_rgb (1.0, 0.5, 0.25);
@@ -105,9 +105,9 @@ test_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);
+ BOOST_CHECK_EQUAL (1.0, rx);
+ BOOST_CHECK_EQUAL (0.5, gx);
+ BOOST_CHECK_EQUAL (0.25, bx);
}
cr->set_source_rgba (0.1, 0.3, 0.5, 0.7);
{
@@ -116,10 +116,10 @@ test_source ()
BOOST_REQUIRE (solid);
double rx, gx, bx, ax;
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);
+ BOOST_CHECK_EQUAL (0.1, rx);
+ BOOST_CHECK_EQUAL (0.3, gx);
+ BOOST_CHECK_EQUAL (0.5, bx);
+ BOOST_CHECK_EQUAL (0.7, ax);
}
}
@@ -128,7 +128,7 @@ test_tolerance ()
{
CREATE_CONTEXT(cr);
cr->set_tolerance (3.0);
- BOOST_CHECK (cr->get_tolerance () == 3.0);
+ BOOST_CHECK_EQUAL (3.0, cr->get_tolerance ());
}
void
@@ -136,10 +136,10 @@ test_antialias ()
{
CREATE_CONTEXT(cr);
cr->set_antialias (Cairo::ANTIALIAS_GRAY);
- BOOST_CHECK (cr->get_antialias () == Cairo::ANTIALIAS_GRAY);
+ BOOST_CHECK_EQUAL (Cairo::ANTIALIAS_GRAY, cr->get_antialias ());
cr->set_antialias (Cairo::ANTIALIAS_SUBPIXEL);
- BOOST_CHECK (cr->get_antialias () == Cairo::ANTIALIAS_SUBPIXEL);
+ BOOST_CHECK_EQUAL (Cairo::ANTIALIAS_SUBPIXEL, cr->get_antialias ());
}
void
@@ -147,9 +147,9 @@ 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);
+ BOOST_CHECK_EQUAL (Cairo::FILL_RULE_EVEN_ODD, cr->get_fill_rule ());
cr->set_fill_rule (Cairo::FILL_RULE_WINDING);
- BOOST_CHECK (cr->get_fill_rule () == Cairo::FILL_RULE_WINDING);
+ BOOST_CHECK_EQUAL (Cairo::FILL_RULE_WINDING, cr->get_fill_rule ());
}
void
@@ -157,9 +157,9 @@ test_line_width ()
{
CREATE_CONTEXT(cr);
cr->set_line_width (1.0);
- BOOST_CHECK (cr->get_line_width () == 1.0);
+ BOOST_CHECK_EQUAL (1.0, cr->get_line_width ());
cr->set_line_width (4.0);
- BOOST_CHECK (cr->get_line_width () == 4.0);
+ BOOST_CHECK_EQUAL (4.0, cr->get_line_width ());
}
void
@@ -167,9 +167,9 @@ test_line_cap ()
{
CREATE_CONTEXT(cr);
cr->set_line_cap (Cairo::LINE_CAP_BUTT);
- BOOST_CHECK (cr->get_line_cap () == Cairo::LINE_CAP_BUTT);
+ BOOST_CHECK_EQUAL (Cairo::LINE_CAP_BUTT, cr->get_line_cap ());
cr->set_line_cap (Cairo::LINE_CAP_ROUND);
- BOOST_CHECK (cr->get_line_cap () == Cairo::LINE_CAP_ROUND);
+ BOOST_CHECK_EQUAL (Cairo::LINE_CAP_ROUND, cr->get_line_cap ());
}
void
@@ -177,9 +177,9 @@ test_line_join ()
{
CREATE_CONTEXT(cr);
cr->set_line_join (Cairo::LINE_JOIN_BEVEL);
- BOOST_CHECK (cr->get_line_join () == Cairo::LINE_JOIN_BEVEL);
+ BOOST_CHECK_EQUAL (Cairo::LINE_JOIN_BEVEL, cr->get_line_join ());
cr->set_line_join (Cairo::LINE_JOIN_MITER);
- BOOST_CHECK (cr->get_line_join () == Cairo::LINE_JOIN_MITER);
+ BOOST_CHECK_EQUAL (Cairo::LINE_JOIN_MITER, cr->get_line_join ());
}
void
@@ -187,18 +187,23 @@ test_miter_limit ()
{
CREATE_CONTEXT (cr);
cr->set_miter_limit (1.3);
- BOOST_CHECK (cr->get_miter_limit () == 1.3);
+ BOOST_CHECK_EQUAL (1.3, cr->get_miter_limit ());
cr->set_miter_limit (4.12);
- BOOST_CHECK (cr->get_miter_limit () == 4.12);
+ BOOST_CHECK_EQUAL (4.12, cr->get_miter_limit ());
}
void
test_matrix ()
{
+ // just excercise the functionality
CREATE_CONTEXT (cr);
- //cr->transform();
- //cr->set_matrix();
- //cr->set_identity_matrix ();
+ Cairo::Matrix matrix;
+ cairo_matrix_init (&matrix, 1.0, 0.1, 0.1, 1.0, 1.5, 1.5);
+ cr->transform(matrix);
+ cairo_matrix_init (&matrix, 1.0, -0.1, -0.1, 1.0, 1.5, 1.5);
+ cr->set_matrix(matrix);
+ cr->set_identity_matrix ();
+ cr->get_matrix (matrix);
}
void
@@ -206,6 +211,21 @@ test_user_device ()
{
// scale / transform a context, and then verify that user-to-device and
// device-to-user things work.
+ CREATE_CONTEXT (cr);
+ cr->scale (2.3, 2.3);
+ double x = 1.8, y = 1.8;
+ cr->user_to_device (x, y);
+ // x = (0.0 + x) * 2.3 => 1.8 * 2.3 = 5.29
+ BOOST_CHECK_EQUAL (4.14, x);
+ BOOST_CHECK_EQUAL (4.14, y);
+ cr->device_to_user (x, y);
+ BOOST_CHECK_EQUAL (1.8, x);
+ BOOST_CHECK_EQUAL (1.8, y);
+ cr->translate (0.5, 0.5);
+ cr->user_to_device (x, y);
+ // x = (0.5 + x) * 2.3 => 2.3 * 2.3 = 5.29
+ BOOST_CHECK_CLOSE (5.29, x, FLT_EPSILON);
+ BOOST_CHECK_CLOSE (5.29, y, FLT_EPSILON);
}
void
@@ -273,8 +293,8 @@ init_unit_test_suite(int argc, char* argv[])
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_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));