Back to index

bamf  0.2.120
test-window.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as 
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by Jason Smith <jason.smith@canonical.com>
00017  *
00018  */
00019  
00020 #include <glib.h>
00021 #include <stdlib.h>
00022 #include "bamf-window.h"
00023 #include "bamf-legacy-window.h"
00024 #include "bamf-legacy-window-test.h"
00025 
00026 static void test_allocation    (void);
00027 static void test_xid           (void);
00028 static void test_active        (void);
00029 static void test_urgent        (void);
00030 static void test_user_visible  (void);
00031 static void test_maximized     (void);
00032 static void test_vmaximized    (void);
00033 static void test_hmaximized    (void);
00034 static void test_hmaximized    (void);
00035 
00036 static gboolean signal_seen = FALSE;
00037 static gboolean signal_result = FALSE;
00038 
00039 void
00040 test_window_create_suite (void)
00041 {
00042 #define DOMAIN "/Window"
00043 
00044   g_test_add_func (DOMAIN"/Allocation", test_allocation);
00045   g_test_add_func (DOMAIN"/Xid", test_xid);
00046   g_test_add_func (DOMAIN"/Events/Active", test_active);
00047   g_test_add_func (DOMAIN"/Events/Urgent", test_urgent);
00048   g_test_add_func (DOMAIN"/Events/UserVisible", test_user_visible);
00049   g_test_add_func (DOMAIN"/Events/Maximized", test_maximized);
00050   g_test_add_func (DOMAIN"/Events/VerticallyMaximized", test_vmaximized);
00051   g_test_add_func (DOMAIN"/Events/HorizontallyMaximized", test_hmaximized);
00052 }
00053 
00054 void 
00055 test_allocation (void)
00056 {
00057   BamfWindow *window;
00058   BamfLegacyWindowTest *test;
00059   
00060   test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
00061   
00062   window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
00063   
00064   g_assert (BAMF_IS_WINDOW (window));
00065   
00066   g_object_unref (window);
00067   
00068   g_assert (!BAMF_IS_WINDOW (window));
00069   
00070   g_object_unref (test);
00071 }
00072 
00073 void
00074 test_xid (void)
00075 {
00076   BamfWindow *window;
00077   BamfLegacyWindowTest *test;
00078   
00079   test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
00080   
00081   window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
00082 
00083   g_assert (bamf_window_get_xid (window) == 20);  
00084   
00085   g_object_unref (window);
00086   g_object_unref (test);
00087 }
00088 
00089 void
00090 on_urgent_changed (BamfWindow *window, gboolean result, gpointer pointer)
00091 {
00092   signal_seen = TRUE;
00093   signal_result = result;
00094 }
00095 
00096 void
00097 test_urgent (void)
00098 {
00099   signal_seen = FALSE;
00100 
00101   BamfWindow *window;
00102   BamfLegacyWindowTest *test;
00103   
00104   test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
00105   
00106   window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
00107   g_signal_connect (G_OBJECT (window), "urgent-changed", (GCallback) on_urgent_changed, NULL);
00108   
00109   g_assert (!bamf_view_is_urgent (BAMF_VIEW (window)));
00110   g_assert (!signal_seen);
00111   
00112   bamf_legacy_window_test_set_attention (test, TRUE);  
00113   g_assert (bamf_view_is_urgent (BAMF_VIEW (window)));
00114   g_assert (signal_seen);
00115   g_assert (signal_result);
00116   
00117   signal_seen = FALSE;
00118   
00119   bamf_legacy_window_test_set_attention (test, FALSE);  
00120   g_assert (!bamf_view_is_urgent (BAMF_VIEW (window)));
00121   g_assert (signal_seen);
00122   g_assert (!signal_result);
00123   
00124   g_object_unref (window);
00125   g_object_unref (test);
00126 }
00127 
00128 void
00129 on_active_changed (BamfWindow *window, gboolean result, gpointer pointer)
00130 {
00131   signal_seen = TRUE;
00132   signal_result = result;
00133 }
00134 
00135 void
00136 test_active (void)
00137 {
00138   signal_seen = FALSE;
00139 
00140   BamfWindow *window;
00141   BamfLegacyWindowTest *test;
00142   
00143   test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
00144   
00145   window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
00146   g_signal_connect (G_OBJECT (window), "active-changed", (GCallback) on_active_changed, NULL);
00147   
00148   g_assert (!bamf_view_is_active (BAMF_VIEW (window)));
00149   g_assert (!signal_seen);
00150   
00151   bamf_legacy_window_test_set_active (test, TRUE);  
00152   g_assert (bamf_view_is_active (BAMF_VIEW (window)));
00153   g_assert (signal_seen);
00154   g_assert (signal_result);
00155   
00156   signal_seen = FALSE;
00157   
00158   bamf_legacy_window_test_set_active (test, FALSE);  
00159   g_assert (!bamf_view_is_active (BAMF_VIEW (window)));
00160   g_assert (signal_seen);
00161   g_assert (!signal_result);
00162   
00163   g_object_unref (window);
00164   g_object_unref (test);
00165 }
00166 
00167 void
00168 on_user_visible_changed (BamfWindow *window, gboolean result, gpointer pointer)
00169 {
00170   signal_seen = TRUE;
00171   signal_result = result;
00172 }
00173 
00174 void
00175 test_user_visible (void)
00176 {
00177   signal_seen = FALSE;
00178 
00179   BamfWindow *window;
00180   BamfLegacyWindowTest *test;
00181   
00182   test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
00183   
00184   window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
00185   g_signal_connect (G_OBJECT (window), "user-visible-changed", (GCallback) on_user_visible_changed, NULL);
00186   
00187   g_assert (bamf_view_user_visible (BAMF_VIEW (window)));
00188   g_assert (!signal_seen);
00189   
00190   bamf_legacy_window_test_set_skip (test, TRUE);  
00191   g_assert (!bamf_view_user_visible (BAMF_VIEW (window)));
00192   g_assert (signal_seen);
00193   g_assert (!signal_result);
00194   
00195   signal_seen = FALSE;
00196   
00197   bamf_legacy_window_test_set_skip (test, FALSE);  
00198   g_assert (bamf_view_user_visible (BAMF_VIEW (window)));
00199   g_assert (signal_seen);
00200   g_assert (signal_result);
00201   
00202   g_object_unref (window);
00203   g_object_unref (test);
00204 }
00205 
00206 void
00207 on_maximized_changed (BamfWindow *window, gint old, gint new, gpointer pointer)
00208 {
00209   signal_seen = TRUE;
00210   signal_result = (old == BAMF_WINDOW_FLOATING && new == BAMF_WINDOW_MAXIMIZED);
00211 }
00212 
00213 
00214 void
00215 test_maximized (void)
00216 {
00217   signal_seen = FALSE;
00218 
00219   BamfWindow *window;
00220   BamfLegacyWindowTest *test;
00221 
00222   test = bamf_legacy_window_test_new (20,"Maximized Window X", "class", "exec");
00223 
00224   window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
00225   g_signal_connect (G_OBJECT (window), "maximized-changed", (GCallback) on_maximized_changed, NULL);
00226 
00227   g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
00228   g_assert (!signal_seen);
00229 
00230   bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_MAXIMIZED);  
00231   g_assert (bamf_window_maximized (window) == BAMF_WINDOW_MAXIMIZED);
00232   g_assert (signal_seen);
00233   g_assert (signal_result);
00234   
00235   signal_seen = FALSE;
00236 
00237   bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_FLOATING);  
00238   g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
00239   g_assert (signal_seen);
00240   g_assert (!signal_result);
00241   
00242   g_object_unref (window);
00243   g_object_unref (test);
00244 }
00245 
00246 void
00247 on_vmaximized_changed (BamfWindow *window, gint old, gint new, gpointer pointer)
00248 {
00249   signal_seen = TRUE;
00250   signal_result = (old == BAMF_WINDOW_FLOATING && new == BAMF_WINDOW_VERTICAL_MAXIMIZED);
00251 }
00252 
00253 void
00254 test_vmaximized (void)
00255 {
00256   signal_seen = FALSE;
00257 
00258   BamfWindow *window;
00259   BamfLegacyWindowTest *test;
00260 
00261   test = bamf_legacy_window_test_new (20,"Maximized Window X", "class", "exec");
00262 
00263   window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
00264   g_signal_connect (G_OBJECT (window), "maximized-changed", (GCallback) on_vmaximized_changed, NULL);
00265 
00266   g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
00267   g_assert (!signal_seen);
00268 
00269   bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_VERTICAL_MAXIMIZED);  
00270   g_assert (bamf_window_maximized (window) == BAMF_WINDOW_VERTICAL_MAXIMIZED);
00271   g_assert (signal_seen);
00272   g_assert (signal_result);
00273   
00274   signal_seen = FALSE;
00275 
00276   bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_FLOATING);  
00277   g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
00278   g_assert (signal_seen);
00279   g_assert (!signal_result);
00280   
00281   g_object_unref (window);
00282   g_object_unref (test);
00283 }
00284 
00285 void
00286 on_hmaximized_changed (BamfWindow *window, gint old, gint new, gpointer pointer)
00287 {
00288   signal_seen = TRUE;
00289   signal_result = (old == BAMF_WINDOW_FLOATING && new == BAMF_WINDOW_HORIZONTAL_MAXIMIZED);
00290 }
00291 
00292 void
00293 test_hmaximized (void)
00294 {
00295   signal_seen = FALSE;
00296 
00297   BamfWindow *window;
00298   BamfLegacyWindowTest *test;
00299 
00300   test = bamf_legacy_window_test_new (20,"Maximized Window X", "class", "exec");
00301 
00302   window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
00303   g_signal_connect (G_OBJECT (window), "maximized-changed", (GCallback) on_hmaximized_changed, NULL);
00304 
00305   g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
00306   g_assert (!signal_seen);
00307 
00308   bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_HORIZONTAL_MAXIMIZED);  
00309   g_assert (bamf_window_maximized (window) == BAMF_WINDOW_HORIZONTAL_MAXIMIZED);
00310   g_assert (signal_seen);
00311   g_assert (signal_result);
00312   
00313   signal_seen = FALSE;
00314 
00315   bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_FLOATING);  
00316   g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
00317   g_assert (signal_seen);
00318   g_assert (!signal_result);
00319   
00320   g_object_unref (window);
00321   g_object_unref (test);
00322 }