2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/dali.h>
22 #include <dali-test-suite-utils.h>
25 #include <dali/public-api/object/any.h>
29 void utc_dali_any_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_any_cleanup(void)
36 test_return_value = TET_PASS;
39 int UtcDaliAnyConstructors(void)
41 TestApplication application;
43 tet_infoline("Test Any constructors.");
45 // Test default constructor.
48 DALI_TEST_CHECK( typeid( void ) == value.GetType() );
50 // Test constructor Any( const Type& )
53 // Test constructor Any( const Any& )
56 // Test constructor Any( const Any& ) with a non initialized Any
59 DALI_TEST_CHECK( typeid( unsigned int ) == value1.GetType() );
60 DALI_TEST_CHECK( typeid( unsigned int ) == value2.GetType() );
61 DALI_TEST_CHECK( typeid( void ) == value3.GetType() );
63 unsigned int uiValue1 = 0u;
64 unsigned int uiValue2 = 0u;
65 value1.Get( uiValue1 );
66 value2.Get( uiValue2 );
68 DALI_TEST_EQUALS( uiValue1, uiValue2, TEST_LOCATION );
72 int UtcDaliAnyAssignmentOperators(void)
74 TestApplication application;
76 tet_infoline("Test assignment operators.");
82 value1 = 4.f; // Test operator=( const Type& ) when current object is not initialized.
86 DALI_TEST_EQUALS( fValue, 4.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
90 value2 = 9.f; // Test operator=( const Type& ).
94 DALI_TEST_EQUALS( fValue, 9.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
98 value1 = value3; // Test operator=( const Any& ).
100 value1.Get( fValue );
102 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
106 value4 = value3; // Test operator=( const Any& ) when current object is not initialized.
108 value4.Get( fValue );
110 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
112 // Test assign a value to value3 doesn't modify value1.
115 value1.Get( fValue );
117 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
119 value3.Get( fValue );
121 DALI_TEST_EQUALS( fValue, 3.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
123 // Test the branch when copying the same object.
125 Any& value6( value5 );
129 value6.Get( fValue );
130 DALI_TEST_EQUALS( fValue, 3.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
134 int UtcDaliAnyNegativeAssignmentOperators(void)
136 TestApplication application;
138 tet_infoline("Test assignment operators.");
147 value1 = value2; // Test operator=( const Any& );
149 catch( Dali::DaliException& e )
151 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
157 tet_result( TET_PASS );
161 tet_result( TET_FAIL );
166 int UtcDaliAnyGetType(void)
168 TestApplication application;
170 tet_infoline("Test GetType().");
174 DALI_TEST_CHECK( typeid( void ) == value.GetType() );
178 DALI_TEST_CHECK( typeid( float ) == value.GetType() );
182 int UtcDaliAnyGet(void)
184 TestApplication application;
186 tet_infoline("Test Get().");
190 float fValue = value1.Get<float>();
192 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
195 value1.Get( fValue );
196 DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
200 int UtcDaliAnyNegativeGet(void)
202 TestApplication application;
203 tet_infoline("Test Get().");
208 bool assert1 = false;
209 bool assert2 = false;
211 unsigned int uiValue = 0u;
215 uiValue = value1.Get< unsigned int >();
218 catch( Dali::DaliException& e )
220 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
226 uiValue = value2.Get< unsigned int >();
229 catch( Dali::DaliException& e )
231 tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
235 if( assert1 && assert2 )
237 tet_result( TET_PASS );
241 tet_result( TET_FAIL );
243 uiValue++; // supresss warning from unused variable