Blame winpr/libwinpr/path/test/TestPathCchAddExtension.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 testExtDot[] = _T(".exe");
Packit 1fb8d4
static const TCHAR testExtNoDot[] = _T("exe");
Packit 1fb8d4
static const TCHAR testPathNoExtension[] = _T("C:\\Windows\\System32\\cmd");
Packit 1fb8d4
static const TCHAR testPathExtension[] = _T("C:\\Windows\\System32\\cmd.exe");
Packit 1fb8d4
Packit 1fb8d4
int TestPathCchAddExtension(int argc, char* argv[])
Packit 1fb8d4
{
Packit 1fb8d4
	HRESULT status;
Packit 1fb8d4
	TCHAR Path[PATHCCH_MAX_CCH];
Packit 1fb8d4
Packit 1fb8d4
	/* Path: no extension, Extension: dot */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, testPathNoExtension);
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot);
Packit Service 5a9772
Packit 1fb8d4
	if (status != S_OK)
Packit 1fb8d4
	{
Packit Service 5a9772
		_tprintf(_T("PathCchAddExtension status: 0x%08") _T(PRIX32) _T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (_tcscmp(Path, testPathExtension) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Path: no extension, Extension: no dot */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, testPathNoExtension);
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtNoDot);
Packit Service 5a9772
Packit 1fb8d4
	if (status != S_OK)
Packit 1fb8d4
	{
Packit Service 5a9772
		_tprintf(_T("PathCchAddExtension status: 0x%08") _T(PRIX32) _T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (_tcscmp(Path, testPathExtension) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Path: extension, Extension: dot */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, testPathExtension);
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot);
Packit Service 5a9772
Packit 1fb8d4
	if (status != S_FALSE)
Packit 1fb8d4
	{
Packit Service 5a9772
		_tprintf(_T("PathCchAddExtension status: 0x%08") _T(PRIX32) _T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (_tcscmp(Path, testPathExtension) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Path: extension, Extension: no dot */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, testPathExtension);
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot);
Packit Service 5a9772
Packit 1fb8d4
	if (status != S_FALSE)
Packit 1fb8d4
	{
Packit Service 5a9772
		_tprintf(_T("PathCchAddExtension status: 0x%08") _T(PRIX32) _T("\n"), status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (_tcscmp(Path, testPathExtension) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Path: NULL */
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAddExtension(NULL, PATHCCH_MAX_CCH, testExtDot);
Packit 1fb8d4
	if (status != E_INVALIDARG)
Packit 1fb8d4
	{
Packit Service 5a9772
		_tprintf(_T("PathCchAddExtension with null buffer returned status: 0x%08") _T(
Packit Service 5a9772
		             PRIX32) _T(" (expected E_INVALIDARG)\n"),
Packit Service 5a9772
		         status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Extension: NULL */
Packit 1fb8d4
Packit 1fb8d4
	status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, NULL);
Packit 1fb8d4
	if (status != E_INVALIDARG)
Packit 1fb8d4
	{
Packit Service 5a9772
		_tprintf(_T("PathCchAddExtension with null extension returned status: 0x%08") _T(
Packit Service 5a9772
		             PRIX32) _T(" (expected E_INVALIDARG)\n"),
Packit Service 5a9772
		         status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Insufficient Buffer size */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, _T("C:\\456789"));
Packit 1fb8d4
	status = PathCchAddExtension(Path, 9 + 4, _T(".jpg"));
Packit 1fb8d4
	if (SUCCEEDED(status))
Packit 1fb8d4
	{
Packit Service 5a9772
		_tprintf(_T("PathCchAddExtension with insufficient buffer unexpectedly succeeded with ")
Packit Service 5a9772
		         _T("status: 0x%08") _T(PRIX32) _T("\n"),
Packit Service 5a9772
		         status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* Minimum required buffer size */
Packit 1fb8d4
Packit 1fb8d4
	_tcscpy(Path, _T("C:\\456789"));
Packit 1fb8d4
	status = PathCchAddExtension(Path, 9 + 4 + 1, _T(".jpg"));
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit Service 5a9772
		_tprintf(_T("PathCchAddExtension with sufficient buffer unexpectedly failed with status: ")
Packit Service 5a9772
		         _T("0x%08") _T(PRIX32) _T("\n"),
Packit Service 5a9772
		         status);
Packit 1fb8d4
		return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}