Coverage report for bus/test.c.gcov

        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:10114
        -:    0:Programs:2
        -:    1:/* -*- mode: C; c-file-style: "gnu" -*- */
        -:    2:/* test.c  unit test routines
        -:    3: *
        -:    4: * Copyright (C) 2003 Red Hat, Inc.
        -:    5: *
        -:    6: * Licensed under the Academic Free License version 2.1
        -:    7: * 
        -:    8: * This program is free software; you can redistribute it and/or modify
        -:    9: * it under the terms of the GNU General Public License as published by
        -:   10: * the Free Software Foundation; either version 2 of the License, or
        -:   11: * (at your option) any later version.
        -:   12: *
        -:   13: * This program is distributed in the hope that it will be useful,
        -:   14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   16: * GNU General Public License for more details.
        -:   17: * 
        -:   18: * You should have received a copy of the GNU General Public License
        -:   19: * along with this program; if not, write to the Free Software
        -:   20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        -:   21: *
        -:   22: */
        -:   23:
        -:   24:#include <config.h>
        -:   25:
        -:   26:#ifdef DBUS_BUILD_TESTS
        -:   27:#include "test.h"
        -:   28:#include <dbus/dbus-internals.h>
        -:   29:#include <dbus/dbus-list.h>
        -:   30:
        -:   31:/* The "debug client" watch/timeout handlers don't dispatch messages,
        -:   32: * as we manually pull them in order to verify them. This is why they
        -:   33: * are different from the real handlers in connection.c
        -:   34: */
        -:   35:static DBusList *clients = NULL;
        -:   36:static DBusLoop *client_loop = NULL;
        -:   37:
        -:   38:static dbus_bool_t
        -:   39:client_watch_callback (DBusWatch     *watch,
        -:   40:                       unsigned int   condition,
        -:   41:                       void          *data)
function client_watch_callback called 66919 returned 100% blocks executed 100%
    66919:   42:{
        -:   43:  /* FIXME this can be done in dbus-mainloop.c
        -:   44:   * if the code in activation.c for the babysitter
        -:   45:   * watch handler is fixed.
        -:   46:   */
        -:   47: 
    66919:   48:  return dbus_watch_handle (watch, condition);
call    0 returned 100%
        -:   49:}
        -:   50:
        -:   51:static dbus_bool_t
        -:   52:add_client_watch (DBusWatch      *watch,
        -:   53:                  void           *data)
function add_client_watch called 10840 returned 100% blocks executed 100%
    10840:   54:{
    10840:   55:  DBusConnection *connection = data;
        -:   56:  
    10840:   57:  return _dbus_loop_add_watch (client_loop,
call    0 returned 100%
        -:   58:                               watch, client_watch_callback, connection,
        -:   59:                               NULL);
        -:   60:}
        -:   61:
        -:   62:static void
        -:   63:remove_client_watch (DBusWatch      *watch,
        -:   64:                     void           *data)
function remove_client_watch called 10822 returned 100% blocks executed 100%
    10822:   65:{
    10822:   66:  DBusConnection *connection = data;
        -:   67:  
    10822:   68:  _dbus_loop_remove_watch (client_loop,
call    0 returned 100%
        -:   69:                           watch, client_watch_callback, connection);
    10822:   70:}
        -:   71:
        -:   72:static void
        -:   73:client_timeout_callback (DBusTimeout   *timeout,
        -:   74:                         void          *data)
function client_timeout_callback called 0 returned 0% blocks executed 0%
    #####:   75:{
    #####:   76:  DBusConnection *connection = data;
        -:   77:
    #####:   78:  dbus_connection_ref (connection);
call    0 never executed
        -:   79:
        -:   80:  /* can return FALSE on OOM but we just let it fire again later */
    #####:   81:  dbus_timeout_handle (timeout);
call    0 never executed
        -:   82:
    #####:   83:  dbus_connection_unref (connection);
call    0 never executed
    #####:   84:}
        -:   85:
        -:   86:static dbus_bool_t
        -:   87:add_client_timeout (DBusTimeout    *timeout,
        -:   88:                    void           *data)
function add_client_timeout called 0 returned 0% blocks executed 0%
    #####:   89:{
    #####:   90:  DBusConnection *connection = data;
        -:   91:  
    #####:   92:  return _dbus_loop_add_timeout (client_loop, timeout, client_timeout_callback, connection, NULL);
