summaryrefslogtreecommitdiff
path: root/tests/lib/logger-test-helper.c
blob: fd20bafbd12c5b31c883540cf7b594d37900f04b (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
/*
 * logger-test-helper.c
 *
 * Copyright (C) 2013 Collabora Ltd. <http://www.collabora.co.uk/>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <config.h>

#include "logger-test-helper.h"

#include <stdlib.h>

#include "util.h"

void
tpl_test_create_and_prepare_account (TpDBusDaemon *dbus,
    TpClientFactory *factory,
    const gchar *path,
    TpAccount **account,
    TpTestsSimpleAccount **account_service)
{
  GError *error = NULL;
  GArray *features;
  GQuark zero = 0;

  *account_service = g_object_new (TP_TESTS_TYPE_SIMPLE_ACCOUNT,
      NULL);
  g_assert (*account_service != NULL);

  tp_dbus_daemon_register_object (dbus, path, *account_service);

  *account = tp_client_factory_ensure_account (factory, path, NULL,
      &error);
  g_assert_no_error (error);
  g_assert (*account != NULL);

  features = tp_client_factory_dup_account_features (factory, *account);
  g_array_append_val (features, zero);

  tp_tests_proxy_run_until_prepared (*account, (GQuark *) features->data);
  g_array_free (features, FALSE);
}

void
tpl_test_release_account (TpDBusDaemon *dbus,
    TpAccount *account,
    TpTestsSimpleAccount *account_service)
{
  tp_dbus_daemon_unregister_object (dbus, account_service);
  g_object_unref (account_service);
  g_object_unref (account);
}

void
tp_tests_copy_dir (const gchar *from_dir, const gchar *to_dir)
{
  gchar *command;

  // If destination directory exist erase it
  command = g_strdup_printf ("rm -rf %s", to_dir);
  g_assert (system (command) == 0);
  g_free (command);

  command = g_strdup_printf ("cp -r %s %s", from_dir, to_dir);
  g_assert (system (command) == 0);
  g_free (command);

  // In distcheck mode the files and directory are read-only, fix that
  command = g_strdup_printf ("chmod -R +w %s", to_dir);
  g_assert (system (command) == 0);
  g_free (command);
}