summaryrefslogtreecommitdiff
path: root/src/scripts
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2019-10-07 22:38:04 +0200
committerDave Andreoli <dave@gurumeditation.it>2019-10-07 22:38:04 +0200
commit4457a93ae51c62ae50b73090d29291ce6a3e8e77 (patch)
tree51965702157bf9031240ecf3ab9a5ccd891b5741 /src/scripts
parentbc59a9c0a7d5f636a8461e4ca1be852fc06270b0 (diff)
Pyolian: implement some missing eolian functions
with tests
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/pyolian/eolian.py41
-rw-r--r--src/scripts/pyolian/eolian_lib.py34
-rwxr-xr-xsrc/scripts/pyolian/test_eolian.py20
3 files changed, 94 insertions, 1 deletions
diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py
index 70496debc0..c4425e37df 100644
--- a/src/scripts/pyolian/eolian.py
+++ b/src/scripts/pyolian/eolian.py
@@ -36,6 +36,10 @@ except ImportError:
36_already_halted = False 36_already_halted = False
37 37
38 38
39# This is the same as the EOLIAN_FILE_FORMAT_VERSION macro
40file_format_version = lib.eolian_file_format_version_get()
41
42
39# Eolian Enums ############################################################## 43# Eolian Enums ##############################################################
40class Eolian_Object_Type(IntEnum): 44class Eolian_Object_Type(IntEnum):
41 UNKNOWN = 0 45 UNKNOWN = 0
@@ -353,10 +357,18 @@ class Eolian_Unit(EolianBaseObject):
353 return _str_to_py(lib.eolian_unit_file_get(self)) 357 return _str_to_py(lib.eolian_unit_file_get(self))
354 358
355 @cached_property 359 @cached_property
360 def file_path(self):
361 return _str_to_py(lib.eolian_unit_file_path_get(self))
362
363 @cached_property
356 def state(self): 364 def state(self):
357 c_state = lib.eolian_unit_state_get(self) 365 c_state = lib.eolian_unit_state_get(self)
358 return Eolian_State(c_state) if c_state else None 366 return Eolian_State(c_state) if c_state else None
359 367
368 @cached_property
369 def version(self):
370 return lib.eolian_unit_version_get(self)
371
360 @property 372 @property
361 def objects(self): 373 def objects(self):
362 return Iterator(Object, lib.eolian_unit_objects_get(self)) 374 return Iterator(Object, lib.eolian_unit_objects_get(self))
@@ -504,6 +516,9 @@ class Eolian_State(Eolian_Unit):
504 return Iterator(Typedecl, 516 return Iterator(Typedecl,
505 lib.eolian_state_enums_by_file_get(self, _str_to_bytes(file_name))) 517 lib.eolian_state_enums_by_file_get(self, _str_to_bytes(file_name)))
506 518
519 def state_check(self):
520 return bool(lib.eolian_state_check(self))
521
507 522
508# Namespace Utility Class ################################################### 523# Namespace Utility Class ###################################################
509 524
@@ -617,6 +632,10 @@ class Object(EolianBaseObject):
617 return _str_to_py(lib.eolian_object_name_get(self)) 632 return _str_to_py(lib.eolian_object_name_get(self))
618 633
619 @cached_property 634 @cached_property
635 def c_name(self):
636 return _str_to_py(lib.eolian_object_c_name_get(self))
637
638 @cached_property
620 def short_name(self): 639 def short_name(self):
621 return _str_to_py(lib.eolian_object_short_name_get(self)) 640 return _str_to_py(lib.eolian_object_short_name_get(self))
622 641
@@ -820,6 +839,11 @@ class Event(Object):
820 return Type(c_type) if c_type else None 839 return Type(c_type) if c_type else None
821 840
822 @cached_property 841 @cached_property
842 def class_(self):
843 c_cls = lib.eolian_event_class_get(self)
844 return Class(c_cls) if c_cls else None
845
846 @cached_property
823 def documentation(self): 847 def documentation(self):
824 c_doc = lib.eolian_event_documentation_get(self) 848 c_doc = lib.eolian_event_documentation_get(self)
825 return Documentation(c_doc) if c_doc else None 849 return Documentation(c_doc) if c_doc else None
@@ -935,6 +959,12 @@ class Function(Object):
935 c_type = lib.eolian_function_return_type_get(self, ftype) 959 c_type = lib.eolian_function_return_type_get(self, ftype)
936 return Type(c_type) if c_type else None 960 return Type(c_type) if c_type else None
937 961
962 def return_c_type_get(self, ftype):
963 s = lib.eolian_function_return_c_type_get(self, ftype)
964 ret = _str_to_py(s)
965 lib.eina_stringshare_del(c_void_p(s))
966 return ret
967
938 def return_default_value(self, ftype): 968 def return_default_value(self, ftype):
939 c_expr = lib.eolian_function_return_default_value_get(self._obj, ftype) 969 c_expr = lib.eolian_function_return_default_value_get(self._obj, ftype)
940 return Expression(c_expr) if c_expr else None 970 return Expression(c_expr) if c_expr else None
@@ -1006,6 +1036,12 @@ class Function_Parameter(Object):
1006 c_expr = lib.eolian_parameter_default_value_get(self) 1036 c_expr = lib.eolian_parameter_default_value_get(self)
1007 return Expression(c_expr) if c_expr else None 1037 return Expression(c_expr) if c_expr else None
1008 1038
1039 def c_type_get(self, as_return=False):
1040 s = lib.eolian_parameter_c_type_get(self, as_return)
1041 ret = _str_to_py(s)
1042 lib.eina_stringshare_del(c_void_p(s))
1043 return ret
1044
1009 1045
1010class Implement(Object): 1046class Implement(Object):
1011 def __repr__(self): 1047 def __repr__(self):
@@ -1022,6 +1058,11 @@ class Implement(Object):
1022 return Class(c_cls) if c_cls else None 1058 return Class(c_cls) if c_cls else None
1023 1059
1024 @cached_property 1060 @cached_property
1061 def implementing_class(self):
1062 c_cls = lib.eolian_implement_implementing_class_get(self)
1063 return Class(c_cls) if c_cls else None
1064
1065 @cached_property
1025 def function(self): 1066 def function(self):
1026 c_func = lib.eolian_implement_function_get(self, None) 1067 c_func = lib.eolian_implement_function_get(self, None)
1027 return Function(c_func) if c_func else None 1068 return Function(c_func) if c_func else None
diff --git a/src/scripts/pyolian/eolian_lib.py b/src/scripts/pyolian/eolian_lib.py
index 10098bf9b3..3e9c89111e 100644
--- a/src/scripts/pyolian/eolian_lib.py
+++ b/src/scripts/pyolian/eolian_lib.py
@@ -93,6 +93,10 @@ lib.eolian_state_all_eo_files_parse.restype = c_bool
93lib.eolian_state_all_eot_files_parse.argtypes = (c_void_p,) 93lib.eolian_state_all_eot_files_parse.argtypes = (c_void_p,)
94lib.eolian_state_all_eot_files_parse.restype = c_bool 94lib.eolian_state_all_eot_files_parse.restype = c_bool
95 95
96# EAPI Eina_Bool eolian_state_check(const Eolian_State *state);
97lib.eolian_state_check.argtypes = (c_void_p,)
98lib.eolian_state_check.restype = c_bool
99
96# EAPI const Eolian_Unit *eolian_state_unit_by_file_get(const Eolian_State *state, const char *file_name); 100# EAPI const Eolian_Unit *eolian_state_unit_by_file_get(const Eolian_State *state, const char *file_name);
97lib.eolian_state_unit_by_file_get.argtypes = (c_void_p, c_char_p) 101lib.eolian_state_unit_by_file_get.argtypes = (c_void_p, c_char_p)
98lib.eolian_state_unit_by_file_get.restype = c_void_p 102lib.eolian_state_unit_by_file_get.restype = c_void_p
@@ -140,6 +144,14 @@ lib.eolian_unit_state_get.restype = c_void_p
140lib.eolian_unit_file_get.argtypes = (c_void_p,) 144lib.eolian_unit_file_get.argtypes = (c_void_p,)
141lib.eolian_unit_file_get.restype = c_char_p 145lib.eolian_unit_file_get.restype = c_char_p
142 146
147# EAPI const char *eolian_unit_file_path_get(const Eolian_Unit *unit);
148lib.eolian_unit_file_path_get.argtypes = (c_void_p,)
149lib.eolian_unit_file_path_get.restype = c_char_p
150
151# EAPI unsigned short eolian_unit_version_get(const Eolian_Unit *unit);
152lib.eolian_unit_version_get.argtypes = (c_void_p,)
153lib.eolian_unit_version_get.restype = c_uint
154
143# EAPI const Eolian_Object *eolian_unit_object_by_name_get(const Eolian_Unit *unit, const char *name); 155# EAPI const Eolian_Object *eolian_unit_object_by_name_get(const Eolian_Unit *unit, const char *name);
144lib.eolian_unit_object_by_name_get.argtypes = (c_void_p, c_char_p) 156lib.eolian_unit_object_by_name_get.argtypes = (c_void_p, c_char_p)
145lib.eolian_unit_object_by_name_get.restype = c_void_p 157lib.eolian_unit_object_by_name_get.restype = c_void_p
@@ -215,6 +227,10 @@ lib.eolian_object_column_get.restype = c_int
215lib.eolian_object_name_get.argtypes = (c_void_p,) 227lib.eolian_object_name_get.argtypes = (c_void_p,)
216lib.eolian_object_name_get.restype = c_char_p 228lib.eolian_object_name_get.restype = c_char_p
217 229
230# EAPI const char *eolian_object_c_name_get(const Eolian_Object *obj);
231lib.eolian_object_c_name_get.argtypes = (c_void_p,)
232lib.eolian_object_c_name_get.restype = c_char_p
233
218# EAPI const char *eolian_object_short_name_get(const Eolian_Object *obj); 234# EAPI const char *eolian_object_short_name_get(const Eolian_Object *obj);
219lib.eolian_object_short_name_get.argtypes = (c_void_p,) 235lib.eolian_object_short_name_get.argtypes = (c_void_p,)
220lib.eolian_object_short_name_get.restype = c_char_p 236lib.eolian_object_short_name_get.restype = c_char_p
@@ -330,9 +346,13 @@ lib.eolian_function_is_static.argtypes = (c_void_p,)
330lib.eolian_function_is_static.restype = c_bool 346lib.eolian_function_is_static.restype = c_bool
331 347
332# EAPI Eina_Bool eolian_function_is_constructor(const Eolian_Function *function_id, const Eolian_Class *klass); 348# EAPI Eina_Bool eolian_function_is_constructor(const Eolian_Function *function_id, const Eolian_Class *klass);
333lib.eolian_function_is_constructor.argtypes = (c_void_p,c_void_p,) 349lib.eolian_function_is_constructor.argtypes = (c_void_p, c_void_p)
334lib.eolian_function_is_constructor.restype = c_bool 350lib.eolian_function_is_constructor.restype = c_bool
335 351
352# EAPI Eina_Stringshare *eolian_parameter_c_type_get(const Eolian_Function_Parameter *param_desc, Eina_Bool as_return);
353lib.eolian_parameter_c_type_get.argtypes = (c_void_p, c_bool)
354lib.eolian_parameter_c_type_get.restype = c_void_p # Stringshare TO BE FREED
355
336# EAPI const Eolian_Type *eolian_function_return_type_get(const Eolian_Function *function_id, Eolian_Function_Type ftype); 356# EAPI const Eolian_Type *eolian_function_return_type_get(const Eolian_Function *function_id, Eolian_Function_Type ftype);
337lib.eolian_function_return_type_get.argtypes = (c_void_p, c_int) 357lib.eolian_function_return_type_get.argtypes = (c_void_p, c_int)
338lib.eolian_function_return_type_get.restype = c_void_p 358lib.eolian_function_return_type_get.restype = c_void_p
@@ -349,6 +369,10 @@ lib.eolian_function_return_documentation_get.restype = c_void_p
349lib.eolian_function_return_allow_unused.argtypes = (c_void_p, c_int) 369lib.eolian_function_return_allow_unused.argtypes = (c_void_p, c_int)
350lib.eolian_function_return_allow_unused.restype = c_bool 370lib.eolian_function_return_allow_unused.restype = c_bool
351 371
372# EAPI Eina_Stringshare *eolian_function_return_c_type_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
373lib.eolian_function_return_c_type_get.argtypes = (c_void_p, c_int)
374lib.eolian_function_return_c_type_get.restype = c_void_p # Stringshare TO BE FREED
375
352# EAPI Eina_Bool eolian_function_object_is_const(const Eolian_Function *function_id); 376# EAPI Eina_Bool eolian_function_object_is_const(const Eolian_Function *function_id);
353lib.eolian_function_object_is_const.argtypes = (c_void_p,) 377lib.eolian_function_object_is_const.argtypes = (c_void_p,)
354lib.eolian_function_object_is_const.restype = c_bool 378lib.eolian_function_object_is_const.restype = c_bool
@@ -404,6 +428,10 @@ lib.eolian_parameter_is_optional.restype = c_bool
404lib.eolian_implement_class_get.argtypes = (c_void_p,) 428lib.eolian_implement_class_get.argtypes = (c_void_p,)
405lib.eolian_implement_class_get.restype = c_void_p 429lib.eolian_implement_class_get.restype = c_void_p
406 430
431# EAPI const Eolian_Class *eolian_implement_implementing_class_get(const Eolian_Implement *impl);
432lib.eolian_implement_implementing_class_get.argtypes = (c_void_p,)
433lib.eolian_implement_implementing_class_get.restype = c_void_p
434
407# EAPI const Eolian_Function *eolian_implement_function_get(const Eolian_Implement *impl, Eolian_Function_Type *func_type); 435# EAPI const Eolian_Function *eolian_implement_function_get(const Eolian_Implement *impl, Eolian_Function_Type *func_type);
408lib.eolian_implement_function_get.argtypes = (c_void_p, c_void_p) 436lib.eolian_implement_function_get.argtypes = (c_void_p, c_void_p)
409lib.eolian_implement_function_get.restype = c_void_p 437lib.eolian_implement_function_get.restype = c_void_p
@@ -462,6 +490,10 @@ lib.eolian_event_type_get.restype = c_void_p
462lib.eolian_event_documentation_get.argtypes = (c_void_p,) 490lib.eolian_event_documentation_get.argtypes = (c_void_p,)
463lib.eolian_event_documentation_get.restype = c_void_p 491lib.eolian_event_documentation_get.restype = c_void_p
464 492
493# EAPI const Eolian_Class *eolian_event_class_get(const Eolian_Event *event);
494lib.eolian_event_class_get.argtypes = (c_void_p,)
495lib.eolian_event_class_get.restype = c_void_p
496
465# EAPI Eolian_Object_Scope eolian_event_scope_get(const Eolian_Event *event); 497# EAPI Eolian_Object_Scope eolian_event_scope_get(const Eolian_Event *event);
466lib.eolian_event_scope_get.argtypes = (c_void_p,) 498lib.eolian_event_scope_get.argtypes = (c_void_p,)
467lib.eolian_event_scope_get.restype = c_int 499lib.eolian_event_scope_get.restype = c_int
diff --git a/src/scripts/pyolian/test_eolian.py b/src/scripts/pyolian/test_eolian.py
index 3a101691a4..c6d8afe5c9 100755
--- a/src/scripts/pyolian/test_eolian.py
+++ b/src/scripts/pyolian/test_eolian.py
@@ -23,6 +23,13 @@ SCAN_FOLDER = os.path.join(root_path, 'src', 'lib')
23eolian_db = None 23eolian_db = None
24 24
25 25
26class TestEolian(unittest.TestCase):
27 def test_file_format(self):
28 v = eolian.file_format_version
29 self.assertIsInstance(v, int)
30 self.assertGreaterEqual(v, 1)
31
32
26class TestBaseObject(unittest.TestCase): 33class TestBaseObject(unittest.TestCase):
27 def test_base_object_equality(self): 34 def test_base_object_equality(self):
28 cls1 = eolian_db.class_by_name_get('Efl.Loop_Timer') 35 cls1 = eolian_db.class_by_name_get('Efl.Loop_Timer')
@@ -85,17 +92,24 @@ class TestEolianState(unittest.TestCase):
85 count += 1 92 count += 1
86 self.assertGreater(count, 1) 93 self.assertGreater(count, 1)
87 94
95 @unittest.skip('Should this return True?')
96 def test_integrity(self):
97 self.assertTrue(eolian_db.state_check())
98
88 99
89class TestEolianUnit(unittest.TestCase): 100class TestEolianUnit(unittest.TestCase):
90 def test_unit_get(self): 101 def test_unit_get(self):
91 unit = eolian_db.unit_by_file_get('efl_ui_win.eo') 102 unit = eolian_db.unit_by_file_get('efl_ui_win.eo')
92 self.assertIsInstance(unit.state, eolian.Eolian_State) 103 self.assertIsInstance(unit.state, eolian.Eolian_State)
93 self.assertEqual(unit.state, eolian_db) 104 self.assertEqual(unit.state, eolian_db)
105 self.assertIsInstance(unit.version, int)
106 self.assertGreaterEqual(unit.version, 1)
94 107
95 def test_file_get(self): 108 def test_file_get(self):
96 unit = eolian_db.unit_by_file_get('efl_ui_win.eo') 109 unit = eolian_db.unit_by_file_get('efl_ui_win.eo')
97 self.assertIsInstance(unit, eolian.Eolian_Unit) 110 self.assertIsInstance(unit, eolian.Eolian_Unit)
98 self.assertEqual(unit.file, 'efl_ui_win.eo') 111 self.assertEqual(unit.file, 'efl_ui_win.eo')
112 self.assertTrue(unit.file_path.endswith('efl_ui_win.eo')) # full path can change
99 113
100 @unittest.skip('Skipped until unit/state support is fixed') 114 @unittest.skip('Skipped until unit/state support is fixed')
101 def test_children_listing(self): 115 def test_children_listing(self):
@@ -299,6 +313,7 @@ class TestEolianObject(unittest.TestCase):
299 def test_name(self): 313 def test_name(self):
300 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 314 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
301 self.assertEqual(obj.name, 'Efl.Ui.Frame') 315 self.assertEqual(obj.name, 'Efl.Ui.Frame')
316 self.assertEqual(obj.c_name, 'Efl_Ui_Frame')
302 317
303 def test_short_name(self): 318 def test_short_name(self):
304 obj = eolian_db.object_by_name_get('Efl.Ui.Frame') 319 obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
@@ -387,6 +402,8 @@ class TestEolianFunction(unittest.TestCase):
387 self.assertIsNone(p.default_value) 402 self.assertIsNone(p.default_value)
388 self.assertFalse(p.is_optional) 403 self.assertFalse(p.is_optional)
389 self.assertEqual(p.type.name, 'double') 404 self.assertEqual(p.type.name, 'double')
405 self.assertEqual(p.c_type_get(False), 'double')
406 self.assertEqual(p.c_type_get(True), 'double')
390 self.assertIsInstance(p.documentation, eolian.Documentation) 407 self.assertIsInstance(p.documentation, eolian.Documentation)
391 408
392 409
@@ -399,6 +416,8 @@ class TestEolianImplement(unittest.TestCase):
399 self.assertEqual(im.name, 'Efl.Loop_Timer.timer_delay') 416 self.assertEqual(im.name, 'Efl.Loop_Timer.timer_delay')
400 self.assertIsInstance(im.class_, eolian.Class) 417 self.assertIsInstance(im.class_, eolian.Class)
401 self.assertIsInstance(im.function, eolian.Function) 418 self.assertIsInstance(im.function, eolian.Function)
419 self.assertIsInstance(im.implementing_class, eolian.Class)
420 self.assertEqual(im.implementing_class.name, 'Efl.Loop_Timer')
402 self.assertIsInstance(im.documentation_get(), eolian.Documentation) # TODO is UNRESOLVED correct ? 421 self.assertIsInstance(im.documentation_get(), eolian.Documentation) # TODO is UNRESOLVED correct ?
403 self.assertFalse(im.is_auto()) 422 self.assertFalse(im.is_auto())
404 self.assertFalse(im.is_empty()) 423 self.assertFalse(im.is_empty())
@@ -431,6 +450,7 @@ class TestEolianEvent(unittest.TestCase):
431 self.assertFalse(ev.is_beta) 450 self.assertFalse(ev.is_beta)
432 self.assertFalse(ev.is_hot) 451 self.assertFalse(ev.is_hot)
433 self.assertFalse(ev.is_restart) 452 self.assertFalse(ev.is_restart)
453 self.assertEqual(ev.class_.name, cls.name)
434 454
435 455
436class TestEolianPart(unittest.TestCase): 456class TestEolianPart(unittest.TestCase):