Adding new test harness
[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 Flora License, Version 1.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://floralicense.org/license/
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 #include <iostream>
18 #include <stdlib.h>
19
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22
23 #include <dali/integration-api/events/key-event-integ.h>
24 #include <dali/integration-api/events/mouse-wheel-event-integ.h>
25 #include <dali/integration-api/events/long-press-gesture-event.h>
26 #include <dali/integration-api/events/pinch-gesture-event.h>
27 #include <dali/integration-api/events/pan-gesture-event.h>
28 #include <dali/integration-api/events/tap-gesture-event.h>
29 #include <dali/integration-api/events/touch-event-integ.h>
30
31 #include "dummy-control.h"
32
33 using namespace Dali;
34 using namespace Dali::Toolkit;
35
36
37 void control_impl_startup(void)
38 {
39   test_return_value = TET_UNDEF;
40 }
41
42 void control_impl_cleanup(void)
43 {
44   test_return_value = TET_PASS;
45 }
46
47
48 int UtcDaliControlImplTypeRegistry(void)
49 {
50   ToolkitTestApplication application;
51
52   // Register Type
53   TypeInfo type;
54   type = TypeRegistry::Get().GetTypeInfo( "Control" );
55   DALI_TEST_CHECK( type );
56   BaseHandle handle = type.CreateInstance();
57   DALI_TEST_CHECK( handle );
58
59   // Check if it's a control
60   DALI_TEST_CHECK( Control::DownCast(handle) );
61   END_TEST;
62 }
63
64
65 ///////////////////////////////////////////////////////////////////////////////////////////////////
66 namespace
67 {
68 static bool MouseWheelEventCallback(Actor actor, const MouseWheelEvent& event)
69 {
70   return false;
71 }
72 }
73
74 int UtcDaliControlImplMouseWheelEvent(void)
75 {
76   ToolkitTestApplication application;
77
78   {
79     DummyControl dummy = DummyControl::New( true );
80     DummyControlImplOverride& dummyImpl = static_cast<DummyControlImplOverride&>(dummy.GetImplementation());
81
82     dummy.SetSize(100.0f, 100.0f);
83     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
84     Stage::GetCurrent().Add(dummy);
85
86     dummy.MouseWheelEventSignal().Connect(&MouseWheelEventCallback);
87
88     application.Render();
89     application.SendNotification();
90     application.Render();
91     application.SendNotification();
92
93     DALI_TEST_EQUALS( dummyImpl.mouseWheelEventCalled, false, TEST_LOCATION );
94
95     // simulate a mouse wheel event
96     Vector2 screenCoordinates( 10.0f, 10.0f );
97     Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u);
98     application.ProcessEvent(event);
99     DALI_TEST_EQUALS( dummyImpl.mouseWheelEventCalled, true, TEST_LOCATION );
100
101     Stage::GetCurrent().Remove(dummy);
102   }
103
104   // Ensure full code coverage
105   {
106     DummyControl dummy = DummyControl::New();
107
108     dummy.SetSize(100.0f, 100.0f);
109     dummy.SetAnchorPoint(AnchorPoint::TOP_LEFT);
110     Stage::GetCurrent().Add(dummy);
111
112     dummy.MouseWheelEventSignal().Connect(&MouseWheelEventCallback);
113
114     application.Render();
115     application.SendNotification();
116     application.Render();
117     application.SendNotification();
118
119     // simulate a mouse wheel event
120     Vector2 screenCoordinates( 20.0f, 20.0f );
121     Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u);
122     application.ProcessEvent(event);
123
124     Stage::GetCurrent().Remove(dummy);
125   }
126   END_TEST;
127 }