[libsoup/wip/meson] tests: Fix build on Visual Studio



commit 8bb0199a08d940ccecaf6677c43b02b47ec10e39
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Dec 4 17:16:58 2017 +0800

    tests: Fix build on Visual Studio
    
    Visual Studio does not come with unistd.h, so we have to:
    -Avoid including unistd.h when on Windows
    -Include the other necessary headers that contain the things we actually
     use that are in the other posixish systems' unistd.h
    -Define sleep() to use the Windows API's Sleep funcions, where we must
     multiply the argument we pass into it by 1000.
    
    The test programs now build on Visual Studio, but there are some
    UNIXisms that need to be checked, though.

 tests/auth-test.c      |    7 +++++++
 tests/multipart-test.c |    5 ++++-
 tests/socket-test.c    |    4 ++++
 3 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 1144dec..32211d2 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -5,6 +5,13 @@
 static const char *base_uri;
 static GMainLoop *loop;
 
+#if defined (G_OS_WIN32) && defined (_MSC_VER)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#define sleep(x) Sleep (x * 1000)
+#endif
+
 typedef struct {
        /* Explanation of what you should see */
        const char *explanation;
diff --git a/tests/multipart-test.c b/tests/multipart-test.c
index 488865a..64a5ebf 100644
--- a/tests/multipart-test.c
+++ b/tests/multipart-test.c
@@ -6,10 +6,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 
 #include "test-utils.h"
 
+#ifndef G_OS_WIN32
+#include <unistd.h>
+#endif
+
 #define READ_BUFFER_SIZE 8192
 
 typedef enum {
diff --git a/tests/socket-test.c b/tests/socket-test.c
index 5b2b390..10229ff 100644
--- a/tests/socket-test.c
+++ b/tests/socket-test.c
@@ -10,6 +10,10 @@
 #include <fcntl.h>
 #include <gio/gnetworking.h>
 
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
+
 static void
 do_unconnected_socket_test (void)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]