From b4f12a17aaa6e9badb25409e59cd32d0c549dbb7 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 8 May 2010 14:49:59 -0400 Subject: [PATCH] Implement regress_make_tempfile on win32 to test evbuffer_add_file (Conclusion: evbuffer_add_file is broken on win32, since it uses recv on a file.) --- test/regress_buffer.c | 4 +--- test/regress_main.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/test/regress_buffer.c b/test/regress_buffer.c index 291eee6e..fa24738e 100644 --- a/test/regress_buffer.c +++ b/test/regress_buffer.c @@ -583,7 +583,6 @@ test_evbuffer_reference(void *ptr) evbuffer_free(src); } -#ifndef WIN32 int _evbuffer_testing_use_sendfile(void); int _evbuffer_testing_use_mmap(void); int _evbuffer_testing_use_linear_file_access(void); @@ -643,7 +642,6 @@ test_evbuffer_add_file(void *ptr) evutil_closesocket(pair[1]); evbuffer_free(src); } -#endif #ifndef _EVENT_DISABLE_MM_REPLACEMENT static void * @@ -1544,9 +1542,9 @@ struct testcase_t evbuffer_testcases[] = { (void*)"sendfile" }, { "add_file_mmap", test_evbuffer_add_file, TT_FORK, &nil_setup, (void*)"mmap" }, +#endif { "add_file_linear", test_evbuffer_add_file, TT_FORK, &nil_setup, (void*)"linear" }, -#endif END_OF_TESTCASES }; diff --git a/test/regress_main.c b/test/regress_main.c index f9544b6c..822ea80b 100644 --- a/test/regress_main.c +++ b/test/regress_main.c @@ -28,6 +28,8 @@ #ifdef WIN32 #include #include +#include +#include #endif #include "event-config.h" @@ -43,7 +45,6 @@ #include #endif #include -#include #include #include #endif @@ -125,8 +126,30 @@ regress_make_tmpfile(const void *data, size_t datalen) unlink(tmpfilename); return (fd); #else - /* we need a windows implementation here */ - return (-1); + /* XXXX actually delete the file later */ + char tmpfilepath[MAX_PATH]; + char tmpfilename[MAX_PATH]; + DWORD r, written; + int tries = 16; + HANDLE h; + r = GetTempPathA(MAX_PATH, tmpfilepath); + if (r > MAX_PATH || r == 0) + return (-1); + for (; tries > 0; --tries) { + r = GetTempFileNameA(tmpfilepath, "LIBEVENT", 0, tmpfilename); + if (r == 0) + return (-1); + h = CreateFileA(tmpfilename, GENERIC_READ|GENERIC_WRITE, + 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (h != INVALID_HANDLE_VALUE) + break; + } + if (tries == 0) + return (-1); + written = 0; + WriteFile(h, data, datalen, &written, NULL); + /* Closing the fd returned by this function will indeed close h. */ + return _open_osfhandle((intptr_t)h,_O_RDONLY); #endif } -- 2.50.1