summaryrefslogtreecommitdiff
path: root/test/manual-paths.c
blob: 0334c71297f2395a5ad5840ea37cb5d2c8635df7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * Copyright 2015 Ralf Habacker
 * Copyright 2015-2020 Collabora Ltd.
 * SPDX-License-Identifier: MIT
 *
 * Simple manual paths check
 *
 * syntax:  manual-paths
 *
*/

#include "config.h"
#include "dbus/dbus-list.h"
#include "dbus/dbus-internals.h"
#include "dbus/dbus-sysdeps.h"
#include "test-utils.h"

#include <stdio.h>

static dbus_bool_t
print_install_root (void)
{
  DBusString runtime_prefix;

  if (!_dbus_string_init (&runtime_prefix))
    {
      _dbus_test_fatal ("out of memory");
      return FALSE;
    }

  if (!_dbus_get_install_root (&runtime_prefix))
    {
      _dbus_test_fatal ("out of memory");
      _dbus_string_free (&runtime_prefix);
      return FALSE;
    }

  if (_dbus_string_get_length (&runtime_prefix) == 0)
    {
      fprintf (stderr, "_dbus_get_install_root() failed\n");
      _dbus_string_free (&runtime_prefix);
      return FALSE;
    }

  fprintf (stdout, "_dbus_get_install_root() returned '%s'\n",
      _dbus_string_get_const_data (&runtime_prefix));
  _dbus_string_free (&runtime_prefix);
  return TRUE;
}

static dbus_bool_t
print_service_dirs (void)
{
  DBusList *dirs;
  DBusList *link;
  dirs = NULL;

  if (!_dbus_get_standard_session_servicedirs (&dirs))
    _dbus_test_fatal ("couldn't get standard dirs");

  while ((link = _dbus_list_pop_first_link (&dirs)))
    {
      printf ("default service dir: %s\n", (char *)link->data);
      dbus_free (link->data);
      _dbus_list_free_link (link);
    }
  dbus_free (dirs);
  return TRUE;
}

static dbus_bool_t print_replace_install_prefix(const char *s)
{
  DBusString str;

  if (!_dbus_string_init (&str))
    {
      _dbus_test_fatal ("out of memory");
      return FALSE;
    }

  if (!_dbus_string_append (&str, s) ||
      !_dbus_replace_install_prefix (&str))
    {
      _dbus_test_fatal ("out of memory");
      _dbus_string_free (&str);
      return FALSE;
    }

  fprintf(stdout, "replaced '%s' by '%s'\n", s,
      _dbus_string_get_const_data (&str));
  _dbus_string_free (&str);
  return TRUE;
}

int
main (int argc, char **argv)
{
  if (!print_install_root())
    return -1;

  if (!print_service_dirs())
    return -2;

  if (!print_replace_install_prefix(DBUS_BINDIR "/dbus-daemon"))
    return -3;

  if (!print_replace_install_prefix("c:\\Windows\\System32\\testfile"))
    return -4;

  return 0;
}