eo: add API for querying the class type
authorMarcel Hollerbach <mail@marcel-hollerbach.de>
Mon, 18 Feb 2019 14:09:27 +0000 (15:09 +0100)
committerWonki Kim <wonki_.kim@samsung.com>
Fri, 8 Mar 2019 11:49:34 +0000 (20:49 +0900)
a class can be a interface mixin abstract or regular.
This adds a API for getting this information

src/lib/eo/Eo.h
src/lib/eo/eo.c
src/tests/eo/interface/interface_main.c
src/tests/eo/mixin/mixin_main.c
src/tests/eo/suite/eo_test_general.c

index 7f90e79..323a1a9 100644 (file)
@@ -776,7 +776,8 @@ enum _Efl_Class_Type
    EFL_CLASS_TYPE_REGULAR = 0, /**< Regular class. */
    EFL_CLASS_TYPE_REGULAR_NO_INSTANT, /**< Regular non instant-able class. */
    EFL_CLASS_TYPE_INTERFACE, /**< Interface */
-   EFL_CLASS_TYPE_MIXIN /**< Mixin */
+   EFL_CLASS_TYPE_MIXIN, /**< Mixin */
+   EFL_CLASS_TYPE_INVALID
 };
 
 /**
@@ -2004,6 +2005,14 @@ EAPI Eina_Value efl_property_reflection_get(Eo *obj, const char *property_name);
 #include "efl_class.eo.h"
 
 /**
+ * @brief Get the type of this class.
+ * @param klass The Efl_Class to get the type from.
+ *
+ * @return The type of this class or INVALID if the klass parameter was invalid.
+ */
+EAPI Efl_Class_Type efl_class_type_get(const Efl_Class *klass);
+
+/**
  * @}
  */
 
index 953b132..5432f39 100644 (file)
@@ -1516,6 +1516,9 @@ efl_class_new(const Efl_Class_Description *desc, const Efl_Class *parent_id, ...
                    return NULL;
                 }
               break;
+           default:
+             ERR("type cannot be INVALID");
+             return NULL;
           }
      }
 
@@ -1542,6 +1545,9 @@ efl_class_new(const Efl_Class_Description *desc, const Efl_Class *parent_id, ...
                      case EFL_CLASS_TYPE_MIXIN:
                        extn_list = eina_list_append(extn_list, extn);
                        break;
+                     default:
+                       ERR("type cannot be INVALID");
+                       return NULL;
                     }
                }
              extn_id = va_arg(p_list, Eo_Id *);
@@ -3660,3 +3666,11 @@ end:
 
    return EINA_VALUE_EMPTY;
 }
+
+EAPI Efl_Class_Type
+efl_class_type_get(const Efl_Class *klass_id)
+{
+   EO_CLASS_POINTER_RETURN_VAL(klass_id, klass, EFL_CLASS_TYPE_INVALID);
+
+   return klass->desc->type;
+}
index ed56c9f..48685bb 100644 (file)
@@ -41,6 +41,8 @@ main(int argc, char *argv[])
    fail_if(!efl_isa(SIMPLE_CLASS, INTERFACE2_CLASS));
    fail_if(efl_isa(INTERFACE_CLASS, INTERFACE2_CLASS));
 
+   fail_if(efl_class_type_get(INTERFACE_CLASS) != EFL_CLASS_TYPE_INTERFACE);
+
    efl_unref(obj);
    efl_object_shutdown();
    return 0;
index 2ef7b36..3b8a022 100644 (file)
@@ -46,6 +46,9 @@ main(int argc, char *argv[])
    printf("%d\n", a);
    fail_if(a != 5);
 
+   fail_if(efl_class_type_get(MIXIN_CLASS) != EFL_CLASS_TYPE_MIXIN);
+
+
    efl_unref(obj);
    efl_object_shutdown();
    return 0;
index c483fc4..1494f46 100644 (file)
@@ -1841,6 +1841,13 @@ EFL_START_TEST(eo_test_class_replacement)
 }
 EFL_END_TEST
 
+EFL_START_TEST(eo_test_class_type)
+{
+   ck_assert_int_eq(efl_class_type_get(SIMPLE_CLASS), EFL_CLASS_TYPE_REGULAR);
+   ck_assert_int_eq(efl_class_type_get((void*)0xAFFE), EFL_CLASS_TYPE_INVALID);
+}
+EFL_END_TEST
+
 void eo_test_general(TCase *tc)
 {
    tcase_add_test(tc, eo_simple);
@@ -1870,4 +1877,5 @@ void eo_test_general(TCase *tc)
    tcase_add_test(tc, efl_object_destruct_test);
    tcase_add_test(tc, efl_object_auto_unref_test);
    tcase_add_test(tc, efl_object_size);
+   tcase_add_test(tc, eo_test_class_type);
 }