Files
Python3-Win9x/scripts/fixtures/vc6_pathcch_smoke.c
T

60 lines
2.1 KiB
C

/* Focused compile smoke test for compat/msvc600/pathcch.h.
*
* The VC6 compatibility header intentionally implements only the single
* PathCch API used by cpython/Modules/getpath.c: PathCchFindExtension().
* This fixture keeps the representative path cases in one place for the
* VC6 probe. The probe is compile-only, so the checks are ordinary C code
* that can also be run later by a tiny Windows harness if needed.
*/
#include <windows.h>
#include <pathcch.h>
#ifndef ARRAYSIZE
#define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif
static int
pathcch_expect_ext(PCWSTR path, size_t cch, size_t offset)
{
PCWSTR ext;
HRESULT hr;
ext = NULL;
hr = PathCchFindExtension(path, cch, &ext);
return SUCCEEDED(hr) && ext == path + offset;
}
static int
pathcch_expect_invalid(PCWSTR path, size_t cch)
{
PCWSTR ext;
HRESULT hr;
ext = (PCWSTR)1;
hr = PathCchFindExtension(path, cch, &ext);
return FAILED(hr);
}
int
vc6_pathcch_find_extension_smoke(void)
{
static const WCHAR exe_path[] = L"C:\\Python311\\python.exe";
static const WCHAR no_ext[] = L"C:\\Python311\\python";
static const WCHAR dir_dot[] = L"C:\\tmp.dir\\python";
static const WCHAR dotfile[] = L"C:\\Python311\\.pythonrc";
static const WCHAR trailing_dir[] = L"C:\\bin\\python.exe\\";
static const WCHAR multi_dot[] = L"C:\\tmp\\archive.tar.gz";
int ok;
ok = 1;
ok = ok && pathcch_expect_ext(exe_path, ARRAYSIZE(exe_path), 20); /* .exe */
ok = ok && pathcch_expect_ext(no_ext, ARRAYSIZE(no_ext), 19); /* NUL */
ok = ok && pathcch_expect_ext(dir_dot, ARRAYSIZE(dir_dot), 17); /* NUL, directory dot ignored */
ok = ok && pathcch_expect_ext(dotfile, ARRAYSIZE(dotfile), 13); /* dotfile extension */
ok = ok && pathcch_expect_ext(trailing_dir, ARRAYSIZE(trailing_dir), 18); /* NUL after separator */
ok = ok && pathcch_expect_ext(multi_dot, ARRAYSIZE(multi_dot), 18); /* last suffix */
ok = ok && pathcch_expect_invalid(exe_path, 4); /* too small: no NUL */
ok = ok && pathcch_expect_invalid(NULL, ARRAYSIZE(exe_path));
return ok ? 0 : 1;
}