Blame gtk/tests/action.c

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