| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
#include <assert.h> |
|---|
| 7 |
#include <src/gtkimageview.h> |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
static void |
|---|
| 17 |
test_only_scale_op_on_new_identical_pixbuf () |
|---|
| 18 |
{ |
|---|
| 19 |
printf ("test_only_scale_op_on_new_identical_pixbuf\n"); |
|---|
| 20 |
|
|---|
| 21 |
GdkPixbuf *pixbuf1 = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); |
|---|
| 22 |
GdkPixbuf *pixbuf2 = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); |
|---|
| 23 |
|
|---|
| 24 |
int interp = GDK_INTERP_BILINEAR; |
|---|
| 25 |
GdkRectangle area = {0, 0, 10, 10}; |
|---|
| 26 |
|
|---|
| 27 |
GdkPixbufDrawOpts o1 = {1, area, 0, 0, interp, pixbuf1, 0, 0}; |
|---|
| 28 |
GdkPixbufDrawOpts o2 = {1, area, 0, 0, interp, pixbuf2, 0, 0}; |
|---|
| 29 |
|
|---|
| 30 |
GdkPixbufDrawMethod meth = gdk_pixbuf_draw_cache_get_method (&o1, &o2); |
|---|
| 31 |
assert (meth == GDK_PIXBUF_DRAW_METHOD_SCALE); |
|---|
| 32 |
|
|---|
| 33 |
g_object_unref (pixbuf1); |
|---|
| 34 |
g_object_unref (pixbuf2); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
static void |
|---|
| 46 |
test_cache_is_used_on_equal_opts () |
|---|
| 47 |
{ |
|---|
| 48 |
printf ("test_cache_is_used_on_equal_opts\n"); |
|---|
| 49 |
int interp = GDK_INTERP_BILINEAR; |
|---|
| 50 |
GdkRectangle area = {0, 0, 10, 10}; |
|---|
| 51 |
GdkPixbuf *pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 30, 30); |
|---|
| 52 |
GdkPixbufDrawOpts o1 = {1, area, 0, 0, interp, pb, 0, 0}; |
|---|
| 53 |
GdkPixbufDrawOpts o2 = {1, area, 0, 0, interp, pb, 0, 0}; |
|---|
| 54 |
|
|---|
| 55 |
GdkPixbufDrawMethod meth = gdk_pixbuf_draw_cache_get_method (&o1, &o2); |
|---|
| 56 |
assert (meth == GDK_PIXBUF_DRAW_METHOD_CONTAINS); |
|---|
| 57 |
|
|---|
| 58 |
g_object_unref (pb); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
static void |
|---|
| 69 |
test_contains_even_if_cache_to_small () |
|---|
| 70 |
{ |
|---|
| 71 |
printf ("test_contains_even_if_cache_to_small\n"); |
|---|
| 72 |
int interp = GDK_INTERP_BILINEAR; |
|---|
| 73 |
GdkRectangle area = {0, 0, 20, 20}; |
|---|
| 74 |
|
|---|
| 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}; |
|---|
| 79 |
|
|---|
| 80 |
GdkPixbufDrawMethod meth = gdk_pixbuf_draw_cache_get_method (&o1, &o2); |
|---|
| 81 |
assert (meth == GDK_PIXBUF_DRAW_METHOD_CONTAINS); |
|---|
| 82 |
g_object_unref (draw_pb); |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
static void |
|---|
| 93 |
test_scroll_needed_if_rect_size_not_equal () |
|---|
| 94 |
{ |
|---|
| 95 |
printf ("test_scroll_needed_if_rect_size_not_equal\n"); |
|---|
| 96 |
int interp = GDK_INTERP_BILINEAR; |
|---|
| 97 |
GdkPixbuf *pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); |
|---|
| 98 |
GdkPixbufDrawOpts o1 = {1, (GdkRectangle){0, 0, 20, 20}, |
|---|
| 99 |
0, 0, interp, pb, 0, 0}; |
|---|
| 100 |
GdkPixbufDrawOpts o2 = {1, (GdkRectangle){20, 0, 10, 10}, |
|---|
| 101 |
0, 0, interp, pb, 0, 0}; |
|---|
| 102 |
|
|---|
| 103 |
GdkPixbufDrawMethod meth = gdk_pixbuf_draw_cache_get_method (&o1, &o2); |
|---|
| 104 |
assert (meth == GDK_PIXBUF_DRAW_METHOD_SCROLL); |
|---|
| 105 |
|
|---|
| 106 |
g_object_unref (pb); |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
static void |
|---|
| 117 |
test_default_draw_options () |
|---|
| 118 |
{ |
|---|
| 119 |
printf ("test_default_draw_options\n"); |
|---|
| 120 |
GdkPixbufDrawCache *cache = gdk_pixbuf_draw_cache_new (); |
|---|
| 121 |
int interp = GDK_INTERP_BILINEAR; |
|---|
| 122 |
GdkPixbuf *pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); |
|---|
| 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); |
|---|
| 128 |
|
|---|
| 129 |
gdk_pixbuf_draw_cache_free (cache); |
|---|
| 130 |
g_object_unref (pb); |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
static void |
|---|
| 141 |
test_invalidate () |
|---|
| 142 |
{ |
|---|
| 143 |
printf ("test_invalidate\n"); |
|---|
| 144 |
GdkPixbufDrawCache *cache = gdk_pixbuf_draw_cache_new (); |
|---|
| 145 |
|
|---|
| 146 |
GdkInterpType interp = GDK_INTERP_BILINEAR; |
|---|
| 147 |
GdkPixbuf *pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 9, 9); |
|---|
| 148 |
GdkPixbufDrawOpts opts = {1, (GdkRectangle){0, 0, 5, 5}, |
|---|
| 149 |
0, 0, interp, pb, 0, 0}; |
|---|
| 150 |
cache->old = opts; |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
assert (gdk_pixbuf_draw_cache_get_method (&cache->old, &opts) |
|---|
| 156 |
== GDK_PIXBUF_DRAW_METHOD_CONTAINS); |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
gdk_pixbuf_draw_cache_invalidate (cache); |
|---|
| 160 |
|
|---|
| 161 |
assert (gdk_pixbuf_draw_cache_get_method (&cache->old, &opts) == |
|---|
| 162 |
GDK_PIXBUF_DRAW_METHOD_SCALE); |
|---|
| 163 |
|
|---|
| 164 |
gdk_pixbuf_draw_cache_free (cache); |
|---|
| 165 |
g_object_unref (pb); |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
int |
|---|
| 169 |
main(int argc, char *argv[]) |
|---|
| 170 |
{ |
|---|
| 171 |
gtk_init (&argc, &argv); |
|---|
| 172 |
test_only_scale_op_on_new_identical_pixbuf (); |
|---|
| 173 |
test_cache_is_used_on_equal_opts (); |
|---|
| 174 |
test_contains_even_if_cache_to_small (); |
|---|
| 175 |
test_scroll_needed_if_rect_size_not_equal (); |
|---|
| 176 |
test_default_draw_options (); |
|---|
| 177 |
test_invalidate (); |
|---|
| 178 |
printf ("6 tests passed.\n"); |
|---|
| 179 |
} |
|---|