Changeset 389

Show
Ignore:
Timestamp:
09/16/07 05:14:15 (6 years ago)
Author:
bjourne
Message:

Update tests per r386.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gtkimageview/tests/test-image-drawer.c

    r281 r389  
    11/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*- */ 
    22/** 
    3  * This file contains tests that validates that the ImageViewDrawer 
     3 * This file contains tests that validates that the GdkPixbufDrawCache 
    44 * class works correctly. 
    55 **/ 
     
    1111 * 
    1212 * The objective of this test is to verify that the cached pixbuf that 
    13  * the ImageViewDrawer holds is not discarded when it receives a new 
     13 * the GdkPixbufDrawCache holds is not discarded when it receives a new 
    1414 * pixbuf with the exact same bit depth and colorspace. 
    1515 **/ 
     
    2121    GdkPixbuf *pixbuf1 = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); 
    2222    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); 
    2423     
    2524    int interp = GDK_INTERP_BILINEAR; 
    2625    GdkRectangle area = {0, 0, 10, 10}; 
    2726     
    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}; 
    3029 
    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); 
    3332 
    3433    g_object_unref (pixbuf1); 
    3534    g_object_unref (pixbuf2); 
    36     g_object_unref (last_pb); 
    3735} 
    3836 
    3937/** 
    40  * test_cache_is_used_on_equal_settings: 
     38 * test_cache_is_used_on_equal_opts: 
    4139 * 
    4240 * 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 is 
    44  * smaller than the cached pixbuf. If so, the DrawMethod should be 
    45  * %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. 
    4644 **/ 
    4745static void 
    48 test_cache_is_used_on_equal_settings () 
     46test_cache_is_used_on_equal_opts () 
    4947{ 
    50     printf ("test_cache_is_used_on_equal_settings\n"); 
     48    printf ("test_cache_is_used_on_equal_opts\n"); 
    5149    int interp = GDK_INTERP_BILINEAR; 
    5250    GdkRectangle area = {0, 0, 10, 10}; 
    5351    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}; 
    5654 
    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); 
    5957 
    6058    g_object_unref (pb); 
     
    6563 * 
    6664 * The objective of this test is to verfy that the method is 
    67  * %DRAW_METHOD_CONTAINS even if the cache is smaller than the 
     65 * %GDK_PIXBUF_DRAW_METHOD_CONTAINS even if the cache is smaller than the 
    6866 * requsted draw area. 
    6967 **/ 
     
    7573    GdkRectangle area = {0, 0, 20, 20}; 
    7674     
    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}; 
    8079 
    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); 
    8482    g_object_unref (draw_pb); 
    85     g_object_unref (last_pb); 
    8683} 
    8784 
     
    9996    int interp = GDK_INTERP_BILINEAR; 
    10097    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}, 
    10299                           0, 0, interp, pb, 0, 0}; 
    103     DrawSettings parms2 = {1, (GdkRectangle){20, 0, 10, 10}, 
     100    GdkPixbufDrawOpts o2 = {1, (GdkRectangle){20, 0, 10, 10}, 
    104101                           0, 0, interp, pb, 0, 0}; 
    105102 
    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); 
    108105 
    109106    g_object_unref (pb); 
     
    111108 
    112109/** 
    113  * test_default_draw_settings: 
     110 * test_default_draw_options: 
    114111 * 
    115112 * 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. 
    117115 **/ 
    118116static void 
    119 test_default_draw_settings () 
     117test_default_draw_options () 
    120118{ 
    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 (); 
    123121    int interp = GDK_INTERP_BILINEAR; 
    124122    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); 
    130128     
    131     image_view_drawer_free (drawer); 
     129    gdk_pixbuf_draw_cache_free (cache); 
    132130    g_object_unref (pb); 
    133131} 
    134132 
    135133/** 
    136  * test_force_scale_operation
     134 * test_invalidate
    137135 * 
    138136 * 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. 
    140139 **/ 
    141140static void 
    142 test_force_scale_operation () 
     141test_invalidate () 
    143142{ 
    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 (); 
    146145     
    147146    GdkInterpType interp = GDK_INTERP_BILINEAR; 
    148147    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; 
    152151 
    153152 
    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); 
    157157 
    158158    /* Force a scale operation in the next draw. */ 
    159     image_view_drawer_force_scale (drawer); 
     159    gdk_pixbuf_draw_cache_invalidate (cache); 
    160160 
    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); 
    163163     
    164     image_view_drawer_free (drawer); 
     164    gdk_pixbuf_draw_cache_free (cache); 
    165165    g_object_unref (pb); 
    166166} 
     
    171171    gtk_init (&argc, &argv); 
    172172    test_only_scale_op_on_new_identical_pixbuf (); 
    173     test_cache_is_used_on_equal_settings (); 
     173    test_cache_is_used_on_equal_opts (); 
    174174    test_contains_even_if_cache_to_small (); 
    175175    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 (); 
    178178    printf ("6 tests passed.\n"); 
    179179}