Branch data Line data Source code
1 : : /* GIO - GLib Input, Output and Streaming Library 2 : : * 3 : : * Copyright 2019 Red Hat, Inc. 4 : : * 5 : : * SPDX-License-Identifier: LGPL-2.1-or-later 6 : : * 7 : : * This library is free software; you can redistribute it and/or 8 : : * modify it under the terms of the GNU Lesser General Public 9 : : * License as published by the Free Software Foundation; either 10 : : * version 2.1 of the License, or (at your option) any later version. 11 : : * 12 : : * This library is distributed in the hope that it will be useful, 13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 : : * Lesser General Public License for more details. 16 : : * 17 : : * You should have received a copy of the GNU Lesser General 18 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. 19 : : */ 20 : : 21 : : #include <gio/gio.h> 22 : : 23 : : static void 24 : 1 : test_dup_default (void) 25 : : { 26 : : GMemoryMonitor *monitor; 27 : : 28 : 1 : monitor = g_memory_monitor_dup_default (); 29 : 1 : g_assert_nonnull (monitor); 30 : 1 : g_object_unref (monitor); 31 : 1 : } 32 : : 33 : : static void 34 : 0 : warning_cb (GMemoryMonitor *m, 35 : : GMemoryMonitorWarningLevel level) 36 : : { 37 : 0 : char *str = g_enum_to_string (G_TYPE_MEMORY_MONITOR_WARNING_LEVEL, level); 38 : 0 : g_message ("Warning level: %s (%d)", str , level); 39 : 0 : g_free (str); 40 : 0 : } 41 : : 42 : : static void 43 : 0 : do_watch_memory (void) 44 : : { 45 : : GMemoryMonitor *m; 46 : : GMainLoop *loop; 47 : : 48 : 0 : m = g_memory_monitor_dup_default (); 49 : 0 : g_signal_connect (G_OBJECT (m), "low-memory-warning", 50 : : G_CALLBACK (warning_cb), NULL); 51 : : 52 : 0 : loop = g_main_loop_new (NULL, TRUE); 53 : 0 : g_main_loop_run (loop); 54 : 0 : } 55 : : 56 : : int 57 : 1 : main (int argc, char **argv) 58 : : { 59 : : int ret; 60 : : 61 [ - + - - ]: 1 : if (argc == 2 && !strcmp (argv[1], "--watch")) 62 : : { 63 : 0 : do_watch_memory (); 64 : 0 : return 0; 65 : : } 66 : : 67 : 1 : g_test_init (&argc, &argv, NULL); 68 : : 69 : 1 : g_test_add_func ("/memory-monitor/default", test_dup_default); 70 : : 71 : 1 : ret = g_test_run (); 72 : : 73 : 1 : return ret; 74 : : }