File: CeMoveFile.cpp

package info (click to toggle)
librapi2 0.9.0-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,204 kB
  • ctags: 1,258
  • sloc: sh: 9,013; ansic: 5,743; cpp: 522; makefile: 171
file content (42 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Test CeCreateFile, CeCloseHandle, CeWriteFile, CeReadFile, CeDeleteFile
//
#include "test.h"

int main()
{
	VERIFY_HRESULT(CeRapiInit());

	DWORD length;
	WCHAR filename1[MAX_PATH];
	WCHAR filename2[MAX_PATH];
	VERIFY_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_PERSONAL, MAX_PATH, filename1));
	wstrcpy(filename2, filename1);
	wstr_append(filename1, to_unicode("\\librapi test file 1.txt"), sizeof(filename1));
	wstr_append(filename2, to_unicode("\\librapi test file 2.txt"), sizeof(filename2));

	HANDLE handle;

	// Open file for writing, create if it does not exist, close immediatly
	VERIFY_NOT_EQUAL(INVALID_HANDLE_VALUE, handle = CeCreateFile(filename1,
				GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0));
	
	// Get file size
	VERIFY_EQUAL(0, CeGetFileSize(handle, NULL));
	
	VERIFY_NOT_FALSE(CeCloseHandle(handle));

	// Delete second file if it exists (ignore return value)
	CeDeleteFile(filename2);

	// Move from first to second filename
	TEST_NOT_FALSE(CeMoveFile(filename1, filename2));
	
	// Delete second file, should succeed
	TEST_NOT_FALSE(CeDeleteFile(filename2));

	
	VERIFY_HRESULT(CeRapiUninit());
	return TEST_SUCCEEDED;
}