~3v1n0/unity/overlay-border-scale

« back to all changes in this revision

Viewing changes to tests/test_switcher_controller.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
Merged latest lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2012 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * version 3 along with this program.  If not, see
 
15
 * <http://www.gnu.org/licenses/>
 
16
 *
 
17
 * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
 
18
 *
 
19
 */
 
20
 
 
21
#include <gtest/gtest.h>
 
22
 
 
23
#include "SwitcherController.h"
 
24
#include "test_utils.h"
 
25
 
 
26
 
 
27
using namespace unity::switcher;
 
28
 
 
29
namespace
 
30
{
 
31
 
 
32
unsigned int DEFAULT_LAZY_CONSTRUCT_TIMEOUT = 20;
 
33
 
 
34
class MockSwitcherController : public Controller
 
35
{
 
36
public:
 
37
  MockSwitcherController()
 
38
    : Controller()
 
39
    , window_constructed_(false)
 
40
    , view_constructed_(false)
 
41
    , view_shown_(false)
 
42
  {};
 
43
 
 
44
  MockSwitcherController(unsigned int load_timeout)
 
45
    : Controller(load_timeout)
 
46
    , window_constructed_(false)
 
47
    , view_constructed_(false)
 
48
    , view_shown_(false)
 
49
  {};
 
50
 
 
51
  virtual void ConstructWindow()
 
52
  {
 
53
    window_constructed_ = true;
 
54
  }
 
55
 
 
56
  virtual void ConstructView()
 
57
  {
 
58
    view_constructed_ = true;
 
59
  }
 
60
 
 
61
  virtual void ShowView()
 
62
  {
 
63
    view_shown_ = true;
 
64
  }
 
65
 
 
66
  unsigned int GetConstructTimeout() const
 
67
  {
 
68
    return construct_timeout_;
 
69
  }
 
70
 
 
71
  bool window_constructed_;
 
72
  bool view_constructed_;
 
73
  bool view_shown_;
 
74
};
 
75
 
 
76
TEST(TestSwitcherController, Construction)
 
77
{
 
78
  Controller controller;
 
79
  EXPECT_FALSE(controller.Visible());
 
80
}
 
81
 
 
82
TEST(TestSwitcherController, LazyConstructionTimeoutLength)
 
83
{
 
84
  MockSwitcherController controller;
 
85
  EXPECT_EQ(controller.GetConstructTimeout(), DEFAULT_LAZY_CONSTRUCT_TIMEOUT);
 
86
}
 
87
 
 
88
TEST(TestSwitcherController, LazyWindowConstruction)
 
89
{
 
90
  // Setting the timeout to a lower value to speed-up the test
 
91
  MockSwitcherController controller(2);
 
92
 
 
93
  EXPECT_EQ(controller.GetConstructTimeout(), 2);
 
94
 
 
95
  g_timeout_add_seconds(controller.GetConstructTimeout()/2, [] (gpointer data) -> gboolean {
 
96
    auto controller = static_cast<MockSwitcherController*>(data);
 
97
    EXPECT_FALSE(controller->window_constructed_);
 
98
 
 
99
    return FALSE;
 
100
  }, &controller);
 
101
 
 
102
  Utils::WaitUntil(controller.window_constructed_, controller.GetConstructTimeout() + 1);
 
103
  EXPECT_TRUE(controller.window_constructed_);
 
104
}
 
105
 
 
106
}