2 * Copyright (c) 2016 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;
35 BaseHandle* CreateCustomNamedInit(void)
37 CreateCustomNamedInitCalled = true;
39 BaseHandle* x = new BaseHandle();
44 // Property Registration
45 bool setPropertyCalled = false;
46 bool getPropertyCalled = false;
47 int intPropertyValue = 0;
48 void SetProperty( BaseObject* object, Property::Index* index, Property::Value* value )
51 value->Get( intPropertyValue );
53 setPropertyCalled = true;
55 Property::Value* GetProperty( BaseObject* object, Property::Index* index )
57 getPropertyCalled = true;
58 Property::Value* x = new Property::Value( 10 );
64 int UtcDaliRegisterCSharpTypeP(void)
67 TestApplication application;
69 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
71 GetImplementation(Dali::TypeRegistry::Get()).CallInitFunctions();
73 DALI_TEST_EQUALS( CreateCustomNamedInitCalled, true, TEST_LOCATION );
78 int UtcDaliRegisterCSharpTypeNoInitP(void)
81 TestApplication application;
82 CreateCustomNamedInitCalled = false;
84 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, false);
86 GetImplementation(Dali::TypeRegistry::Get()).CallInitFunctions();
88 DALI_TEST_EQUALS( CreateCustomNamedInitCalled, false, TEST_LOCATION );
93 int UtcDaliRegisterCSharpTypeN(void)
95 TestApplication application;
97 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
99 // should cause an assert because we're registering same type twice
102 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
103 tet_result( TET_FAIL );
105 catch ( DaliException& e )
107 DALI_TEST_ASSERT( e, "Duplicate type name for Type Registation", TEST_LOCATION );
113 int UtcDaliRegisterCSharpTypeCreateP(void)
116 TestApplication application;
117 CreateCustomNamedInitCalled = false;
119 CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, false);
122 TypeInfo info = Dali::TypeRegistry::Get().GetTypeInfo( "CSharpControl");
126 BaseHandle handle = info.CreateInstance();
128 DALI_TEST_EQUALS( CreateCustomNamedInitCalled, true, TEST_LOCATION );
135 int UtcDaliRegisterCSharpPropertyP(void)
137 TestApplication application;
139 CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
142 bool registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
149 DALI_TEST_EQUALS( registered, true, TEST_LOCATION );
156 int UtcDaliRegisterCSharpPropertyN(void)
158 TestApplication application;
160 // register the same property twice
161 CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
164 bool registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
171 DALI_TEST_EQUALS( registered, true, TEST_LOCATION );
174 // should fail second time with an assert as the property is already registered
177 registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
184 tet_result( TET_FAIL );
186 catch ( DaliException& e )
188 DALI_TEST_ASSERT( e, "Property index already added to Type", TEST_LOCATION );
194 int UtcDaliRegisterCSharpPropertySetP(void)
196 TestApplication application;
198 // register the same property twice
199 CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
201 Property::Index index(100001);
203 CSharpTypeRegistry::RegisterProperty( "DateControl",
210 TypeRegistry typeRegistry = TypeRegistry::Get();
212 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "DateControl" );
215 // Check the property is writable in the type registry
216 Internal::TypeInfo& typeInfoImpl = GetImplementation( typeInfo );
218 Property::Value value(25);
220 typeInfoImpl.SetProperty( NULL, index, value );
222 DALI_TEST_EQUALS( 25, intPropertyValue , TEST_LOCATION );
224 Property::Value value2(50);
226 typeInfoImpl.SetProperty( NULL, "year", value2 );
228 DALI_TEST_EQUALS( 50, intPropertyValue , TEST_LOCATION );
230 DALI_TEST_EQUALS( setPropertyCalled, true, TEST_LOCATION );
236 int UtcDaliRegisterCSharpPropertyGetP(void)
238 TestApplication application;
240 // register the same property twice
241 CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
243 Property::Index index(100001);
245 CSharpTypeRegistry::RegisterProperty( "DateControl",
252 TypeRegistry typeRegistry = TypeRegistry::Get();
254 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "DateControl" );
257 // Check the property is writable in the type registry
258 Internal::TypeInfo& typeInfoImpl = GetImplementation( typeInfo );
260 Property::Value value(1);
262 value = typeInfoImpl.GetProperty( NULL, index );
265 value.Get( propValue );
267 DALI_TEST_EQUALS( getPropertyCalled, true, TEST_LOCATION );
268 DALI_TEST_EQUALS( propValue, 10, TEST_LOCATION );
270 value = typeInfoImpl.GetProperty( NULL, "year");
271 value.Get( propValue );
273 DALI_TEST_EQUALS( propValue, 10, TEST_LOCATION );
278 int UtcDaliRegisterCSharpPropertyNotRegisteredN(void)
280 TestApplication application;
282 // control not registered, should fail
283 bool registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
290 DALI_TEST_EQUALS( registered, false, TEST_LOCATION );