GCC Code Coverage Report


Directory: ./
File: tests/test-fpi-assembling.c
Date: 2024-05-04 14:54:39
Exec Total Coverage
Lines: 59 59 100.0%
Functions: 3 3 100.0%
Branches: 16 24 66.7%

Line Branch Exec Source
1 /*
2 * Example fingerprint device prints listing and deletion
3 * Enrolls your right index finger and saves the print to disk
4 * Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <glib.h>
22 #include <cairo.h>
23 #include "fpi-assembling.h"
24 #include "fpi-image.h"
25
26 typedef struct
27 {
28 struct fpi_frame frame;
29 cairo_surface_t *surf;
30 guchar *data;
31 guint stride;
32 guint width;
33 guint height;
34 guint x;
35 guint y;
36 } cairo_frame;
37
38 static unsigned char
39 79483776 cairo_get_pixel (struct fpi_frame_asmbl_ctx *ctx,
40 struct fpi_frame *frame,
41 unsigned int x,
42 unsigned int y)
43 {
44 79483776 cairo_frame *c_frame = (void *) frame; /* Indirect cast to avoid alignment warning. */
45
46 79483776 x = x + c_frame->x;
47 79483776 y = y + c_frame->y;
48
49
1/2
✓ Branch 0 taken 79483776 times.
✗ Branch 1 not taken.
79483776 g_assert (x < c_frame->width);
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79483776 times.
79483776 g_assert (y < c_frame->height);
51
52 79483776 return c_frame->data[x * 4 + y * c_frame->stride + 1];
53 }
54
55 static void
56 1 test_frame_assembling (void)
57 {
58 2 g_autofree char *path = NULL;
59 1 cairo_surface_t *img = NULL;
60 1 int width, height, stride, offset;
61 1 int test_height;
62 1 guchar *data;
63 1 struct fpi_frame_asmbl_ctx ctx = { 0, };
64 1 gint xborder = 5;
65
66 1 g_autoptr(FpImage) fp_img = NULL;
67 1 GSList *frames = NULL;
68
69 1 path = g_test_build_filename (G_TEST_DIST, "vfs5011", "capture.png", NULL);
70
71 1 img = cairo_image_surface_create_from_png (path);
72 1 data = cairo_image_surface_get_data (img);
73 1 width = cairo_image_surface_get_width (img);
74 1 height = cairo_image_surface_get_height (img);
75 1 stride = cairo_image_surface_get_stride (img);
76
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 g_assert_cmpint (cairo_image_surface_get_format (img), ==, CAIRO_FORMAT_RGB24);
77
78 1 ctx.get_pixel = cairo_get_pixel;
79 1 ctx.frame_width = width;
80 1 ctx.frame_height = 20;
81 1 ctx.image_width = width - 2 * xborder;
82
83
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 g_assert (height > ctx.frame_height);
84
85 1 offset = 10;
86 1 test_height = height - (height - ctx.frame_height) % offset;
87
88 /* for now, fixed offset */
89
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1 times.
33 for (int y = 0; y + ctx.frame_height < height; y += offset)
90 {
91 32 cairo_frame *frame = g_new0 (cairo_frame, 1);
92
93 32 frame->surf = img;
94 32 frame->width = width;
95 32 frame->height = height;
96 32 frame->stride = stride;
97 32 frame->data = data;
98 32 frame->x = 0;
99 32 frame->y = y;
100 //frame->y = test_height - ctx.frame_height - y;
101
102 32 frames = g_slist_append (frames, frame);
103 }
104 //offset = -offset;
105
106 1 fpi_do_movement_estimation (&ctx, frames);
107
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
32 for (GSList *l = frames->next; l != NULL; l = l->next)
108 {
109 31 cairo_frame * frame = l->data;
110
111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 g_assert_cmpint (frame->frame.delta_x, ==, 0);
112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 g_assert_cmpint (frame->frame.delta_y, ==, offset);
113 }
114
115 1 fp_img = fpi_assemble_frames (&ctx, frames);
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 g_assert_cmpint (fp_img->height, ==, test_height);
117
118 /* The FpImage and cairo surface need to be identical in the test area */
119
2/2
✓ Branch 0 taken 330 times.
✓ Branch 1 taken 1 times.
331 for (int y = 0; y < test_height; y++)
120
2/2
✓ Branch 0 taken 49500 times.
✓ Branch 1 taken 330 times.
49830 for (int x = 0; x < ctx.image_width; x++)
121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49500 times.
49500 g_assert_cmpint (data[(x + xborder) * 4 + y * stride + 1], ==, fp_img->data[x + y * ctx.image_width]);
122
123 1 g_slist_free_full (frames, g_free);
124 1 cairo_surface_destroy (img);
125 1 g_assert (1);
126 1 }
127
128 int
129 1 main (int argc, char *argv[])
130 {
131 1 g_test_init (&argc, &argv, NULL);
132
133 1 g_test_add_func ("/assembling/frames", test_frame_assembling);
134
135 1 return g_test_run ();
136 }
137