~azzar1/unity/fix-trash-li-blocking

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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2012 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
 */

#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <dash/ScopeBar.h>

#include "unity-shared/DashStyle.h"
#include "test_mock_scope.h"

namespace unity
{
namespace dash
{

class TestScopeBar : public ::testing::Test
{
public:
  TestScopeBar()
  {
  }

  void CheckSize(ScopeBar const& scope_bar, int size)
  {
    EXPECT_EQ(scope_bar.icons_.size(), size);
  }

  dash::Style style;
};

TEST_F(TestScopeBar, TestAddScopes)
{
  ScopeBar scope_bar;

  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope1.scope"), "TestScope1", "icon-sub1.svg"));
  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope2.scope"), "TestScope2", "icon-sub2.svg"));
  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope3.scope"), "TestScope3", "icon-sub3.svg"));

  CheckSize(scope_bar, 3);
}

TEST_F(TestScopeBar, TestActivate)
{
  ScopeBar scope_bar;

  std::string active_scope = "";
  scope_bar.scope_activated.connect([&active_scope](std::string const& activated) { active_scope = activated; } );

  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope1.scope"), "TestScope1", "icon-sub1.svg"));
  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope2.scope"), "TestScope2", "icon-sub2.svg"));
  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope3.scope"), "TestScope3", "icon-sub3.svg"));

  scope_bar.Activate("testscope1.scope");
  EXPECT_EQ(active_scope, "testscope1.scope");

  scope_bar.Activate("testscope2.scope");
  EXPECT_EQ(active_scope, "testscope2.scope");

  scope_bar.Activate("testscope3.scope");
  EXPECT_EQ(active_scope, "testscope3.scope");
}

TEST_F(TestScopeBar, TestActivateNext)
{
  ScopeBar scope_bar;

  std::string active_scope = "";
  scope_bar.scope_activated.connect([&active_scope](std::string const& activated) { active_scope = activated; } );

  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope1.scope"), "TestScope1", "icon-sub1.svg"));
  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope2.scope"), "TestScope2", "icon-sub2.svg"));
  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope3.scope"), "TestScope3", "icon-sub3.svg"));

  scope_bar.ActivateNext();
  EXPECT_EQ(active_scope, "testscope1.scope");

  scope_bar.ActivateNext();
  EXPECT_EQ(active_scope, "testscope2.scope");

  scope_bar.ActivateNext();
  EXPECT_EQ(active_scope, "testscope3.scope");

  scope_bar.ActivateNext();
  EXPECT_EQ(active_scope, "testscope1.scope");
}

TEST_F(TestScopeBar, TestActivatePrevious)
{
  ScopeBar scope_bar;

  std::string active_scope = "";
  scope_bar.scope_activated.connect([&active_scope](std::string const& activated) { active_scope = activated; } );

  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope1.scope"), "TestScope1", "icon-sub1.svg"));
  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope2.scope"), "TestScope2", "icon-sub2.svg"));
  scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope3.scope"), "TestScope3", "icon-sub3.svg"));

  scope_bar.ActivatePrevious();
  EXPECT_EQ(active_scope, "testscope3.scope");

  scope_bar.ActivatePrevious();
  EXPECT_EQ(active_scope, "testscope2.scope");

  scope_bar.ActivatePrevious();
  EXPECT_EQ(active_scope, "testscope1.scope");

  scope_bar.ActivatePrevious();
  EXPECT_EQ(active_scope, "testscope3.scope");
}


}
}