forked from enlightenment/efl
Eldbus: add test suite for eldbus (eldbus_pending_cancel*)
Summary: add tests for next API: eldbus_pending_cancel() eldbus_pending_destination_get() eldbus_pending_interface_get() eldbus_pending_method_get() eldbus_pending_path_get() Reviewers: cedric, NikaWhite, myoungwoon, raster, artem.popov Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D5660
This commit is contained in:
parent
43c0122dd6
commit
346e9a1904
|
@ -135,6 +135,7 @@ tests/eldbus/eldbus_test_eldbus_object.c \
|
|||
tests/eldbus/eldbus_test_eldbus_message.c \
|
||||
tests/eldbus/eldbus_test_eldbus_signal_handler.c \
|
||||
tests/eldbus/eldbus_test_eldbus_proxy.c \
|
||||
tests/eldbus/eldbus_test_eldbus_pending_cancel.c \
|
||||
tests/eldbus/eldbus_test_fake_server_eldbus_model_proxy.c \
|
||||
tests/eldbus/eldbus_fake_server.c \
|
||||
tests/eldbus/eldbus_suite.h
|
||||
|
|
|
@ -15,6 +15,7 @@ set(SOURCES
|
|||
eldbus_test_eldbus_message.c
|
||||
eldbus_test_eldbus_signal_handler.c
|
||||
eldbus_test_eldbus_proxy.c
|
||||
eldbus_test_eldbus_pending_cancel.c
|
||||
eldbus_test_fake_server_eldbus_model_proxy.c
|
||||
)
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ static const Efl_Test_Case etc[] = {
|
|||
{ "eldbus_test_eldbus_message", eldbus_test_eldbus_message },
|
||||
{ "eldbus_test_eldbus_signal_handler", eldbus_test_eldbus_signal_handler },
|
||||
{ "eldbus_test_eldbus_proxy", eldbus_test_eldbus_proxy },
|
||||
{ "eldbus_test_eldbus_pending_cancel", eldbus_test_eldbus_pending_cancel },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -15,4 +15,5 @@ void eldbus_test_eldbus_object(TCase *tc);
|
|||
void eldbus_test_eldbus_message(TCase *tc);
|
||||
void eldbus_test_eldbus_signal_handler(TCase *tc);
|
||||
void eldbus_test_eldbus_proxy(TCase *tc);
|
||||
void eldbus_test_eldbus_pending_cancel(TCase *tc);
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,208 @@
|
|||
#include <check.h>
|
||||
#include <Eldbus.h>
|
||||
#include <Ecore.h>
|
||||
#include <Eina.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "eldbus_suite.h"
|
||||
|
||||
static Eina_Bool is_success_cb = EINA_FALSE;
|
||||
|
||||
static Ecore_Timer *timeout = NULL;
|
||||
|
||||
static Eldbus_Connection *conn = NULL;
|
||||
static Eldbus_Object *obj = NULL;
|
||||
static Eldbus_Message *message = NULL;
|
||||
|
||||
const char *bus = "org.freedesktop.DBus";
|
||||
const char *path = "/org/freedesktop/DBus";
|
||||
const char *interface = "org.freedesktop.DBus";
|
||||
const char *member = "GetId";
|
||||
|
||||
/**
|
||||
* @addtogroup eldbus
|
||||
* @{
|
||||
* @defgroup eldbus_pending_info_get_cancel
|
||||
* @li eldbus_pending_cancel()
|
||||
* @li eldbus_pending_destination_get()
|
||||
* @li eldbus_pending_interface_get()
|
||||
* @li eldbus_pending_method_get()
|
||||
* @li eldbus_pending_path_get()
|
||||
*
|
||||
* @precondition
|
||||
* @step 1 Initialize ecore with ecore_init()
|
||||
* @step 2 Initialize eldbus with eldbus_init()
|
||||
*/
|
||||
|
||||
static void
|
||||
_setup(void)
|
||||
{
|
||||
ecore_init();
|
||||
int ret = eldbus_init();
|
||||
ck_assert_int_ge(ret, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
_teardown(void)
|
||||
{
|
||||
eldbus_shutdown();
|
||||
ecore_shutdown();
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_ecore_loop_close(void *data EINA_UNUSED)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
|
||||
return ECORE_CALLBACK_CANCEL;
|
||||
}
|
||||
|
||||
static void
|
||||
_response_message_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
|
||||
{
|
||||
if (timeout != NULL)
|
||||
{
|
||||
ecore_timer_del(timeout);
|
||||
timeout = NULL;
|
||||
}
|
||||
|
||||
if (!pending)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
return;
|
||||
}
|
||||
|
||||
const char *pending_path = eldbus_pending_path_get(pending);
|
||||
if ((!pending_path) || (strcmp(pending_path, path)))
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
return;
|
||||
}
|
||||
|
||||
const char *pending_method = eldbus_pending_method_get(pending);
|
||||
if ((!pending_method) || (strcmp(pending_method, member)))
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
return;
|
||||
}
|
||||
|
||||
const char *pending_interface = eldbus_pending_interface_get(pending);
|
||||
if ((!pending_interface) || (strcmp(pending_interface, interface)))
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
return;
|
||||
}
|
||||
|
||||
const char *pending_destination = eldbus_pending_destination_get(pending);
|
||||
if ((!pending_destination) || (strcmp(pending_destination, bus)))
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
return;
|
||||
}
|
||||
|
||||
const char *errname, *errmsg;
|
||||
|
||||
if (eldbus_message_error_get(msg, &errname, &errmsg))
|
||||
{
|
||||
is_success_cb = EINA_TRUE;
|
||||
}
|
||||
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static Eldbus_Pending *
|
||||
_pending_connection_get()
|
||||
{
|
||||
const int send_timeout_ms = 500;
|
||||
|
||||
conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
|
||||
if (!conn)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj = eldbus_object_get(conn, bus, path);
|
||||
if (!obj)
|
||||
{
|
||||
eldbus_connection_unref(conn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
message = eldbus_object_method_call_new(obj, interface, member);
|
||||
if (!message)
|
||||
{
|
||||
eldbus_object_unref(obj);
|
||||
eldbus_connection_unref(conn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Eldbus_Pending *pending = eldbus_connection_send(conn, message, _response_message_cb, NULL, send_timeout_ms);
|
||||
if (!pending)
|
||||
{
|
||||
eldbus_message_unref(message);
|
||||
eldbus_object_unref(obj);
|
||||
eldbus_connection_unref(conn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pending;
|
||||
}
|
||||
|
||||
/**
|
||||
* @addtogroup eldbus_pending_info_get_cancel
|
||||
* @{
|
||||
* @objective Positive test case checks if pending connection object canceled success.
|
||||
* If functions eldbus_pending_cancel() eldbus_pending_destination_get()
|
||||
* eldbus_pending_interface_get() eldbus_pending_method_get() eldbus_pending_path_get()
|
||||
* returned expected values
|
||||
*
|
||||
* @n Input Data:
|
||||
* @li the pending connection object
|
||||
* @li callback function to be called
|
||||
* @li the bus name of bus who listens
|
||||
* @li the path Dbus object path
|
||||
* @li the interface Dbus interface name
|
||||
* @li the member name of the method to be called.
|
||||
*
|
||||
* @procedure
|
||||
* @step 1 Get pendindig connection object and check on NULL
|
||||
* @step 2 Call eldbus_pending_cancel to cancel the pending message
|
||||
* @step 3 Set timer for preschedule termination of main loop if tested callback wasn't executed.
|
||||
* @step 4 Start of main loop and wait for tested response in callback executing.
|
||||
* @step 5 Check static variable named is_success_cb.
|
||||
* If are equals 1, that pending message was canceled and pending object
|
||||
* returned expeted information about connection services. In other cases error.
|
||||
* @step 6 Call eldbus_message_unref function to delete message object
|
||||
* @step 7 Call eldbus_object_unref function to delete connection dbus object
|
||||
* @step 8 Call eldbus_connection_unref function to delete connection object
|
||||
*
|
||||
* @passcondition Variables named is_success_cb must equals 1, and there is no segmentation fault.
|
||||
* @}
|
||||
*/
|
||||
|
||||
START_TEST(utc_eldbus_pending_info_get_cancel_p)
|
||||
{
|
||||
Eldbus_Pending *pending = _pending_connection_get();
|
||||
ck_assert_ptr_ne(NULL, pending);
|
||||
|
||||
eldbus_pending_cancel(pending);
|
||||
|
||||
timeout = ecore_timer_add(1.5, _ecore_loop_close, NULL);
|
||||
ck_assert_ptr_ne(NULL, timeout);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
ck_assert(is_success_cb == EINA_TRUE);
|
||||
|
||||
eldbus_message_unref(message);
|
||||
eldbus_object_unref(obj);
|
||||
eldbus_connection_unref(conn);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void
|
||||
eldbus_test_eldbus_pending_cancel(TCase *tc)
|
||||
{
|
||||
tcase_add_checked_fixture(tc, _setup, _teardown);
|
||||
tcase_add_test(tc, utc_eldbus_pending_info_get_cancel_p);
|
||||
}
|
Loading…
Reference in New Issue