LCOV - code coverage report
Current view: top level - tests - mainloop-test.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 33 38 86.8 %
Date: 2012-07-17 Functions: 3 4 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 18 38.9 %

           Branch data     Line data    Source code
       1                 :            : /***
       2                 :            :   This file is part of PulseAudio.
       3                 :            : 
       4                 :            :   PulseAudio is free software; you can redistribute it and/or modify
       5                 :            :   it under the terms of the GNU Lesser General Public License as published
       6                 :            :   by the Free Software Foundation; either version 2.1 of the License,
       7                 :            :   or (at your option) any later version.
       8                 :            : 
       9                 :            :   PulseAudio is distributed in the hope that it will be useful, but
      10                 :            :   WITHOUT ANY WARRANTY; without even the implied warranty of
      11                 :            :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      12                 :            :   General Public License for more details.
      13                 :            : 
      14                 :            :   You should have received a copy of the GNU Lesser General Public License
      15                 :            :   along with PulseAudio; if not, write to the Free Software
      16                 :            :   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
      17                 :            :   USA.
      18                 :            : ***/
      19                 :            : 
      20                 :            : #ifdef HAVE_CONFIG_H
      21                 :            : #include <config.h>
      22                 :            : #endif
      23                 :            : 
      24                 :            : #include <stdio.h>
      25                 :            : #include <unistd.h>
      26                 :            : #include <sys/time.h>
      27                 :            : #include <assert.h>
      28                 :            : 
      29                 :            : #include <pulse/rtclock.h>
      30                 :            : #include <pulse/timeval.h>
      31                 :            : 
      32                 :            : #include <pulsecore/core-util.h>
      33                 :            : #include <pulsecore/core-rtclock.h>
      34                 :            : 
      35                 :            : #ifdef GLIB_MAIN_LOOP
      36                 :            : 
      37                 :            : #include <glib.h>
      38                 :            : #include <pulse/glib-mainloop.h>
      39                 :            : 
      40                 :            : static GMainLoop* glib_main_loop = NULL;
      41                 :            : 
      42                 :            : #else /* GLIB_MAIN_LOOP */
      43                 :            : #include <pulse/mainloop.h>
      44                 :            : #endif /* GLIB_MAIN_LOOP */
      45                 :            : 
      46                 :            : static pa_defer_event *de;
      47                 :            : 
      48                 :          0 : static void iocb(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
      49                 :            :     unsigned char c;
      50         [ #  # ]:          0 :     pa_assert_se(read(fd, &c, sizeof(c)) >= 0);
      51         [ #  # ]:          0 :     fprintf(stderr, "IO EVENT: %c\n", c < 32 ? '.' : c);
      52                 :          0 :     a->defer_enable(de, 1);
      53                 :          0 : }
      54                 :            : 
      55                 :          2 : static void dcb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) {
      56                 :          2 :     fprintf(stderr, "DEFER EVENT\n");
      57                 :          2 :     a->defer_enable(e, 0);
      58                 :          2 : }
      59                 :            : 
      60                 :          2 : static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) {
      61                 :          2 :     fprintf(stderr, "TIME EVENT\n");
      62                 :            : 
      63                 :            : #if defined(GLIB_MAIN_LOOP)
      64                 :          1 :     g_main_loop_quit(glib_main_loop);
      65                 :            : #else
      66                 :          1 :     a->quit(a, 0);
      67                 :            : #endif
      68                 :          2 : }
      69                 :            : 
      70                 :          2 : int main(int argc, char *argv[]) {
      71                 :            :     pa_mainloop_api *a;
      72                 :            :     pa_io_event *ioe;
      73                 :            :     pa_time_event *te;
      74                 :            :     struct timeval tv;
      75                 :            : 
      76                 :            : #ifdef GLIB_MAIN_LOOP
      77                 :            :     pa_glib_mainloop *g;
      78                 :            : 
      79                 :          1 :     glib_main_loop = g_main_loop_new(NULL, FALSE);
      80         [ -  + ]:          1 :     assert(glib_main_loop);
      81                 :            : 
      82                 :          1 :     g = pa_glib_mainloop_new(NULL);
      83         [ -  + ]:          1 :     assert(g);
      84                 :            : 
      85                 :          1 :     a = pa_glib_mainloop_get_api(g);
      86         [ -  + ]:          1 :     assert(a);
      87                 :            : #else /* GLIB_MAIN_LOOP */
      88                 :            :     pa_mainloop *m;
      89                 :            : 
      90                 :          1 :     m = pa_mainloop_new();
      91         [ -  + ]:          1 :     assert(m);
      92                 :            : 
      93                 :          1 :     a = pa_mainloop_get_api(m);
      94         [ -  + ]:          1 :     assert(a);
      95                 :            : #endif /* GLIB_MAIN_LOOP */
      96                 :            : 
      97                 :          2 :     ioe = a->io_new(a, 0, PA_IO_EVENT_INPUT, iocb, NULL);
      98         [ -  + ]:          2 :     assert(ioe);
      99                 :            : 
     100                 :          2 :     de = a->defer_new(a, dcb, NULL);
     101         [ -  + ]:          2 :     assert(de);
     102                 :            : 
     103                 :          2 :     te = a->time_new(a, pa_timeval_rtstore(&tv, pa_rtclock_now() + 2 * PA_USEC_PER_SEC, TRUE), tcb, NULL);
     104                 :            : 
     105                 :            : #if defined(GLIB_MAIN_LOOP)
     106                 :          1 :     g_main_loop_run(glib_main_loop);
     107                 :            : #else
     108                 :          1 :     pa_mainloop_run(m, NULL);
     109                 :            : #endif
     110                 :            : 
     111                 :          2 :     a->time_free(te);
     112                 :          2 :     a->defer_free(de);
     113                 :          2 :     a->io_free(ioe);
     114                 :            : 
     115                 :            : #ifdef GLIB_MAIN_LOOP
     116                 :          1 :     pa_glib_mainloop_free(g);
     117                 :          1 :     g_main_loop_unref(glib_main_loop);
     118                 :            : #else
     119                 :          1 :     pa_mainloop_free(m);
     120                 :            : #endif
     121                 :            : 
     122                 :            :     return 0;
     123                 :            : }

Generated by: LCOV version 1.9