summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-01-14 20:16:01 -0600
committerEdward Thomson <ethomson@microsoft.com>2015-01-19 13:28:47 -0600
commit5331ba770212167dc8a408904db61419d5d868b4 (patch)
treeb5f291bcb6548d697cde2c90a4cc1ee816ce6fa9
parent90bc025f487b2f10960400fa990403784747345a (diff)
downloadlibgit2-5331ba770212167dc8a408904db61419d5d868b4.tar.gz
checkout tests: emulate p_realpath poorly on Win32
-rw-r--r--tests/checkout/icase.c65
1 files changed, 64 insertions, 1 deletions
diff --git a/tests/checkout/icase.c b/tests/checkout/icase.c
index 625f19627..a6c9073cf 100644
--- a/tests/checkout/icase.c
+++ b/tests/checkout/icase.c
@@ -3,6 +3,10 @@
#include "git2/checkout.h"
#include "path.h"
+#ifdef GIT_WIN32
+# include <Windows.h>
+#endif
+
static git_repository *repo;
static git_object *obj;
static git_checkout_options checkout_opts;
@@ -26,12 +30,71 @@ void test_checkout_icase__cleanup(void)
cl_git_sandbox_cleanup();
}
+static char *p_realpath(const char *in)
+{
+#ifdef GIT_WIN32
+ /*
+
+ HANDLE fh, mh;
+ HINSTANCE psapi;
+ BY_HANDLE_FILE_INFORMATION fi;
+ void *map;
+ char *filename;
+ size_t filename_len = 1024;
+
+ typedef DWORD (__stdcall *getmappedfilename)(HANDLE, LPVOID, LPTSTR, DWORD);
+ getmappedfilename getfunc;
+
+ cl_assert(filename = malloc(filename_len));
+
+ cl_win32_pass(psapi = LoadLibrary("psapi.dll"));
+ cl_win32_pass(getfunc = (getmappedfilename)GetProcAddress(psapi, "GetMappedFileNameA"));
+
+ cl_win32_pass(fh = CreateFileA(in, GENERIC_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
+ cl_win32_pass(mh = CreateFileMapping(fh, NULL, PAGE_READONLY, 0, 1, NULL));
+
+ cl_win32_pass(map = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, 1));
+
+ cl_win32_pass(getfunc(GetCurrentProcess(), map, filename, filename_len));
+
+ UnmapViewOfFile(map);
+ CloseHandle(mh);
+ CloseHandle(fh);
+*/
+
+ HANDLE fh;
+ HINSTANCE kerneldll;
+ char *filename;
+
+ typedef DWORD (__stdcall *getfinalpathname)(HANDLE, LPSTR, DWORD, DWORD);
+ getfinalpathname getfinalpathfn;
+
+ cl_assert(filename = malloc(MAX_PATH));
+ cl_win32_pass(kerneldll = LoadLibrary("kernel32.dll"));
+ cl_win32_pass(getfinalpathfn = (getfinalpathname)GetProcAddress(kerneldll, "GetFinalPathNameByHandleA"));
+
+ cl_win32_pass(fh = CreateFileA(in, FILE_READ_ATTRIBUTES | STANDARD_RIGHTS_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL));
+
+ cl_win32_pass(getfinalpathfn(fh, filename, MAX_PATH, VOLUME_NAME_DOS));
+
+ CloseHandle(fh);
+
+ git_path_mkposix(filename);
+
+ return filename;
+#else
+ return realpath(in, NULL);
+#endif
+}
+
static void assert_name_is(const char *expected)
{
char *actual;
size_t actual_len, expected_len, start;
- cl_assert(actual = realpath(expected, NULL));
+ cl_assert(actual = p_realpath(expected));
expected_len = strlen(expected);
actual_len = strlen(actual);