Back to index

bamf  0.2.120
Defines | Functions | Variables
test-application.c File Reference
#include <stdlib.h>
#include <glib.h>
#include <glib-object.h>
#include "bamf-application.h"
#include "bamf-window.h"
#include "bamf-legacy-window.h"
#include "bamf-legacy-window-test.h"

Go to the source code of this file.

Defines

#define DESKTOP_FILE   "/usr/share/applications/gnome-terminal.desktop"
#define DOMAIN   "/Application"

Functions

static void test_allocation (void)
static void test_desktop_file (void)
static void test_urgent (void)
static void test_active (void)
static void test_get_xids (void)
static void test_manages_xid (void)
static void test_user_visible (void)
static void test_window_added (void)
static void test_window_removed (void)
void test_application_create_suite (GDBusConnection *connection)
static void on_urgent_changed (BamfApplication *application, gboolean result, gpointer data)
static void on_active_changed (BamfApplication *application, gboolean result, gpointer data)
static void on_user_visible_changed (BamfApplication *application, gboolean result, gpointer data)
static void on_window_added (BamfApplication *application, char *window, gpointer data)
static void on_window_removed (BamfApplication *application, char *window, gpointer data)

Variables

static gboolean signal_seen = FALSE
static gboolean signal_result = FALSE
static char * signal_window = NULL
static GDBusConnection * gdbus_connection = NULL

Define Documentation

#define DESKTOP_FILE   "/usr/share/applications/gnome-terminal.desktop"

Definition at line 29 of file test-application.c.

#define DOMAIN   "/Application"

Function Documentation

static void on_active_changed ( BamfApplication *  application,
gboolean  result,
gpointer  data 
) [static]

Definition at line 168 of file test-application.c.

Here is the caller graph for this function:

static void on_urgent_changed ( BamfApplication *  application,
gboolean  result,
gpointer  data 
) [static]

Definition at line 105 of file test-application.c.

Here is the caller graph for this function:

static void on_user_visible_changed ( BamfApplication *  application,
gboolean  result,
gpointer  data 
) [static]

Definition at line 321 of file test-application.c.

Here is the caller graph for this function:

static void on_window_added ( BamfApplication *  application,
char *  window,
gpointer  data 
) [static]

Definition at line 391 of file test-application.c.

{
  signal_seen = TRUE;
  signal_window = g_strdup (window);
}

Here is the caller graph for this function:

static void on_window_removed ( BamfApplication *  application,
char *  window,
gpointer  data 
) [static]

Definition at line 435 of file test-application.c.

{
  signal_seen = TRUE;
  signal_window = g_strdup (window);
}

Here is the caller graph for this function:

static void test_active ( void  ) [static]

Definition at line 175 of file test-application.c.

