Back to index

unity  6.0.0
TestQuicklistMenuitems.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Canonical Ltd.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License version 3, as published
00006  * by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * version 3 along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>
00016  *
00017  * Authored by: Mirco Müller <mirco.mueller@canonical.com>
00018  *
00019  */
00020 
00021 #include "config.h"
00022 
00023 #include "QuicklistMenuItem.h"
00024 #include "QuicklistMenuItemCheckmark.h"
00025 #include "QuicklistMenuItemLabel.h"
00026 #include "QuicklistMenuItemRadio.h"
00027 #include "QuicklistMenuItemSeparator.h"
00028 
00029 #include "Nux/Nux.h"
00030 #include "Nux/VLayout.h"
00031 #include "Nux/HLayout.h"
00032 #include "Nux/WindowThread.h"
00033 #include "Nux/WindowCompositor.h"
00034 #include "Nux/BaseWindow.h"
00035 
00036 #include "QuicklistView.h"
00037 #include "TestThreadHelper.h"
00038 
00039 using unity::QuicklistView;
00040 using unity::QuicklistMenuItem;
00041 using unity::QuicklistMenuItemCheckmark;
00042 using unity::QuicklistMenuItemLabel;
00043 using unity::QuicklistMenuItemRadio;
00044 using unity::QuicklistMenuItemSeparator;
00045 
00046 static void TestMenuItemCheckmark(void);
00047 static void TestMenuItemLabel(void);
00048 static void TestMenuItemRadio(void);
00049 static void TestMenuItemSeparator(void);
00050 static void TestQuicklistMenuItem(void);
00051 
00052 nux::WindowThread* thread = NULL;
00053 
00054 void
00055 TestQuicklistMenuitemsCreateSuite()
00056 {
00057 #define _DOMAIN "/Unit/QuicklistMenuitems"
00058 
00059   g_test_add_func(_DOMAIN"/MenuItemCheckmark", TestMenuItemCheckmark);
00060   g_test_add_func(_DOMAIN"/MenuItemLabel",     TestMenuItemLabel);
00061   g_test_add_func(_DOMAIN"/MenuItemRadio",     TestMenuItemRadio);
00062   g_test_add_func(_DOMAIN"/MenuItemSeparator", TestMenuItemSeparator);
00063   g_test_add_func(_DOMAIN"/QuicklistMenuItem", TestQuicklistMenuItem);
00064 }
00065 
00066 static void
00067 TestMenuItemCheckmark()
00068 {
00069   DbusmenuMenuitem* item = NULL;
00070 
00071 
00072   item = dbusmenu_menuitem_new();
00073 
00074   dbusmenu_menuitem_property_set(item,
00075                                  DBUSMENU_MENUITEM_PROP_LABEL,
00076                                  "Unchecked");
00077 
00078   dbusmenu_menuitem_property_set(item,
00079                                  DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
00080                                  DBUSMENU_MENUITEM_TOGGLE_CHECK);
00081 
00082   dbusmenu_menuitem_property_set_bool(item,
00083                                       DBUSMENU_MENUITEM_PROP_ENABLED,
00084                                       false);
00085 
00086   dbusmenu_menuitem_property_set_int(item,
00087                                      DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
00088                                      DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
00089 
00090   QuicklistMenuItemCheckmark* qlCheckmarkItem = NULL;
00091 
00092   qlCheckmarkItem = new QuicklistMenuItemCheckmark(item, true);
00093 
00094   g_assert_cmpstr(qlCheckmarkItem->GetLabel(), == , "Unchecked");
00095   g_assert_cmpint(qlCheckmarkItem->GetEnabled(), == , false);
00096   g_assert_cmpint(qlCheckmarkItem->GetActive(), == , false);
00097   g_assert_cmpint(qlCheckmarkItem->GetSelectable(), == , false);
00098   g_assert_cmpint(qlCheckmarkItem->IsMarkupEnabled(), == , false);
00099 
00100   //qlCheckmarkItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass,
00101   //                                                    &CallerClass::RecvChanged));
00102 
00103 
00104   qlCheckmarkItem->Dispose();
00105   g_object_unref(item);
00106 }
00107 
00108 static void
00109 TestMenuItemLabel()
00110 {
00111   DbusmenuMenuitem* item = NULL;
00112 
00113   item = dbusmenu_menuitem_new();
00114 
00115   dbusmenu_menuitem_property_set(item,
00116                                  DBUSMENU_MENUITEM_PROP_LABEL,
00117                                  "A Label");
00118 
00119   dbusmenu_menuitem_property_set_bool(item,
00120                                       DBUSMENU_MENUITEM_PROP_ENABLED,
00121                                       true);
00122 
00123   dbusmenu_menuitem_property_set_bool(item,
00124                                       "unity-use-markup",
00125                                       true);
00126 
00127   QuicklistMenuItemLabel* qlLabelItem = NULL;
00128 
00129   qlLabelItem = new QuicklistMenuItemLabel(item, true);
00130 
00131   g_assert_cmpstr(qlLabelItem->GetLabel(), == , "A Label");
00132   g_assert_cmpint(qlLabelItem->GetEnabled(), == , true);
00133   g_assert_cmpint(qlLabelItem->GetSelectable(), == , true);
00134   g_assert_cmpint(qlLabelItem->IsMarkupEnabled(), == , true);
00135 
00136   //qlLabelItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass,
00137   //                                                &CallerClass::RecvChanged));
00138 
00139   qlLabelItem->Dispose();
00140   g_object_unref(item);
00141 }
00142 
00143 static void
00144 TestMenuItemRadio()
00145 {
00146   DbusmenuMenuitem* item = NULL;
00147 
00148   item = dbusmenu_menuitem_new();
00149 
00150   dbusmenu_menuitem_property_set(item,
00151                                  DBUSMENU_MENUITEM_PROP_LABEL,
00152                                  "Radio Active");
00153 
00154   dbusmenu_menuitem_property_set(item,
00155                                  DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
00156                                  DBUSMENU_MENUITEM_TOGGLE_RADIO);
00157 
00158   dbusmenu_menuitem_property_set_bool(item,
00159                                       DBUSMENU_MENUITEM_PROP_ENABLED,
00160                                       true);
00161 
00162   dbusmenu_menuitem_property_set_int(item,
00163                                      DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
00164                                      DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
00165 
00166   QuicklistMenuItemRadio* qlRadioItem = NULL;
00167 
00168   qlRadioItem = new QuicklistMenuItemRadio(item, true);
00169   qlRadioItem->EnableLabelMarkup(true);
00170 
00171   g_assert_cmpstr(qlRadioItem->GetLabel(), == , "Radio Active");
00172   g_assert_cmpint(qlRadioItem->GetEnabled(), == , true);
00173   g_assert_cmpint(qlRadioItem->GetActive(), == , true);
00174   g_assert_cmpint(qlRadioItem->GetSelectable(), == , true);
00175   g_assert_cmpint(qlRadioItem->IsMarkupEnabled(), == , true);
00176 
00177   //qlRadioItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass,
00178   //                                                &CallerClass::RecvChanged));
00179 
00180   qlRadioItem->Dispose();
00181   g_object_unref(item);
00182 }
00183 
00184 static void
00185 TestMenuItemSeparator()
00186 {
00187   DbusmenuMenuitem* item = NULL;
00188 
00189   item = dbusmenu_menuitem_new();
00190 
00191   dbusmenu_menuitem_property_set(item,
00192                                  "type",
00193                                  DBUSMENU_CLIENT_TYPES_SEPARATOR);
00194 
00195   dbusmenu_menuitem_property_set_bool(item,
00196                                       DBUSMENU_MENUITEM_PROP_ENABLED,
00197                                       true);
00198 
00199   QuicklistMenuItemSeparator* qlSeparatorItem = NULL;
00200 
00201   qlSeparatorItem = new QuicklistMenuItemSeparator(item, true);
00202 
00203   g_assert_cmpint(qlSeparatorItem->GetEnabled(), == , true);
00204   g_assert_cmpint(qlSeparatorItem->GetSelectable(), == , false);
00205 
00206   qlSeparatorItem->Dispose();
00207   g_object_unref(item);
00208 }
00209 
00210 static void
00211 TestQuicklistMenuItem()
00212 {
00213   DbusmenuMenuitem* root = dbusmenu_menuitem_new();
00214 
00215   dbusmenu_menuitem_set_root(root, true);
00216 
00217   DbusmenuMenuitem* child = dbusmenu_menuitem_new();
00218   dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL);
00219   dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 0");
00220   dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
00221   dbusmenu_menuitem_child_append(root, child);
00222 
00223   child = dbusmenu_menuitem_new();
00224   dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
00225   dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
00226   dbusmenu_menuitem_child_append(root, child);
00227 
00228   child = dbusmenu_menuitem_new();
00229   dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL);
00230   dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 1");
00231   dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
00232   dbusmenu_menuitem_child_append(root, child);
00233 
00234   child = dbusmenu_menuitem_new();
00235   dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK);
00236   dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "check mark 0");
00237   dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
00238   dbusmenu_menuitem_property_set_int(child, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
00239   dbusmenu_menuitem_child_append(root, child);
00240 
00241   QuicklistView* quicklist = new QuicklistView();
00242 
00243   quicklist->TestMenuItems(root);
00244 
00245   g_assert_cmpint(quicklist->GetNumItems(), == , 4);
00246   g_assert_cmpint(quicklist->GetNthType(0), == , unity::MENUITEM_TYPE_LABEL);
00247   g_assert_cmpint(quicklist->GetNthType(1), == , unity::MENUITEM_TYPE_SEPARATOR);
00248   g_assert_cmpint(quicklist->GetNthType(2), == , unity::MENUITEM_TYPE_LABEL);
00249   g_assert_cmpint(quicklist->GetNthType(3), == , unity::MENUITEM_TYPE_CHECK);
00250 
00251   g_assert_cmpstr(quicklist->GetNthItems(0)->GetLabel(), == , "label 0");
00252   g_assert_cmpstr(quicklist->GetNthItems(2)->GetLabel(), == , "label 1");
00253   g_assert_cmpstr(quicklist->GetNthItems(3)->GetLabel(), == , "check mark 0");
00254 
00255   g_assert_cmpint(quicklist->GetChildren().size(), == , 4);
00256 
00257   quicklist->Dispose();
00258 }