File: polkittesthelper.c

package info (click to toggle)
policykit-1 0.105-15~deb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 8,644 kB
  • ctags: 4,294
  • sloc: ansic: 18,560; sh: 11,430; xml: 3,384; makefile: 767
file content (68 lines) | stat: -rw-r--r-- 2,011 bytes parent folder | download | duplicates (8)
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
/*
 * Copyright (C) 2011 Google Inc.
 *
 * 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 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., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Nikki VonHollen <vonhollen@google.com>
 */

#include "polkittesthelper.h"
#include <stdlib.h>


/* TODO: Log handling with unit tests is horrible. Figure out a way to always
 *       show logs, without munging up test output. For now, we hide them
 *       unless --verbose is used with g_test_message(...).
 */

void
polkit_test_log_handler (const gchar *log_domain,
                         GLogLevelFlags log_level,
                         const gchar *message,
                         gpointer user_data)
{
  g_test_message("%s", message);
}

/**
 * Send all future log messages to g_test_message(...).
 *
 * Logs will only be shown when test programs are run with --verbose.
 */
void
polkit_test_redirect_logs (void)
{
  g_log_set_default_handler (polkit_test_log_handler, NULL);
}

/**
 * Get absolute path to test data.
 *
 * Requires POLKIT_TEST_DATA environment variable to point to root data dir.
 *
 * @param relpath Relative path to test data
 * @return Full path to data as string. Free with g_free().
 */
gchar *
polkit_test_get_data_path (const gchar *relpath)
{
  const gchar *root = getenv ("POLKIT_TEST_DATA");
  if (root == NULL)
    return NULL;

  return g_strconcat(root, "/", relpath, NULL);
}