Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-Button.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 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali/integration-api/events/touch-event-integ.h>
21 #include <dali-toolkit/dali-toolkit.h>
22
23 using namespace Dali;
24 using namespace Toolkit;
25
26 void dali_button_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void dali_button_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36
37 namespace
38 {
39 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
40 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
41 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
42 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
43 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
44 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
45
46 static bool gObjectCreatedCallBackCalled;
47
48 static void TestObjectCreatedCallback(BaseHandle handle)
49 {
50   gObjectCreatedCallBackCalled = true;
51 }
52
53 } // namespace
54
55
56
57 // Positive test case for a method
58 int UtcDaliButtonNew(void)
59 {
60   ToolkitTestApplication application;
61   tet_infoline(" UtcDaliButtonNew");
62
63   CheckBoxButton checkBoxButton = CheckBoxButton::New();
64   DALI_TEST_CHECK( checkBoxButton );
65
66   CheckBoxButton checkBoxButton2( checkBoxButton );
67   DALI_TEST_CHECK( checkBoxButton2 );
68   checkBoxButton2 = NULL;
69
70
71   //Additional check to ensure object is created by checking if it's registered
72   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
73   DALI_TEST_CHECK( registry );
74
75   gObjectCreatedCallBackCalled = false;
76   registry.ObjectCreatedSignal().Connect( &TestObjectCreatedCallback );
77   {
78     CheckBoxButton checkBoxButton = CheckBoxButton::New();
79   }
80   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
81
82   gObjectCreatedCallBackCalled = false;
83   registry.ObjectCreatedSignal().Connect( &TestObjectCreatedCallback );
84   {
85     PushButton pushButton = PushButton::New();
86   }
87   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
88
89   // Test down cast
90   Handle handleButton = checkBoxButton;
91   Button downCastCheckBoxButton = Button::DownCast( handleButton );
92   DALI_TEST_CHECK( downCastCheckBoxButton );
93   CheckBoxButton downCastCheckBoxButton2 = CheckBoxButton::DownCast( handleButton );
94   DALI_TEST_CHECK( downCastCheckBoxButton2 );
95   END_TEST;
96 }
97
98 int UtcDaliButtonProperties(void)
99 {
100   tet_infoline("UtcDaliButtonSetProperty: ");
101   ToolkitTestApplication application;
102
103   CheckBoxButton checkBoxButton = CheckBoxButton::New();
104   PushButton pushButton = PushButton::New();
105
106   //Test various properties
107   checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("dimmed"), false );
108   DALI_TEST_CHECK( false == checkBoxButton.IsDimmed() );
109
110   checkBoxButton.SetProperty( checkBoxButton.GetPropertyIndex("dimmed"), true );
111   DALI_TEST_CHECK( true == checkBoxButton.IsDimmed() );
112   END_TEST;
113 }
114
115 int UtcDaliButtonSetGetDimmed(void)
116 {
117   ToolkitTestApplication application;
118   tet_infoline(" UtcDaliButtonSetGetDimmed");
119
120   CheckBoxButton checkBoxButton = CheckBoxButton::New();
121   checkBoxButton.SetDimmed( true );
122
123   DALI_TEST_CHECK( checkBoxButton.IsDimmed() );
124   checkBoxButton.SetDimmed( false );
125
126   DALI_TEST_CHECK( !checkBoxButton.IsDimmed() );
127   checkBoxButton.SetDimmed( true );
128
129   DALI_TEST_CHECK( checkBoxButton.IsDimmed() );
130   checkBoxButton.SetDimmed( false );
131
132   DALI_TEST_CHECK( !checkBoxButton.IsDimmed() );
133   END_TEST;
134 }