From: hyunuk.tak Date: Tue, 22 Mar 2022 04:44:52 +0000 (+0900) Subject: Add core test case for getting device role property X-Git-Tag: accepted/tizen/unified/20220914.164046~100 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=304da999abe9001c087bfc73364cec46eeaf4cf4;p=platform%2Fcore%2Fapi%2Fthread.git Add core test case for getting device role property Change-Id: I78c544c81edcd16a7d617faa570b0abaeaf28b49 Signed-off-by: hyunuk.tak --- diff --git a/tests/unittest/mocks/thread-mock-dbus.cpp b/tests/unittest/mocks/thread-mock-dbus.cpp index be8d356..06256b4 100644 --- a/tests/unittest/mocks/thread-mock-dbus.cpp +++ b/tests/unittest/mocks/thread-mock-dbus.cpp @@ -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) diff --git a/tests/unittest/mocks/thread-mock-dummy.cpp b/tests/unittest/mocks/thread-mock-dummy.cpp index 02af7aa..b09a2a0 100644 --- a/tests/unittest/mocks/thread-mock-dummy.cpp +++ b/tests/unittest/mocks/thread-mock-dummy.cpp @@ -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 diff --git a/tests/unittest/mocks/thread-mock-dummy.h b/tests/unittest/mocks/thread-mock-dummy.h index 0cae601..0f71083 100644 --- a/tests/unittest/mocks/thread-mock-dummy.h +++ b/tests/unittest/mocks/thread-mock-dummy.h @@ -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 diff --git a/tests/unittest/thread-unittest-core.cpp b/tests/unittest/thread-unittest-core.cpp index 51b94c7..658b9e5 100644 --- a/tests/unittest/thread-unittest-core.cpp +++ b/tests/unittest/thread-unittest-core.cpp @@ -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