a14ac98edc4054878ac76eb750faf8d3b42d258c
[reactos.git] / rostests / apitests / kernel32 / TunnelCache.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Tests for Tunnel Cache
5 * PROGRAMMER: Pierre Schweitzer <pierre.schweitzer@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <stdio.h>
12 #include <ndk/rtlfuncs.h>
13
14 static
15 void
16 Test_ShortTests(void)
17 {
18 UCHAR i = 0;
19 CHAR ShortName[14];
20 HANDLE hFile, hFind;
21 WIN32_FIND_DATA FileInfo;
22 CHAR TestDir[] = "XTestDirTunnelCache";
23 CHAR OldDir[MAX_PATH];
24
25 /* Create a blank test directory */
26 if (GetCurrentDirectory(MAX_PATH, OldDir) == 0)
27 {
28 win_skip("No test directory available\n");
29 return;
30 }
31
32 /* Create a blank test directory */
33 for (; i < 10; ++i)
34 {
35 TestDir[0] = '0' + i;
36 if (CreateDirectory(TestDir, NULL))
37 {
38 if (SetCurrentDirectory(TestDir) == 0)
39 {
40 RemoveDirectory(TestDir);
41 win_skip("No test directory available\n");
42 return;
43 }
44
45 break;
46 }
47 }
48
49 if (i == 10)
50 {
51 win_skip("No test directory available\n");
52 return;
53 }
54
55 hFile = CreateFile("verylongfilename",
56 GENERIC_READ | GENERIC_WRITE,
57 0, NULL,
58 CREATE_NEW,
59 FILE_ATTRIBUTE_NORMAL,
60 NULL);
61 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
62 CloseHandle(hFile);
63
64 hFind = FindFirstFile("verylongfilename", &FileInfo);
65 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstFile() failed\n");
66 FindClose(hFind);
67 RtlCopyMemory(ShortName, FileInfo.cAlternateFileName, sizeof(ShortName));
68
69 ok(MoveFile("verylongfilename", "verylongfilename2") != FALSE, "MoveFile() failed\n");
70 hFind = FindFirstFile("verylongfilename2", &FileInfo);
71 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstFile() failed\n");
72 FindClose(hFind);
73 ok(strcmp(FileInfo.cAlternateFileName, ShortName) == 0, "strcmp() failed\n");
74
75 hFile = CreateFile("randomfilename",
76 GENERIC_READ | GENERIC_WRITE,
77 0, NULL,
78 CREATE_NEW,
79 FILE_ATTRIBUTE_NORMAL,
80 NULL);
81 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
82 CloseHandle(hFile);
83
84 ok(MoveFileEx("randomfilename", "verylongfilename2", MOVEFILE_REPLACE_EXISTING) != FALSE, "MoveFile() failed\n");
85 hFind = FindFirstFile("verylongfilename2", &FileInfo);
86 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstFile() failed\n");
87 FindClose(hFind);
88 ok(strcmp(FileInfo.cAlternateFileName, ShortName) == 0, "strcmp() failed\n");
89
90 DeleteFile("randomfilename");
91 DeleteFile("verylongfilename");
92 DeleteFile("verylongfilename2");
93
94 SetCurrentDirectory(OldDir);
95 RemoveDirectory(TestDir);
96 }
97
98 START_TEST(TunnelCache)
99 {
100 Test_ShortTests();
101 }