msxml3: Fold in reset_output_buffer.
[wine/zf.git] / programs / fsutil / tests / fsutil.c
blobeff47a4f8ec8bc4dc277d37d1ce523a14a88cd30
1 /*
2 * Copyright 2020 Arkadiusz Hiler for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <windows.h>
20 #include <stdio.h>
22 #include "wine/test.h"
24 static BOOL is_process_elevated(void)
26 HANDLE token;
27 if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token ))
29 TOKEN_ELEVATION_TYPE type;
30 DWORD size;
31 BOOL ret;
33 ret = GetTokenInformation( token, TokenElevationType, &type, sizeof(type), &size );
34 CloseHandle( token );
35 return (ret && type == TokenElevationTypeFull);
37 return FALSE;
40 static DWORD runcmd(const char* cmd)
42 STARTUPINFOA si = { sizeof(STARTUPINFOA) };
43 PROCESS_INFORMATION pi;
44 char* wcmd;
45 DWORD rc;
47 /* Create a writable copy for CreateProcessA() */
48 wcmd = HeapAlloc(GetProcessHeap(), 0, strlen(cmd) + 1);
49 strcpy(wcmd, cmd);
51 rc = CreateProcessA(NULL, wcmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
52 HeapFree(GetProcessHeap(), 0, wcmd);
54 if (!rc)
55 return 260;
57 rc = WaitForSingleObject(pi.hProcess, 5000);
59 if (rc == WAIT_OBJECT_0)
60 GetExitCodeProcess(pi.hProcess, &rc);
61 else
62 TerminateProcess(pi.hProcess, 1);
64 CloseHandle(pi.hThread);
65 CloseHandle(pi.hProcess);
67 return rc;
70 static void test_hardlink(void)
72 DWORD rc;
73 BOOL boolrc;
74 HANDLE hfile;
75 BY_HANDLE_FILE_INFORMATION info;
77 hfile = CreateFileA("file", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
78 FILE_ATTRIBUTE_NORMAL, NULL);
79 ok(hfile != INVALID_HANDLE_VALUE, "failed to create a file\n");
80 CloseHandle(hfile);
82 rc = runcmd("fsutil");
83 if (rc == 1 && !is_process_elevated())
85 win_skip("Cannot run fsutil without elevated privileges on Windows <= 7\n");
86 return;
88 ok(rc == 0, "failed to run fsutil\n");
90 rc = runcmd("fsutil hardlink");
91 ok(rc == 0, "failed to run fsutil hardlink\n");
93 rc = runcmd("fsutil hardlink create link file");
94 ok(rc == 0, "failed to create a hardlink\n");
96 hfile = CreateFileA("link", GENERIC_READ, 0, NULL, OPEN_EXISTING,
97 FILE_ATTRIBUTE_NORMAL, NULL);
98 ok(hfile != INVALID_HANDLE_VALUE, "failed to open the hardlink\n");
99 boolrc = GetFileInformationByHandle(hfile, &info);
100 ok(boolrc, "failed to get info about hardlink, error %#x\n", GetLastError());
101 CloseHandle(hfile);
103 ok(info.nNumberOfLinks == 2, "our link is not a hardlink");
105 rc = runcmd("fsutil hardlink create link file");
106 ok(rc == 1, "fsutil didn't complain about already existing destination\n");
108 rc = runcmd("fsutil hardlink create newlink nonexistingfile");
109 ok(rc == 1, "fsutil didn't complain about nonexisting source file\n");
111 boolrc = DeleteFileA("link");
112 ok(boolrc, "failed to delete the hardlink, error %#x\n", GetLastError());
113 boolrc = DeleteFileA("file");
114 ok(boolrc, "failed to delete the file, error %#x\n", GetLastError());
117 START_TEST(fsutil)
119 char tmpdir[MAX_PATH];
121 GetTempPathA(MAX_PATH, tmpdir);
122 SetCurrentDirectoryA(tmpdir);
124 test_hardlink();