6
use Clutter::TestHelper tests => 50;
10
my $DEFAULT_FILL_COLOR = Champlain::Polygon->new()->get_fill_color;
11
my $DEFAULT_STROKE_NAME = Champlain::Polygon->new()->get_stroke_color;
24
my $polygon = Champlain::Polygon->new();
25
isa_ok($polygon, 'Champlain::Polygon');
27
my @points = $polygon->get_points();
28
is_deeply(\@points, [], "No points on a new polygon");
30
$polygon->clear_points();
31
is_deeply(\@points, [], "No points on a cleared polygon");
33
$polygon->clear_points();
34
is_deeply(\@points, [], "No points on a cleared polygon (2 times)");
36
is_color($polygon->get_fill_color, $DEFAULT_FILL_COLOR, "fill_color is set on a new polygon");
37
is_color($polygon->get_stroke_color, $DEFAULT_STROKE_NAME, "stroke_color is set on a new polygon");
39
ok(!$polygon->get_fill, "fill is unset on a new polygon");
40
ok($polygon->get_stroke, "stroke is set on a new polygon");
41
is($polygon->get_stroke_width, 2, "stroke_width is set on a new polygon");
43
# These fields have no accessor yet
44
ok(!$polygon->get('closed-path'), "closed-path is unset on a new polygon");
45
ok($polygon->get('visible'), "closed-path is set on a new polygon");
50
my $polygon = Champlain::Polygon->new();
51
isa_ok($polygon, 'Champlain::Polygon');
56
$color = Clutter::Color->new(0xaa, 0xdd, 0x37, 0xbb);
57
$polygon->set_fill_color($color);
58
is_color($polygon->get_fill_color, $color, "set_fill_color");
60
$color = Clutter::Color->new(0x44, 0x33, 0x23, 0x2b);
61
$polygon->set_stroke_color($color);
62
is_color($polygon->get_stroke_color, $color, "set_stroke_color");
65
my $old_fill = $polygon->get_fill;
66
$polygon->set_fill(!$old_fill);
67
is($polygon->get_fill, !$old_fill, "set_fill()");
71
my $old_stroke = $polygon->get_stroke;
72
$polygon->set_stroke(!$old_stroke);
73
is($polygon->get_stroke, !$old_stroke, "set_stroke()");
77
my $old_stroke_width = $polygon->get_stroke_width;
78
$polygon->set_stroke_width($old_stroke_width + 2);
79
is($polygon->get_stroke_width, $old_stroke_width + 2, "set_stroke_width()");
84
ok(!$polygon->get('visible'), "hide()");
86
ok($polygon->get('visible'), "show()");
91
my $polygon = Champlain::Polygon->new();
92
isa_ok($polygon, 'Champlain::Polygon');
96
$polygon->append_point(8, 4);
105
push @remove, $polygon->append_point(4, 9);
115
$polygon->insert_point(7, 10, 1);
123
"insert_point() in the middle"
126
$polygon->append_point(5, 3);
138
push @remove, $polygon->insert_point(1, 2, 0);
148
"insert_point() at the beginning"
151
$polygon->insert_point(10, 20, 5);
162
"insert_point() at the end"
165
push @remove, $polygon->insert_point(30, 240, 17);
177
"insert_point() past the end"
180
foreach my $point (@remove) {
181
$polygon->remove_point($point);
195
# Clear the polygon (it should be empty after)
196
$polygon->clear_points();
197
is_polygon($polygon, [], "clear_points()");
199
$polygon->append_point(100, 200);
200
is_polygon($polygon, [100, 200], "add_point on a cleared polygon");
205
# Assert that two colors are identical.
208
my ($polygon, $expected, $message) = @_;
210
my @points = map { ($_->lat, $_->lon) } $polygon->get_points;
211
is_deeply(\@points, $expected, $message);
216
# Assert that two colors are identical.
219
my ($got, $expected, $message) = @_;
220
my $tester = Test::Builder->new();
222
$are_colors &= $tester->is_eq(ref($got), 'Clutter::Color', "$message, got is a Clutter::Color");
223
$are_colors &= $tester->is_eq(ref($expected), 'Clutter::Color', "$message, expected a Clutter::Color");
226
$tester->ok(0, "$message, can't compare color components") for 1 .. 4;
230
$tester->is_num($got->red, $expected->red, "$message, red matches");
231
$tester->is_num($got->green, $expected->green, "$message, green matches");
232
$tester->is_num($got->blue, $expected->blue, "$message, blue matches");
233
$tester->is_num($got->alpha, $expected->alpha, "$message, alpha matches");