[PATCH libevdev 9/9] test: test for logging function

David Herrmann dh.herrmann at gmail.com
Mon Sep 9 08:30:29 PDT 2013


Hi Benjamin

On Mon, Sep 9, 2013 at 5:09 PM, Benjamin Tissoires
<benjamin.tissoires at gmail.com> wrote:
> On Tue, Sep 3, 2013 at 9:07 AM, Peter Hutterer <peter.hutterer at who-t.net> wrote:
>> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
>> ---
>>  test/test-libevdev-init.c | 25 +++++++++++++++++--------
>>  1 file changed, 17 insertions(+), 8 deletions(-)
>>
>> diff --git a/test/test-libevdev-init.c b/test/test-libevdev-init.c
>> index 8f1d0d1..2610975 100644
>> --- a/test/test-libevdev-init.c
>> +++ b/test/test-libevdev-init.c
>> @@ -93,10 +93,16 @@ START_TEST(test_init_and_change_fd)
>>  }
>>  END_TEST
>>
>> +
>> +static int log_fn_called = 0;
>> +static char *logdata = "test";
>>  static void logfunc(enum libevdev_log_priority priority,
>>                     void *data,
>>                     const char *file, int line, const char *func,
>> -                   const char *f, va_list args) {}
>> +                   const char *f, va_list args) {
>> +       ck_assert_int_eq(strcmp(logdata, data), 0);
>> +       log_fn_called++;
>> +}
>>
>>  START_TEST(test_log_init)
>>  {
>> @@ -107,16 +113,19 @@ START_TEST(test_log_init)
>>
>>         dev = libevdev_new();
>>         ck_assert(dev != NULL);
>> -       libevdev_set_log_function(logfunc, NULL);
>> -       libevdev_free(dev);
>>
>> -       dev = libevdev_new();
>> -       ck_assert(dev != NULL);
>> +       libevdev_set_log_function(logfunc, logdata);
>> +       libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, NULL);
>> +
>>         libevdev_set_log_function(NULL, NULL);
>> -       libevdev_set_log_function(logfunc, NULL);
>> +       libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, NULL);
>> +
>> +       libevdev_set_log_function(logfunc, logdata);
>
> Shoudn't this be "libevdev_set_log_function(logfunc, NULL);"?
> Otherwise, I don't get the "2" below.

You would get a NULL-deref in strcmp() in logfunc() if it's NULL. I
think it looks all good. He tests _next_event() 3 times. First and
last time with logfunc+logdata and in the middle without. So
log_fn_called is 2 afterwards as the one in the middle is omitted.

Cheers
David


More information about the Input-tools mailing list