e0d84e15f01e45514739ddcf8c68de8b288d1564
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-ControlImpl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/mouse-wheel-event-integ.h>
26 #include <dali/integration-api/events/long-press-gesture-event.h>
27 #include <dali/integration-api/events/pinch-gesture-event.h>
28 #include <dali/integration-api/events/pan-gesture-event.h>
29 #include <dali/integration-api/events/tap-gesture-event.h>
30 #include <dali/integration-api/events/touch-event-integ.h>
31
32 #include "dummy-control.h"
33
34 using namespace Dali;
35 using namespace Dali::Toolkit;
36
37
38 void control_impl_startup(void)
39 {
40   test_return_value = TET_UNDEF;
41 }
42
43 void control_impl_cleanup(void)
44 {
45   test_return_value = TET_PASS;
46 }
47
48
49 int UtcDaliControlImplTypeRegistry(void)
50 {
51   ToolkitTestApplication application;
52
53   // Register Type
54   TypeInfo type;
55   type = TypeRegistry::Get().GetTypeInfo( "Control" );
56   DALI_TEST_CHECK( type );
57   BaseHandle handle = type.CreateInstance();
58   DALI_TEST_CHECK( handle );
59
60   // Check if it's a control
61   DALI_TEST_CHECK( Control::DownCast(handle) );
62   END_TEST;
63 }
64
65
66 ///////////////////////////////////////////////////////////////////////////////////////////////////
67 namespace
68 {
69 static bool MouseWheelEventCallback(Actor actor, const MouseWheelEvent& event)
70 {
71   return false;
72 }
73 }
74
75 int UtcDaliControlImplMouseWheelEvent(void)
76 {
77   ToolkitTestApplication application;
78
79   {
80     DummyControl dummy = DummyControl::New( true );
81     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
82
83     dummy.SetSize(100.0f, 100.0f);
84     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
85     Stage::GetCurrent().Add(dummy);
86
87     dummy.MouseWheelEventSignal().Connect(&MouseWheelEventCallback);
88
89     application.Render();
90     application.SendNotification();
91     application.Render();
92     application.SendNotification();
93
94     DALI_TEST_EQUALS( dummyImpl.mouseWheelEventCalled, false, TEST_LOCATION );
95
96     // simulate a mouse wheel event
97     Vector2 screenCoordinates( 10.0f, 10.0f );
98     Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u);
99     application.ProcessEvent(event);
100     DALI_TEST_EQUALS( dummyImpl.mouseWheelEventCalled, true, TEST_LOCATION );
101
102     Stage::GetCurrent().Remove(dummy);
103   }
104
105   // Ensure full code coverage
106   {
107     DummyControl dummy = DummyControl::New();
108
109     dummy.SetSize(100.0f, 100.0f);
110     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
111     Stage::GetCurrent().Add(dummy);
112
113     dummy.MouseWheelEventSignal().Connect(&MouseWheelEventCallback);
114
115     application.Render();
116     application.SendNotification();
117     application.Render();
118     application.SendNotification();
119
120     // simulate a mouse wheel event
121     Vector2 screenCoordinates( 20.0f, 20.0f );
122     Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u);
123     application.ProcessEvent(event);
124
125     Stage::GetCurrent().Remove(dummy);
126   }
127   END_TEST;
128 }