testuite: Add tests for gsk_curve_get_point()
Add a few tests for gsk_curve_get_point(). Since GskCurve is not public api, we add gskcurve.c as source to the test binary.
This commit is contained in:
89
testsuite/gsk/curve.c
Normal file
89
testsuite/gsk/curve.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include "gsk/gskcurveprivate.h"
|
||||
|
||||
static void
|
||||
init_random_point (graphene_point_t *p)
|
||||
{
|
||||
p->x = g_test_rand_double_range (0, 1000);
|
||||
p->y = g_test_rand_double_range (0, 1000);
|
||||
}
|
||||
|
||||
static float
|
||||
random_weight (void)
|
||||
{
|
||||
if (g_test_rand_bit ())
|
||||
return g_test_rand_double_range (0, 100);
|
||||
else
|
||||
return 1.0 / g_test_rand_double_range (1, 100);
|
||||
}
|
||||
|
||||
static void
|
||||
init_random_curve (GskCurve *curve)
|
||||
{
|
||||
switch (g_test_rand_int_range (GSK_PATH_LINE, GSK_PATH_CONIC + 1))
|
||||
{
|
||||
case GSK_PATH_LINE:
|
||||
{
|
||||
graphene_point_t p[2];
|
||||
|
||||
init_random_point (&p[0]);
|
||||
init_random_point (&p[1]);
|
||||
gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_LINE, p));
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_PATH_CURVE:
|
||||
{
|
||||
graphene_point_t p[4];
|
||||
|
||||
init_random_point (&p[0]);
|
||||
init_random_point (&p[1]);
|
||||
init_random_point (&p[2]);
|
||||
init_random_point (&p[3]);
|
||||
gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_CURVE, p));
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_PATH_CONIC:
|
||||
{
|
||||
graphene_point_t p[4];
|
||||
|
||||
init_random_point (&p[0]);
|
||||
init_random_point (&p[1]);
|
||||
p[2] = GRAPHENE_POINT_INIT (random_weight(), 0);
|
||||
init_random_point (&p[3]);
|
||||
gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_CONIC, p));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_points (void)
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
GskCurve c;
|
||||
graphene_point_t p;
|
||||
|
||||
init_random_curve (&c);
|
||||
|
||||
gsk_curve_eval (&c, 0, &p, NULL);
|
||||
g_assert_true (graphene_point_near (gsk_curve_get_start_point (&c), &p, 0.01));
|
||||
gsk_curve_eval (&c, 1, &p, NULL);
|
||||
g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c), &p, 0.01));
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/curve/points", test_curve_points);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
@@ -208,6 +208,7 @@ foreach test : node_parser_tests
|
||||
endforeach
|
||||
|
||||
tests = [
|
||||
['curve', ['../../gsk/gskcurve.c'], ['-DGTK_COMPILATION']],
|
||||
['path'],
|
||||
['path-special-cases'],
|
||||
['rounded-rect'],
|
||||
|
||||
Reference in New Issue
Block a user