[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / kernel32 / SetCurrentDirectory.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for SetCurrentDirectory
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <stdio.h>
12 #include <ndk/rtltypes.h>
13
14 static
15 VOID
16 SetUnrelatedDirectory(VOID)
17 {
18 WCHAR Buffer[MAX_PATH];
19 BOOL Ret;
20
21 GetWindowsDirectoryW(Buffer, sizeof(Buffer) / sizeof(WCHAR));
22 Ret = SetCurrentDirectoryW(Buffer);
23 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
24 }
25
26 static
27 VOID
28 TestSetCurrentDirectoryA(VOID)
29 {
30 BOOL Ret;
31 CHAR Buffer[MAX_PATH];
32 DWORD Length;
33
34 SetUnrelatedDirectory();
35
36 Ret = SetCurrentDirectoryA("C:\\");
37 ok(Ret == TRUE, "SetCurrentDirectoryA failed\n");
38 Length = GetCurrentDirectoryA(sizeof(Buffer), Buffer);
39 ok(Length == 3, "Length = %lu\n", Length);
40 ok(!strcmp(Buffer, "C:\\"), "Current directory is %s\n", Buffer);
41
42 /* Same directory - succeeds */
43 Ret = SetCurrentDirectoryA("C:\\");
44 ok(Ret == TRUE, "SetCurrentDirectoryA failed\n");
45 Length = GetCurrentDirectoryA(sizeof(Buffer), Buffer);
46 ok(Length == 3, "Length = %lu\n", Length);
47 ok(!strcmp(Buffer, "C:\\"), "Current directory is %s\n", Buffer);
48
49 /* Same directory, lowercase - succeeds and does not change case */
50 Ret = SetCurrentDirectoryA("c:\\");
51 ok(Ret == TRUE, "SetCurrentDirectoryA failed\n");
52 Length = GetCurrentDirectoryA(sizeof(Buffer), Buffer);
53 ok(Length == 3, "Length = %lu\n", Length);
54 ok(!strcmp(Buffer, "C:\\"), "Current directory is %s\n", Buffer);
55
56 SetUnrelatedDirectory();
57
58 /* Now this one does change case */
59 Ret = SetCurrentDirectoryA("c:\\");
60 ok(Ret == TRUE, "SetCurrentDirectoryA failed\n");
61 Length = GetCurrentDirectoryA(sizeof(Buffer), Buffer);
62 ok(Length == 3, "Length = %lu\n", Length);
63 ok(!strcmp(Buffer, "c:\\"), "Current directory is %s\n", Buffer);
64 }
65
66 static
67 VOID
68 TestSetCurrentDirectoryW(VOID)
69 {
70 BOOL Ret;
71 WCHAR Buffer[MAX_PATH];
72 DWORD Length;
73
74 SetUnrelatedDirectory();
75
76 Ret = SetCurrentDirectoryW(L"C:\\");
77 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
78 Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
79 ok(Length == 3, "Length = %lu\n", Length);
80 ok(!wcscmp(Buffer, L"C:\\"), "Current directory is %ls\n", Buffer);
81
82 /* Same directory - succeeds */
83 Ret = SetCurrentDirectoryW(L"C:\\");
84 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
85 Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
86 ok(Length == 3, "Length = %lu\n", Length);
87 ok(!wcscmp(Buffer, L"C:\\"), "Current directory is %ls\n", Buffer);
88
89 /* Same directory, lowercase - succeeds and does not change case */
90 Ret = SetCurrentDirectoryW(L"c:\\");
91 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
92 Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
93 ok(Length == 3, "Length = %lu\n", Length);
94 ok(!wcscmp(Buffer, L"C:\\"), "Current directory is %ls\n", Buffer);
95
96 SetUnrelatedDirectory();
97
98 /* Now this one does change case */
99 Ret = SetCurrentDirectoryW(L"c:\\");
100 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
101 Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
102 ok(Length == 3, "Length = %lu\n", Length);
103 ok(!wcscmp(Buffer, L"c:\\"), "Current directory is %ls\n", Buffer);
104 }
105
106 START_TEST(SetCurrentDirectory)
107 {
108 TestSetCurrentDirectoryA();
109 TestSetCurrentDirectoryW();
110 }