Files
mtgodot-poc/extension/tests/port_common_test.cpp
T
shenleiandClaude Opus 5 2bae8d7644 port(2A): port/common Win32 layer, port_logic target and header gate
- Win32Types.h: fixed-width Win32 scalars, pointer-sized handles, static_asserts
- Win32Crt.{h,cpp}: MSVC _snprintf truncation contract, stricmp, timeGetTime wrap
- port_logic static lib linked into libmtgodot; standalone MTGODOT_BUILD_PORT build
- port_header_gate: every port/**.h compiles alone (twice) with its lib's
  40250 Distribute|Win32 defines (NDEBUG, USE_LOD, _DISTRIBUTE)
- script/port_gate.sh: macOS/Android/iOS/Windows(mingw) PASS, Linux BLOCKED

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 19:57:58 +09:00

56 lines
1.8 KiB
C++

// port/common: Win32 widths and MSVC CRT semantics the ported 40250 logic relies on.
#include "common/StdAfx.h"
#include <cstdio>
#include <cstdlib>
static int g_failures = 0;
#define CHECK(cond) \
do { \
if (!(cond)) { \
std::fprintf(stderr, "%s:%d: CHECK(%s)\n", __FILE__, __LINE__, #cond); \
++g_failures; \
} \
} while (0)
int main()
{
// MSVC _snprintf: shorter output is terminated.
char buf[8];
std::memset(buf, 'x', sizeof(buf));
CHECK(_snprintf(buf, 8, "%s", "abc") == 3);
CHECK(std::strcmp(buf, "abc") == 0);
// Exactly `count` bytes: written unterminated, returns count.
std::memset(buf, 'x', sizeof(buf));
CHECK(_snprintf(buf, 4, "%s", "abcd") == 4);
CHECK(std::memcmp(buf, "abcdx", 5) == 0);
// Longer: `count` bytes written unterminated, returns -1.
std::memset(buf, 'x', sizeof(buf));
CHECK(_snprintf(buf, 4, "%d", 123456) == -1);
CHECK(std::memcmp(buf, "1234x", 5) == 0);
CHECK(stricmp("PLAYER", "player") == 0);
CHECK(_strnicmp("d:/ymir work/A", "D:/YMIR WORK/b", 12) == 0);
char s[] = "MixEd";
CHECK(std::strcmp(_strlwr(s), "mixed") == 0);
CHECK(MAKELONG(0x1234, 0xABCD) == static_cast<LONG>(0xABCD1234u));
CHECK(LOWORD(0xABCD1234u) == 0x1234 && HIWORD(0xABCD1234u) == 0xABCD);
CHECK(MAKEWORD(0x34, 0x12) == 0x1234);
// DWORD arithmetic wraps like the 32-bit original.
DWORD t = 0xFFFFFFF0u;
t += 0x20;
CHECK(t == 0x10);
const DWORD a = timeGetTime();
const DWORD b = timeGetTime();
CHECK(static_cast<DWORD>(b - a) < 1000);
if (g_failures)
return EXIT_FAILURE;
std::puts("port_common_test: ok");
return EXIT_SUCCESS;
}