ReactOS  0.4.12-dev-375-g61fed54
movefile.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Test applications
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: base/applications/testsets/smss/movefile.cpp
5  * PURPOSE: Provides testing for the "move file after reboot"
6  * function of smss.exe/kernel32.dll
7  * PROGRAMMERS: Dmitriy Philippov (shedon@mail.ru)
8  */
9 
10 
11 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
12 #include "windows.h"
13 #include <stdio.h>
14 #include <tchar.h>
15 #include "stdlib.h"
16 #include "string.h"
17 
18 
19 void Usage()
20 {
21  printf(" Usage: smssTest.exe -g|c|s|d \n \
22  g - generate test files \n \
23  c - check files after reboot \n \
24  s - show registry entry \n \
25  d - delete registry value \n");
26 }
27 
29 {
30  BYTE lpBuff[255];
31  memset(lpBuff, 0, sizeof(lpBuff));
32 
33  DWORD lSize = sizeof(lpBuff);
34  HKEY hKey;
35  LONG retValue;
36  // test registry entry
37  retValue = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Session Manager", 0, KEY_QUERY_VALUE, &hKey);
38  if( ERROR_SUCCESS != retValue ) {
39  printf("RegOpenKeyEx err=%ld \n", retValue);
40  return 1;
41  }
42 
43  retValue = RegQueryValueEx(hKey, "PendingFileRenameOperations", NULL, NULL, lpBuff, &lSize);
44  if( ERROR_SUCCESS != retValue ) {
45  printf("RegQueryValueEx err=%ld \n", retValue);
46  lSize = 0;
47  }
48 
49  printf("reg data: \n");
50  for(UINT i=0; i<lSize; i++) {
51  printf("%c", lpBuff[i]);
52  }
53  printf("\n");
54 
55  RegCloseKey(hKey);
56 
57  return 0;
58 }
59 
61 {
62  HKEY hKey;
63  LONG retValue;
64  // test registry entry
65  retValue = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Session Manager", 0, KEY_SET_VALUE, &hKey);
66  if( ERROR_SUCCESS != retValue ) {
67  printf("RegOpenKeyEx err=%ld \n", retValue);
68  return 1;
69  }
70 
71  retValue = RegDeleteValue(hKey, "PendingFileRenameOperations");
72  if( ERROR_SUCCESS != retValue ) {
73  printf("RegDeleteValue err=%ld \n", retValue);
74  }
75 
76  RegCloseKey(hKey);
77 
78  return 0;
79 }
80 
81 int Generate()
82 {
83  char sBuf[255];
84  DWORD dwSize;
85  HANDLE hFile = NULL;
86  BOOL fReturnValue;
87 
88  const char szxReplacedFile[] = "c:\\testFileIsReplaced";
89  const char szxMovedFileWithRepl[] = "c:\\testFileShouldBeMovedW";
90  const char szxMovedFile[] = "c:\\testFileShouldBeMoved";
91  const char szxNewMovedFile[] = "c:\\testFileIsMoved";
92  const char szxDeletedFile[] = "c:\\testFileShouldBeDeleted";
93 
94  memset(sBuf, 0xaa, sizeof(sBuf));
95 
96  // create the first file for moving
97  hFile = CreateFile(
98  szxMovedFile,
100  0,
101  NULL,
104  NULL);
105  if(NULL == hFile) {
106  printf("Can't create the %s file, err=%ld \n", szxMovedFile, GetLastError());
107  return 1;
108  }
109  WriteFile(hFile, sBuf, sizeof(sBuf), &dwSize, NULL);
111 
112  // create the second file for removing
113  hFile = CreateFile(
114  szxDeletedFile,
116  0,
117  NULL,
120  NULL);
121  if(NULL == hFile) {
122  printf("Can't create the %s file, err=%ld \n", szxDeletedFile, GetLastError());
123  return 1;
124  }
125  WriteFile(hFile, sBuf, sizeof(sBuf), &dwSize, NULL);
127 
128  hFile = CreateFile(
129  szxReplacedFile,
131  0,
132  NULL,
135  NULL);
136  if(NULL == hFile) {
137  printf("Can't create the %s file, err=%ld \n", szxReplacedFile, GetLastError());
138  return 1;
139  }
140  WriteFile(hFile, sBuf, sizeof(sBuf), &dwSize, NULL);
142 
143 
144  hFile = CreateFile(
145  szxMovedFileWithRepl,
147  0,
148  NULL,
151  NULL);
152  if(NULL == hFile) {
153  printf("Can't create the %s file, err=%ld \n", szxMovedFileWithRepl, GetLastError());
154  return 1;
155  }
156  WriteFile(hFile, sBuf, sizeof(sBuf), &dwSize, NULL);
158 
159 
160  fReturnValue = MoveFileEx(
161  szxDeletedFile,
162  NULL,
164  if( !fReturnValue ) {
165  printf("Can't move the %s file, err=%ld \n", szxDeletedFile, GetLastError());
166  return 1;
167  }
168 
169  ShowRegValue();
170 
171  fReturnValue = MoveFileEx(
172  szxMovedFile,
173  szxNewMovedFile,
175  if( !fReturnValue ) {
176  printf("Can't move the %s file, err=%ld \n", szxMovedFile, GetLastError());
177  return 1;
178  }
179 
180  ShowRegValue();
181 
182  fReturnValue = MoveFileEx(
183  szxMovedFileWithRepl,
184  szxReplacedFile,
186  if( !fReturnValue ) {
187  printf("Can't move the %s file, err=%ld \n", szxMovedFileWithRepl, GetLastError());
188  return 1;
189  }
190 
191  ShowRegValue();
192 
193  return 0;
194 }
195 
196 int Check()
197 {
198  return 0;
199 }
200 
201 int _tmain(int argc, _TCHAR* argv[])
202 {
203  if( argc<2 ) {
204  Usage();
205  return 1;
206  }
207 
208  if( 0 == strncmp(argv[1], "-g", 2) )
209  {
210  // generate test files and registry values
211  return Generate();
212  }
213  else if( 0 == strncmp(argv[1], "-c", 2) )
214  {
215  // check generated files
216  return Check();
217  }
218  else if( 0 == strncmp(argv[1], "-s", 2) )
219  {
220  //
221  return ShowRegValue();
222  }
223  else if( 0 == strncmp(argv[1], "-d", 2) )
224  {
225  return DeleteValue();
226  }
227  else
228  {
229  Usage();
230  return 1;
231  }
232 
233  return 0;
234 }
235 
#define RegQueryValueEx
Definition: winreg.h:524
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static int argc
Definition: ServiceArgs.c:12
int ShowRegValue()
Definition: movefile.cpp:28
void Usage()
Definition: movefile.cpp:19
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
#define MOVEFILE_REPLACE_EXISTING
Definition: filesup.h:28
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define MoveFileEx
Definition: winbase.h:3692
#define argv
Definition: mplay32.c:18
GLenum GLclampf GLint i
Definition: glfuncs.h:14
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
int Check()
Definition: movefile.cpp:196
long LONG
Definition: pedump.c:60
int DeleteValue()
Definition: movefile.cpp:60
smooth NULL
Definition: ftsmooth.c:416
#define MOVEFILE_DELAY_UNTIL_REBOOT
Definition: winbase.h:381
char _TCHAR
Definition: tchar.h:1392
#define RegDeleteValue
Definition: winreg.h:508
unsigned int BOOL
Definition: ntddk_ex.h:94
int _tmain(int argc, _TCHAR *argv[])
Definition: movefile.cpp:201
unsigned int UINT
Definition: ndis.h:50
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
unsigned char BYTE
Definition: mem.h:68
_In_ HANDLE hFile
Definition: mswsock.h:90
int Generate()
Definition: movefile.cpp:81
#define RegOpenKeyEx
Definition: winreg.h:520
#define CREATE_ALWAYS
Definition: disk.h:72
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define memset(x, y, z)
Definition: compat.h:39
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define printf
Definition: config.h:203
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12