// port/common: Win32 widths and MSVC CRT semantics the ported 40250 logic relies on. #include "common/StdAfx.h" #include #include 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(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(b - a) < 1000); if (g_failures) return EXIT_FAILURE; std::puts("port_common_test: ok"); return EXIT_SUCCESS; }