summaryrefslogtreecommitdiff
path: root/src/tests/eo/suite
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-04-18 20:41:11 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-04-19 11:15:30 +0900
commit19b9234f23af78daf73784bd37d3458e94e3459f (patch)
tree371ef8cf57847ab29d20b68f2bfc7dec9be6fd42 /src/tests/eo/suite
parent85636658e00de58db1a3c5f8b03e495a5ad1bda8 (diff)
eo: Add new API efl_cast
This is similar to efl_super but the specified class is the one we want to call the function on. This is similar to dynamic_cast<> in C++. Note: both efl_super() and efl_cast() need documentation! This is an experimental feature. Fixes T5311 @feature Maniphest Tasks: T5311 Differential Revision: https://phab.enlightenment.org/D4797
Diffstat (limited to 'src/tests/eo/suite')
-rw-r--r--src/tests/eo/suite/eo_test_general.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/tests/eo/suite/eo_test_general.c b/src/tests/eo/suite/eo_test_general.c
index b956eae53e..8798e2a80e 100644
--- a/src/tests/eo/suite/eo_test_general.c
+++ b/src/tests/eo/suite/eo_test_general.c
@@ -1584,6 +1584,102 @@ START_TEST(eo_domain)
1584} 1584}
1585END_TEST 1585END_TEST
1586 1586
1587
1588static int
1589_inherit_value_1(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED)
1590{
1591 return 1;
1592}
1593
1594static int
1595_inherit_value_2(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED)
1596{
1597 return 2;
1598}
1599
1600EFL_FUNC_BODY(inherit_value, int, 0);
1601
1602static Eina_Bool
1603_cast_inherit_class_initializer_1(Efl_Class *klass)
1604{
1605 EFL_OPS_DEFINE(ops, EFL_OBJECT_OP_FUNC(inherit_value, _inherit_value_1), );
1606 return efl_class_functions_set(klass, &ops, NULL);
1607}
1608
1609static Eina_Bool
1610_cast_inherit_class_initializer_2(Efl_Class *klass)
1611{
1612 EFL_OPS_DEFINE(ops, EFL_OBJECT_OP_FUNC(inherit_value, _inherit_value_2), );
1613 return efl_class_functions_set(klass, &ops, NULL);
1614}
1615
1616START_TEST(efl_cast_test)
1617{
1618 efl_object_init();
1619
1620 static const Efl_Class_Description class_desc_1 = {
1621 EO_VERSION,
1622 "FirstInherit",
1623 EFL_CLASS_TYPE_REGULAR,
1624 0,
1625 _cast_inherit_class_initializer_1,
1626 NULL,
1627 NULL
1628 };
1629
1630 static const Efl_Class_Description class_desc_2 = {
1631 EO_VERSION,
1632 "SecondInherit",
1633 EFL_CLASS_TYPE_REGULAR,
1634 0,
1635 _cast_inherit_class_initializer_2,
1636 NULL,
1637 NULL
1638 };
1639
1640 const Efl_Class *klass1 = efl_class_new(&class_desc_1, SIMPLE_CLASS, NULL);
1641 fail_if(!klass1);
1642
1643 const Efl_Class *klass2 = efl_class_new(&class_desc_2, klass1, NULL);
1644 fail_if(!klass2);
1645
1646 Eo *obj;
1647
1648 // Testing normal calls
1649 obj = efl_add(SIMPLE_CLASS, NULL);
1650 fail_if(!obj);
1651 ck_assert_int_eq(inherit_value(obj), 0);
1652 efl_unref(obj);
1653
1654 obj = efl_add(klass1, NULL);
1655 fail_if(!obj);
1656 ck_assert_int_eq(inherit_value(obj), 1);
1657 efl_unref(obj);
1658
1659 obj = efl_add(klass2, NULL);
1660 fail_if(!obj);
1661 ck_assert_int_eq(inherit_value(obj), 2);
1662 efl_unref(obj);
1663
1664 // Testing efl_super
1665 obj = efl_add(klass2, NULL);
1666 fail_if(!obj);
1667 ck_assert_int_eq(inherit_value(efl_super(obj, klass2)), 1);
1668 ck_assert_int_eq(inherit_value(efl_super(obj, klass1)), 0);
1669 efl_unref(obj);
1670
1671 // Testing efl_cast
1672 obj = efl_add(klass2, NULL);
1673 fail_if(!obj);
1674 ck_assert_int_eq(inherit_value(efl_cast(obj, klass2)), 2);
1675 ck_assert_int_eq(inherit_value(efl_cast(obj, klass1)), 1);
1676 ck_assert_int_eq(inherit_value(efl_cast(obj, SIMPLE_CLASS)), 0);
1677 efl_unref(obj);
1678
1679 efl_object_shutdown();
1680}
1681END_TEST
1682
1587void eo_test_general(TCase *tc) 1683void eo_test_general(TCase *tc)
1588{ 1684{
1589 tcase_add_test(tc, eo_simple); 1685 tcase_add_test(tc, eo_simple);
@@ -1607,4 +1703,5 @@ void eo_test_general(TCase *tc)
1607 tcase_add_test(tc, eo_comment); 1703 tcase_add_test(tc, eo_comment);
1608 tcase_add_test(tc, eo_rec_interface); 1704 tcase_add_test(tc, eo_rec_interface);
1609 tcase_add_test(tc, eo_domain); 1705 tcase_add_test(tc, eo_domain);
1706 tcase_add_test(tc, efl_cast_test);
1610} 1707}