1 /*
2 * Copyright © 2020 Red Hat, Inc.
3 *
4 * Author: Jakub Jelen <jjelen@redhat.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * See the included COPYING file for more information.
14 */
15
16 #include <glib.h>
17
18 /* The function g_get_user_database_entry() is called from the
19 * g_get_real_name(), g_get_user_name() and g_build_home_dir()
20 * functions. These two calls are here just to invoke the code
21 * paths. The real-test is the ld_preload used to inject the
22 * NULL in place of pw->pw_name.
23 */
24 static void
25 test_get_user_database_entry (void)
26 {
27 const gchar *r = NULL;
28
29 r = g_get_user_name ();
30 g_assert_cmpstr (r, ==, "somebody");
31
32 r = g_get_real_name ();
33 g_assert_cmpstr (r, ==, "Unknown");
34 }
35
36 int
37 main (int argc, char *argv[])
38 {
39 g_test_init (&argc, &argv, NULL);
40
41 g_test_add_func ("/gutils/get_user_database_entry", test_get_user_database_entry);
42
43 return g_test_run ();
44 }