2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
24 #include <dali/public-api/object/any.h>
28 void utc_dali_any_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_any_cleanup(void)
35 test_return_value = TET_PASS;
38 int UtcDaliAnyConstructors(void)
40 TestApplication application;
42 tet_infoline("Test Any constructors.");
44 // Test default constructor.
47 DALI_TEST_CHECK( typeid( void ) == value.GetType() );
49 // Test constructor Any( const Type& )
52 // Test constructor Any( const Any& )
55 // Test constructor Any( const Any& ) with a non initialized Any
58 DALI_TEST_CHECK( typeid( unsigned int ) == value1.GetType() );
59 DALI_TEST_CHECK( typeid( unsigned int ) == value2.GetType() );
60 DALI_TEST_CHECK( typeid( void ) == value3.GetType() );
62 unsigned int uiValue1 = 0u;
63 unsigned int uiValue2 = 0u;
64 value1.Get( uiValue1 );
65 value2.Get( uiValue2 );
67 DALI_TEST_EQUALS( uiValue1, uiValue2, TEST_LOCATION );
71 int UtcDaliAnyAssignmentOperators(void)
73 TestApplication application;
75 tet_infoline("Test assignment operators.");
81 value1 = 4.f; // Test operator=( const Type& ) when current object is not initialized.
85 DALI_TEST_EQUALS( fValue, 4.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
89 value2 = 9.f; // Test operator=( const Type& ).
93 DALI_TEST_EQUALS( fValue, 9.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
97 value1 = value3; // Test operator=( const Any& ).
101 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
105 value4 = value3; // Test operator=( const Any& ) when current object is not initialized.
107 value4.Get( fValue );
109 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
111 // Test assign a value to value3 doesn't modify value1.
114 value1.Get( fValue );
116 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
118 value3.Get( fValue );
120 DALI_TEST_EQUALS( fValue, 3.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
122 // Test the branch when copying the same object.
124 Any& value6( value5 );
128 value6.Get( fValue );
129 DALI_TEST_EQUALS( fValue, 3.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
133 int UtcDaliAnyNegativeAssignmentOperators(void)
135 TestApplication application;
137 tet_infoline("Test assignment operators.");
146 value1 = value2; // Test operator=( const Any& );
148 catch( Dali::DaliException& e )
150 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
156 tet_result( TET_PASS );
160 tet_result( TET_FAIL );
165 int UtcDaliAnyGetType(void)
167 TestApplication application;
169 tet_infoline("Test GetType().");
173 DALI_TEST_CHECK( typeid( void ) == value.GetType() );
177 DALI_TEST_CHECK( typeid( float ) == value.GetType() );
181 int UtcDaliAnyGet(void)
183 TestApplication application;
185 tet_infoline("Test Get().");
189 float fValue = value1.Get<float>();
191 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
194 value1.Get( fValue );
195 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
199 int UtcDaliAnyNegativeGet(void)
201 TestApplication application;
202 tet_infoline("Test Get().");
207 bool assert1 = false;
208 bool assert2 = false;
210 unsigned int uiValue = 0u;
214 uiValue = value1.Get< unsigned int >();
217 catch( Dali::DaliException& e )
219 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
225 uiValue = value2.Get< unsigned int >();
228 catch( Dali::DaliException& e )
230 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
234 if( assert1 && assert2 )
236 tet_result( TET_PASS );
240 tet_result( TET_FAIL );
242 uiValue++; // supresss warning from unused variable