Changeset 389
- Timestamp:
- 09/16/07 05:14:15 (6 years ago)
- Files:
-
- gtkimageview/tests/test-image-drawer.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gtkimageview/tests/test-image-drawer.c
r281 r389 1 1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*- */ 2 2 /** 3 * This file contains tests that validates that the ImageViewDrawer3 * This file contains tests that validates that the GdkPixbufDrawCache 4 4 * class works correctly. 5 5 **/ … … 11 11 * 12 12 * The objective of this test is to verify that the cached pixbuf that 13 * the ImageViewDrawerholds is not discarded when it receives a new13 * the GdkPixbufDrawCache holds is not discarded when it receives a new 14 14 * pixbuf with the exact same bit depth and colorspace. 15 15 **/ … … 21 21 GdkPixbuf *pixbuf1 = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); 22 22 GdkPixbuf *pixbuf2 = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); 23 GdkPixbuf *last_pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 50, 50);24 23 25 24 int interp = GDK_INTERP_BILINEAR; 26 25 GdkRectangle area = {0, 0, 10, 10}; 27 26 28 DrawSettings parms1 = {1, area, 0, 0, interp, pixbuf1, 0, 0};29 DrawSettings parms2 = {1, area, 0, 0, interp, pixbuf2, 0, 0};27 GdkPixbufDrawOpts o1 = {1, area, 0, 0, interp, pixbuf1, 0, 0}; 28 GdkPixbufDrawOpts o2 = {1, area, 0, 0, interp, pixbuf2, 0, 0}; 30 29 31 DrawMethod meth = draw_settings_get_method (&parms1, &parms2, last_pb);32 assert (meth == DRAW_METHOD_SCALE);30 GdkPixbufDrawMethod meth = gdk_pixbuf_draw_cache_get_method (&o1, &o2); 31 assert (meth == GDK_PIXBUF_DRAW_METHOD_SCALE); 33 32 34 33 g_object_unref (pixbuf1); 35 34 g_object_unref (pixbuf2); 36 g_object_unref (last_pb);37 35 } 38 36 39 37 /** 40 * test_cache_is_used_on_equal_ settings:38 * test_cache_is_used_on_equal_opts: 41 39 * 42 40 * The objective of this test is to verify that the cache is used when 43 * the new draw settings are identical to the old ones if the area is44 * smaller than the cached pixbuf. If so, the DrawMethod should be45 * %DRAW_METHOD_CONTAINS.41 * the new draw options are identical to the old ones if the area is 42 * smaller than the cached pixbuf. If so, the #GdkPixbufDrawMethod 43 * should be %GDK_PIXBUF_DRAW_METHOD_CONTAINS. 46 44 **/ 47 45 static void 48 test_cache_is_used_on_equal_ settings ()46 test_cache_is_used_on_equal_opts () 49 47 { 50 printf ("test_cache_is_used_on_equal_ settings\n");48 printf ("test_cache_is_used_on_equal_opts\n"); 51 49 int interp = GDK_INTERP_BILINEAR; 52 50 GdkRectangle area = {0, 0, 10, 10}; 53 51 GdkPixbuf *pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 30, 30); 54 DrawSettings parms1 = {1, area, 0, 0, interp, pb, 0, 0};55 DrawSettings parms2 = {1, area, 0, 0, interp, pb, 0, 0};52 GdkPixbufDrawOpts o1 = {1, area, 0, 0, interp, pb, 0, 0}; 53 GdkPixbufDrawOpts o2 = {1, area, 0, 0, interp, pb, 0, 0}; 56 54 57 DrawMethod meth = draw_settings_get_method (&parms1, &parms2, pb);58 assert (meth == DRAW_METHOD_CONTAINS);55 GdkPixbufDrawMethod meth = gdk_pixbuf_draw_cache_get_method (&o1, &o2); 56 assert (meth == GDK_PIXBUF_DRAW_METHOD_CONTAINS); 59 57 60 58 g_object_unref (pb); … … 65 63 * 66 64 * The objective of this test is to verfy that the method is 67 * % DRAW_METHOD_CONTAINS even if the cache is smaller than the65 * %GDK_PIXBUF_DRAW_METHOD_CONTAINS even if the cache is smaller than the 68 66 * requsted draw area. 69 67 **/ … … 75 73 GdkRectangle area = {0, 0, 20, 20}; 76 74 77 GdkPixbuf *draw_pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 30, 30); 78 DrawSettings parms1 = {1, area, 0, 0, interp, draw_pb, 0, 0}; 79 DrawSettings parms2 = {1, area, 0, 0, interp, draw_pb, 0, 0}; 75 GdkPixbuf *draw_pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 76 8, 30, 30); 77 GdkPixbufDrawOpts o1 = {1, area, 0, 0, interp, draw_pb, 0, 0}; 78 GdkPixbufDrawOpts o2 = {1, area, 0, 0, interp, draw_pb, 0, 0}; 80 79 81 GdkPixbuf *last_pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 10, 10); 82 DrawMethod meth = draw_settings_get_method (&parms1, &parms2, last_pb); 83 assert (meth == DRAW_METHOD_CONTAINS); 80 GdkPixbufDrawMethod meth = gdk_pixbuf_draw_cache_get_method (&o1, &o2); 81 assert (meth == GDK_PIXBUF_DRAW_METHOD_CONTAINS); 84 82 g_object_unref (draw_pb); 85 g_object_unref (last_pb);86 83 } 87 84 … … 99 96 int interp = GDK_INTERP_BILINEAR; 100 97 GdkPixbuf *pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); 101 DrawSettings parms1 = {1, (GdkRectangle){0, 0, 20, 20},98 GdkPixbufDrawOpts o1 = {1, (GdkRectangle){0, 0, 20, 20}, 102 99 0, 0, interp, pb, 0, 0}; 103 DrawSettings parms2 = {1, (GdkRectangle){20, 0, 10, 10},100 GdkPixbufDrawOpts o2 = {1, (GdkRectangle){20, 0, 10, 10}, 104 101 0, 0, interp, pb, 0, 0}; 105 102 106 DrawMethod meth = draw_settings_get_method (&parms1, &parms2, pb);107 assert (meth == DRAW_METHOD_SCROLL);103 GdkPixbufDrawMethod meth = gdk_pixbuf_draw_cache_get_method (&o1, &o2); 104 assert (meth == GDK_PIXBUF_DRAW_METHOD_SCROLL); 108 105 109 106 g_object_unref (pb); … … 111 108 112 109 /** 113 * test_default_draw_ settings:110 * test_default_draw_options: 114 111 * 115 112 * The objective of this test is to verify that the default draw 116 * settings in the image drawer results in the correct draw flags. 113 * options in the pixbuf draw cache results in the correct draw 114 * method. 117 115 **/ 118 116 static void 119 test_default_draw_ settings ()117 test_default_draw_options () 120 118 { 121 printf ("test_default_draw_ settings\n");122 ImageViewDrawer *drawer = image_view_drawer_new ();119 printf ("test_default_draw_options\n"); 120 GdkPixbufDrawCache *cache = gdk_pixbuf_draw_cache_new (); 123 121 int interp = GDK_INTERP_BILINEAR; 124 122 GdkPixbuf *pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); 125 DrawSettings parms= {1, (GdkRectangle){0, 0, 20, 20},126 0, 0, interp, pb, 0, 0};127 DrawMethod meth = draw_settings_get_method (&drawer->old, &parms,128 drawer->last_pixbuf);129 assert (meth == DRAW_METHOD_SCALE);123 GdkPixbufDrawOpts o = {1, (GdkRectangle){0, 0, 20, 20}, 124 0, 0, interp, pb, 0, 0}; 125 GdkPixbufDrawMethod meth = 126 gdk_pixbuf_draw_cache_get_method (&cache->old, &o); 127 assert (meth == GDK_PIXBUF_DRAW_METHOD_SCALE); 130 128 131 image_view_drawer_free (drawer);129 gdk_pixbuf_draw_cache_free (cache); 132 130 g_object_unref (pb); 133 131 } 134 132 135 133 /** 136 * test_ force_scale_operation:134 * test_invalidate: 137 135 * 138 136 * The objective of this test is to verify that forcing the 139 * ImageViewDrawer to apply a scale operation works as expected. 137 * GdkPixbufDrawCache to apply a scale operation by invalidating works 138 * as expected. 140 139 **/ 141 140 static void 142 test_ force_scale_operation()141 test_invalidate () 143 142 { 144 printf ("test_ force_scale_operation\n");145 ImageViewDrawer *drawer = image_view_drawer_new ();143 printf ("test_invalidate\n"); 144 GdkPixbufDrawCache *cache = gdk_pixbuf_draw_cache_new (); 146 145 147 146 GdkInterpType interp = GDK_INTERP_BILINEAR; 148 147 GdkPixbuf *pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); 149 DrawSettings parms = {1, (GdkRectangle){0, 0, 5, 5},150 0, 0, interp, pb, 0, 0};151 drawer->old = parms;148 GdkPixbufDrawOpts opts = {1, (GdkRectangle){0, 0, 5, 5}, 149 0, 0, interp, pb, 0, 0}; 150 cache->old = opts; 152 151 153 152 154 /* DrawSettings are identical, so no allocation or scale necessary. */ 155 assert (draw_settings_get_method (&drawer->old, &parms, pb) 156 == DRAW_METHOD_CONTAINS); 153 /* GdkPixbufDrawOpts are identical, so no allocation or scale 154 necessary. */ 155 assert (gdk_pixbuf_draw_cache_get_method (&cache->old, &opts) 156 == GDK_PIXBUF_DRAW_METHOD_CONTAINS); 157 157 158 158 /* Force a scale operation in the next draw. */ 159 image_view_drawer_force_scale (drawer);159 gdk_pixbuf_draw_cache_invalidate (cache); 160 160 161 DrawMethod meth = draw_settings_get_method (&drawer->old, &parms, pb);162 assert (meth ==DRAW_METHOD_SCALE);161 assert (gdk_pixbuf_draw_cache_get_method (&cache->old, &opts) == 162 GDK_PIXBUF_DRAW_METHOD_SCALE); 163 163 164 image_view_drawer_free (drawer);164 gdk_pixbuf_draw_cache_free (cache); 165 165 g_object_unref (pb); 166 166 } … … 171 171 gtk_init (&argc, &argv); 172 172 test_only_scale_op_on_new_identical_pixbuf (); 173 test_cache_is_used_on_equal_ settings ();173 test_cache_is_used_on_equal_opts (); 174 174 test_contains_even_if_cache_to_small (); 175 175 test_scroll_needed_if_rect_size_not_equal (); 176 test_default_draw_ settings ();177 test_ force_scale_operation();176 test_default_draw_options (); 177 test_invalidate (); 178 178 printf ("6 tests passed.\n"); 179 179 }
