~3v1n0/unity/bfb-quicklist-does-not-close-dash

« back to all changes in this revision

Viewing changes to tests/unit/TestQuicklistMenuitems.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2012-08-13 13:41:13 UTC
  • Revision ID: mail@3v1n0.net-20120813134113-4glknkup31my3jje
QuicklistMenuItem: remove debug bits, factorize duplicated code, remove friendship, use smart pointers

Removed a lot of duplicated code between implementations, use top-level factorized code, use enum class,
c++ types and better pointer deletions
Tests updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "config.h"
22
22
 
 
23
#include <libdbusmenu-glib/client.h>
 
24
 
23
25
#include "QuicklistMenuItem.h"
24
26
#include "QuicklistMenuItemCheckmark.h"
25
27
#include "QuicklistMenuItemLabel.h"
26
28
#include "QuicklistMenuItemRadio.h"
27
29
#include "QuicklistMenuItemSeparator.h"
28
30
 
29
 
#include "Nux/Nux.h"
30
31
#include "Nux/VLayout.h"
31
32
#include "Nux/HLayout.h"
32
33
#include "Nux/WindowThread.h"
33
34
#include "Nux/WindowCompositor.h"
34
 
#include "Nux/BaseWindow.h"
35
35
 
36
36
#include "QuicklistView.h"
37
37
#include "TestThreadHelper.h"
89
89
 
90
90
  QuicklistMenuItemCheckmark* qlCheckmarkItem = NULL;
91
91
 
92
 
  qlCheckmarkItem = new QuicklistMenuItemCheckmark(item, true);
 
92
  qlCheckmarkItem = new QuicklistMenuItemCheckmark(item);
93
93
 
94
 
  g_assert_cmpstr(qlCheckmarkItem->GetLabel(), == , "Unchecked");
 
94
  g_assert_cmpstr(qlCheckmarkItem->GetLabel().c_str(), == , "Unchecked");
95
95
  g_assert_cmpint(qlCheckmarkItem->GetEnabled(), == , false);
96
96
  g_assert_cmpint(qlCheckmarkItem->GetActive(), == , false);
97
97
  g_assert_cmpint(qlCheckmarkItem->GetSelectable(), == , false);
126
126
 
127
127
  QuicklistMenuItemLabel* qlLabelItem = NULL;
128
128
 
129
 
  qlLabelItem = new QuicklistMenuItemLabel(item, true);
 
129
  qlLabelItem = new QuicklistMenuItemLabel(item);
130
130
 
131
 
  g_assert_cmpstr(qlLabelItem->GetLabel(), == , "A Label");
 
131
  g_assert_cmpstr(qlLabelItem->GetLabel().c_str(), == , "A Label");
132
132
  g_assert_cmpint(qlLabelItem->GetEnabled(), == , true);
133
133
  g_assert_cmpint(qlLabelItem->GetSelectable(), == , true);
134
134
  g_assert_cmpint(qlLabelItem->IsMarkupEnabled(), == , true);
165
165
 
166
166
  QuicklistMenuItemRadio* qlRadioItem = NULL;
167
167
 
168
 
  qlRadioItem = new QuicklistMenuItemRadio(item, true);
 
168
  qlRadioItem = new QuicklistMenuItemRadio(item);
169
169
  qlRadioItem->EnableLabelMarkup(true);
170
170
 
171
 
  g_assert_cmpstr(qlRadioItem->GetLabel(), == , "Radio Active");
 
171
  g_assert_cmpstr(qlRadioItem->GetLabel().c_str(), == , "Radio Active");
172
172
  g_assert_cmpint(qlRadioItem->GetEnabled(), == , true);
173
173
  g_assert_cmpint(qlRadioItem->GetActive(), == , true);
174
174
  g_assert_cmpint(qlRadioItem->GetSelectable(), == , true);
198
198
 
199
199
  QuicklistMenuItemSeparator* qlSeparatorItem = NULL;
200
200
 
201
 
  qlSeparatorItem = new QuicklistMenuItemSeparator(item, true);
 
201
  qlSeparatorItem = new QuicklistMenuItemSeparator(item);
202
202
 
