Blame winpr/libwinpr/path/test/TestPathCchAppend.c

Packit 1fb8d4
Packit 1fb8d4
#include <stdio.h>
Packit 1fb8d4
#include <winpr/crt.h>
Packit 1fb8d4
#include <winpr/path.h>
Packit 1fb8d4
#include <winpr/tchar.h>
Packit 1fb8d4
#include <winpr/winpr.h>
Packit 1fb8d4
Packit 1fb8d4
static const TCHAR testBasePathBackslash[] = _T("C:\\Program Files\\");
Packit 1fb8d4
static const TCHAR testBasePathNoBackslash[] = _T("C:\\Program Files");
Packit 1fb8d4
static const TCHAR testMorePathBackslash[] = _T("\\Microsoft Visual Studio 11.0");
Packit 1fb8d4
static const TCHAR testMorePathNoBackslash[] = _T("Microsoft Visual Studio 11.0");
Packit 1fb8d4
static const TCHAR testPathOut[] = _T("C:\\Program Files\\Microsoft Visual Studio 11.0");
Packit 1fb8d4
Packit 1fb8d4
int TestPathCchAppend(int argc, char* argv[])
Packit 1fb8d4
{
Packit 1fb8d4
	HRESULT status;
Packit 1fb8d4
	TCHAR Path[PATHCCH_MAX_CCH];
Packit 1fb8d4
	size_t i;
Packit 1fb8d4
Packit 1fb8d4
	/* Base Path: Backslash, More Path: No Backslash */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, testBasePathBackslash);
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathNoBackslash);
Packit 1fb8d4
Packit 1fb8d4
	if (status != S_OK)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("PathCchAppend status: 0x%08")_T(PRIX32)_T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (_tcscmp(Path, testPathOut) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Base Path: Backslash, More Path: Backslash */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, testBasePathBackslash);
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathBackslash);
Packit 1fb8d4
Packit 1fb8d4
	if (status != S_OK)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("PathCchAppend status: 0x%08")_T(PRIX32)_T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (_tcscmp(Path, testPathOut) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Base Path: No Backslash, More Path: Backslash */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, testBasePathNoBackslash);
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathBackslash);
Packit 1fb8d4
Packit 1fb8d4
	if (status != S_OK)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("PathCchAppend status: 0x%08")_T(PRIX32)_T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (_tcscmp(Path, testPathOut) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Base Path: No Backslash, More Path: No Backslash */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, testBasePathNoBackslash);
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathNoBackslash);
Packit 1fb8d4
Packit 1fb8d4
	if (status != S_OK)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("PathCchAppend status: 0x%08")_T(PRIX32)_T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (_tcscmp(Path, testPathOut) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* According to msdn a NULL Path is an invalid argument */
Packit 1fb8d4
	status = PathCchAppend(NULL, PATHCCH_MAX_CCH, testMorePathNoBackslash);
Packit 1fb8d4
	if (status != E_INVALIDARG)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("PathCchAppend with NULL path unexpectedly returned status: 0x%08")_T(PRIX32)_T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* According to msdn a NULL pszMore is an invalid argument (although optional !?) */
Packit 1fb8d4
	_tcscpy(Path, testBasePathNoBackslash);
Packit 1fb8d4
	status = PathCchAppend(Path, PATHCCH_MAX_CCH, NULL);
Packit 1fb8d4
	if (status != E_INVALIDARG)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("PathCchAppend with NULL pszMore unexpectedly returned status: 0x%08")_T(PRIX32)_T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* According to msdn cchPath must be > 0 and <= PATHCCH_MAX_CCH */
Packit 1fb8d4
	_tcscpy(Path, testBasePathNoBackslash);
Packit 1fb8d4
	status = PathCchAppend(Path, 0, testMorePathNoBackslash);
Packit 1fb8d4
	if (status != E_INVALIDARG)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("PathCchAppend with cchPath value 0 unexpectedly returned status: 0x%08")_T(PRIX32)_T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
	_tcscpy(Path, testBasePathNoBackslash);
Packit 1fb8d4
	status = PathCchAppend(Path, PATHCCH_MAX_CCH + 1, testMorePathNoBackslash);
Packit 1fb8d4
	if (status != E_INVALIDARG)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("PathCchAppend with cchPath value > PATHCCH_MAX_CCH unexpectedly returned status: 0x%08")_T(PRIX32)_T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Resulting file must not exceed PATHCCH_MAX_CCH */
Packit 1fb8d4
Packit 1fb8d4
	for (i = 0; i < PATHCCH_MAX_CCH - 1; i++)
Packit 1fb8d4
		Path[i] = _T('X');
Packit 1fb8d4
Packit 1fb8d4
	Path[PATHCCH_MAX_CCH - 1] = 0;
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAppend(Path, PATHCCH_MAX_CCH, _T("\\This cannot be appended to Path"));
Packit 1fb8d4
	if (SUCCEEDED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("PathCchAppend unexepectedly succeeded with status: 0x%08")_T(PRIX32)_T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4