2 * Copyright (c) 2017 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/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <dali/devel-api/object/csharp-type-info.h>
24 #include <dali/devel-api/object/csharp-type-registry.h>
25 #include <dali/internal/event/common/type-registry-impl.h>
26 #include <dali/public-api/object/property.h>
34 static bool CreateCustomNamedInitCalled = false;
37 BaseHandle* CreateCustomNamedInit(const char* const typeName )
39 CreateCustomNamedInitCalled = true;
41 BaseHandle* x = new BaseHandle();
46 // Property Registration
47 bool setPropertyCalled = false;
48 bool getPropertyCalled = false;
49 int intPropertyValue = 0;
51 void SetProperty( BaseObject* object, const char* const propertyName , Property::Value* value )
54 value->Get( intPropertyValue );
56 setPropertyCalled = true;
59 Property::Value* GetProperty( BaseObject* object, const char* const propertyName )
61 getPropertyCalled = true;
62 Property::Value* x = new Property::Value( 10 );
68 int UtcDaliRegisterCSharpTypeP(void)
71 TestApplication application;
73 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit );
75 Dali::TypeInfo info = Dali::TypeRegistry::Get().GetTypeInfo( "CSharpControl" );
77 info.CreateInstance();
79 DALI_TEST_EQUALS( CreateCustomNamedInitCalled, true, TEST_LOCATION );
84 int UtcDaliRegisterCSharpTypeNoInitP(void)
87 TestApplication application;
89 CreateCustomNamedInitCalled = false;
91 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit );
93 GetImplementation(Dali::TypeRegistry::Get()).CallInitFunctions();
95 DALI_TEST_EQUALS( CreateCustomNamedInitCalled, false, TEST_LOCATION );
100 int UtcDaliRegisterCSharpTypeN(void)
102 TestApplication application;
104 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit );
106 // should cause an assert because we're registering same type twice
109 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit );
110 tet_result( TET_FAIL );
112 catch ( DaliException& e )
114 DALI_TEST_ASSERT( e, "Duplicate type name in Type Registration", TEST_LOCATION );
120 int UtcDaliRegisterCSharpTypeCreateP(void)
123 TestApplication application;
124 CreateCustomNamedInitCalled = false;
126 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit );
129 TypeInfo info = Dali::TypeRegistry::Get().GetTypeInfo( "CSharpControl");
131 BaseHandle handle = info.CreateInstance();
133 DALI_TEST_EQUALS( CreateCustomNamedInitCalled, true, TEST_LOCATION );
140 int UtcDaliRegisterCSharpPropertyP(void)
142 TestApplication application;
144 CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit );
147 bool registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
154 DALI_TEST_EQUALS( registered, true, TEST_LOCATION );
161 int UtcDaliRegisterCSharpPropertyN(void)
163 TestApplication application;
165 // register the same property twice
166 CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit );
169 bool registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
176 DALI_TEST_EQUALS( registered, true, TEST_LOCATION );
179 // should fail second time with an assert as the property is already registered
182 registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
189 tet_result( TET_FAIL );
191 catch ( DaliException& e )
193 DALI_TEST_ASSERT( e, "Property index already added to Type", TEST_LOCATION );
199 int UtcDaliRegisterCSharpPropertySetP(void)
201 TestApplication application;
203 // register the same property twice
204 CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit );;
206 Property::Index index(100001);
208 CSharpTypeRegistry::RegisterProperty( "DateControl",
215 TypeRegistry typeRegistry = TypeRegistry::Get();
217 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "DateControl" );
220 // Check the property is writable in the type registry
221 Internal::TypeInfo& typeInfoImpl = GetImplementation( typeInfo );
223 Property::Value value(25);
225 typeInfoImpl.SetProperty( NULL, index, value );
227 DALI_TEST_EQUALS( 25, intPropertyValue , TEST_LOCATION );
229 Property::Value value2(50);
231 typeInfoImpl.SetProperty( NULL, "year", value2 );
233 DALI_TEST_EQUALS( 50, intPropertyValue , TEST_LOCATION );
235 DALI_TEST_EQUALS( setPropertyCalled, true, TEST_LOCATION );
241 int UtcDaliRegisterCSharpPropertyGetP(void)
243 TestApplication application;
245 // register the same property twice
246 CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit );
248 Property::Index index(100001);
250 CSharpTypeRegistry::RegisterProperty( "DateControl",
257 TypeRegistry typeRegistry = TypeRegistry::Get();
259 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "DateControl" );
262 // Check the property is writable in the type registry
263 Internal::TypeInfo& typeInfoImpl = GetImplementation( typeInfo );
265 Property::Value value(1);
267 value = typeInfoImpl.GetProperty( NULL, index );
270 value.Get( propValue );
272 DALI_TEST_EQUALS( getPropertyCalled, true, TEST_LOCATION );
273 DALI_TEST_EQUALS( propValue, 10, TEST_LOCATION );
275 value = typeInfoImpl.GetProperty( NULL, "year");
276 value.Get( propValue );
278 DALI_TEST_EQUALS( propValue, 10, TEST_LOCATION );
283 int UtcDaliRegisterCSharpPropertyNotRegisteredN(void)
285 TestApplication application;
287 // control not registered, should fail
288 bool registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
295 DALI_TEST_EQUALS( registered, false, TEST_LOCATION );