Add tests for icon.c
This commit is contained in:
parent
651be8eee9
commit
3f7de41732
@ -8,3 +8,32 @@
|
||||
...
|
||||
fun:main
|
||||
}
|
||||
|
||||
# librsvg leaks some memory, when an invalid svg file is read
|
||||
# TODO: find the memory leak and fix it upstream
|
||||
{
|
||||
invalid_svgs1
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:gdk_pixbuf__svg_image_load_increment
|
||||
...
|
||||
fun:get_pixbuf_from_file
|
||||
}
|
||||
|
||||
{
|
||||
invalid_svgs2
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:gdk_pixbuf__svg_image_begin_load
|
||||
...
|
||||
fun:get_pixbuf_from_file
|
||||
}
|
||||
|
||||
{
|
||||
invalid_svgs3
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:rsvg_handle_write
|
||||
...
|
||||
fun:get_pixbuf_from_file
|
||||
}
|
||||
|
1
test/data/icons/invalid.png
Normal file
1
test/data/icons/invalid.png
Normal file
@ -0,0 +1 @@
|
||||
Got'cha! This has to be invalid!
|
1
test/data/icons/invalid.svg
Normal file
1
test/data/icons/invalid.svg
Normal file
@ -0,0 +1 @@
|
||||
Got'cha! This has to be invalid!
|
1
test/data/icons/path/invalid/icon1.png
Symbolic link
1
test/data/icons/path/invalid/icon1.png
Symbolic link
@ -0,0 +1 @@
|
||||
../../invalid.png
|
1
test/data/icons/path/invalid/icon1.svg
Symbolic link
1
test/data/icons/path/invalid/icon1.svg
Symbolic link
@ -0,0 +1 @@
|
||||
../../invalid.svg
|
1
test/data/icons/path/valid/icon1.png
Symbolic link
1
test/data/icons/path/valid/icon1.png
Symbolic link
@ -0,0 +1 @@
|
||||
../../valid.png
|
1
test/data/icons/path/valid/icon1.svg
Symbolic link
1
test/data/icons/path/valid/icon1.svg
Symbolic link
@ -0,0 +1 @@
|
||||
../../valid.svg
|
1
test/data/icons/path/valid/onlypng.png
Symbolic link
1
test/data/icons/path/valid/onlypng.png
Symbolic link
@ -0,0 +1 @@
|
||||
../../valid.png
|
1
test/data/icons/path/valid/onlysvg.svg
Symbolic link
1
test/data/icons/path/valid/onlysvg.svg
Symbolic link
@ -0,0 +1 @@
|
||||
../../valid.svg
|
BIN
test/data/icons/valid.png
Normal file
BIN
test/data/icons/valid.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 193 B |
65
test/data/icons/valid.svg
Normal file
65
test/data/icons/valid.svg
Normal file
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<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="16px"
|
||||
height="16px"
|
||||
viewBox="0 0 16 16"
|
||||
version="1.1"
|
||||
id="SVGRoot"
|
||||
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
|
||||
sodipodi:docname="valid.svg">
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="16"
|
||||
inkscape:cx="4.6127988"
|
||||
inkscape:cy="8"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="958"
|
||||
inkscape:window-height="1034"
|
||||
inkscape:window-x="960"
|
||||
inkscape:window-y="46"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:grid-bbox="true" />
|
||||
<defs
|
||||
id="defs20" />
|
||||
<metadata
|
||||
id="metadata23">
|
||||
<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>
|
||||
<g
|
||||
id="layer1"
|
||||
inkscape:groupmode="layer"
|
||||
inkscape:label="Layer 1">
|
||||
<rect
|
||||
style="opacity:0.98999999;fill:#cccccc;fill-opacity:1;stroke:#cccccc;stroke-width:1;stroke-miterlimit:4.19999981;stroke-dasharray:none;stroke-opacity:0.15686275"
|
||||
id="rect36"
|
||||
width="8"
|
||||
height="15.4375"
|
||||
x="3.75"
|
||||
y="0.25"
|
||||
ry="4.875" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.9 KiB |
98
test/icon.c
Normal file
98
test/icon.c
Normal file
@ -0,0 +1,98 @@
|
||||
#include "greatest.h"
|
||||
#include "../src/icon.h"
|
||||
#include "../src/utils.h"
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <glib.h>
|
||||
|
||||
#define ICONPREFIX "./data/icons/path"
|
||||
|
||||
/* As there are no hints to test if the loaded GdkPixbuf is
|
||||
* read from a PNG or an SVG file, the sample icons in the
|
||||
* test structure have different sizes
|
||||
*/
|
||||
#define IS_ICON_PNG(pb) 4 == gdk_pixbuf_get_width(pb)
|
||||
#define IS_ICON_SVG(pb) 16 == gdk_pixbuf_get_width(pb)
|
||||
|
||||
TEST test_get_pixbuf_from_path_invalid(void)
|
||||
{
|
||||
GdkPixbuf *pixbuf = get_pixbuf_from_path("invalid");
|
||||
ASSERT(pixbuf == NULL);
|
||||
g_clear_pointer(&pixbuf, g_object_unref);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_get_pixbuf_from_path_both(void)
|
||||
{
|
||||
GdkPixbuf *pixbuf = get_pixbuf_from_path("icon1");
|
||||
ASSERT(pixbuf);
|
||||
ASSERTm("SVG pixbuf hasn't precedence", IS_ICON_SVG(pixbuf));
|
||||
g_clear_pointer(&pixbuf, g_object_unref);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_get_pixbuf_from_path_onlysvg(void)
|
||||
{
|
||||
GdkPixbuf *pixbuf = get_pixbuf_from_path("onlysvg");
|
||||
ASSERT(pixbuf);
|
||||
ASSERTm("SVG pixbuf isn't loaded", IS_ICON_SVG(pixbuf));
|
||||
g_clear_pointer(&pixbuf, g_object_unref);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_get_pixbuf_from_path_onlypng(void)
|
||||
{
|
||||
GdkPixbuf *pixbuf = get_pixbuf_from_path("onlypng");
|
||||
ASSERT(pixbuf);
|
||||
ASSERTm("PNG pixbuf isn't loaded", IS_ICON_PNG(pixbuf));
|
||||
g_clear_pointer(&pixbuf, g_object_unref);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_get_pixbuf_from_path_filename(void)
|
||||
{
|
||||
char *icon = string_append(g_get_current_dir(), "/data/icons/valid.png", NULL);
|
||||
GdkPixbuf *pixbuf = get_pixbuf_from_path(icon);
|
||||
ASSERT(pixbuf);
|
||||
ASSERTm("PNG pixbuf isn't loaded", IS_ICON_PNG(pixbuf));
|
||||
g_clear_pointer(&pixbuf, g_object_unref);
|
||||
|
||||
g_free(icon);
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_get_pixbuf_from_path_fileuri(void)
|
||||
{
|
||||
char *curdir = g_get_current_dir();
|
||||
char *icon = g_strconcat("file://", curdir,"/data/icons/valid.svg", NULL);
|
||||
GdkPixbuf *pixbuf = get_pixbuf_from_path(icon);
|
||||
ASSERT(pixbuf);
|
||||
ASSERTm("SVG pixbuf isn't loaded", IS_ICON_SVG(pixbuf));
|
||||
g_clear_pointer(&pixbuf, g_object_unref);
|
||||
|
||||
g_free(icon);
|
||||
g_free(curdir);
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(suite_icon)
|
||||
{
|
||||
settings.icon_path =
|
||||
ICONPREFIX "/invalid"
|
||||
":" ICONPREFIX "/valid"
|
||||
":" ICONPREFIX "/both";
|
||||
|
||||
RUN_TEST(test_get_pixbuf_from_path_invalid);
|
||||
RUN_TEST(test_get_pixbuf_from_path_both);
|
||||
RUN_TEST(test_get_pixbuf_from_path_onlysvg);
|
||||
RUN_TEST(test_get_pixbuf_from_path_onlypng);
|
||||
RUN_TEST(test_get_pixbuf_from_path_filename);
|
||||
RUN_TEST(test_get_pixbuf_from_path_fileuri);
|
||||
|
||||
settings.icon_path = NULL;
|
||||
}
|
||||
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
@ -120,6 +120,8 @@ SUITE(suite_notification)
|
||||
g_free(b);
|
||||
|
||||
RUN_TEST(test_notification_replace_single_field);
|
||||
|
||||
g_clear_pointer(&settings.icon_path, g_free);
|
||||
}
|
||||
|
||||
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
||||
|
@ -8,6 +8,7 @@ SUITE_EXTERN(suite_utils);
|
||||
SUITE_EXTERN(suite_option_parser);
|
||||
SUITE_EXTERN(suite_notification);
|
||||
SUITE_EXTERN(suite_markup);
|
||||
SUITE_EXTERN(suite_icon);
|
||||
|
||||
GREATEST_MAIN_DEFS();
|
||||
|
||||
@ -20,6 +21,7 @@ int main(int argc, char *argv[]) {
|
||||
RUN_SUITE(suite_option_parser);
|
||||
RUN_SUITE(suite_notification);
|
||||
RUN_SUITE(suite_markup);
|
||||
RUN_SUITE(suite_icon);
|
||||
GREATEST_MAIN_END();
|
||||
}
|
||||
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
||||
|
Loading…
x
Reference in New Issue
Block a user