Hi Ryuan,

Thank you for this patch.
Don't you think it would be better if the timeout could be chosen by the
caller itself?

D2, alias JackDanielZ

On 07/16/2014 06:36 PM, Daniel Juyung Seo wrote:
> Oh.. this must be useful :)
>
> Thanks.
>
> Daniel Juyung Seo (SeoZ)
>
>
> On Wed, Jul 16, 2014 at 11:32 PM, Ryuan Choi <[email protected]> wrote:
>
>> ryuan pushed a commit to branch master.
>>
>>
>> http://git.enlightenment.org/core/elementary.git/commit/?id=bbb916375d99e65b8083a037323d88acbbcdbec5
>>
>> commit bbb916375d99e65b8083a037323d88acbbcdbec5
>> Author: Ryuan Choi <[email protected]>
>> Date:   Wed Jul 16 23:17:31 2014 +0900
>>
>>     tests: Add elm_test_helper_wait_flag to avoid infinite loop
>>
>>     Test of elm_fileselector_selected and future tests may have
>> conditional loop
>>     which some flag.
>>     This patch adds elm_test_helper_wait_flag, simple wrapper of the loop
>> with timer
>>     in order to exit the loop when expected callbacks are not called.
>> ---
>>  src/tests/Makefile.am             |  1 +
>>  src/tests/elm_suite.h             |  1 +
>>  src/tests/elm_test_fileselector.c |  6 ++++--
>>  src/tests/elm_test_helper.c       | 41
>> +++++++++++++++++++++++++++++++++++++++
>>  src/tests/elm_test_helper.h       |  8 ++++++++
>>  5 files changed, 55 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
>> index 11dcd87..12fc454 100644
>> --- a/src/tests/Makefile.am
>> +++ b/src/tests/Makefile.am
>> @@ -6,6 +6,7 @@ TESTS = elm_suite
>>  check_PROGRAMS = elm_suite
>>  elm_suite_SOURCES = \
>>         elm_suite.c \
>> +       elm_test_helper.c \
>>         elm_test_atspi.c \
>>         elm_test_check.c \
>>         elm_test_colorselector.c \
>> diff --git a/src/tests/elm_suite.h b/src/tests/elm_suite.h
>> index 7918a4e..1a19179 100644
>> --- a/src/tests/elm_suite.h
>> +++ b/src/tests/elm_suite.h
>> @@ -2,6 +2,7 @@
>>  #define _ELM_SUITE_H
>>
>>  #include <check.h>
>> +#include "elm_test_helper.h"
>>
>>  void elm_test_init(TCase *tc);
>>  void elm_test_check(TCase *tc);
>> diff --git a/src/tests/elm_test_fileselector.c
>> b/src/tests/elm_test_fileselector.c
>> index e5dd067..a204917 100644
>> --- a/src/tests/elm_test_fileselector.c
>> +++ b/src/tests/elm_test_fileselector.c
>> @@ -69,12 +69,14 @@ START_TEST (elm_fileselector_selected)
>>
>>     selected = EINA_FALSE;
>>     ck_assert(elm_fileselector_selected_set(fileselector, path));
>> -   while (!selected) ecore_main_loop_iterate();
>> +   ck_assert(elm_test_helper_wait_flag(&selected));
>> +
>>     ck_assert_str_eq(elm_fileselector_selected_get(fileselector), path);
>>
>>     selected = EINA_FALSE;
>>     ck_assert(elm_fileselector_selected_set(fileselector, exist));
>> -   while (!selected) ecore_main_loop_iterate();
>> +   ck_assert(elm_test_helper_wait_flag(&selected));
>> +
>>     ck_assert_str_eq(elm_fileselector_selected_get(fileselector), exist);
>>
>>     eina_stringshare_del(exist);
>> diff --git a/src/tests/elm_test_helper.c b/src/tests/elm_test_helper.c
>> new file mode 100644
>> index 0000000..453e888
>> --- /dev/null
>> +++ b/src/tests/elm_test_helper.c
>> @@ -0,0 +1,41 @@
>> +#ifdef HAVE_CONFIG_H
>> +# include "elementary_config.h"
>> +#endif
>> +
>> +#include <Ecore.h>
>> +#include "elm_suite.h"
>> +
>> +const double timeout = 10;
>> +
>> +typedef struct _Callback_Data
>> +{
>> +   Ecore_Timer *timer;
>> +   Eina_Bool did_timeout;
>> +} Callback_Data;
>> +
>> +static Eina_Bool
>> +timer_expired_cb(void *user_data)
>> +{
>> +   Callback_Data *data = user_data;
>> +   data->did_timeout = EINA_TRUE;
>> +   data->timer = NULL;
>> +
>> +   return ECORE_CALLBACK_CANCEL;
>> +}
>> +
>> +Eina_Bool
>> +elm_test_helper_wait_flag(Eina_Bool *done)
>> +{
>> +   Callback_Data data;
>> +
>> +   data.did_timeout = EINA_FALSE;
>> +   data.timer = ecore_timer_add(timeout, timer_expired_cb, &data);
>> +
>> +   while (*done == EINA_FALSE && data.did_timeout == EINA_FALSE)
>> +     ecore_main_loop_iterate();
>> +
>> +   if (data.timer)
>> +     ecore_timer_del(data.timer);
>> +
>> +   return !data.did_timeout;
>> +}
>> diff --git a/src/tests/elm_test_helper.h b/src/tests/elm_test_helper.h
>> new file mode 100644
>> index 0000000..62974f1
>> --- /dev/null
>> +++ b/src/tests/elm_test_helper.h
>> @@ -0,0 +1,8 @@
>> +#ifndef _ELM_TEST_HELPER_H
>> +#define _ELM_TEST_HELPER_H
>> +
>> +#include <Eina.h>
>> +
>> +Eina_Bool elm_test_helper_wait_flag(Eina_Bool *done);
>> +
>> +#endif /* _ELM_TEST_HELPER_H */
>>
>> --
>>
>>
>>
> ------------------------------------------------------------------------------
> Want fast and easy access to all the code in your enterprise? Index and
> search up to 200,000 lines of code with a free copy of Black Duck
> Code Sight - the same software that powers the world's largest code
> search on Ohloh, the Black Duck Open Hub! Try it now.
> http://p.sf.net/sfu/bds
> _______________________________________________
> enlightenment-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
>


------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to