From f037bd695099134eb7a72585a741a0726290f34c Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 3 Apr 2026 10:41:41 -0400 Subject: [PATCH] Tests/VSResource: Port from C++ to C This will make the test usable without a C++ compiler. The test's code was basically C compiled as C++ anyway. --- Tests/VSResource/CMakeLists.txt | 6 +-- Tests/VSResource/{lib.cpp => lib.c} | 2 +- Tests/VSResource/{main.cpp => main.c} | 42 ++++++++++--------- Tests/VSResourceNinjaForceRSP/CMakeLists.txt | 6 +-- .../{lib.cpp => lib.c} | 2 +- .../{main.cpp => main.c} | 0 6 files changed, 31 insertions(+), 27 deletions(-) rename Tests/VSResource/{lib.cpp => lib.c} (53%) rename Tests/VSResource/{main.cpp => main.c} (59%) rename Tests/VSResourceNinjaForceRSP/{lib.cpp => lib.c} (53%) rename Tests/VSResourceNinjaForceRSP/{main.cpp => main.c} (100%) diff --git a/Tests/VSResource/CMakeLists.txt b/Tests/VSResource/CMakeLists.txt index be6154c1be..55e924e986 100644 --- a/Tests/VSResource/CMakeLists.txt +++ b/Tests/VSResource/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(VSResource) +project(VSResource LANGUAGES C) string(REPLACE "/INCREMENTAL:YES" "" CMAKE_EXE_LINKER_FLAGS_DEBUG @@ -45,9 +45,9 @@ else() include_directories(${CMAKE_CURRENT_BINARY_DIR}) endif() -add_library(ResourceLib STATIC lib.cpp lib.rc) +add_library(ResourceLib STATIC lib.c lib.rc) -add_executable(VSResource main.cpp test.rc) +add_executable(VSResource main.c test.rc) target_link_libraries(VSResource ResourceLib) if(MSVC AND NOT MSVC_VERSION VERSION_LESS 1600) diff --git a/Tests/VSResource/lib.cpp b/Tests/VSResource/lib.c similarity index 53% rename from Tests/VSResource/lib.cpp rename to Tests/VSResource/lib.c index c91239731b..abe3b787c6 100644 --- a/Tests/VSResource/lib.cpp +++ b/Tests/VSResource/lib.c @@ -1,4 +1,4 @@ -int lib() +int lib(void) { return 0; } diff --git a/Tests/VSResource/main.cpp b/Tests/VSResource/main.c similarity index 59% rename from Tests/VSResource/main.cpp rename to Tests/VSResource/main.c index 65e33b860e..68078d1a8f 100644 --- a/Tests/VSResource/main.cpp +++ b/Tests/VSResource/main.c @@ -2,7 +2,7 @@ #include -extern int lib(); +extern int lib(void); struct x { @@ -12,6 +12,7 @@ struct x int main(int argc, char** argv) { int ret = 1; + HRSRC hello = FindResource(NULL, MAKEINTRESOURCE(1025), "TEXTFILE"); fprintf(stdout, "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)\n"); @@ -20,30 +21,31 @@ int main(int argc, char** argv) #endif #ifdef CMAKE_RCDEFINE_NO_QUOTED_STRINGS - // Expect CMAKE_RCDEFINE to preprocess to exactly test.txt - x test; - test.txt = "*exactly* test.txt"; - fprintf(stdout, "CMAKE_RCDEFINE_NO_QUOTED_STRINGS defined\n"); - fprintf(stdout, "CMAKE_RCDEFINE is %s, and is *not* a string constant\n", - CMAKE_RCDEFINE); + { + // Expect CMAKE_RCDEFINE to preprocess to exactly test.txt + struct x test; + test.txt = "*exactly* test.txt"; + fprintf(stdout, "CMAKE_RCDEFINE_NO_QUOTED_STRINGS defined\n"); + fprintf(stdout, "CMAKE_RCDEFINE is %s, and is *not* a string constant\n", + CMAKE_RCDEFINE); + } #else // Expect CMAKE_RCDEFINE to be a string: fprintf(stdout, "CMAKE_RCDEFINE='%s', and is a string constant\n", CMAKE_RCDEFINE); #endif - HRSRC hello = ::FindResource(NULL, MAKEINTRESOURCE(1025), "TEXTFILE"); if (hello) { + HGLOBAL hgbl = LoadResource(NULL, hello); + int datasize = (int)SizeofResource(NULL, hello); fprintf(stdout, "FindResource worked\n"); - HGLOBAL hgbl = ::LoadResource(NULL, hello); - int datasize = (int)::SizeofResource(NULL, hello); if (hgbl && datasize > 0) { + void* data = LockResource(hgbl); fprintf(stdout, "LoadResource worked\n"); fprintf(stdout, "SizeofResource returned datasize='%d'\n", datasize); - void* data = ::LockResource(hgbl); if (data) { - fprintf(stdout, "LockResource worked\n"); char* str = (char*)malloc(datasize + 4); + fprintf(stdout, "LockResource worked\n"); if (str) { memcpy(str, data, datasize); str[datasize] = 'E'; @@ -58,13 +60,15 @@ int main(int argc, char** argv) #ifdef CMAKE_RCDEFINE_NO_QUOTED_STRINGS fprintf(stdout, "LoadString skipped\n"); #else - char buf[256]; - if (::LoadString(NULL, 1026, buf, sizeof(buf)) > 0) { - fprintf(stdout, "LoadString worked\n"); - fprintf(stdout, "buf='%s'\n", buf); - } else { - fprintf(stdout, "LoadString failed\n"); - ret = 1; + { + char buf[256]; + if (LoadString(NULL, 1026, buf, sizeof(buf)) > 0) { + fprintf(stdout, "LoadString worked\n"); + fprintf(stdout, "buf='%s'\n", buf); + } else { + fprintf(stdout, "LoadString failed\n"); + ret = 1; + } } #endif } diff --git a/Tests/VSResourceNinjaForceRSP/CMakeLists.txt b/Tests/VSResourceNinjaForceRSP/CMakeLists.txt index d9d0bd0112..909e0bea90 100644 --- a/Tests/VSResourceNinjaForceRSP/CMakeLists.txt +++ b/Tests/VSResourceNinjaForceRSP/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.10) -project(VSResourceNinjaForceRSP) +project(VSResourceNinjaForceRSP LANGUAGES C) set(CMAKE_NINJA_FORCE_RESPONSE_FILE TRUE) -add_library(ResourceLib lib.cpp test.rc) -add_executable(VSResourceNinjaForceRSP main.cpp test.rc) +add_library(ResourceLib lib.c test.rc) +add_executable(VSResourceNinjaForceRSP main.c test.rc) diff --git a/Tests/VSResourceNinjaForceRSP/lib.cpp b/Tests/VSResourceNinjaForceRSP/lib.c similarity index 53% rename from Tests/VSResourceNinjaForceRSP/lib.cpp rename to Tests/VSResourceNinjaForceRSP/lib.c index c91239731b..abe3b787c6 100644 --- a/Tests/VSResourceNinjaForceRSP/lib.cpp +++ b/Tests/VSResourceNinjaForceRSP/lib.c @@ -1,4 +1,4 @@ -int lib() +int lib(void) { return 0; } diff --git a/Tests/VSResourceNinjaForceRSP/main.cpp b/Tests/VSResourceNinjaForceRSP/main.c similarity index 100% rename from Tests/VSResourceNinjaForceRSP/main.cpp rename to Tests/VSResourceNinjaForceRSP/main.c