Add more icontheme tests

This test is focused on svgs, and how we scale them when
loading.
This commit is contained in:
Matthias Clasen 2014-06-14 15:06:57 -04:00
parent fd53732035
commit 84cf748eae
6 changed files with 186 additions and 7 deletions

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
version="1.1"
id="svg3033"
inkscape:version="0.48.4 r9939"
sodipodi:docname="only32-svg.svg">
<metadata
id="metadata3041">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs3039" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="640"
inkscape:window-height="480"
id="namedview3037"
showgrid="false"
inkscape:zoom="11.313708"
inkscape:cx="16"
inkscape:cy="16.526174"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="0"
inkscape:current-layer="svg3033" />
<text
x="16"
y="24"
font-size="24"
id="text3035"
style="font-size:24px;text-anchor:middle">16</text>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
version="1.1"
id="svg3033"
inkscape:version="0.48.4 r9939"
sodipodi:docname="only32-svg.svg">
<metadata
id="metadata3041">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs3039" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="640"
inkscape:window-height="480"
id="namedview3037"
showgrid="false"
inkscape:zoom="11.313708"
inkscape:cx="16"
inkscape:cy="16.526174"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="0"
inkscape:current-layer="svg3033" />
<text
x="16"
y="24"
font-size="24"
id="text3035"
style="font-size:24px;text-anchor:middle">16</text>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,4 @@
<?xml version="1.0" standalone="no"?>
<svg width="32" height="32" version="1.1" xmlns="http://www.w3.org/2000/svg">
<text x="16" y="24" text-anchor="middle" font-size="24">32</text>
</svg>

After

Width:  |  Height:  |  Size: 191 B

View File

@ -0,0 +1,4 @@
<?xml version="1.0" standalone="no"?>
<svg width="32" height="32" version="1.1" xmlns="http://www.w3.org/2000/svg">
<text x="16" y="24" text-anchor="middle" font-size="24">32</text>
</svg>

After

Width:  |  Height:  |  Size: 191 B

View File

@ -3,7 +3,7 @@ Name=Icons
Comment=Testing of the Icon theme code
Example=16x16/simple.png
Directories=16x16,32x32,scalable
Directories=16x16,16x16s,32x32,32x32s,scalable
[16x16]
Context=16x16 icons
@ -15,9 +15,23 @@ Context=32x32 icons
Size=32
Type=Fixed
[16x16s]
Context=scalable 16x16 icons
Size=16
MinSize=12
MaxSize=24
Type=Scalable
[32x32s]
Context=scalable 32x32 icons
Size=32
MinSize=24
MaxSize=48
Type=Scalable
[scalable]
Context=scalable icons
Type=Scalable
Size=128
Min-Size=1
Max-Size=256
MinSize=1
MaxSize=256

View File

@ -45,10 +45,11 @@ lookup_flags_to_string (GtkIconLookupFlags flags)
}
static void
assert_icon_lookup (const char *icon_name,
gint size,
GtkIconLookupFlags flags,
const char *filename)
assert_icon_lookup_size (const char *icon_name,
gint size,
GtkIconLookupFlags flags,
const char *filename,
gint pixbuf_size)
{
GtkIconInfo *info;
@ -68,9 +69,29 @@ assert_icon_lookup (const char *icon_name,
return;
}
if (pixbuf_size > 0)
{
GdkPixbuf *pixbuf;
GError *error = NULL;
pixbuf = gtk_icon_info_load_icon (info, &error);
g_assert_no_error (error);
g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, pixbuf_size);
g_object_unref (pixbuf);
}
g_object_unref (info);
}
static void
assert_icon_lookup (const char *icon_name,
gint size,
GtkIconLookupFlags flags,
const char *filename)
{
assert_icon_lookup_size (icon_name, size, flags, filename, -1);
}
static void
assert_icon_lookup_fails (const char *icon_name,
gint size,
@ -424,6 +445,29 @@ test_symbolic_single_size (void)
"/icons/32x32/only32-symbolic.svg");
}
static void
test_svg_size (void)
{
/* To understand these results, keep in mind that we never allow upscaling,
* and don't respect min/max size for scaling (though we do take it into
* account for choosing).
*/
/* Check we properly load a svg icon from a sized directory */
assert_icon_lookup_size ("twosize-fixed", 48, 0, "/icons/32x32/twosize-fixed.svg", 32);
assert_icon_lookup_size ("twosize-fixed", 32, 0, "/icons/32x32/twosize-fixed.svg", 32);
assert_icon_lookup_size ("twosize-fixed", 20, 0, "/icons/32x32/twosize-fixed.svg", 32);
assert_icon_lookup_size ("twosize-fixed", 16, 0, "/icons/16x16/twosize-fixed.svg", 16);
/* Check that we still properly load it even if a different size is requested */
assert_icon_lookup_size ("twosize", 64, 0, "/icons/32x32s/twosize.svg", 64);
assert_icon_lookup_size ("twosize", 48, 0, "/icons/32x32s/twosize.svg", 48);
assert_icon_lookup_size ("twosize", 32, 0, "/icons/32x32s/twosize.svg", 32);
assert_icon_lookup_size ("twosize", 24, 0, "/icons/32x32s/twosize.svg", 24);
assert_icon_lookup_size ("twosize", 16, 0, "/icons/16x16s/twosize.svg", 16);
assert_icon_lookup_size ("twosize", 12, 0, "/icons/16x16s/twosize.svg", 12);
assert_icon_lookup_size ("twosize", 8, 0, "/icons/16x16s/twosize.svg", 8);
}
int
main (int argc, char *argv[])
{
@ -436,6 +480,7 @@ main (int argc, char *argv[])
g_test_add_func ("/icontheme/force-regular", test_force_regular);
g_test_add_func ("/icontheme/rtl", test_rtl);
g_test_add_func ("/icontheme/symbolic-single-size", test_symbolic_single_size);
g_test_add_func ("/icontheme/svg-size", test_svg_size);
return g_test_run();
}