2
* Copyright 2010 Inalogic® Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
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 applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jaytaoko@inalogic.com>
19
* Marco Trevisan <marco.trevisan@canonical.com>
5
22
#include <gmock/gmock.h>
6
#include <boost/filesystem.hpp>
23
#include <boost/shared_ptr.hpp>
9
24
#include "Nux/Nux.h"
10
25
#include "Nux/HLayout.h"
11
26
#include "Nux/StaticText.h"
19
TEST(TestArea, TestAreaSize)
21
nux::NuxInitialize(0);
22
nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Area Test", 300, 200,
23
nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL);
25
nux::TestView* test_view = new nux::TestView("");
34
struct MockTestView : nux::TestView
37
: nux::TestView("MockTestView")
40
void SetNextObjectToKeyFocusArea(nux::Area* area)
42
TestView::SetNextObjectToKeyFocusArea(area);
45
nux::Area* GetNextObjectToKeyFocusArea()
47
return TestView::GetNextObjectToKeyFocusArea();
51
struct TestArea : public testing::Test
55
nux::NuxInitialize(0);
56
wnd_thread.reset(nux::CreateNuxWindow("Area Test", 300, 200, nux::WINDOWSTYLE_NORMAL,
57
NULL, false, NULL, NULL));
58
test_view = new MockTestView();
61
boost::shared_ptr<nux::WindowThread> wnd_thread;
62
nux::ObjectPtr<MockTestView> test_view;
65
TEST_F(TestArea, TestAreaSize)
27
67
EXPECT_EQ(test_view->GetMinimumWidth(), nux::AREA_MIN_WIDTH);
28
68
EXPECT_EQ(test_view->GetMaximumWidth(), nux::AREA_MAX_WIDTH);
29
69
EXPECT_EQ(test_view->GetMinimumHeight(), nux::AREA_MIN_HEIGHT);
48
88
EXPECT_EQ(test_view->GetMaximumWidth(), 4321);
49
89
EXPECT_EQ(test_view->GetMinimumHeight(), 432);
50
90
EXPECT_EQ(test_view->GetMaximumHeight(), 1234);
52
test_view->UnReference();
56
TEST(TestArea, TestAreaGeometry)
93
TEST_F(TestArea, TestAreaGeometry)
58
nux::NuxInitialize(0);
59
nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Area Test", 300, 200,
60
nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL);
62
nux::TestView* test_view = new nux::TestView("");
64
static_cast<nux::Area*>(test_view)->SetGeometry(0, 0, 100, 100);
95
static_cast<nux::Area*>(test_view.GetPointer())->SetGeometry(0, 0, 100, 100);
66
97
EXPECT_EQ(test_view->GetBaseX(), 0);
67
98
EXPECT_EQ(test_view->GetBaseX(), 0);
68
99
EXPECT_EQ(test_view->GetBaseWidth(), 100);
69
100
EXPECT_EQ(test_view->GetBaseHeight(), 100);
72
test_view->UnReference();
76
103
static bool object_destroyed = false;
79
106
object_destroyed = true;
82
TEST(TestArea, TestUnParentKeyFocus)
109
TEST_F(TestArea, TestUnParentKeyFocus)
84
nux::NuxInitialize(0);
85
nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Area Test", 300, 200,
86
nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL);
111
nux::TestView* test_view1 = new nux::TestView("");
88
112
nux::HLayout* layout = new nux::HLayout();
89
nux::TestView* test_view = new nux::TestView("");
90
test_view->object_destroyed.connect(sigc::ptr_fun(&OnObjectDestroyed));
113
test_view1->object_destroyed.connect(sigc::ptr_fun(&OnObjectDestroyed));
92
test_view->Reference();
94
layout->AddView(test_view, 1);
115
test_view1->Reference();
116
layout->AddView(test_view1, 1);
96
118
wnd_thread->SetLayout(layout);
98
EXPECT_EQ(test_view->HasKeyFocus(), false);
99
nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(test_view);
100
EXPECT_EQ(test_view->HasKeyFocus(), true);
101
layout->RemoveChildObject(test_view);
102
EXPECT_EQ(test_view->HasKeyFocus(), false);
103
test_view->UnReference();
120
EXPECT_EQ(test_view1->HasKeyFocus(), false);
121
nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(test_view1);
122
EXPECT_EQ(test_view1->HasKeyFocus(), true);
123
layout->RemoveChildObject(test_view1);
124
EXPECT_EQ(test_view1->HasKeyFocus(), false);
125
test_view1->UnReference();
104
126
EXPECT_EQ(object_destroyed, true);
129
TEST_F(TestArea, NextObjectToKeyFocusSetReset)
131
MockTestView* parent = new MockTestView();
132
MockTestView* brother = new MockTestView();
133
MockTestView* child1 = new MockTestView();
134
MockTestView* child2 = new MockTestView();
135
MockTestView* child3 = new MockTestView();
137
parent->SetNextObjectToKeyFocusArea(brother);
138
ASSERT_EQ(parent->GetNextObjectToKeyFocusArea(), brother);
140
child1->SetParentObject(parent);
141
child1->SetNextObjectToKeyFocusArea(child2);
142
ASSERT_EQ(child1->GetNextObjectToKeyFocusArea(), child2);
144
child2->SetParentObject(parent);
145
child2->SetNextObjectToKeyFocusArea(child3);
146
ASSERT_EQ(child2->GetNextObjectToKeyFocusArea(), child3);
148
child3->SetParentObject(parent);
149
ASSERT_EQ(child3->GetNextObjectToKeyFocusArea(), nullptr);
151
child1->UnReference();
152
EXPECT_EQ(child2->GetNextObjectToKeyFocusArea(), nullptr);
153
EXPECT_EQ(parent->GetNextObjectToKeyFocusArea(), nullptr);
155
parent->UnReference();