ReactOS 0.4.16-dev-927-g467dec4
PathMakeUniqueName.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Tests for PathMakeUniqueName
5 * COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8#include "shelltest.h"
9#include <stdio.h>
10#include <versionhelpers.h>
11
12#define ok_wstri(x, y) \
13 ok(_wcsicmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
14
15/* IsLFNDriveW */
17
19{
20 WCHAR szPath[MAX_PATH], szCurDir[MAX_PATH], szTempDir[MAX_PATH];
21 BOOL result, bUseLong = FALSE;
22 FN_IsLFNDriveW pIsLFNDriveW =
24
25 // Move to temporary folder
26 GetCurrentDirectoryW(_countof(szCurDir), szCurDir);
27 GetEnvironmentVariableW(L"TEMP", szTempDir, _countof(szTempDir));
28 SetCurrentDirectoryW(szTempDir);
29
30 if (pIsLFNDriveW)
31 bUseLong = pIsLFNDriveW(szTempDir) && IsWindowsVistaOrGreater();
32 trace("bUseLong: %d\n", bUseLong);
33
34 DeleteFileW(L"test.txt");
35
36 // Test 1: Basic operation
40 ok_wstri(szPath, L"test (1).txt");
41
42 // Test 2: Specify directory
46 ok_wstri(szPath, (bUseLong ? L".\\test (1).txt" : L".\\test1.txt"));
47
48 // Test 3: Duplicated filename
53 ok_wstri(szPath, L"test (1).txt");
54 DeleteFileW(L"test.txt");
55
56 // Build long name
57 WCHAR longName[MAX_PATH + 32];
58 for (auto& ch : longName)
59 ch = L'A';
60 longName[_countof(longName) - 10] = UNICODE_NULL;
61 lstrcatW(longName, L".txt");
62
63 // Test 4: Long filename
67 ok_wstri(szPath, L"");
68
69 // Test 5: Invalid parameter
71 result = PathMakeUniqueName(NULL, 0, L"test.txt", NULL, NULL);
73
74 // Test 6: Template and longplate
76 result = PathMakeUniqueName(szPath, _countof(szPath), L"template.txt", L"longplate.txt", NULL);
78 ok_wstri(szPath, L"longplate (1).txt");
79
80 // Test 7: Template only
84 ok_wstri(szPath, L"template (1).txt");
85
86 // Test 8: Folder and duplicated filename
91 ok_wstri(szPath, (bUseLong ? L".\\test (1).txt" : L".\\test1.txt"));
92 DeleteFileW(L".\\test.txt");
93
94 // Test 9: Test extension
97 result = PathMakeUniqueName(szPath, _countof(szPath), L"test.hoge", NULL, L".");
99 ok_wstri(szPath, (bUseLong ? L".\\test (1).hoge" : L".\\test1.hoge"));
100 DeleteFileW(L".\\test.hoge");
101
102 // Test 10: Folder in folder
103 CreateDirectoryW(L".\\hoge", NULL);
104 szPath[0] = UNICODE_NULL;
105 result = PathMakeUniqueName(szPath, _countof(szPath), L"test.txt", NULL, L".\\hoge");
107 ok_wstri(szPath, (bUseLong ? L".\\hoge\\test (1).txt" : L".\\hoge\\test1.txt"));
108 RemoveDirectoryW(L".\\hoge");
109
110 // Test 11: File in folder
112 szPath[0] = UNICODE_NULL;
113 result = PathMakeUniqueName(szPath, _countof(szPath), L"test.txt", NULL, L".");
115 ok_wstri(szPath, (bUseLong ? L".\\test (1).txt" : L".\\test1.txt"));
116 DeleteFileW(L".\\hoge.txt");
117
118 SetCurrentDirectoryW(szCurDir);
119}
#define ok_wstri(x, y)
BOOL(WINAPI * FN_IsLFNDriveW)(LPCWSTR)
#define trace
Definition: atltest.h:70
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2249
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint64EXT * result
Definition: glext.h:11304
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
#define CREATE_ALWAYS
Definition: disk.h:72
LPCWSTR szPath
Definition: env.c:37
#define BOOL
Definition: nt_native.h:43
#define GENERIC_WRITE
Definition: nt_native.h:90
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
BOOL WINAPI PathMakeUniqueName(_Out_ PWSTR pszUniqueName, _In_ UINT cchMax, _In_ PCWSTR pszTemplate, _In_opt_ PCWSTR pszLongPlate, _In_opt_ PCWSTR pszDir)
#define _countof(array)
Definition: sndvol32.h:70
VERSIONHELPERAPI IsWindowsVistaOrGreater()
#define WINAPI
Definition: msvc.h:6
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185