tests: Break out assert_fd_was_closed() into a header

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2023-05-31 12:00:28 +01:00 committed by Philip Withnall
parent f31db7d370
commit 26c7b308ba
3 changed files with 53 additions and 20 deletions

View File

@ -35,6 +35,7 @@ if get_option('gtk_doc')
'glib-init.h',
'gconstructor.h',
'gconstructorprivate.h',
'testutils.h',
'valgrind.h',
'gutilsprivate.h',
'gvalgrind.h',

View File

@ -60,6 +60,8 @@
#define G_TEST_DIR_MODE (S_IWRITE | S_IREAD)
#endif
#include "testutils.h"
#define S G_DIR_SEPARATOR_S
static void
@ -2473,26 +2475,6 @@ test_win32_zero_terminate_symlink (void)
#endif
static void
assert_fd_was_closed (int fd)
{
/* We can't tell a fd was really closed without behaving as though it
* was still valid */
if (g_test_undefined ())
{
int result, errsv;
GWin32InvalidParameterHandler handler;
GLIB_PRIVATE_CALL (g_win32_push_empty_invalid_parameter_handler) (&handler);
result = g_fsync (fd);
errsv = errno;
GLIB_PRIVATE_CALL (g_win32_pop_invalid_parameter_handler) (&handler);
g_assert_cmpint (result, !=, 0);
g_assert_cmpint (errsv, ==, EBADF);
}
}
static void
test_clear_fd_ebadf (void)
{

50
glib/tests/testutils.h Normal file
View File

@ -0,0 +1,50 @@
/*
* Copyright 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright 2023 Collabora Ltd.
*
* SPDX-License-Identifier: LicenseRef-old-glib-tests
*
* This work is provided "as is"; redistribution and modification
* in whole or in part, in any medium, physical or electronic is
* permitted without restriction.
*
* This work 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.
*
* In no event shall the authors or contributors be liable for any
* direct, indirect, incidental, special, exemplary, or consequential
* damages (including, but not limited to, procurement of substitute
* goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether
* in contract, strict liability, or tort (including negligence or
* otherwise) arising in any way out of the use of this software, even
* if advised of the possibility of such damage.
*/
#include "config.h"
#include <errno.h>
#include "glib-private.h"
#include "gstdio.h"
static inline void
assert_fd_was_closed (int fd)
{
/* We can't tell a fd was really closed without behaving as though it
* was still valid */
if (g_test_undefined ())
{
int result, errsv;
GWin32InvalidParameterHandler handler;
GLIB_PRIVATE_CALL (g_win32_push_empty_invalid_parameter_handler) (&handler);
result = g_fsync (fd);
errsv = errno;
GLIB_PRIVATE_CALL (g_win32_pop_invalid_parameter_handler) (&handler);
g_assert_cmpint (result, !=, 0);
g_assert_cmpint (errsv, ==, EBADF);
}
}