Back to index

unity  6.0.0
unitya11ytests.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 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: Alejandro PiƱeiro Iglesias <apinheiro@igalia.com>
00017  */
00018 
00019 #include "unitya11ytests.h"
00020 
00021 #include <glib.h>
00022 
00023 #include "unitya11y.h"
00024 #include "unity-util-accessible.h"
00025 
00026 /* nux accessible objects */
00027 #include "nux-view-accessible.h"
00028 #include "nux-base-window-accessible.h"
00029 #include "nux-layout-accessible.h"
00030 
00031 /* unity accessible objects */
00032 #include <Nux/Button.h>
00033 
00034 #include "Launcher.h"
00035 #include "LauncherIcon.h"
00036 #include "SimpleLauncherIcon.h"
00037 #include "PanelView.h"
00038 #include "DashView.h"
00039 #include "unity-launcher-accessible.h"
00040 #include "unity-launcher-icon-accessible.h"
00041 #include "unity-panel-view-accessible.h"
00042 
00043 using unity::launcher::Launcher;
00044 using unity::launcher::LauncherIcon;
00045 using unity::launcher::SimpleLauncherIcon;
00046 
00047 /*
00048  * This unit test checks if the destroy management is working:
00049  *
00050  * - If the state of a accessibility object is properly updated after
00051  *   the object destruction
00052  *
00053  */
00054 static gboolean
00055 a11y_unit_test_destroy_management(void)
00056 {
00057   unity::QuicklistView* quicklist = NULL;
00058   AtkObject* accessible = NULL;
00059   nux::Object* base_object = NULL;
00060   AtkStateSet* state_set = NULL;
00061 
00062   quicklist = new unity::QuicklistView();
00063   quicklist->SinkReference();
00064   accessible = unity_a11y_get_accessible(quicklist);
00065 
00066   base_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(accessible));
00067   if (base_object != quicklist)
00068   {
00069     g_debug("[a11y] destroy management unit test: base object"
00070             " different to the original one");
00071     return FALSE;
00072   }
00073 
00074   if (quicklist->UnReference() == false)
00075   {
00076     g_debug("[a11y] destroy management unit test: base object not destroyed");
00077     return FALSE;
00078   }
00079 
00080   base_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(accessible));
00081   if (base_object != NULL)
00082   {
00083     g_debug("[a11y] destroy management unit test: base object"
00084             " not NULL after base object destruction");
00085     return FALSE;
00086   }
00087 
00088   state_set = atk_object_ref_state_set(accessible);
00089   if (!atk_state_set_contains_state(state_set, ATK_STATE_DEFUNCT))
00090   {
00091     g_debug("[a11y] destroy management unit test: accessible object"
00092             " doesn't include DEFUNCT state");
00093     return FALSE;
00094   }
00095 
00096   g_object_unref(state_set);
00097   g_object_unref(accessible);
00098 
00099   return TRUE;
00100 }
00101 
00108 static gboolean
00109 a11y_unit_test_hash_table_destroy_management(void)
00110 {
00111   unity::QuicklistView* quicklist = NULL;
00112   nux::Layout* layout = NULL;
00113   AtkObject* accessible = NULL;
00114   guint prev_hash_size = 0;
00115   guint hash_size = 0;
00116 
00117   /* test the hash table management with the accessible destroy */
00118 
00119   prev_hash_size = g_hash_table_size(_unity_a11y_get_accessible_table());
00120 
00121   layout = new nux::Layout();
00122   layout->SinkReference();
00123   accessible = unity_a11y_get_accessible(layout);
00124 
00125   if (accessible == NULL)
00126   {
00127     g_debug("[a11y] hash table destroy management unit test: error creating"
00128             " the accessible object (accessible == NULL)");
00129     return FALSE;
00130   }
00131 
00132   hash_size = g_hash_table_size(_unity_a11y_get_accessible_table());
00133 
00134   if ((hash_size - prev_hash_size) != 1)
00135   {
00136     g_debug("[a11y] hash table destroy management unit test: accessible object"
00137             " not added to the hash table after his creation");
00138     return FALSE;
00139   }
00140 
00141   prev_hash_size = g_hash_table_size(_unity_a11y_get_accessible_table());
00142 
00143   g_object_unref(accessible);
00144 
00145   hash_size = g_hash_table_size(_unity_a11y_get_accessible_table());
00146 
00147   if ((prev_hash_size - hash_size) != 1)
00148   {
00149     g_debug("[a11y] hash table destroy management unit test: accessible object"
00150             " not removed from the hash table after his destruction");
00151     return FALSE;
00152   }
00153 
00154   layout->UnReference();
00155 
00156   /* Test the hash table management after the object destroy */
00157 
00158   prev_hash_size = g_hash_table_size(_unity_a11y_get_accessible_table());
00159 
00160   quicklist = new unity::QuicklistView();
00161   quicklist->SinkReference();
00162   accessible = unity_a11y_get_accessible(quicklist);
00163 
00164   if (accessible == NULL)
00165   {
00166     g_debug("[a11y] hash table destroy management unit test: error creating"
00167             " the accessible object (accessible == NULL)");
00168     return FALSE;
00169   }
00170 
00171   hash_size = g_hash_table_size(_unity_a11y_get_accessible_table());
00172 
00173   if ((hash_size - prev_hash_size) != 1)
00174   {
00175     g_debug("[a11y] hash table destroy management unit test: accessible object"
00176             " not added to the hash table after his creation");
00177     return FALSE;
00178   }
00179 
00180   prev_hash_size = g_hash_table_size(_unity_a11y_get_accessible_table());
00181 
00182   if (quicklist->UnReference() == false)
00183   {
00184     g_debug("[a11y] hash table destroy management unit test: base object not destroyed");
00185     return FALSE;
00186   }
00187 
00188   hash_size = g_hash_table_size(_unity_a11y_get_accessible_table());
00189 
00190   if ((prev_hash_size - hash_size) != 1)
00191   {
00192     g_debug("[a11y] hash table destroy management unit test: accessible object"
00193             " not removed from the hash table after base object destruction");
00194     return FALSE;
00195   }
00196 
00197   return TRUE;
00198 }
00199 
00203 static gboolean
00204 a11y_unit_test_launcher_connection(void)
00205 {
00206   Launcher* launcher = NULL;
00207   nux::BaseWindow* window = NULL;
00208   AtkObject* launcher_accessible = NULL;
00209   LauncherIcon* launcher_icon = NULL;
00210   AtkObject* launcher_icon_accessible = NULL;
00211 
00212   window = new nux::BaseWindow(TEXT(""));
00213   launcher = new Launcher(window, NULL);
00214   launcher->SinkReference();
00215   launcher_accessible = unity_a11y_get_accessible(launcher);
00216 
00217   if (!UNITY_IS_LAUNCHER_ACCESSIBLE(launcher_accessible))
00218   {
00219     g_debug("[a11y] wrong launcher accessible type");
00220     return FALSE;
00221   }
00222   else
00223   {
00224     g_debug("[a11y] Launcher accessible created correctly");
00225   }
00226 
00227   launcher_icon = new SimpleLauncherIcon();
00228   launcher_icon->SinkReference();
00229   launcher_icon_accessible = unity_a11y_get_accessible(launcher_icon);
00230 
00231   if (!UNITY_IS_LAUNCHER_ICON_ACCESSIBLE(launcher_icon_accessible))
00232   {
00233     g_debug("[a11y] wrong launcher icon accessible type");
00234     return FALSE;
00235   }
00236   else
00237   {
00238     g_debug("[a11y] LauncherIcon accessible created correctly");
00239   }
00240 
00241   launcher->UnReference();
00242   launcher_icon->UnReference();
00243 
00244   return TRUE;
00245 }
00246 
00250 static gboolean
00251 a11y_unit_test_children_addition(void)
00252 {
00253   nux::View* view[3];
00254   AtkObject* view_accessible[3];
00255   nux::Layout* layout[2];
00256   AtkObject* layout_accessible[2];
00257   gint i = 0;
00258 
00259   /* Test setting a layout on a view  */
00260   view[0] = new nux::Button("Test");
00261   view[0]->SinkReference();
00262   view_accessible[0] = unity_a11y_get_accessible(view[0]);
00263 
00264   for (i = 0; i < 2; i++)
00265   {
00266     layout[i] = new nux::Layout();
00267     layout[i]->SinkReference();
00268     layout_accessible[i] = unity_a11y_get_accessible(layout[i]);
00269   }
00270 
00271   view[0]->SetLayout(layout[0]);
00272   view[0]->SetLayout(layout[0]);
00273 
00274   view[0]->UnReference();
00275   g_object_unref(view_accessible[0]);
00276 
00277   for (i = 0; i < 2; i++)
00278   {
00279     layout[i]->UnReference();
00280     g_object_unref(layout_accessible[i]);
00281   }
00282 
00283   /* Test adding a view on a layout */
00284   layout[0] = new nux::Layout();
00285   layout[0]->SinkReference();
00286   layout_accessible[0] = unity_a11y_get_accessible(layout[0]);
00287 
00288   for (i = 0; i < 3; i ++)
00289   {
00290     view[i] = new nux::Button("Test");
00291     view[i]->SinkReference();
00292     view_accessible[i] = unity_a11y_get_accessible(view[i]);
00293 
00294     layout[0]->AddView(view[i]);
00295   }
00296 
00297   /* when this is removed it should be notified the removal with index 1*/
00298   layout[0]->RemoveChildObject(view[1]);
00299   layout[0]->UnReference();
00300   for (i = 0; i < 3; i++)
00301   {
00302     view[i]->UnReference();
00303     g_object_unref(view_accessible [i]);
00304   }
00305 
00306   return TRUE;
00307 }
00308 
00309 /* public */
00310 
00311 void
00312 unity_run_a11y_unit_tests(void)
00313 {
00314   if (a11y_unit_test_destroy_management())
00315     g_debug("[a11y] destroy management unit test: SUCCESS");
00316   else
00317     g_debug("[a11y] destroy management unit test: FAIL");
00318 
00319   if (a11y_unit_test_hash_table_destroy_management())
00320     g_debug("[a11y] hash table destroy management unit test: SUCCESS");
00321   else
00322     g_debug("[a11y] hash table destroy management unit test: FAIL");
00323 
00324   if (a11y_unit_test_launcher_connection())
00325     g_debug("[a11y] launcher connection: SUCCESS");
00326   else
00327     g_debug("[a11y] launcher connection: FAIL");
00328 
00329   if (a11y_unit_test_children_addition())
00330     g_debug("[a11y] children addition: SUCCESS");
00331   else
00332     g_debug("[a11y] children addition: FAIL");
00333 }