2 * Copyright (c) 2020 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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/object/csharp-type-info.h>
20 #include <dali/devel-api/object/csharp-type-registry.h>
21 #include <dali/internal/event/common/type-registry-impl.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali/public-api/object/property.h>
32 static bool CreateCustomNamedInitCalled = false;
34 BaseHandle* CreateCustomNamedInit(const char* const typeName)
36 CreateCustomNamedInitCalled = true;
38 BaseHandle* x = new BaseHandle();
43 // Property Registration
44 bool setPropertyCalled = false;
45 bool getPropertyCalled = false;
46 int intPropertyValue = 0;
48 void SetProperty(BaseObject* object, const char* const propertyName, Property::Value* value)
50 value->Get(intPropertyValue);
52 setPropertyCalled = true;
55 Property::Value* GetProperty(BaseObject* object, const char* const propertyName)
57 getPropertyCalled = true;
58 Property::Value* x = new Property::Value(10);
64 int UtcDaliRegisterCSharpTypeP(void)
66 TestApplication application;
68 CSharpTypeRegistry::RegisterType("CSharpControl", typeid(Dali::Actor), &CreateCustomNamedInit);
70 Dali::TypeInfo info = Dali::TypeRegistry::Get().GetTypeInfo("CSharpControl");
72 info.CreateInstance();
74 DALI_TEST_EQUALS(CreateCustomNamedInitCalled, true, TEST_LOCATION);
79 int UtcDaliRegisterCSharpTypeNoInitP(void)
81 TestApplication application;
83 CreateCustomNamedInitCalled = false;
85 CSharpTypeRegistry::RegisterType("CSharpControl", typeid(Dali::Actor), &CreateCustomNamedInit);
87 GetImplementation(Dali::TypeRegistry::Get()).CallInitFunctions();
89 DALI_TEST_EQUALS(CreateCustomNamedInitCalled, false, TEST_LOCATION);
94 int UtcDaliRegisterCSharpTypeN(void)
96 TestApplication application;
98 CSharpTypeRegistry::RegisterType("CSharpControl", typeid(Dali::Actor), &CreateCustomNamedInit);
100 // should cause an assert because we're registering same type twice
103 CSharpTypeRegistry::RegisterType("CSharpControl", typeid(Dali::Actor), &CreateCustomNamedInit);
104 tet_result(TET_FAIL);
106 catch(DaliException& e)
108 DALI_TEST_ASSERT(e, "Duplicate type name in Type Registration", TEST_LOCATION);
114 int UtcDaliRegisterCSharpTypeCreateP(void)
116 TestApplication application;
117 CreateCustomNamedInitCalled = false;
119 CSharpTypeRegistry::RegisterType("CSharpControl", typeid(Dali::Actor), &CreateCustomNamedInit);
121 TypeInfo info = Dali::TypeRegistry::Get().GetTypeInfo("CSharpControl");
123 BaseHandle handle = info.CreateInstance();
125 DALI_TEST_EQUALS(CreateCustomNamedInitCalled, true, TEST_LOCATION);
130 int UtcDaliRegisterCSharpPropertyP(void)
132 TestApplication application;
134 CSharpTypeRegistry::RegisterType("DateControl", typeid(Dali::Actor), &CreateCustomNamedInit);
136 bool registered = CSharpTypeRegistry::RegisterProperty("DateControl",
143 DALI_TEST_EQUALS(registered, true, TEST_LOCATION);
148 int UtcDaliRegisterCSharpPropertyN(void)
150 TestApplication application;
152 // register the same property twice
153 CSharpTypeRegistry::RegisterType("DateControl", typeid(Dali::Actor), &CreateCustomNamedInit);
155 bool registered = CSharpTypeRegistry::RegisterProperty("DateControl",
162 DALI_TEST_EQUALS(registered, true, TEST_LOCATION);
164 // should fail second time with an assert as the property is already registered
167 registered = CSharpTypeRegistry::RegisterProperty("DateControl",
174 tet_result(TET_FAIL);
176 catch(DaliException& e)
178 DALI_TEST_ASSERT(e, "Property index already added to Type", TEST_LOCATION);
184 int UtcDaliRegisterCSharpPropertySetP(void)
186 TestApplication application;
188 // register the same property twice
189 CSharpTypeRegistry::RegisterType("DateControl", typeid(Dali::Actor), &CreateCustomNamedInit);
192 Property::Index index(100001);
194 CSharpTypeRegistry::RegisterProperty("DateControl",
201 TypeRegistry typeRegistry = TypeRegistry::Get();
203 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo("DateControl");
205 // Check the property is writable in the type registry
206 Internal::TypeInfo& typeInfoImpl = GetImplementation(typeInfo);
208 Property::Value value(25);
210 typeInfoImpl.SetProperty(NULL, index, value);
212 DALI_TEST_EQUALS(25, intPropertyValue, TEST_LOCATION);
214 Property::Value value2(50);
216 typeInfoImpl.SetProperty(NULL, "year", value2);
218 DALI_TEST_EQUALS(50, intPropertyValue, TEST_LOCATION);
220 DALI_TEST_EQUALS(setPropertyCalled, true, TEST_LOCATION);
225 int UtcDaliRegisterCSharpPropertyGetP(void)
227 TestApplication application;
229 // register the same property twice
230 CSharpTypeRegistry::RegisterType("DateControl", typeid(Dali::Actor), &CreateCustomNamedInit);
232 Property::Index index(100001);
234 CSharpTypeRegistry::RegisterProperty("DateControl",
241 TypeRegistry typeRegistry = TypeRegistry::Get();
243 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo("DateControl");
245 // Check the property is writable in the type registry
246 Internal::TypeInfo& typeInfoImpl = GetImplementation(typeInfo);
248 Property::Value value(1);
250 value = typeInfoImpl.GetProperty(NULL, index);
253 value.Get(propValue);
255 DALI_TEST_EQUALS(getPropertyCalled, true, TEST_LOCATION);
256 DALI_TEST_EQUALS(propValue, 10, TEST_LOCATION);
258 value = typeInfoImpl.GetProperty(NULL, "year");
259 value.Get(propValue);
261 DALI_TEST_EQUALS(propValue, 10, TEST_LOCATION);
266 int UtcDaliRegisterCSharpPropertyNotRegisteredN(void)
268 TestApplication application;
270 // control not registered, should fail
271 bool registered = CSharpTypeRegistry::RegisterProperty("DateControl",
278 DALI_TEST_EQUALS(registered, false, TEST_LOCATION);