Add core test case for getting device role property 82/272882/1
authorhyunuk.tak <hyunuk.tak@samsung.com>
Tue, 22 Mar 2022 04:44:52 +0000 (13:44 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 28 Mar 2022 01:51:44 +0000 (10:51 +0900)
Change-Id: I78c544c81edcd16a7d617faa570b0abaeaf28b49
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
tests/unittest/mocks/thread-mock-dbus.cpp
tests/unittest/mocks/thread-mock-dummy.cpp
tests/unittest/mocks/thread-mock-dummy.h
tests/unittest/thread-unittest-core.cpp

index be8d356..06256b4 100644 (file)
@@ -22,7 +22,7 @@
 GDBusConnection *g_bus_get_sync(GBusType bus_type,
                                                                GCancellable *cancellable, GError **error)
 {
-       return (GDBusConnection *)0x1234;
+       return (GDBusConnection *)GINT_TO_POINTER(0x1234);
 }
 
 GDBusProxy *g_dbus_proxy_new_for_bus_sync(GBusType bus_type,
@@ -31,7 +31,7 @@ GDBusProxy *g_dbus_proxy_new_for_bus_sync(GBusType bus_type,
                                                                                  const gchar *interface_name, GCancellable *cancellable,
                                                                                  GError **error)
 {
-       return (GDBusProxy *)0x1234;
+       return (GDBusProxy *)GINT_TO_POINTER(0x1234);
 }
 
 GDBusProxy *g_dbus_proxy_new_sync(GDBusConnection *connection,
@@ -40,7 +40,7 @@ GDBusProxy *g_dbus_proxy_new_sync(GDBusConnection *connection,
                                                                  const gchar *interface_name, GCancellable *cancellable,
                                                                  GError **error)
 {
-       return (GDBusProxy *)0x1234;
+       return (GDBusProxy *)GINT_TO_POINTER(0x5678);
 }
 
 guint g_dbus_connection_signal_subscribe(GDBusConnection *connection,
@@ -72,7 +72,11 @@ GVariant *g_dbus_proxy_call_sync(GDBusProxy *proxy,
 {
        retv_if(proxy == NULL, NULL);
 
-       return _handle_sync_method(method_name, parameters);
+       if (proxy == GINT_TO_POINTER(0x1234))
+               return _handle_sync_method(method_name, parameters);
+
+       if (proxy == GINT_TO_POINTER(0x5678))
+               return _handle_get_property(parameters);
 }
 
 void g_object_unref(gpointer object)
index 02af7aa..b09a2a0 100644 (file)
@@ -33,6 +33,11 @@ static GVariant *__method_factoryreset(GVariant *parameters)
        return g_variant_new("(i)", THREAD_ERROR_NONE);
 }
 
+static GVariant *__property_device_role()
+{
+       return g_variant_new("(v)", g_variant_new("s", "router"));
+}
+
 struct {
        const gchar *interface_name;
        const gchar *signal_name;
@@ -58,7 +63,7 @@ struct {
 
 struct {
        const gchar *method_name;
-       GVariant *(*sync_handler)(GVariant *parameters);
+       GVariant *(*handler)(GVariant *parameters);
 } thread_gdbus_method_list[] = {
        {
                THREAD_DBUS_RESET_METHOD,
@@ -66,7 +71,21 @@ struct {
        },
        {
                THREAD_DBUS_FACTORY_RESET_METHOD,
-               __method_factoryreset
+               __method_factoryreset,
+       },
+       {
+               NULL,
+               NULL,
+       }
+};
+
+struct {
+       const gchar *property_name;
+       GVariant *(*handler)(void);
+} thread_gdbus_property_list[] = {
+       {
+               THREAD_DBUS_PROPERTY_DEVICE_ROLE,
+               __property_device_role,
        },
        {
                NULL,
@@ -85,6 +104,11 @@ static bool __is_same_method(int i, const char *method_name)
        return (g_strcmp0(thread_gdbus_method_list[i].method_name, method_name) == 0);
 }
 
+static bool __is_same_property(int i, const char *property_name)
+{
+       return (g_strcmp0(thread_gdbus_property_list[i].property_name, property_name) == 0);
+}
+
 guint _subscribe_signal(const char *interface_name,
                const char *member, GDBusSignalCallback callback,
                gpointer user_data)
@@ -108,6 +132,20 @@ GVariant *_handle_sync_method(const gchar *method_name,
                        return nullptr;
 
                if (__is_same_method(i, method_name))
-                       return thread_gdbus_method_list[i].sync_handler(parameters);
+                       return thread_gdbus_method_list[i].handler(parameters);
+       }
+}
+
+GVariant *_handle_get_property(GVariant *parameters)
+{
+       const char *property_name;
+       g_variant_get(parameters, "(ss)", nullptr, &property_name);
+
+       for (int i = 0; ; ++i) {
+               if (thread_gdbus_property_list[i].property_name == NULL)
+                       return nullptr;
+
+               if (__is_same_property(i, property_name))
+                       return thread_gdbus_property_list[i].handler();
        }
 }
\ No newline at end of file
index 0cae601..0f71083 100644 (file)
@@ -31,3 +31,5 @@ guint _subscribe_signal(const char *interface_name,
 
 GVariant *_handle_sync_method(const gchar *method_name,
                GVariant *parameters);
+
+GVariant *_handle_get_property(GVariant *parameters);
\ No newline at end of file
index 51b94c7..658b9e5 100644 (file)
@@ -22,6 +22,7 @@ class ThreadCoreTest : public ::testing::Test
 {
 public:
        thread_instance_h instance;
+       thread_device_role_e deviceRole;
 
 protected:
        void SetUp() override
@@ -131,4 +132,24 @@ TEST_F(ThreadCoreTest, FactoryresetErrorNone)
 {
        EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
        EXPECT_EQ(THREAD_ERROR_NONE, thread_factoryreset(instance));
+}
+
+TEST_F(ThreadCoreTest, GetDeviceRoleNotInitialized)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_deinitialize());
+       EXPECT_EQ(THREAD_ERROR_NOT_INITIALIZED, thread_get_device_role(instance, &deviceRole));
+}
+
+TEST_F(ThreadCoreTest, GetDeviceRoleInvalidParameter)
+{
+       EXPECT_EQ(THREAD_ERROR_INVALID_PARAMETER, thread_get_device_role(nullptr, &deviceRole));
+
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
+       EXPECT_EQ(THREAD_ERROR_INVALID_PARAMETER, thread_get_device_role(instance, nullptr));
+}
+
+TEST_F(ThreadCoreTest, GetDeviceRoleErrorNone)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_get_device_role(instance, &deviceRole));
 }
\ No newline at end of file