{
  signal_seen = FALSE;
  
  BamfApplication *application;
  BamfWindow *window1, *window2;
  BamfLegacyWindowTest *test1, *test2;
  
  application = bamf_application_new ();
  
  g_signal_connect (G_OBJECT (application), "active-changed", (GCallback) on_active_changed, NULL);
  
  test1 = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
  test2 = bamf_legacy_window_test_new (20, "Window Y", "class", "exec");
  
  window1 = bamf_window_new (BAMF_LEGACY_WINDOW (test1));
  window2 = bamf_window_new (BAMF_LEGACY_WINDOW (test2));
  
  // Ensure we are not active with no windows
  g_assert (!bamf_view_is_active (BAMF_VIEW (application)));
  
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  
  // Test that when added, we signaled properly
  g_assert (!bamf_view_is_active (BAMF_VIEW (application)));
  g_assert (!signal_seen);
  
  bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  
  // Test that we unset and signal properly
  g_assert (!bamf_view_is_active (BAMF_VIEW (application)));
  g_assert (!signal_seen);
  
  bamf_legacy_window_test_set_active (test1, TRUE);
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  
  // Ensure that when adding a skip-tasklist window, we dont set this to visible 
  g_assert (bamf_view_is_active (BAMF_VIEW (application)));
  g_assert (signal_seen);
  g_assert (signal_result);
  
  signal_seen = FALSE;

  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window2));
  
  g_assert (bamf_view_is_active (BAMF_VIEW (application)));
  g_assert (!signal_seen);
  
  bamf_legacy_window_test_set_active (test1, FALSE);
  
  g_assert (!bamf_view_is_active (BAMF_VIEW (application)));
  g_assert (signal_seen);
  g_assert (!signal_result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_allocation ( void  ) [static]

Definition at line 66 of file test-application.c.

{
  BamfApplication    *application;

  /* Check it allocates */
  application = bamf_application_new ();
  g_assert (BAMF_IS_APPLICATION (application));

  g_object_unref (application);
  g_assert (!BAMF_IS_APPLICATION (application));

  application = bamf_application_new_from_desktop_file (DESKTOP_FILE);
  g_assert (BAMF_IS_APPLICATION (application));

  g_object_unref (application);
  g_assert (!BAMF_IS_APPLICATION (application));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void test_application_create_suite ( GDBusConnection *  connection)

Definition at line 48 of file test-application.c.

{
#define DOMAIN "/Application"

  gdbus_connection = connection;

  g_test_add_func (DOMAIN"/Allocation", test_allocation);
  g_test_add_func (DOMAIN"/DesktopFile", test_desktop_file);
  g_test_add_func (DOMAIN"/ManagesXid", test_manages_xid);
  g_test_add_func (DOMAIN"/Xids", test_get_xids);
  g_test_add_func (DOMAIN"/Events/Active", test_active);
  g_test_add_func (DOMAIN"/Events/Urgent", test_urgent);
  g_test_add_func (DOMAIN"/Events/UserVisible", test_user_visible);
  g_test_add_func (DOMAIN"/Events/WindowAdded", test_window_added);
  g_test_add_func (DOMAIN"/Events/WindowRemoved", test_window_removed);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_desktop_file ( void  ) [static]

Definition at line 85 of file test-application.c.

{
  BamfApplication    *application;

  /* Check it allocates */
  application = bamf_application_new ();
  g_assert (bamf_application_get_desktop_file (application) == NULL);

  bamf_application_set_desktop_file (application, DESKTOP_FILE);
  g_assert (g_strcmp0 (bamf_application_get_desktop_file (application), DESKTOP_FILE) == 0);

  g_object_unref (application);

  application = bamf_application_new_from_desktop_file (DESKTOP_FILE);
  g_assert (g_strcmp0 (bamf_application_get_desktop_file (application), DESKTOP_FILE) == 0);

  g_object_unref (application);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_get_xids ( void  ) [static]

Definition at line 231 of file test-application.c.

{
  BamfApplication *application;
  BamfWindow *window1, *window2;
  BamfLegacyWindowTest *lwin1, *lwin2;
  GVariant *container;
  GVariantIter *xids;
  gboolean found;
  guint32 xid;

  application = bamf_application_new ();
  
  lwin1 = bamf_legacy_window_test_new (25, "window1", "class", "exec");
  lwin2 = bamf_legacy_window_test_new (50, "window2", "class", "exec");
  window1 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin1));
  window2 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin2));

  container = bamf_application_get_xids (application);
  g_assert (g_variant_type_equal (g_variant_get_type (container),
                                  G_VARIANT_TYPE ("(au)")));
  g_assert (g_variant_n_children (container) == 1);
  g_variant_get (container, "(au)", &xids);
  g_assert (g_variant_iter_n_children (xids) == 0);
  g_variant_iter_free (xids);
  g_variant_unref (container);

  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window2));

  container = bamf_application_get_xids (application);
  g_assert (g_variant_n_children (container) == 1);
  g_variant_get (container, "(au)", &xids);
  g_assert (g_variant_iter_n_children (xids) == 2);

  found = FALSE;
  while (g_variant_iter_loop (xids, "u", &xid))
    {
      if (xid == 25)
        {
          found = TRUE;
          break;
        }
    }

  g_assert (found);

  found = FALSE;
  g_variant_get (container, "(au)", &xids);
  while (g_variant_iter_loop (xids, "u", &xid))
    {
      if (xid == 50)
        {
          found = TRUE;
          break;
        }
    }

  g_assert (found);

  g_variant_iter_free (xids);
  g_variant_unref (container);
 
  g_object_unref (lwin1);
  g_object_unref (lwin2);
  g_object_unref (window1);
  g_object_unref (window2);
  g_object_unref (application);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_manages_xid ( void  ) [static]

Definition at line 301 of file test-application.c.

{
  BamfApplication *application;
  BamfLegacyWindowTest *lwin;
  BamfWindow *test;

  application = bamf_application_new ();
  lwin = bamf_legacy_window_test_new (20, "window", "class", "exec");
  test = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));

  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));

  g_assert (bamf_application_manages_xid (application, 20));

  g_object_unref (lwin);
  g_object_unref (test);
  g_object_unref (application);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_urgent ( void  ) [static]

Definition at line 112 of file test-application.c.

