2015-01-09 08:20:14 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2016-02-04 05:52:49 -08:00
|
|
|
#include <stdbool.h>
|
2015-01-09 08:20:14 -08:00
|
|
|
|
|
|
|
#include <Eina.h>
|
2016-02-04 05:52:49 -08:00
|
|
|
#include <Ecore.h>
|
2015-01-09 08:20:14 -08:00
|
|
|
#include <Eldbus_Model.h>
|
|
|
|
|
2016-02-04 05:52:49 -08:00
|
|
|
#include "eldbus_test_eldbus_model.h"
|
|
|
|
#include "eldbus_suite.h"
|
2015-01-09 08:20:14 -08:00
|
|
|
|
|
|
|
static Eo *connection = NULL;
|
|
|
|
|
|
|
|
#define UNIQUE_NAME_PROPERTY "unique_name"
|
|
|
|
|
|
|
|
static void
|
|
|
|
_setup(void)
|
|
|
|
{
|
2016-04-20 13:07:53 -07:00
|
|
|
connection = create_connection();
|
2015-01-09 08:20:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_teardown(void)
|
|
|
|
{
|
2018-05-02 13:42:52 -07:00
|
|
|
efl_del(connection);
|
2015-01-09 08:20:14 -08:00
|
|
|
}
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(properties_get)
|
2015-01-09 08:20:14 -08:00
|
|
|
{
|
2018-11-23 08:25:19 -08:00
|
|
|
Eina_Iterator *properties = NULL;
|
2016-04-20 13:07:53 -07:00
|
|
|
properties = efl_model_properties_get(connection);
|
2015-01-09 08:20:14 -08:00
|
|
|
ck_assert_ptr_ne(NULL, properties);
|
|
|
|
|
|
|
|
const unsigned int expected_properties_count = 1;
|
2018-11-23 08:25:19 -08:00
|
|
|
unsigned int actual_properties_count = 0;
|
|
|
|
const char *prop;
|
|
|
|
|
|
|
|
EINA_ITERATOR_FOREACH(properties, prop)
|
|
|
|
actual_properties_count++;
|
|
|
|
eina_iterator_free(properties);
|
|
|
|
|
2015-01-09 08:20:14 -08:00
|
|
|
ck_assert_int_eq(expected_properties_count, actual_properties_count);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-01-09 08:20:14 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(property_get)
|
2015-01-09 08:20:14 -08:00
|
|
|
{
|
2018-02-12 11:06:48 -08:00
|
|
|
Eina_Value *v;
|
|
|
|
|
|
|
|
v = efl_model_property_get(connection, UNIQUE_NAME_PROPERTY);
|
|
|
|
fail_if(v == NULL);
|
2016-04-20 13:07:53 -07:00
|
|
|
|
|
|
|
// Nonexistent property must raise ERROR
|
2018-02-12 11:06:48 -08:00
|
|
|
v = efl_model_property_get(connection, "nonexistent");
|
|
|
|
fail_if(v == NULL);
|
|
|
|
fail_if(eina_value_type_get(v) != EINA_VALUE_TYPE_ERROR);
|
|
|
|
/* fail_if(v != NULL || eina_value_type_get(v) != EINA_VALUE_TYPE_ERROR); */
|
2015-01-09 08:20:14 -08:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-01-09 08:20:14 -08:00
|
|
|
|
2018-02-12 11:06:48 -08:00
|
|
|
static Eina_Value
|
|
|
|
_failed_property_set(void *data, const Eina_Value v,
|
|
|
|
const Eina_Future *dead_future EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Eina_Value *expected = data;
|
|
|
|
|
|
|
|
fail_if(eina_value_type_get(expected) != eina_value_type_get(&v));
|
|
|
|
|
|
|
|
if (eina_value_type_get(expected) == EINA_VALUE_TYPE_ERROR)
|
|
|
|
{
|
|
|
|
Eina_Error exerr = 0, goterr = 0;
|
|
|
|
|
|
|
|
eina_value_error_get(expected, &exerr);
|
|
|
|
eina_value_error_get(&v, &goterr);
|
|
|
|
|
|
|
|
fail_if(exerr != goterr);
|
|
|
|
}
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(property_set)
|
2015-01-09 08:20:14 -08:00
|
|
|
{
|
|
|
|
Eina_Value value;
|
2018-02-12 11:06:48 -08:00
|
|
|
Eina_Future *future;
|
2016-04-20 13:07:53 -07:00
|
|
|
|
|
|
|
// Nonexistent property must raise ERROR
|
2015-01-09 08:20:14 -08:00
|
|
|
eina_value_setup(&value, EINA_VALUE_TYPE_INT);
|
|
|
|
eina_value_set(&value, 1);
|
2016-09-29 09:12:09 -07:00
|
|
|
future = efl_model_property_set(connection, "nonexistent", &value);
|
2018-11-07 06:52:41 -08:00
|
|
|
eina_future_then(future, _failed_property_set, eina_value_error_new(EFL_MODEL_ERROR_NOT_FOUND), NULL);
|
2018-02-12 11:06:48 -08:00
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
2015-01-09 08:20:14 -08:00
|
|
|
|
|
|
|
// UNIQUE_NAME_PROPERTY is read-only
|
2016-09-29 09:12:09 -07:00
|
|
|
future = efl_model_property_set(connection, UNIQUE_NAME_PROPERTY, &value);
|
2018-11-07 06:52:41 -08:00
|
|
|
eina_future_then(future, _failed_property_set, eina_value_error_new(EFL_MODEL_ERROR_READ_ONLY), NULL);
|
2018-02-12 11:06:48 -08:00
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
2016-04-20 13:07:53 -07:00
|
|
|
|
2015-01-09 08:20:14 -08:00
|
|
|
eina_value_flush(&value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-01-09 08:20:14 -08:00
|
|
|
|
2018-02-12 11:06:48 -08:00
|
|
|
static Eina_Value
|
|
|
|
_leave(void *data EINA_UNUSED, const Eina_Value v,
|
|
|
|
const Eina_Future *dead EINA_UNUSED)
|
|
|
|
{
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
_count_changed(void *data EINA_UNUSED, const Efl_Event *ev)
|
|
|
|
{
|
|
|
|
Eina_Future *f;
|
|
|
|
f = efl_loop_job(efl_provider_find(ev->object, EFL_LOOP_CLASS));
|
2018-11-07 06:52:41 -08:00
|
|
|
eina_future_then(f, _leave, NULL, NULL);
|
2018-02-12 11:06:48 -08:00
|
|
|
}
|
|
|
|
|
2015-01-09 08:20:14 -08:00
|
|
|
static void
|
|
|
|
_test_children_count(Eo *efl_model)
|
|
|
|
{
|
|
|
|
// At least this connection <unique_name> and 'org.freedesktop.DBus' must exist
|
2018-02-12 11:06:48 -08:00
|
|
|
efl_event_callback_add(efl_model, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, _count_changed, NULL);
|
|
|
|
if (!efl_model_children_count_get(efl_model))
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
efl_event_callback_del(efl_model, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, _count_changed, NULL);
|
|
|
|
|
2015-01-09 08:20:14 -08:00
|
|
|
check_efl_model_children_count_ge(efl_model, 2);
|
|
|
|
}
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(children_count)
|
2015-01-09 08:20:14 -08:00
|
|
|
{
|
|
|
|
_test_children_count(connection);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-01-09 08:20:14 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(children_slice_get)
|
2015-01-09 08:20:14 -08:00
|
|
|
{
|
2018-02-12 11:06:48 -08:00
|
|
|
efl_event_callback_add(connection, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, _count_changed, NULL);
|
|
|
|
if (!efl_model_children_count_get(connection))
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
efl_event_callback_del(connection, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, _count_changed, NULL);
|
|
|
|
|
2015-01-09 08:20:14 -08:00
|
|
|
check_efl_model_children_slice_get(connection);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-01-09 08:20:14 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(child_add)
|
2015-01-09 08:20:14 -08:00
|
|
|
{
|
|
|
|
Eo *child;
|
2016-03-01 10:06:28 -08:00
|
|
|
child = efl_model_child_add(connection);
|
2015-01-09 08:20:14 -08:00
|
|
|
ck_assert_ptr_eq(NULL, child);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-01-09 08:20:14 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(child_del)
|
2015-01-09 08:20:14 -08:00
|
|
|
{
|
|
|
|
unsigned int expected_children_count = 0;
|
2018-02-12 11:06:48 -08:00
|
|
|
unsigned int actual_children_count = 0;
|
|
|
|
Eo *child;
|
2015-01-09 08:20:14 -08:00
|
|
|
|
2018-02-12 11:06:48 -08:00
|
|
|
expected_children_count = efl_model_children_count_get(connection);
|
|
|
|
|
|
|
|
child = efl_model_first_child_get(connection);
|
2016-04-20 13:07:53 -07:00
|
|
|
efl_model_child_del(connection, child);
|
2015-01-09 08:20:14 -08:00
|
|
|
|
2018-02-12 11:06:48 -08:00
|
|
|
actual_children_count = efl_model_children_count_get(connection);
|
2015-01-09 08:20:14 -08:00
|
|
|
|
|
|
|
ck_assert_int_le(expected_children_count, actual_children_count);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-01-09 08:20:14 -08:00
|
|
|
|
|
|
|
void eldbus_test_eldbus_model_connection(TCase *tc)
|
|
|
|
{
|
|
|
|
tcase_add_checked_fixture(tc, _setup, _teardown);
|
|
|
|
tcase_add_test(tc, properties_get);
|
|
|
|
tcase_add_test(tc, property_get);
|
|
|
|
tcase_add_test(tc, property_set);
|
|
|
|
tcase_add_test(tc, children_count);
|
|
|
|
tcase_add_test(tc, children_slice_get);
|
2018-01-22 14:57:38 -08:00
|
|
|
tcase_add_test(tc, child_add);
|
|
|
|
tcase_add_test(tc, child_del);
|
2015-01-09 08:20:14 -08:00
|
|
|
}
|