forked from AuroraMiddleware/gtk
testsuite: Add a basic icontheme test
Most of the work here is creating the infrastructure to have a custom icon theme to add icons to and run tests against.
This commit is contained in:
parent
5e07b80854
commit
5ba4a085e2
@ -40,6 +40,7 @@ TEST_PROGS += \
|
||||
floating \
|
||||
grid \
|
||||
gtkmenu \
|
||||
icontheme \
|
||||
keyhash \
|
||||
listbox \
|
||||
no-gtk-init \
|
||||
@ -124,10 +125,15 @@ keyhash_SOURCES = \
|
||||
$(NULL)
|
||||
|
||||
|
||||
test_icontheme = \
|
||||
icons/16x16/simple.png \
|
||||
icons/index.theme \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST += \
|
||||
file-chooser-test-dir/empty \
|
||||
file-chooser-test-dir/text.txt \
|
||||
$(test_icontheme) \
|
||||
$(NULL)
|
||||
|
||||
GTK_GSETTINGS_SCHEMAS = \
|
||||
@ -149,6 +155,7 @@ all-am: gschemas.compiled
|
||||
if BUILDOPT_INSTALL_TESTS
|
||||
insttestdir = $(pkglibexecdir)/installed-tests
|
||||
insttest_PROGRAMS = $(TEST_PROGS)
|
||||
insttest_DATA = $(test_icontheme)
|
||||
|
||||
%.test: %$(EXEEXT) Makefile
|
||||
$(AM_V_GEN) (echo '[Test]' > $@.tmp; \
|
||||
|
BIN
testsuite/gtk/icons/16x16/simple.png
Normal file
BIN
testsuite/gtk/icons/16x16/simple.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 174 B |
12
testsuite/gtk/icons/index.theme
Normal file
12
testsuite/gtk/icons/index.theme
Normal file
@ -0,0 +1,12 @@
|
||||
[Icon Theme]
|
||||
Name=Icons
|
||||
Comment=Testing of the Icon theme code
|
||||
Example=16x16/simple.png
|
||||
|
||||
Directories=16x16
|
||||
|
||||
[16x16]
|
||||
Context=16x16 icons
|
||||
Size=16
|
||||
Type=Fixed
|
||||
|
86
testsuite/gtk/icontheme.c
Normal file
86
testsuite/gtk/icontheme.c
Normal file
@ -0,0 +1,86 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static GtkIconTheme *
|
||||
get_test_icontheme (void)
|
||||
{
|
||||
static GtkIconTheme *icon_theme = NULL;
|
||||
const char *current_dir;
|
||||
|
||||
if (icon_theme)
|
||||
return icon_theme;
|
||||
|
||||
icon_theme = gtk_icon_theme_new ();
|
||||
gtk_icon_theme_set_custom_theme (icon_theme, "icons");
|
||||
current_dir = g_get_current_dir ();
|
||||
gtk_icon_theme_set_search_path (icon_theme, ¤t_dir, 1);
|
||||
|
||||
return icon_theme;
|
||||
}
|
||||
|
||||
static char *
|
||||
lookup_flags_to_string (GtkIconLookupFlags flags)
|
||||
{
|
||||
GValue flags_value = { 0, }, string_value = { 0, };
|
||||
char *result;
|
||||
|
||||
g_value_init (&flags_value, GTK_TYPE_ICON_LOOKUP_FLAGS);
|
||||
g_value_init (&string_value, G_TYPE_STRING);
|
||||
|
||||
g_value_set_flags (&flags_value, flags);
|
||||
if (!g_value_transform (&flags_value, &string_value))
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
result = g_value_dup_string (&string_value);
|
||||
|
||||
g_value_unset (&flags_value);
|
||||
g_value_unset (&string_value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
assert_icon_lookup (const char *icon_name,
|
||||
gint size,
|
||||
GtkIconLookupFlags flags,
|
||||
const char *filename)
|
||||
{
|
||||
GtkIconInfo *info;
|
||||
|
||||
info = gtk_icon_theme_lookup_icon (get_test_icontheme (), icon_name, size, flags);
|
||||
if (info == NULL)
|
||||
{
|
||||
g_error ("Could not look up an icon for \"%s\" with flags %s at size %d",
|
||||
icon_name, lookup_flags_to_string (flags), size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_str_has_suffix (gtk_icon_info_get_filename (info), filename))
|
||||
{
|
||||
g_error ("Icon for \"%s\" with flags %s at size %d should be \"...%s\" but is \"...%s\"",
|
||||
icon_name, lookup_flags_to_string (flags), size,
|
||||
filename, gtk_icon_info_get_filename (info) + strlen (gtk_icon_info_get_filename (info)) - strlen (filename));
|
||||
return;
|
||||
}
|
||||
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
static void
|
||||
test_basics (void)
|
||||
{
|
||||
assert_icon_lookup ("simple", 16, 0, "/icons/16x16/simple.png");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv);
|
||||
|
||||
g_test_add_func ("/icontheme/basics", test_basics);
|
||||
|
||||
return g_test_run();
|
||||
}
|
Loading…
Reference in New Issue
Block a user