[KERNEL32_APITEST] Add a PCH.
[reactos.git] / modules / 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 "precomp.h"
9
10 static
11 VOID
12 SetUnrelatedDirectory(VOID)
13 {
14 WCHAR Buffer[MAX_PATH];
15 BOOL Ret;
16
17 GetWindowsDirectoryW(Buffer, sizeof(Buffer) / sizeof(WCHAR));
18 Ret = SetCurrentDirectoryW(Buffer);
19 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
20 }
21
22 static
23 VOID
24 TestSetCurrentDirectoryA(VOID)
25 {
26 BOOL Ret;
27 CHAR Buffer[MAX_PATH];
28 DWORD Length;
29
30 SetUnrelatedDirectory();
31
32 Ret = SetCurrentDirectoryA("C:\\");
33 ok(Ret == TRUE, "SetCurrentDirectoryA failed\n");
34 Length = GetCurrentDirectoryA(sizeof(Buffer), Buffer);
35 ok(Length == 3, "Length = %lu\n", Length);
36 ok(!strcmp(Buffer, "C:\\"), "Current directory is %s\n", Buffer);
37
38 /* Same directory - succeeds */
39 Ret = SetCurrentDirectoryA("C:\\");
40 ok(Ret == TRUE, "SetCurrentDirectoryA failed\n");
41 Length = GetCurrentDirectoryA(sizeof(Buffer), Buffer);
42 ok(Length == 3, "Length = %lu\n", Length);
43 ok(!strcmp(Buffer, "C:\\"), "Current directory is %s\n", Buffer);
44
45 /* Same directory, lowercase - succeeds and does not change case */
46 Ret = SetCurrentDirectoryA("c:\\");
47 ok(Ret == TRUE, "SetCurrentDirectoryA failed\n");
48 Length = GetCurrentDirectoryA(sizeof(Buffer), Buffer);
49 ok(Length == 3, "Length = %lu\n", Length);
50 ok(!strcmp(Buffer, "C:\\"), "Current directory is %s\n", Buffer);
51
52 SetUnrelatedDirectory();
53
54 /* Now this one does change case */
55 Ret = SetCurrentDirectoryA("c:\\");
56 ok(Ret == TRUE, "SetCurrentDirectoryA failed\n");
57 Length = GetCurrentDirectoryA(sizeof(Buffer), Buffer);
58 ok(Length == 3, "Length = %lu\n", Length);
59 ok(!strcmp(Buffer, "c:\\"), "Current directory is %s\n", Buffer);
60 }
61
62 static
63 VOID
64 TestSetCurrentDirectoryW(VOID)
65 {
66 BOOL Ret;
67 WCHAR Buffer[MAX_PATH];
68 DWORD Length;
69
70 SetUnrelatedDirectory();
71
72 Ret = SetCurrentDirectoryW(L"C:\\");
73 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
74 Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
75 ok(Length == 3, "Length = %lu\n", Length);
76 ok(!wcscmp(Buffer, L"C:\\"), "Current directory is %ls\n", Buffer);
77
78 /* Same directory - succeeds */
79 Ret = SetCurrentDirectoryW(L"C:\\");
80 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
81 Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
82 ok(Length == 3, "Length = %lu\n", Length);
83 ok(!wcscmp(Buffer, L"C:\\"), "Current directory is %ls\n", Buffer);
84
85 /* Same directory, lowercase - succeeds and does not change case */
86 Ret = SetCurrentDirectoryW(L"c:\\");
87 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
88 Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
89 ok(Length == 3, "Length = %lu\n", Length);
90 ok(!wcscmp(Buffer, L"C:\\"), "Current directory is %ls\n", Buffer);
91
92 SetUnrelatedDirectory();
93
94 /* Now this one does change case */
95 Ret = SetCurrentDirectoryW(L"c:\\");
96 ok(Ret == TRUE, "SetCurrentDirectoryW failed\n");
97 Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
98 ok(Length == 3, "Length = %lu\n", Length);
99 ok(!wcscmp(Buffer, L"c:\\"), "Current directory is %ls\n", Buffer);
100 }
101
102 START_TEST(SetCurrentDirectory)
103 {
104 TestSetCurrentDirectoryA();
105 TestSetCurrentDirectoryW();
106 }