From 5a60c0bca5d91ba701ca4a2f9bcfae9eec65253b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 2 Jul 2022 17:33:56 +0100 Subject: [PATCH] Move assertion/test utilities to a separate header A lot of recent convenience APIs can easily be backported, but they'll clutter glnx-backports.h. In preparation, split these out. Another reason to separate these is that when we start adding backports of test utilities that need implementation code in the libglnx static library, we'll want their implementations to be in a separate translation unit, so that they don't get linked into production executables, only into tests. Signed-off-by: Simon McVittie --- Makefile-libglnx.am | 1 + glnx-backport-testutils.h | 43 +++++++++++++++++++++++++++++++++++++++ glnx-backports.h | 12 ----------- libglnx.h | 1 + meson.build | 1 + 5 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 glnx-backport-testutils.h diff --git a/Makefile-libglnx.am b/Makefile-libglnx.am index bea7b13f..f699ff2d 100644 --- a/Makefile-libglnx.am +++ b/Makefile-libglnx.am @@ -33,6 +33,7 @@ libglnx_la_SOURCES = \ $(libglnx_srcpath)/glnx-macros.h \ $(libglnx_srcpath)/glnx-backport-autocleanups.h \ $(libglnx_srcpath)/glnx-backport-autoptr.h \ + $(libglnx_srcpath)/glnx-backport-testutils.h \ $(libglnx_srcpath)/glnx-backports.h \ $(libglnx_srcpath)/glnx-backports.c \ $(libglnx_srcpath)/glnx-local-alloc.h \ diff --git a/glnx-backport-testutils.h b/glnx-backport-testutils.h new file mode 100644 index 00000000..f43c204b --- /dev/null +++ b/glnx-backport-testutils.h @@ -0,0 +1,43 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * Copyright 2015 Colin Walters + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#pragma once + +#include + +#include "glnx-backports.h" + +G_BEGIN_DECLS + +#ifndef g_assert_nonnull +#define g_assert_nonnull(x) g_assert (x != NULL) +#endif + +#ifndef g_assert_null +#define g_assert_null(x) g_assert (x == NULL) +#endif + +#if !GLIB_CHECK_VERSION (2, 38, 0) +#define g_test_skip(s) g_test_message ("SKIP: %s", s) +#endif + +G_END_DECLS diff --git a/glnx-backports.h b/glnx-backports.h index 6f766a37..b535e2df 100644 --- a/glnx-backports.h +++ b/glnx-backports.h @@ -84,16 +84,4 @@ gboolean glnx_set_object (GObject **object_ptr, #define G_OPTION_ENTRY_NULL { NULL, 0, 0, 0, NULL, NULL, NULL } #endif -#ifndef g_assert_nonnull -#define g_assert_nonnull(x) g_assert (x != NULL) -#endif - -#ifndef g_assert_null -#define g_assert_null(x) g_assert (x == NULL) -#endif - -#if !GLIB_CHECK_VERSION (2, 38, 0) -#define g_test_skip(s) g_test_message ("SKIP: %s", s) -#endif - G_END_DECLS diff --git a/libglnx.h b/libglnx.h index ca82ba5c..63d73adc 100644 --- a/libglnx.h +++ b/libglnx.h @@ -29,6 +29,7 @@ G_BEGIN_DECLS #include #include #include +#include #include #include #include diff --git a/meson.build b/meson.build index 4787c859..86535a8a 100644 --- a/meson.build +++ b/meson.build @@ -57,6 +57,7 @@ libglnx_inc = include_directories('.') libglnx_sources = [ 'glnx-backport-autocleanups.h', 'glnx-backport-autoptr.h', + 'glnx-backport-testutils.h', 'glnx-backports.c', 'glnx-backports.h', 'glnx-console.c',