[librsvg: 14/29] Test rsvg_handle_set_dpi() / rsvg_handle_set_dpi_x_y()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 14/29] Test rsvg_handle_set_dpi() / rsvg_handle_set_dpi_x_y()
- Date: Tue, 6 Feb 2018 21:05:16 +0000 (UTC)
commit 0eb8273a33140d67204055d761a3118ee33a3897
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Feb 6 11:06:37 2018 -0600
Test rsvg_handle_set_dpi() / rsvg_handle_set_dpi_x_y()
We will not test rsvg_set_default_dpi() and rsvg_set_default_dpi_x_y()
because they are unsound. See the next commit for their deprecation
and explanation.
tests/api.c | 45 +++++++++++++++++++++++++++++++++++++++++----
tests/fixtures/api/dpi.svg | 5 +++++
2 files changed, 46 insertions(+), 4 deletions(-)
---
diff --git a/tests/api.c b/tests/api.c
index e4f222b..144b7f6 100644
--- a/tests/api.c
+++ b/tests/api.c
@@ -33,10 +33,6 @@ rsvg_handle_render_cairo
rsvg_handle_set_base_gfile
rsvg_handle_write
rsvg_handle_read_stream_sync
-rsvg_set_default_dpi
-rsvg_set_default_dpi_x_y
-rsvg_handle_set_dpi
-rsvg_handle_set_dpi_x_y
rsvg_handle_get_title
rsvg_handle_get_desc
rsvg_handle_get_metadata
@@ -192,6 +188,46 @@ noops (void)
g_assert (rsvg_cleanup != NULL); /* shouldn't call this one! */
}
+static void
+set_dpi (void)
+{
+ char *filename = get_test_filename ("dpi.svg");
+ GError *error = NULL;
+ RsvgHandle *handle;
+
+ /* Get dimensions at default DPI */
+
+ RsvgDimensionData dim_100_dpi;
+ RsvgDimensionData dim_200_300_dpi;
+
+ /* Set 100 DPI */
+
+ handle = rsvg_handle_new_from_file (filename, &error);
+ g_assert (handle != NULL);
+ g_assert (error == NULL);
+
+ rsvg_handle_set_dpi (handle, 100.0);
+ rsvg_handle_get_dimensions (handle, &dim_100_dpi);
+ g_assert_cmpint (dim_100_dpi.width, ==, 100);
+ g_assert_cmpint (dim_100_dpi.height, ==, 400);
+ g_object_unref (handle);
+
+ /* Set 200x300 DPI */
+
+ handle = rsvg_handle_new_from_file (filename, &error);
+ g_assert (handle != NULL);
+ g_assert (error == NULL);
+
+ rsvg_handle_set_dpi_x_y (handle, 200.0, 300.0);
+ rsvg_handle_get_dimensions (handle, &dim_200_300_dpi);
+ g_object_unref (handle);
+
+ /* Check! */
+
+ g_assert_cmpint (dim_100_dpi.width * 2, ==, dim_200_300_dpi.width);
+ g_assert_cmpint (dim_100_dpi.height * 3, ==, dim_200_300_dpi.height);
+}
+
int
main (int argc, char **argv)
{
@@ -205,6 +241,7 @@ main (int argc, char **argv)
g_test_add_func ("/api/handle_has_gtype", handle_has_gtype);
g_test_add_func ("/api/noops", noops);
+ g_test_add_func ("/api/set_dpi", set_dpi);
return g_test_run ();
}
diff --git a/tests/fixtures/api/dpi.svg b/tests/fixtures/api/dpi.svg
new file mode 100644
index 0000000..499ee20
--- /dev/null
+++ b/tests/fixtures/api/dpi.svg
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="1in" height="4in" viewBox="0 0 100 400">
+ <rect id="one" x="0" y="0" width="100" height="200" fill="rgb(0,255,0)"/>
+ <rect id="two" x="0" y="200" width="100" height="200" fill="rgb(0,0,255)"/>
+</svg>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]