[gimp/metadata-browser] app: Add /gimptilebackendtilemanager/basic_write unit test



commit 3f5d41081ba7f81da067eddcd3986f7503d2d823
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Oct 2 07:24:41 2011 +0200

    app: Add /gimptilebackendtilemanager/basic_write unit test
    
    Rename the 'basic_usage' test to 'basic_read' and add 'basic_write'
    test. Implement GimpTileBackendTileManagerPrivate enough to make them
    pass.
    
    Note that these tests currently do not work with GIMP's "effective
    tile size" optimization.

 app/gegl/gimptilebackendtilemanager.c       |   24 +++-----
 app/tests/test-gimptilebackendtilemanager.c |   84 +++++++++++++++++++++++----
 2 files changed, 81 insertions(+), 27 deletions(-)
---
diff --git a/app/gegl/gimptilebackendtilemanager.c b/app/gegl/gimptilebackendtilemanager.c
index 46dab38..b457c4d 100644
--- a/app/gegl/gimptilebackendtilemanager.c
+++ b/app/gegl/gimptilebackendtilemanager.c
@@ -37,7 +37,7 @@
 #include "gimp-gegl-utils.h"
 
 
-struct _GimpTileBackendTileManagerPrivate 
+struct _GimpTileBackendTileManagerPrivate
 {
   GHashTable      *entries;
   TileManager     *tile_manager;
@@ -176,29 +176,23 @@ gimp_tile_backend_tile_manager_command (GeglTileSource  *tile_store,
     case GEGL_TILE_GET:
       {
         GeglTile *tile;
-        gint      tile_size;
         Tile     *gimp_tile;
-        gint      tile_stride;
-        gint      gimp_tile_stride;
-        int       row;
 
         gimp_tile = tile_manager_get_at (backend_tm->priv->tile_manager,
                                          x, y, TRUE, FALSE);
 
         g_return_val_if_fail (gimp_tile != NULL, NULL);
 
-        tile_size        = gegl_tile_backend_get_tile_size (backend);
-        tile_stride      = TILE_WIDTH * tile_bpp (gimp_tile);
-        gimp_tile_stride = tile_ewidth (gimp_tile) * tile_bpp (gimp_tile);
-
-        /* XXX: Point to Tile data directly instead of using memcpy */
-        tile = gegl_tile_new (tile_size);
-        for (row = 0; row < tile_eheight (gimp_tile); row++)
+        if (tile_ewidth (gimp_tile)  != TILE_WIDTH ||
+            tile_eheight (gimp_tile) != TILE_HEIGHT)
           {
-            memcpy (gegl_tile_get_data (tile) + row * tile_stride,
-                    tile_data_pointer (gimp_tile, 0, row),
-                    gimp_tile_stride);
+            g_warning ("GimpTileBackendTileManager does not support != %dx%d tiles yet",
+                       TILE_WIDTH, TILE_HEIGHT);
           }
+        tile = gegl_tile_new_bare ();
+        gegl_tile_set_data (tile,
+                            tile_data_pointer (gimp_tile, 0, 0),
+                            tile_size (gimp_tile));
 
         return tile;
       }
diff --git a/app/tests/test-gimptilebackendtilemanager.c b/app/tests/test-gimptilebackendtilemanager.c
index 7206759..e6fda09 100644
--- a/app/tests/test-gimptilebackendtilemanager.c
+++ b/app/tests/test-gimptilebackendtilemanager.c
@@ -51,22 +51,30 @@ typedef struct
 } GimpTestFixture;
 
 
+static const guchar  opaque_magenta8[4]    = { 0xff,   0x00,   0xff,   0xff   };
+static const guchar  transparent_black8[4] = { 0x00,   0x00,   0x00,   0x00   };
+
+static const guint16 opaque_magenta16[4]   = { 0xffff, 0x0000, 0xffff, 0xffff };
+
+/* FIXME: Add tests for non-tile sized rects, they currently won't
+ * pass
+ */
+static const GeglRectangle rect            = { 0, 0, 64, 64 };
+static const GeglRectangle center_pixel    = { 5, 5, 1,  1  };
+
+
 /**
- * basic_usage:
+ * basic_read:
  * @fixture:
  * @data:
  *
- * Test basic usage.
+ * Test that the backend can be used for basic reading of TileManager
+ * data.
  **/
 static void
-basic_usage (GimpTestFixture *fixture,
-             gconstpointer    data)
+basic_read (GimpTestFixture *fixture,
+            gconstpointer    data)
 {
-  GeglRectangle rect                = { 0, 0, 10, 10 };
-  GeglRectangle pixel_rect          = { 5, 5, 1, 1 };
-  guchar        opaque_magenta8[4]  = { 0xff, 0, 0xff, 0xff };
-  guint16       opaque_magenta16[4] = { 0xffff, 0, 0xffff, 0xffff };
-
   PixelRegion      pr;
   TileManager     *tm;
   GeglTileBackend *backend;
@@ -84,8 +92,59 @@ basic_usage (GimpTestFixture *fixture,
    */
   backend = gimp_tile_backend_tile_manager_new (tm);
   buffer  = gegl_buffer_new_for_backend (NULL, backend);
-  gegl_buffer_get (buffer, 1.0 /*scale*/, &pixel_rect, babl_format ("RGBA u16"), actual_data, GEGL_AUTO_ROWSTRIDE);
-  g_assert_cmpint (0, ==, memcmp (opaque_magenta16, actual_data, sizeof (actual_data)));
+  gegl_buffer_get (buffer, 1.0 /*scale*/, &center_pixel,
+                   babl_format ("RGBA u16"), actual_data,
+                   GEGL_AUTO_ROWSTRIDE);
+  g_assert_cmpint (0, ==, memcmp (opaque_magenta16,
+                                  actual_data,
+                                  sizeof (actual_data)));
+}
+
+/**
+ * basic_write:
+ * @fixture:
+ * @data:
+ *
+ * Test that the backend can be used for basic writing of TileManager
+ * data.
+ **/
+static void
+basic_write (GimpTestFixture *fixture,
+             gconstpointer    data)
+{
+  PixelRegion      pr;
+  TileManager     *tm;
+  GeglTileBackend *backend;
+  GeglBuffer      *buffer;
+  guchar           actual_data[4];
+  gint             x, y;
+
+  /* Clear the TileManager */
+  tm = tile_manager_new (rect.width, rect.height, 4);
+  pixel_region_init (&pr, tm, rect.x, rect.y, rect.width, rect.height, TRUE);
+  color_region (&pr, transparent_black8);
+
+  /* Write some data using the GeglBuffer and the backend. Use u16 to
+   * complicate code paths, decreasing risk of the test accidentally
+   * passing
+   */
+  backend = gimp_tile_backend_tile_manager_new (tm);
+  buffer  = gegl_buffer_new_for_backend (NULL, backend);
+  for (y = 0; y < rect.height; y++)
+    for (x = 0; x < rect.width; x++)
+      {
+        GeglRectangle moving_rect = { x, y, 1, 1 };
+        gegl_buffer_set (buffer, &moving_rect,
+                         babl_format ("RGBA u16"), (gpointer) opaque_magenta16,
+                         GEGL_AUTO_ROWSTRIDE);
+      }
+
+  /* Make sure we can read the written data from the TileManager */
+  tile_manager_read_pixel_data_1 (tm, center_pixel.x, center_pixel.y,
+                                  actual_data);
+  g_assert_cmpint (0, ==, memcmp (opaque_magenta8,
+                                  actual_data,
+                                  sizeof (actual_data)));
 }
 
 int
@@ -97,7 +156,8 @@ main (int    argc,
   gegl_init (&argc, &argv);
   g_test_init (&argc, &argv, NULL);
 
-  ADD_TEST (basic_usage);
+  ADD_TEST (basic_read);
+  ADD_TEST (basic_write);
 
   return g_test_run ();
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]