From 212ecbf23017c86edd4c6ff2a802d98ea89e600d Mon Sep 17 00:00:00 2001 From: Duncan Horn <40036384+dunhor@users.noreply.github.com> Date: Tue, 24 Mar 2020 13:37:44 -0700 Subject: [PATCH] Add Windows 7 tests and update ifdefs/etc. to match (#120) --- include/wil/token_helpers.h | 4 ++++ scripts/runtests.cmd | 2 ++ tests/CMakeLists.txt | 1 + tests/ResultTests.cpp | 7 +++++-- tests/TokenHelpersTests.cpp | 6 ++++++ tests/wiTest.cpp | 12 +++++++++++- tests/win7/CMakeLists.txt | 21 +++++++++++++++++++++ 7 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tests/win7/CMakeLists.txt diff --git a/include/wil/token_helpers.h b/include/wil/token_helpers.h index 746a13ef7..6da81c38a 100644 --- a/include/wil/token_helpers.h +++ b/include/wil/token_helpers.h @@ -122,6 +122,7 @@ namespace wil } #endif // WIL_ENABLE_EXCEPTIONS +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) // Returns tokenHandle or the effective thread token if tokenHandle is null. // Note, this returns an token handle who's lifetime is managed independently // and it may be a pseudo token, don't free it! @@ -287,6 +288,7 @@ namespace wil return tokenInfo; } #endif +#endif // _WIN32_WINNT >= _WIN32_WINNT_WIN8 /// @cond namespace details @@ -524,6 +526,7 @@ namespace wil return S_OK; } +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) /** Determine whether a token represents an app container This method uses the passed in token and emits a boolean indicating that whether TokenIsAppContainer is true. @@ -573,6 +576,7 @@ namespace wil return value; } #endif // WIL_ENABLE_EXCEPTIONS +#endif // _WIN32_WINNT >= _WIN32_WINNT_WIN8 template bool test_token_membership_failfast(_In_opt_ HANDLE token, const SID_IDENTIFIER_AUTHORITY& sidAuthority, Ts&&... subAuthorities) diff --git a/scripts/runtests.cmd b/scripts/runtests.cmd index e9282fbbc..46d9a2f92 100644 --- a/scripts/runtests.cmd +++ b/scripts/runtests.cmd @@ -56,6 +56,8 @@ call :execute_test noexcept witest.noexcept.exe if %ERRORLEVEL% NEQ 0 ( popd && goto :eof ) call :execute_test normal witest.exe if %ERRORLEVEL% NEQ 0 ( popd && goto :eof ) +call :execute_test win7 witest.win7.exe +if %ERRORLEVEL% NEQ 0 ( popd && goto :eof ) popd goto :eof diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a9c0fae15..bd4e4f55a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,3 +17,4 @@ add_subdirectory(app) add_subdirectory(cpplatest) add_subdirectory(noexcept) add_subdirectory(normal) +add_subdirectory(win7) diff --git a/tests/ResultTests.cpp b/tests/ResultTests.cpp index be9371911..cf49a5ae6 100644 --- a/tests/ResultTests.cpp +++ b/tests/ResultTests.cpp @@ -1,7 +1,10 @@ #include #include + +#if (NTDDI_VERSION >= NTDDI_WIN8) #include +#endif #include @@ -479,7 +482,7 @@ TEST_CASE("ResultTests::ErrorMacros", "[result]") } // The originate helper isn't compatible with CX so don't test it in that mode. -#ifndef __cplusplus_winrt +#if !defined(__cplusplus_winrt) && (NTDDI_VERSION >= NTDDI_WIN8) TEST_CASE("ResultTests::NoOriginationByDefault", "[result]") { ::wil::SetOriginateErrorCallback(nullptr); @@ -572,4 +575,4 @@ TEST_CASE("ResultTests::AutomaticOriginationOnFailure", "[result]") }(); REQUIRE(S_FALSE == GetRestrictedErrorInfo(&restrictedErrorInformation)); } -#endif // __cplusplus_winrt +#endif diff --git a/tests/TokenHelpersTests.cpp b/tests/TokenHelpersTests.cpp index 39295405b..c504ceaf5 100644 --- a/tests/TokenHelpersTests.cpp +++ b/tests/TokenHelpersTests.cpp @@ -38,6 +38,7 @@ TEST_CASE("TokenHelpersTests::VerifyOpenCurrentAccessToken", "[token_helpers]") } #endif +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) TEST_CASE("TokenHelpersTests::VerifyGetTokenInformationNoThrow", "[token_helpers]") { SECTION("Passing a null token") @@ -92,6 +93,7 @@ TEST_CASE("TokenHelpersTests::VerifyLinkedToken", "[token_helpers]") #endif } #endif +#endif bool IsImpersonating() { @@ -186,6 +188,7 @@ TEST_CASE("TokenHelpersTests::VerifyResetThreadToken", "[token_helpers]") } #endif // WIL_ENABLE_EXCEPTIONS +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) template ::FixedSize>* = nullptr> void TestGetTokenInfoForCurrentThread() { @@ -251,6 +254,7 @@ TEST_CASE("TokenHelpersTests::VerifyGetTokenInformationSecurityImpersonationLeve RevertToSelf(); } +#endif bool operator==(const SID_IDENTIFIER_AUTHORITY& left, const SID_IDENTIFIER_AUTHORITY& right) { @@ -274,6 +278,7 @@ TEST_CASE("TokenHelpersTests::StaticSid", "[token_helpers]") REQUIRE(*GetSidSubAuthority(staticSid.get(), 1) == DOMAIN_ALIAS_RID_GUESTS); } +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) TEST_CASE("TokenHelpersTests::TestMembership", "[token_helpers]") { bool member; @@ -318,3 +323,4 @@ TEST_CASE("TokenHelpersTests::Verify_impersonate_token", "[token_helpers]") REQUIRE_NOTHROW(wil::get_token_information()); } #endif // WIL_ENABLE_EXCEPTIONS +#endif diff --git a/tests/wiTest.cpp b/tests/wiTest.cpp index 4b23b5999..b341f1b1a 100644 --- a/tests/wiTest.cpp +++ b/tests/wiTest.cpp @@ -3,7 +3,9 @@ #include #include #include +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) #include +#endif #include #ifdef WIL_ENABLE_EXCEPTIONS @@ -1015,9 +1017,13 @@ TEST_CASE("WindowsInternalTests::UniqueHandle", "[resource][unique_any]") wchar_t tempFileName[MAX_PATH]; REQUIRE_SUCCEEDED(witest::GetTempFileName(tempFileName)); +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) CREATEFILE2_EXTENDED_PARAMETERS params = { sizeof(params) }; params.dwFileAttributes = FILE_ATTRIBUTE_TEMPORARY; wil::unique_hfile spValidHandle(::CreateFile2(tempFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, CREATE_ALWAYS, ¶ms)); +#else + wil::unique_hfile spValidHandle(::CreateFileW(tempFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, nullptr)); +#endif ::DeleteFileW(tempFileName); REQUIRE(spValidHandle.get() != INVALID_HANDLE_VALUE); @@ -1072,9 +1078,13 @@ TEST_CASE("WindowsInternalTests::UniqueHandle", "[resource][unique_any]") wchar_t tempFileName2[MAX_PATH]; REQUIRE_SUCCEEDED(witest::GetTempFileName(tempFileName2)); +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) CREATEFILE2_EXTENDED_PARAMETERS params2 = { sizeof(params2) }; params2.dwFileAttributes = FILE_ATTRIBUTE_TEMPORARY; *(&spMoveHandle) = ::CreateFile2(tempFileName2, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, CREATE_ALWAYS, ¶ms2); +#else + *(&spMoveHandle) = ::CreateFileW(tempFileName2, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, nullptr); +#endif ::DeleteFileW(tempFileName2); REQUIRE(spMoveHandle); @@ -2931,7 +2941,7 @@ TEST_CASE("WindowsInternalTests::TestUniqueArrayCases", "[resource]") } #endif -#ifndef __cplusplus_winrt +#if !defined(__cplusplus_winrt) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8) TEST_CASE("WindowsInternalTests::VerifyMakeAgileCallback", "[wrl]") { using namespace ABI::Windows::Foundation; diff --git a/tests/win7/CMakeLists.txt b/tests/win7/CMakeLists.txt new file mode 100644 index 000000000..8eebc498b --- /dev/null +++ b/tests/win7/CMakeLists.txt @@ -0,0 +1,21 @@ + +project(witest.win7) +add_executable(witest.win7) + +add_definitions("-D_WIN32_WINNT=0x0601") + +target_sources(witest.win7 PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/../main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../CommonTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../ComTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../FileSystemTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../ResourceTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../ResultTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../Rpc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../SafeCastTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../StlTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../TokenHelpersTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../WatcherTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../WistdTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../wiTest.cpp + )