Force binary mode for stdout in printf tests

This allows test calls to produce output with \n
line separators on Windows, instead of \r\n.
Reduces the number of ifdefs, since all checks
can be done against one template on all platforms.
This commit is contained in:
Руслан Ижбулатов 2018-06-09 00:00:58 +00:00
parent e3280675f5
commit ce1e32ec34

View File

@ -24,6 +24,10 @@
#include <string.h>
#include "glib.h"
#include "gstdio.h"
#ifdef G_OS_WIN32
#include <io.h>
#include <fcntl.h>
#endif
static void
test_retval_and_trunc (void)
@ -637,11 +641,7 @@ test_positional_params2 (void)
}
g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_passed ();
#ifndef G_OS_WIN32
g_test_trap_assert_stdout ("a b\n ab\nabcabc\n");
#else
g_test_trap_assert_stdout ("a b\r\n ab\r\nabcabc\r\n");
#endif
}
static void
@ -858,25 +858,17 @@ _Pragma ("GCC diagnostic pop")
static void
test_64bit2 (void)
{
#ifndef G_OS_WIN32
g_test_trap_subprocess ("/printf/test-64bit/subprocess/base", 0, 0);
g_test_trap_assert_passed ();
g_test_trap_assert_stdout ("123456\n-123456\n123456\n"
"361100\n0361100\n1e240\n"
"0x1e240\n1E240\n");
#else
g_test_trap_subprocess ("/printf/test-64bit/subprocess/base", 0, 0);
g_test_trap_assert_passed ();
g_test_trap_assert_stdout ("123456\r\n-123456\r\n123456\r\n"
"361100\r\n0361100\r\n1e240\r\n"
"0x1e240\r\n1E240\r\n");
#ifdef G_OS_WIN32
g_test_trap_subprocess ("/printf/test-64bit/subprocess/win32", 0, 0);
g_test_trap_assert_passed ();
g_test_trap_assert_stdout ("123456\r\n-123456\r\n123456\r\n"
"361100\r\n0361100\r\n1e240\r\n"
"0x1e240\r\n1E240\r\n");
g_test_trap_assert_stdout ("123456\n-123456\n123456\n"
"361100\n0361100\n1e240\n"
"0x1e240\n1E240\n");
#endif
}
@ -907,6 +899,13 @@ int
main (int argc,
char *argv[])
{
#ifdef G_OS_WIN32
/* Ensure binary mode for stdout, this way
* tests produce \n line endings on Windows instead of the
* default \r\n.
*/
_setmode (fileno (stdout), _O_BINARY);
#endif
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/snprintf/retval-and-trunc", test_retval_and_trunc);