-///
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
#include <iostream>
#include <stdlib.h>
-#include <dali/dali.h>
+#include <dali/public-api/dali-core.h>
#include <dali-test-suite-utils.h>
// Temp include
#include <dali/public-api/object/any.h>
+namespace
+{
+struct MyStruct
+{
+ MyStruct()
+ : mFloatValue( 0.f ),
+ mIntValue( 0 )
+ {}
+
+ MyStruct( float fValue, int iValue )
+ : mFloatValue( fValue ),
+ mIntValue( iValue )
+ {}
+
+ MyStruct( const MyStruct& myStruct )
+ : mFloatValue( myStruct.mFloatValue ),
+ mIntValue( myStruct.mIntValue )
+ {}
+
+ MyStruct& operator=( const MyStruct& myStruct )
+ {
+ mFloatValue = myStruct.mFloatValue;
+ mIntValue = myStruct.mIntValue;
+
+ return *this;
+ }
+
+ float mFloatValue;
+ int mIntValue;
+};
+}
+
using namespace Dali;
void utc_dali_any_startup(void)
DALI_TEST_EQUALS( fValue, 4.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
- Any value2 = 0.f;
+ value1 = 9.f; // Test operator=( const Type& ).
- value2 = 9.f; // Test operator=( const Type& ).
-
- value2.Get( fValue );
+ value1.Get( fValue );
DALI_TEST_EQUALS( fValue, 9.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
value6.Get( fValue );
DALI_TEST_EQUALS( fValue, 3.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ // test assignment for non-empty Any = empty Any
+ Any value7;
+ value6 = value7;
+ DALI_TEST_CHECK( value6.Empty() );
+
+
END_TEST;
}
}
catch( Dali::DaliException& e )
{
- tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
+ DALI_TEST_PRINT_ASSERT( e );
assert = true;
}
fValue = 0.f;
value1.Get( fValue );
DALI_TEST_EQUALS( fValue, 5.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ class MyClass
+ {
+ public:
+ MyClass( float fValue, int iValue )
+ : mAny( MyStruct( fValue, iValue ) )
+ {
+ }
+
+ const MyStruct& Get() const
+ {
+ return AnyCastReference<MyStruct>( mAny );
+ }
+
+ MyStruct* GetPointer()
+ {
+ return AnyCast<MyStruct>( &mAny );
+ }
+
+ const MyStruct* GetPointer() const
+ {
+ return AnyCast<MyStruct>( &mAny );
+ }
+
+ private:
+ Dali::Any mAny;
+ };
+
+ MyClass myClass( 3.25f, 3 );
+
+ MyStruct myStruct1 = myClass.Get();
+ const MyStruct& myStruct2 = myClass.Get();
+ MyStruct* myStruct3 = myClass.GetPointer();
+ const MyStruct* myStruct4 = myClass.GetPointer();
+
+ if( myStruct3 == NULL )
+ {
+ tet_result( TET_FAIL );
+ END_TEST;
+ }
+
+ if( myStruct4 == NULL )
+ {
+ tet_result( TET_FAIL );
+ END_TEST;
+ }
+
+ DALI_TEST_EQUALS( myStruct1.mFloatValue, 3.25f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+ DALI_TEST_EQUALS( myStruct2.mFloatValue, 3.25f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+ DALI_TEST_EQUALS( myStruct3->mFloatValue, 3.25f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+ DALI_TEST_EQUALS( myStruct4->mFloatValue, 3.25f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+ DALI_TEST_EQUALS( myStruct1.mIntValue, 3, TEST_LOCATION );
+ DALI_TEST_EQUALS( myStruct2.mIntValue, 3, TEST_LOCATION );
+ DALI_TEST_EQUALS( myStruct3->mIntValue, 3, TEST_LOCATION );
+ DALI_TEST_EQUALS( myStruct4->mIntValue, 3, TEST_LOCATION );
+
+ // Test on empty any object
+ Dali::Any myAny;
+ float* f = myAny.GetPointer<float>();
+ DALI_TEST_CHECK( f == NULL );
+
+ // Test on getting wrong type
+ myAny = 1.f;
+ try
+ {
+ myAny.GetPointer<int>();
+ tet_result( TET_FAIL );
+ }
+ catch( Dali::DaliException& e )
+ {
+ DALI_TEST_PRINT_ASSERT( e );
+ }
+
END_TEST;
}
catch( Dali::DaliException& e )
{
- tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
+ DALI_TEST_PRINT_ASSERT( e );
assert1 = true;
}
catch( Dali::DaliException& e )
{
- tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
+ DALI_TEST_PRINT_ASSERT( e );
assert2 = true;
}