File: testlib.h

package info (click to toggle)
flatpak 1.16.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,020 kB
  • sloc: ansic: 101,028; xml: 11,453; sh: 4,871; python: 2,251; yacc: 1,236; makefile: 86; csh: 20
file content (97 lines) | stat: -rw-r--r-- 3,158 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright © 2018-2021 Collabora Ltd.
 *
 * This program 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, see <http://www.gnu.org/licenses/>.
 */

#ifndef TESTLIB_H
#define TESTLIB_H

#include <glib.h>
#include <gio/gio.h>
#include <libglnx.h>

char *assert_mkdtemp (char *tmpl);

extern char *isolated_test_dir;
void isolated_test_dir_global_setup (void);
void isolated_test_dir_global_teardown (void);

typedef struct
{
  GSubprocess *dbus_daemon;
  gchar *dbus_address;
  gchar *temp_dir;
} TestsDBusDaemon;

void tests_dbus_daemon_setup (TestsDBusDaemon *self);
void tests_dbus_daemon_teardown (TestsDBusDaemon *self);

typedef struct _TestsStdoutToStderr TestsStdoutToStderr;
TestsStdoutToStderr *tests_stdout_to_stderr_begin (void);
void tests_stdout_to_stderr_end (TestsStdoutToStderr *original);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TestsStdoutToStderr, tests_stdout_to_stderr_end);

#define TESTS_SCOPED_STDOUT_TO_STDERR \
  G_GNUC_UNUSED g_autoptr(TestsStdoutToStderr) _tests_stdout_to_stderr = tests_stdout_to_stderr_begin ()

/*
 * assert_cmpstr_free_lhs:
 * @lhs: (transfer full): An expression returning an owned string,
 *  which will be freed
 * @op: Either `==`, `!=`, `<=`, `<`, `>` or `>=`
 * @rhs: (transfer none): An expression returning an unowned string
 *
 * Assert that @lhs has the given relationship with @rhs, then free @lhs.
 */
#define assert_cmpstr_free_lhs(lhs, op, rhs) \
  do { \
    g_autofree char *free_lhs = NULL; \
    g_assert_cmpstr ((free_lhs = (lhs)), op, (rhs)); \
  } while (0)

/*
 * assert_cmpstr_free_rhs:
 * @lhs: (transfer none): An expression returning an unowned string
 * @op: Either `==`, `!=`, `<=`, `<`, `>` or `>=`
 * @rhs: (transfer full): An expression returning an owned string,
 *  which will be freed
 *
 * Assert that @lhs has the given relationship with @rhs, then free @rhs.
 */
#define assert_cmpstr_free_rhs(lhs, op, rhs) \
  do { \
    g_autofree char *free_rhs = NULL; \
    g_assert_cmpstr ((lhs), op, (free_rhs = (rhs))); \
  } while (0)

/*
 * assert_cmpstr_free_both:
 * @lhs: (transfer full): An expression returning an owned string,
 *  which will be freed
 * @op: Either `==`, `!=`, `<=`, `<`, `>` or `>=`
 * @rhs: (transfer full): An expression returning an owned string,
 *  which will be freed
 *
 * Assert that @lhs has the given relationship with @rhs, then free both
 * strings.
 */
#define assert_cmpstr_free_both(lhs, op, rhs) \
  do { \
    g_autofree char *free_lhs = NULL; \
    g_autofree char *free_rhs = NULL; \
    g_assert_cmpstr ((free_lhs = (lhs)), op, (free_rhs = (rhs))); \
  } while (0)

#endif