forked from AuroraMiddleware/gtk
5f794773aa
Check that the lookup order works properly when forcing either symbolic or regular icons.
217 lines
8.1 KiB
C
217 lines
8.1 KiB
C
#include <gtk/gtk.h>
|
|
|
|
#include <string.h>
|
|
|
|
#define SCALABLE_IMAGE_SIZE (128)
|
|
|
|
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 (g_get_current_dir ()));
|
|
return;
|
|
}
|
|
|
|
g_object_unref (info);
|
|
}
|
|
|
|
static void
|
|
assert_icon_lookup_fails (const char *icon_name,
|
|
gint size,
|
|
GtkIconLookupFlags flags)
|
|
{
|
|
static gboolean seen_could_not_find_message = FALSE;
|
|
GtkIconInfo *info;
|
|
|
|
if (!seen_could_not_find_message)
|
|
g_test_expect_message ("Gtk", G_LOG_LEVEL_WARNING, "Could not find the icon*");
|
|
info = gtk_icon_theme_lookup_icon (get_test_icontheme (), icon_name, size, flags);
|
|
if (!seen_could_not_find_message)
|
|
{
|
|
g_test_assert_expected_messages ();
|
|
seen_could_not_find_message = TRUE;
|
|
}
|
|
if (info != NULL)
|
|
{
|
|
g_error ("Should not find an icon for \"%s\" with flags %s at size %d, but found \"%s\"",
|
|
icon_name, lookup_flags_to_string (flags), size, gtk_icon_info_get_filename (info) + strlen (g_get_current_dir ()));
|
|
g_object_unref (info);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
static void
|
|
test_basics (void)
|
|
{
|
|
assert_icon_lookup ("simple", 16, 0, "/icons/16x16/simple.png");
|
|
}
|
|
|
|
static void
|
|
test_force_symbolic (void)
|
|
{
|
|
/* check forcing symbolic works */
|
|
assert_icon_lookup ("everything",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
"/icons/scalable/everything-symbolic.svg");
|
|
/* check forcing symbolic also works for symbolic icons (d'oh) */
|
|
assert_icon_lookup ("everything-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
"/icons/scalable/everything-symbolic.svg");
|
|
|
|
/* check all the combos for fallbacks on an icon that only exists as symbolic */
|
|
assert_icon_lookup ("everything-justsymbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
assert_icon_lookup ("everything-justsymbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
assert_icon_lookup ("everything-justsymbolic-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
assert_icon_lookup ("everything-justsymbolic-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
|
|
/* check all the combos for fallbacks, this time for an icon that only exists as regular */
|
|
assert_icon_lookup ("everything-justregular",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
"/icons/scalable/everything-justregular.svg");
|
|
assert_icon_lookup ("everything-justregular",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
"/icons/scalable/everything-symbolic.svg");
|
|
assert_icon_lookup_fails ("everything-justregular-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC);
|
|
assert_icon_lookup ("everything-justregular-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
"/icons/scalable/everything-symbolic.svg");
|
|
}
|
|
|
|
static void
|
|
test_force_regular (void)
|
|
{
|
|
/* check forcing regular works (d'oh) */
|
|
assert_icon_lookup ("everything",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
"/icons/scalable/everything.svg");
|
|
/* check forcing regular also works for symbolic icons ) */
|
|
assert_icon_lookup ("everything-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
"/icons/scalable/everything.svg");
|
|
|
|
/* check all the combos for fallbacks on an icon that only exists as regular */
|
|
assert_icon_lookup ("everything-justregular",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
"/icons/scalable/everything-justregular.svg");
|
|
assert_icon_lookup ("everything-justregular",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
"/icons/scalable/everything-justregular.svg");
|
|
assert_icon_lookup ("everything-justregular-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
"/icons/scalable/everything-justregular.svg");
|
|
assert_icon_lookup ("everything-justregular-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
"/icons/scalable/everything-justregular.svg");
|
|
|
|
/* check all the combos for fallbacks, this time for an icon that only exists as symbolic */
|
|
assert_icon_lookup_fails ("everything-justsymbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR);
|
|
assert_icon_lookup ("everything-justsymbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
"/icons/scalable/everything.svg");
|
|
assert_icon_lookup ("everything-justsymbolic-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
assert_icon_lookup ("everything-justsymbolic-symbolic",
|
|
SCALABLE_IMAGE_SIZE,
|
|
GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
"/icons/scalable/everything.svg");
|
|
}
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
gtk_test_init (&argc, &argv);
|
|
|
|
g_test_add_func ("/icontheme/basics", test_basics);
|
|
g_test_add_func ("/icontheme/force-symbolic", test_force_symbolic);
|
|
g_test_add_func ("/icontheme/force-regular", test_force_regular);
|
|
|
|
return g_test_run();
|
|
}
|