LCOV - code coverage report
Current view: top level - libsystemd/sd-bus - test-bus-vtable.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 18 18 100.0 %
Date: 2019-08-22 15:41:25 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <stdbool.h>
       4             : #include <stddef.h>
       5             : 
       6             : /* We use system assert.h here, because we don't want to keep macro.h and log.h C++ compatible */
       7             : #undef NDEBUG
       8             : #include <assert.h>
       9             : #include <errno.h>
      10             : #include <stdio.h>
      11             : 
      12             : #include "sd-bus-vtable.h"
      13             : 
      14             : #ifndef __cplusplus
      15             : #  include "bus-objects.h"
      16             : #endif
      17             : 
      18             : #include "test-vtable-data.h"
      19             : 
      20             : #define DEFAULT_BUS_PATH "unix:path=/run/dbus/system_bus_socket"
      21             : 
      22           1 : static void test_vtable(void) {
      23           1 :         sd_bus *bus = NULL;
      24           1 :         struct context c = {};
      25             :         int r;
      26             : 
      27           1 :         assert(sd_bus_new(&bus) >= 0);
      28             : 
      29           1 :         assert(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.testVtable", test_vtable_2, &c) >= 0);
      30           1 :         assert(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.testVtable2", test_vtable_2, &c) >= 0);
      31             :         /* the cast on the line below is needed to test with the old version of the table */
      32           1 :         assert(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.testVtable221",
      33             :                                         (const sd_bus_vtable *)vtable_format_221, &c) >= 0);
      34             : 
      35           1 :         assert(sd_bus_set_address(bus, DEFAULT_BUS_PATH) >= 0);
      36           1 :         r = sd_bus_start(bus);
      37           1 :         assert(r == 0 ||     /* success */
      38             :                r == -ENOENT  /* dbus is inactive */ );
      39             : 
      40             : #ifndef __cplusplus
      41           1 :         _cleanup_free_ char *s = NULL;
      42             : 
      43           1 :         assert_se(introspect_path(bus, "/foo", NULL, false, true, NULL, &s, NULL) == 1);
      44           1 :         fputs(s, stdout);
      45             : #endif
      46             : 
      47           1 :         sd_bus_unref(bus);
      48           1 : }
      49             : 
      50           1 : int main(int argc, char **argv) {
      51           1 :         test_vtable();
      52             : 
      53           1 :         return 0;
      54             : }

Generated by: LCOV version 1.14