{
  signal_seen = FALSE;
  
  BamfApplication *application;
  BamfWindow *window1, *window2;
  BamfLegacyWindowTest *test1, *test2;
  
  application = bamf_application_new ();
  
  g_signal_connect (G_OBJECT (application), "urgent-changed", (GCallback) on_urgent_changed, NULL);
  
  test1 = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
  test2 = bamf_legacy_window_test_new (20, "Window Y", "class", "exec");
  
  window1 = bamf_window_new (BAMF_LEGACY_WINDOW (test1));
  window2 = bamf_window_new (BAMF_LEGACY_WINDOW (test2));
  
  // Ensure we are not visible with no windows
  g_assert (!bamf_view_is_urgent (BAMF_VIEW (application)));
  
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  
  // Test that when added, we signaled properly
  g_assert (!bamf_view_is_urgent (BAMF_VIEW (application)));
  g_assert (!signal_seen);
  
  bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  
  // Test that we unset and signal properly
  g_assert (!bamf_view_is_urgent (BAMF_VIEW (application)));
  g_assert (!signal_seen);
  
  bamf_legacy_window_test_set_attention (test1, TRUE);
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  
  // Ensure that when adding a skip-tasklist window, we dont set this to visible 
  g_assert (bamf_view_is_urgent (BAMF_VIEW (application)));
  g_assert (signal_seen);
  g_assert (signal_result);
  
  signal_seen = FALSE;

  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window2));
  
  g_assert (bamf_view_is_urgent (BAMF_VIEW (application)));
  g_assert (!signal_seen);
  
  bamf_legacy_window_test_set_attention (test1, FALSE);
  
  g_assert (!bamf_view_is_urgent (BAMF_VIEW (application)));
  g_assert (signal_seen);
  g_assert (!signal_result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_user_visible ( void  ) [static]

Definition at line 328 of file test-application.c.

{
  signal_seen = FALSE;
  
  BamfApplication *application;
  BamfWindow *window1, *window2;
  BamfLegacyWindowTest *test1, *test2;
  
  application = bamf_application_new ();
  
  g_signal_connect (G_OBJECT (application), "user-visible-changed", (GCallback) on_user_visible_changed, NULL);
  
  test1 = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
  test2 = bamf_legacy_window_test_new (20, "Window Y", "class", "exec");
  
  window1 = bamf_window_new (BAMF_LEGACY_WINDOW (test1));
  window2 = bamf_window_new (BAMF_LEGACY_WINDOW (test2));
  
  // Ensure we are not visible with no windows
  g_assert (!bamf_view_user_visible (BAMF_VIEW (application)));
  
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  
  // Test that when added, we signaled properly
  g_assert (bamf_view_user_visible (BAMF_VIEW (application)));
  g_assert (signal_seen);
  g_assert (signal_result);
  
  signal_seen = FALSE;
  
  bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  
  // Test that we unset and signal properly
  g_assert (!bamf_view_user_visible (BAMF_VIEW (application)));
  g_assert (signal_seen);
  g_assert (!signal_result);
  
  signal_seen = FALSE;
  
  bamf_legacy_window_test_set_skip (test1, TRUE);
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
  
  // Ensure that when adding a skip-tasklist window, we dont set this to visible 
  g_assert (!bamf_view_user_visible (BAMF_VIEW (application)));
  g_assert (!signal_seen);
  
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window2));
  
  g_assert (bamf_view_user_visible (BAMF_VIEW (application)));
  g_assert (signal_seen);
  g_assert (signal_result);
  
  signal_seen = FALSE;
  
  bamf_legacy_window_test_set_skip (test2, TRUE);
  
  g_assert (!bamf_view_user_visible (BAMF_VIEW (window1)));
  g_assert (!bamf_view_user_visible (BAMF_VIEW (application)));
  g_assert (signal_seen);
  g_assert (!signal_result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_window_added ( void  ) [static]

Definition at line 398 of file test-application.c.

{
  signal_seen = FALSE;
  
  BamfApplication *application;
  BamfWindow *window;
  BamfLegacyWindowTest *test;
  const char *path;
  
  application = bamf_application_new ();
  
  g_signal_connect (G_OBJECT (application), "window-added", (GCallback) on_window_added, NULL);
  
  test = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
  window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
  
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window));
  
  // Ensure we dont signal things that are not on the bus
  g_assert (!signal_seen);
  
  bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window));
  
  path = bamf_view_export_on_bus (BAMF_VIEW (window), gdbus_connection);
  
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window));
  
  g_assert (signal_seen);
  g_assert_cmpstr (signal_window, ==, path);
  
  signal_seen = FALSE;
  
  g_object_unref (window);
  g_object_unref (test);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_window_removed ( void  ) [static]

Definition at line 442 of file test-application.c.

{
  signal_seen = FALSE;
  
  BamfApplication *application;
  BamfWindow *window;
  BamfLegacyWindowTest *test;
  const char *path;
  
  application = bamf_application_new ();
  
  g_signal_connect (G_OBJECT (application), "window-removed", (GCallback) on_window_removed, NULL);
  
  test = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
  window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
  
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window));
  bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window));
  
  // Ensure we dont signal things that are not on the bus
  g_assert (!signal_seen);
  
  path = bamf_view_export_on_bus (BAMF_VIEW (window), gdbus_connection);
  
  bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window));
  bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window));
  
  g_assert (signal_seen);
  g_assert (g_strcmp0 (signal_window, path) == 0);
  
  signal_seen = FALSE;
  
  g_object_unref (window);
  g_object_unref (test);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

GDBusConnection* gdbus_connection = NULL [static]

Definition at line 45 of file test-application.c.

gboolean signal_result = FALSE [static]

Definition at line 43 of file test-application.c.

gboolean signal_seen = FALSE [static]

Definition at line 42 of file test-application.c.

char* signal_window = NULL [static]

Definition at line 44 of file test-application.c.