call    0 never executed
        -:   93:}
        -:   94:
        -:   95:static void
        -:   96:remove_client_timeout (DBusTimeout    *timeout,
        -:   97:                       void           *data)
function remove_client_timeout called 0 returned 0% blocks executed 0%
    #####:   98:{
    #####:   99:  DBusConnection *connection = data;
        -:  100:  
    #####:  101:  _dbus_loop_remove_timeout (client_loop, timeout, client_timeout_callback, connection);
call    0 never executed
    #####:  102:}
        -:  103:
        -:  104:static DBusHandlerResult
        -:  105:client_disconnect_filter (DBusConnection     *connection,
        -:  106:                          DBusMessage        *message,
        -:  107:                          void               *user_data)
function client_disconnect_filter called 5399 returned 100% blocks executed 91%
     5399:  108:{
     5399:  109:  if (!dbus_message_is_signal (message,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  110:                               DBUS_INTERFACE_LOCAL,
        -:  111:                               "Disconnected"))
    #####:  112:    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        -:  113:    
     5399:  114:  _dbus_verbose ("Removing client %p in disconnect handler\n",
call    0 returned 100%
        -:  115:                 connection);
        -:  116:  
     5399:  117:  _dbus_list_remove (&clients, connection);
call    0 returned 100%
        -:  118:
     5399:  119:  dbus_connection_unref (connection);
call    0 returned 100%
        -:  120:  
     5399:  121:  if (clients == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  122:    {
        2:  123:      _dbus_loop_unref (client_loop);
call    0 returned 100%
        2:  124:      client_loop = NULL;
        -:  125:    }
        -:  126:  
     5399:  127:  return DBUS_HANDLER_RESULT_HANDLED;
        -:  128:}
        -:  129:
        -:  130:dbus_bool_t
        -:  131:bus_setup_debug_client (DBusConnection *connection)
function bus_setup_debug_client called 5423 returned 100% blocks executed 81%
     5423:  132:{
        -:  133:  dbus_bool_t retval;  
        -:  134:
     5423:  135:  if (!dbus_connection_add_filter (connection,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  136:                                   client_disconnect_filter,
        -:  137:                                   NULL, NULL))
    #####:  138:    return FALSE;
        -:  139:
     5423:  140:  retval = FALSE;
        -:  141:
     5423:  142:  if (client_loop == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  143:    {
        2:  144:      client_loop = _dbus_loop_new ();
call    0 returned 100%
        2:  145:      if (client_loop == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  146:        goto out;
        -:  147:    }
        -:  148:  
     5423:  149:  if (!dbus_connection_set_watch_functions (connection,
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -:  150:                                            add_client_watch,
        -:  151:                                            remove_client_watch,
        -:  152:                                            NULL,
        -:  153:                                            connection,
        -:  154:                                            NULL))
       18:  155:    goto out;
        -:  156:      
     5405:  157:  if (!dbus_connection_set_timeout_functions (connection,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  158:                                              add_client_timeout,
        -:  159:                                              remove_client_timeout,
        -:  160:                                              NULL,
        -:  161:                                              connection, NULL))
    #####:  162:    goto out;
        -:  163:
     5405:  164:  if (!_dbus_list_append (&clients, connection))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        6:  165:    goto out;
        -:  166:  
     5399:  167:  retval = TRUE;
        -:  168:  
     5423:  169: out:
     5423:  170:  if (!retval)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  171:    {
       24:  172:      dbus_connection_remove_filter (connection,
call    0 returned 100%
        -:  173:                                     client_disconnect_filter,
        -:  174:                                     NULL);
        -:  175:      
       24:  176:      dbus_connection_set_watch_functions (connection,
call    0 returned 100%
        -:  177:                                           NULL, NULL, NULL, NULL, NULL);
       24:  178:      dbus_connection_set_timeout_functions (connection,
call    0 returned 100%
        -:  179:                                             NULL, NULL, NULL, NULL, NULL);
        -:  180:
       24:  181:      _dbus_list_remove_last (&clients, connection);
call    0 returned 100%
        -:  182:
       24:  183:      if (clients == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  184:        {
    #####:  185:          _dbus_loop_unref (client_loop);
call    0 never executed
    #####:  186:          client_loop = NULL;
        -:  187:        }
        -:  188:    }
        -:  189:      
     5423:  190:  return retval;
        -:  191:}
        -:  192:
        -:  193:void
        -:  194:bus_test_clients_foreach (BusConnectionForeachFunction  function,
        -:  195:                          void                         *data)
function bus_test_clients_foreach called 40229 returned 100% blocks executed 91%
    40229:  196:{
        -:  197:  DBusList *link;
        -:  198:  
    40229:  199:  link = _dbus_list_get_first_link (&clients);
call    0 returned 100%
   180372:  200:  while (link != NULL)
branch  0 taken 71%
branch  1 taken 29% (fallthrough)
        -:  201:    {
    99914:  202:      DBusConnection *connection = link->data;
    99914:  203:      DBusList *next = _dbus_list_get_next_link (&clients, link);
branch  0 taken 60% (fallthrough)
branch  1 taken 40%
        -:  204:
    99914:  205:      if (!(* function) (connection, data))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  206:        break;
        -:  207:      
    99914:  208:      link = next;
        -:  209:    }
    40229:  210:}
        -:  211:
        -:  212:dbus_bool_t
        -:  213:bus_test_client_listed (DBusConnection *connection)
function bus_test_client_listed called 8743 returned 100% blocks executed 100%
     8743:  214:{
        -:  215:  DBusList *link;
        -:  216:  
     8743:  217:  link = _dbus_list_get_first_link (&clients);
call    0 returned 100%
    31390:  218:  while (link != NULL)
branch  0 taken 76%
branch  1 taken 24% (fallthrough)
        -:  219:    {
    17248:  220:      DBusConnection *c = link->data;
    17248:  221:      DBusList *next = _dbus_list_get_next_link (&clients, link);
branch  0 taken 49% (fallthrough)
branch  1 taken 51%
        -:  222:
    17248:  223:      if (c == connection)
branch  0 taken 19% (fallthrough)
branch  1 taken 81%
     3344:  224:        return TRUE;
        -:  225:      
    13904:  226:      link = next;
        -:  227:    }
        -:  228:
     5399:  229:  return FALSE;
        -:  230:}
        -:  231:
        -:  232:void
        -:  233:bus_test_run_clients_loop (dbus_bool_t block_once)
function bus_test_run_clients_loop called 396244 returned 100% blocks executed 73%
   396244:  234:{  
   396244:  235:  if (client_loop == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  236:    return;
        -:  237:
   396244:  238:  _dbus_verbose ("---> Dispatching on \"client side\"\n");
call    0 returned 100%
        -:  239:  
        -:  240:  /* dispatch before we block so pending dispatches
        -:  241:   * won't make our block return early
        -:  242:   */
   396244:  243:  _dbus_loop_dispatch (client_loop);
call    0 returned 100%
        -:  244:  
        -:  245:  /* Do one blocking wait, since we're expecting data */
   396244:  246:  if (block_once)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  247:    {
    #####:  248:      _dbus_verbose ("---> blocking on \"client side\"\n");
call    0 never executed
    #####:  249:      _dbus_loop_iterate (client_loop, TRUE);
call    0 never executed
        -:  250:    }
        -:  251:
        -:  252:  /* Then mop everything up */
   440404:  253:  while (_dbus_loop_iterate (client_loop, FALSE))
call    0 returned 100%
branch  1 taken 10%
branch  2 taken 90% (fallthrough)
        -:  254:    ;
        -:  255:
   396244:  256:  _dbus_verbose ("---> Done dispatching on \"client side\"\n");
call    0 returned 100%
        -:  257:}
        -:  258:
        -:  259:void
        -:  260:bus_test_run_bus_loop (BusContext *context,
        -:  261:                       dbus_bool_t block_once)
function bus_test_run_bus_loop called 387478 returned 100% blocks executed 100%
   387478:  262:{
   387478:  263:  _dbus_verbose ("---> Dispatching on \"server side\"\n");
call    0 returned 100%
        -:  264:  
        -:  265:  /* dispatch before we block so pending dispatches
        -:  266:   * won't make our block return early
        -:  267:   */
   387478:  268:  _dbus_loop_dispatch (bus_context_get_loop (context));
call    0 returned 100%
call    1 returned 100%
        -:  269:  
        -:  270:  /* Do one blocking wait, since we're expecting data */
   387478:  271:  if (block_once)
branch  0 taken 95% (fallthrough)
branch  1 taken 5%
        -:  272:    {
   368293:  273:      _dbus_verbose ("---> blocking on \"server side\"\n");
call    0 returned 100%
   368293:  274:      _dbus_loop_iterate (bus_context_get_loop (context), TRUE);
call    0 returned 100%
call    1 returned 100%
        -:  275:    }
        -:  276:
        -:  277:  /* Then mop everything up */
   420980:  278:  while (_dbus_loop_iterate (bus_context_get_loop (context), FALSE))
call    0 returned 100%
call    1 returned 100%
branch  2 taken 8%
branch  3 taken 92% (fallthrough)
        -:  279:    ;
        -:  280:
   387478:  281:  _dbus_verbose ("---> Done dispatching on \"server side\"\n");
call    0 returned 100%
   387478:  282:}
        -:  283:
        -:  284:void
        -:  285:bus_test_run_everything (BusContext *context)
function bus_test_run_everything called 15810 returned 100% blocks executed 100%
    32158:  286:{
    32158:  287:  while (_dbus_loop_iterate (bus_context_get_loop (context), FALSE) ||
call    0 returned 100%
call    1 returned 100%
branch  2 taken 28%
branch  3 taken 72% (fallthrough)
branch  4 taken 0%
branch  5 taken 100% (fallthrough)
call    6 returned 100%
branch  7 taken 32%
branch  8 taken 68% (fallthrough)
        -:  288:         (client_loop == NULL || _dbus_loop_iterate (client_loop, FALSE)))
        -:  289:    ;
    15810:  290:}
        -:  291:
        -:  292:BusContext*
        -:  293:bus_context_new_test (const DBusString *test_data_dir,
        -:  294:                      const char       *filename)
function bus_context_new_test called 2 returned 100% blocks executed 48%
        2:  295:{
        -:  296:  DBusError error;
        -:  297:  DBusString config_file;
        -:  298:  DBusString relative;
        -:  299:  BusContext *context;
        -:  300:  
        2:  301:  if (!_dbus_string_init (&config_file))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  302:    {
    #####:  303:      _dbus_warn ("No memory\n");
call    0 never executed
    #####:  304:      return NULL;
        -:  305:    }
        -:  306:
        2:  307:  if (!_dbus_string_copy (test_data_dir, 0,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  308:                          &config_file, 0))
        -:  309:    {
    #####:  310:      _dbus_warn ("No memory\n");
call    0 never executed
    #####:  311:      _dbus_string_free (&config_file);
call    0 never executed
    #####:  312:      return NULL;
        -:  313:    }
        -:  314:
        2:  315:  _dbus_string_init_const (&relative, filename);
call    0 returned 100%
        -:  316:
        2:  317:  if (!_dbus_concat_dir_and_file (&config_file, &relative))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  318:    {
    #####:  319:      _dbus_warn ("No memory\n");
call    0 never executed
    #####:  320:      _dbus_string_free (&config_file);
call    0 never executed
    #####:  321:      return NULL;
        -:  322:    }
        -:  323:  
        2:  324:  dbus_error_init (&error);
call    0 returned 100%
        2:  325:  context = bus_context_new (&config_file, FALSE, -1, -1, &error);
call    0 returned 100%
        2:  326:  if (context == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  327:    {
    #####:  328:      _DBUS_ASSERT_ERROR_IS_SET (&error);
call    0 never executed
call    1 never executed
        -:  329:      
    #####:  330:      _dbus_warn ("Failed to create debug bus context from configuration file %s: %s\n",
call    0 never executed
        -:  331:                  filename, error.message);
        -:  332:
    #####:  333:      dbus_error_free (&error);
call    0 never executed
        -:  334:      
    #####:  335:      _dbus_string_free (&config_file);
call    0 never executed
        -:  336:      
    #####:  337:      return NULL;
        -:  338:    }
        -:  339:
        2:  340:  _dbus_string_free (&config_file);
call    0 returned 100%
        -:  341:  
        2:  342:  return context;
        -:  343:}
        -:  344:
        -:  345:#endif