203
203
  g_assert_cmpint(qlSeparatorItem->GetEnabled(), == , true);
204
204
  g_assert_cmpint(qlSeparatorItem->GetSelectable(), == , false);
207
207
  g_object_unref(item);
208
208
}
209
209
 
 
210
void populate_test_quicklist(QuicklistView* ql, DbusmenuMenuitem* root)
 
211
{
 
212
  ql->RemoveAllMenuItem();
 
213
 
 
214
  if (root == 0)
 
215
    return;
 
216
 
 
217
  GList* child = NULL;
 
218
  for (child = dbusmenu_menuitem_get_children(root); child != NULL; child = g_list_next(child))
 
219
  {
 
220
    const gchar* type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TYPE);
 
221
    const gchar* toggle_type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE);
 
222
 
 
223
    if (g_strcmp0(type, DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0)
 
224
    {
 
225
      QuicklistMenuItemSeparator* item = new QuicklistMenuItemSeparator((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
 
226
      ql->AddMenuItem(item);
 
227
    }
 
228
    else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_CHECK) == 0)
 
229
    {
 
230
      QuicklistMenuItemCheckmark* item = new QuicklistMenuItemCheckmark((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
 
231
      ql->AddMenuItem(item);
 
232
    }
 
233
    else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_RADIO) == 0)
 
234
    {
 
235
      QuicklistMenuItemRadio* item = new QuicklistMenuItemRadio((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
 
236
      ql->AddMenuItem(item);
 
237
    }
 
238
    else //if (g_strcmp0 (type, DBUSMENU_MENUITEM_PROP_LABEL) == 0)
 
239
    {
 
240
      QuicklistMenuItemLabel* item = new QuicklistMenuItemLabel((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
 
241
      ql->AddMenuItem(item);
 
242
    }
 
243
  }
 
244
}
 
245
 
210
246
static void
211
247
TestQuicklistMenuItem()
212
248
{
239
275
  dbusmenu_menuitem_child_append(root, child);
240
276
 
241
277
  QuicklistView* quicklist = new QuicklistView();
242
 
 
243
 
  quicklist->TestMenuItems(root);
 
278
  populate_test_quicklist(quicklist, root);
244
279
 
245
280
  g_assert_cmpint(quicklist->GetNumItems(), == , 4);
246
 
  g_assert_cmpint(quicklist->GetNthType(0), == , unity::MENUITEM_TYPE_LABEL);
247
 
  g_assert_cmpint(quicklist->GetNthType(1), == , unity::MENUITEM_TYPE_SEPARATOR);
248
 
  g_assert_cmpint(quicklist->GetNthType(2), == , unity::MENUITEM_TYPE_LABEL);
249
 
  g_assert_cmpint(quicklist->GetNthType(3), == , unity::MENUITEM_TYPE_CHECK);
 
281
  g_assert(quicklist->GetNthType(0) == unity::QuicklistMenuItemType::LABEL);
 
282
  g_assert(quicklist->GetNthType(1) == unity::QuicklistMenuItemType::SEPARATOR);
 
283
  g_assert(quicklist->GetNthType(2) == unity::QuicklistMenuItemType::LABEL);
 
284
  g_assert(quicklist->GetNthType(3) == unity::QuicklistMenuItemType::CHECK);
250
285
 
251
 
  g_assert_cmpstr(quicklist->GetNthItems(0)->GetLabel(), == , "label 0");
252
 
  g_assert_cmpstr(quicklist->GetNthItems(2)->GetLabel(), == , "label 1");
253
 
  g_assert_cmpstr(quicklist->GetNthItems(3)->GetLabel(), == , "check mark 0");
 
286
  g_assert_cmpstr(quicklist->GetNthItems(0)->GetLabel().c_str(), == , "label 0");
 
287
  g_assert_cmpstr(quicklist->GetNthItems(2)->GetLabel().c_str(), == , "label 1");
 
288
  g_assert_cmpstr(quicklist->GetNthItems(3)->GetLabel().c_str(), == , "check mark 0");
254
289
 
255
290
  g_assert_cmpint(quicklist->GetChildren().size(), == , 4);
256
291