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,
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,
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,
{
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)
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;
struct {
const gchar *method_name;
- GVariant *(*sync_handler)(GVariant *parameters);
+ GVariant *(*handler)(GVariant *parameters);
} thread_gdbus_method_list[] = {
{
THREAD_DBUS_RESET_METHOD,
},
{
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,
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)
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
GVariant *_handle_sync_method(const gchar *method_name,
GVariant *parameters);
+
+GVariant *_handle_get_property(GVariant *parameters);
\ No newline at end of file
{
public:
thread_instance_h instance;
+ thread_device_role_e deviceRole;
protected:
void SetUp() override
{
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