LCOV - code coverage report
Current view: top level - test - test-bus-util.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 26 30 86.7 %
Date: 2019-08-23 13:36:53 Functions: 3 4 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 26 46.2 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include "bus-util.h"
       4                 :            : #include "log.h"
       5                 :            : #include "tests.h"
       6                 :            : 
       7                 :          0 : static int callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
       8                 :          0 :         return 1;
       9                 :            : }
      10                 :            : 
      11                 :          4 : static void destroy_callback(void *userdata) {
      12                 :          4 :         int *n_called = userdata;
      13                 :            : 
      14                 :          4 :         (*n_called) ++;
      15                 :          4 : }
      16                 :            : 
      17                 :          4 : static void test_destroy_callback(void) {
      18         [ +  - ]:          4 :         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
      19                 :          4 :         sd_bus_slot *slot = NULL;
      20                 :            :         sd_bus_destroy_t t;
      21                 :            : 
      22                 :          4 :         int r, n_called = 0;
      23                 :            : 
      24         [ +  - ]:          4 :         log_info("/* %s */", __func__);
      25                 :            : 
      26                 :          4 :         r = bus_open_system_watch_bind_with_description(&bus, "test-bus");
      27         [ -  + ]:          4 :         if (r < 0) {
      28         [ #  # ]:          0 :                 log_error_errno(r, "Failed to connect to bus: %m");
      29                 :          0 :                 return;
      30                 :            :         }
      31                 :            : 
      32                 :          4 :         r = sd_bus_request_name_async(bus, &slot, "org.freedesktop.systemd.test-bus-util", 0, callback, &n_called);
      33         [ -  + ]:          4 :         assert(r == 1);
      34                 :            : 
      35         [ -  + ]:          4 :         assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 0);
      36         [ -  + ]:          4 :         assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 0);
      37                 :            : 
      38         [ -  + ]:          4 :         assert_se(sd_bus_slot_set_destroy_callback(slot, destroy_callback) == 0);
      39         [ -  + ]:          4 :         assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 1);
      40         [ -  + ]:          4 :         assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 1);
      41         [ -  + ]:          4 :         assert_se(t == destroy_callback);
      42                 :            : 
      43                 :            :         /* Force cleanup so we can look at n_called */
      44         [ -  + ]:          4 :         assert(n_called == 0);
      45                 :          4 :         sd_bus_slot_unref(slot);
      46         [ -  + ]:          4 :         assert(n_called == 1);
      47                 :            : }
      48                 :            : 
      49                 :          4 : int main(int argc, char **argv) {
      50                 :          4 :         test_setup_logging(LOG_DEBUG);
      51                 :            : 
      52                 :          4 :         test_destroy_callback();
      53                 :            : 
      54                 :          4 :         return 0;
      55                 :            : }

Generated by: LCOV version 1.14