Blame gtk/tests/action.c

Packit Service fb6fa5
/* GtkAction tests.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Authors: Jan Arne Petersen <jpetersen@openismus.com>
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is free software; you can redistribute it and/or
Packit Service fb6fa5
 * modify it under the terms of the GNU Lesser General Public
Packit Service fb6fa5
 * License as published by the Free Software Foundation; either
Packit Service fb6fa5
 * version 2 of the License, or (at your option) any later version.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is distributed in the hope that it will be useful,
Packit Service fb6fa5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fb6fa5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fb6fa5
 * Lesser General Public License for more details.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You should have received a copy of the GNU Lesser General Public
Packit Service fb6fa5
 * License along with this library; if not, write to the
Packit Service fb6fa5
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service fb6fa5
 * Boston, MA 02111-1307, USA.
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
#include <gtk/gtk.h>
Packit Service fb6fa5
Packit Service fb6fa5
/* Fixture */
Packit Service fb6fa5
Packit Service fb6fa5
typedef struct
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkAction *action;
Packit Service fb6fa5
} ActionTest;
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
action_test_setup (ActionTest    *fixture,
Packit Service fb6fa5
                   gconstpointer  test_data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  fixture->action = gtk_action_new ("name", "label", NULL, NULL);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
action_test_teardown (ActionTest    *fixture,
Packit Service fb6fa5
                      gconstpointer  test_data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_object_unref (fixture->action);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
notify_count_emmisions (GObject    *object,
Packit Service fb6fa5
			GParamSpec *pspec,
Packit Service fb6fa5
			gpointer    data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  unsigned int *i = data;
Packit Service fb6fa5
  (*i)++;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
menu_item_label_notify_count (ActionTest    *fixture,
Packit Service fb6fa5
                              gconstpointer  test_data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkWidget *item = gtk_menu_item_new ();
Packit Service fb6fa5
  unsigned int emmisions = 0;
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_connect (item, "notify::label",
Packit Service fb6fa5
		    G_CALLBACK (notify_count_emmisions), &emmisions);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item),
Packit Service fb6fa5
					 fixture->action);
Packit Service fb6fa5
Packit Service fb6fa5
  g_assert_cmpuint (emmisions, ==, 1);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_action_set_label (fixture->action, "new label");
Packit Service fb6fa5
Packit Service fb6fa5
  g_assert_cmpuint (emmisions, ==, 2);
Packit Service fb6fa5
Packit Service fb6fa5
  g_object_unref (item);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* main */
Packit Service fb6fa5
Packit Service fb6fa5
int
Packit Service fb6fa5
main (int    argc,
Packit Service fb6fa5
      char **argv)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gtk_test_init (&argc, &argv, NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  g_test_add ("/Action/MenuItem/label-notify-count",
Packit Service fb6fa5
              ActionTest, NULL,
Packit Service fb6fa5
              action_test_setup,
Packit Service fb6fa5
              menu_item_label_notify_count,
Packit Service fb6fa5
              action_test_teardown);
Packit Service fb6fa5
Packit Service fb6fa5
  return g_test_run ();
Packit Service fb6fa5
}
Packit Service fb6fa5