~ubuntu-branches/ubuntu/quantal/unity/quantal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright 2012 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3, as
 * published by the  Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
 *
 */

#include <gmock/gmock.h>
using namespace testing;

#include "DeviceLauncherSection.h"
#include "AbstractVolumeMonitorWrapper.h"
using namespace unity;
using namespace unity::launcher;

#include "gmockvolume.h"
#include "test_utils.h"

namespace
{

class EventListener
{
public:
  EventListener()
    : icon_added(false)
  {}

  void OnIconAdded(AbstractLauncherIcon::Ptr icon)
  {
    icon_added = true;
  }

  bool icon_added;
};

class MockVolumeMonitorWrapper : public AbstractVolumeMonitorWrapper
{
public:
  typedef std::shared_ptr<MockVolumeMonitorWrapper> Ptr;

  MockVolumeMonitorWrapper()
    : volume1(G_VOLUME(g_mock_volume_new()))
    , volume2(G_VOLUME(g_mock_volume_new()))
  {
  }

  VolumeList GetVolumes()
  {
    VolumeList ret;

    ret.push_back(volume1);
    ret.push_back(volume2);

    return ret;
  }

  glib::Object<GVolume> volume1;
  glib::Object<GVolume> volume2;
};

class TestDeviceLauncherSection : public Test
{
public:
  TestDeviceLauncherSection()
    : monitor_(new MockVolumeMonitorWrapper)
    , section_(monitor_)
  {}

  void SetUp()
  {
    // Make sure PopulateEntries is called.
    Utils::WaitForTimeoutMSec(1500);
  }

  MockVolumeMonitorWrapper::Ptr monitor_;
  DeviceLauncherSection section_;
};


TEST_F(TestDeviceLauncherSection, TestNoDuplicates)
{
  std::shared_ptr<EventListener> listener(new EventListener);
  section_.IconAdded.connect(sigc::mem_fun(*listener, &EventListener::OnIconAdded));

  // Emit the signal volume_added for each volume.
  monitor_->volume_added.emit(monitor_->volume1);
  monitor_->volume_added.emit(monitor_->volume2);

  Utils::WaitForTimeoutMSec(500);

  EXPECT_EQ(listener->icon_added, false);
}

}