Skip to content

Commit 212ecbf

Browse files
authored
Add Windows 7 tests and update ifdefs/etc. to match (#120)
1 parent af09372 commit 212ecbf

File tree

7 files changed

+50
-3
lines changed

7 files changed

+50
-3
lines changed

include/wil/token_helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ namespace wil
122122
}
123123
#endif // WIL_ENABLE_EXCEPTIONS
124124

125+
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
125126
// Returns tokenHandle or the effective thread token if tokenHandle is null.
126127
// Note, this returns an token handle who's lifetime is managed independently
127128
// and it may be a pseudo token, don't free it!
@@ -287,6 +288,7 @@ namespace wil
287288
return tokenInfo;
288289
}
289290
#endif
291+
#endif // _WIN32_WINNT >= _WIN32_WINNT_WIN8
290292

291293
/// @cond
292294
namespace details
@@ -524,6 +526,7 @@ namespace wil
524526
return S_OK;
525527
}
526528

529+
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
527530
/** Determine whether a token represents an app container
528531
This method uses the passed in token and emits a boolean indicating that
529532
whether TokenIsAppContainer is true.
@@ -573,6 +576,7 @@ namespace wil
573576
return value;
574577
}
575578
#endif // WIL_ENABLE_EXCEPTIONS
579+
#endif // _WIN32_WINNT >= _WIN32_WINNT_WIN8
576580

577581
template<typename... Ts> bool test_token_membership_failfast(_In_opt_ HANDLE token,
578582
const SID_IDENTIFIER_AUTHORITY& sidAuthority, Ts&&... subAuthorities)

scripts/runtests.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ call :execute_test noexcept witest.noexcept.exe
5656
if %ERRORLEVEL% NEQ 0 ( popd && goto :eof )
5757
call :execute_test normal witest.exe
5858
if %ERRORLEVEL% NEQ 0 ( popd && goto :eof )
59+
call :execute_test win7 witest.win7.exe
60+
if %ERRORLEVEL% NEQ 0 ( popd && goto :eof )
5961
popd
6062

6163
goto :eof

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ add_subdirectory(app)
1717
add_subdirectory(cpplatest)
1818
add_subdirectory(noexcept)
1919
add_subdirectory(normal)
20+
add_subdirectory(win7)

tests/ResultTests.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11

22
#include <wil/com.h>
33
#include <wil/result.h>
4+
5+
#if (NTDDI_VERSION >= NTDDI_WIN8)
46
#include <wil/result_originate.h>
7+
#endif
58

69
#include <roerrorapi.h>
710

@@ -479,7 +482,7 @@ TEST_CASE("ResultTests::ErrorMacros", "[result]")
479482
}
480483

481484
// The originate helper isn't compatible with CX so don't test it in that mode.
482-
#ifndef __cplusplus_winrt
485+
#if !defined(__cplusplus_winrt) && (NTDDI_VERSION >= NTDDI_WIN8)
483486
TEST_CASE("ResultTests::NoOriginationByDefault", "[result]")
484487
{
485488
::wil::SetOriginateErrorCallback(nullptr);
@@ -572,4 +575,4 @@ TEST_CASE("ResultTests::AutomaticOriginationOnFailure", "[result]")
572575
}();
573576
REQUIRE(S_FALSE == GetRestrictedErrorInfo(&restrictedErrorInformation));
574577
}
575-
#endif // __cplusplus_winrt
578+
#endif

tests/TokenHelpersTests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ TEST_CASE("TokenHelpersTests::VerifyOpenCurrentAccessToken", "[token_helpers]")
3838
}
3939
#endif
4040

41+
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
4142
TEST_CASE("TokenHelpersTests::VerifyGetTokenInformationNoThrow", "[token_helpers]")
4243
{
4344
SECTION("Passing a null token")
@@ -92,6 +93,7 @@ TEST_CASE("TokenHelpersTests::VerifyLinkedToken", "[token_helpers]")
9293
#endif
9394
}
9495
#endif
96+
#endif
9597

9698
bool IsImpersonating()
9799
{
@@ -186,6 +188,7 @@ TEST_CASE("TokenHelpersTests::VerifyResetThreadToken", "[token_helpers]")
186188
}
187189
#endif // WIL_ENABLE_EXCEPTIONS
188190

191+
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
189192
template <typename T, wistd::enable_if_t<!wil::details::MapTokenStructToInfoClass<T>::FixedSize>* = nullptr>
190193
void TestGetTokenInfoForCurrentThread()
191194
{
@@ -251,6 +254,7 @@ TEST_CASE("TokenHelpersTests::VerifyGetTokenInformationSecurityImpersonationLeve
251254

252255
RevertToSelf();
253256
}
257+
#endif
254258

255259
bool operator==(const SID_IDENTIFIER_AUTHORITY& left, const SID_IDENTIFIER_AUTHORITY& right)
256260
{
@@ -274,6 +278,7 @@ TEST_CASE("TokenHelpersTests::StaticSid", "[token_helpers]")
274278
REQUIRE(*GetSidSubAuthority(staticSid.get(), 1) == DOMAIN_ALIAS_RID_GUESTS);
275279
}
276280

281+
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
277282
TEST_CASE("TokenHelpersTests::TestMembership", "[token_helpers]")
278283
{
279284
bool member;
@@ -318,3 +323,4 @@ TEST_CASE("TokenHelpersTests::Verify_impersonate_token", "[token_helpers]")
318323
REQUIRE_NOTHROW(wil::get_token_information<TOKEN_TYPE>());
319324
}
320325
#endif // WIL_ENABLE_EXCEPTIONS
326+
#endif

tests/wiTest.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <wil/resource.h>
44
#include <wil/win32_helpers.h>
55
#include <wil/filesystem.h>
6+
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
67
#include <wil/wrl.h>
8+
#endif
79
#include <wil/com.h>
810

911
#ifdef WIL_ENABLE_EXCEPTIONS
@@ -1015,9 +1017,13 @@ TEST_CASE("WindowsInternalTests::UniqueHandle", "[resource][unique_any]")
10151017
wchar_t tempFileName[MAX_PATH];
10161018
REQUIRE_SUCCEEDED(witest::GetTempFileName(tempFileName));
10171019

1020+
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
10181021
CREATEFILE2_EXTENDED_PARAMETERS params = { sizeof(params) };
10191022
params.dwFileAttributes = FILE_ATTRIBUTE_TEMPORARY;
10201023
wil::unique_hfile spValidHandle(::CreateFile2(tempFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, CREATE_ALWAYS, &params));
1024+
#else
1025+
wil::unique_hfile spValidHandle(::CreateFileW(tempFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, nullptr));
1026+
#endif
10211027

10221028
::DeleteFileW(tempFileName);
10231029
REQUIRE(spValidHandle.get() != INVALID_HANDLE_VALUE);
@@ -1072,9 +1078,13 @@ TEST_CASE("WindowsInternalTests::UniqueHandle", "[resource][unique_any]")
10721078
wchar_t tempFileName2[MAX_PATH];
10731079
REQUIRE_SUCCEEDED(witest::GetTempFileName(tempFileName2));
10741080

1081+
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
10751082
CREATEFILE2_EXTENDED_PARAMETERS params2 = { sizeof(params2) };
10761083
params2.dwFileAttributes = FILE_ATTRIBUTE_TEMPORARY;
10771084
*(&spMoveHandle) = ::CreateFile2(tempFileName2, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, CREATE_ALWAYS, &params2);
1085+
#else
1086+
*(&spMoveHandle) = ::CreateFileW(tempFileName2, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, nullptr);
1087+
#endif
10781088

10791089
::DeleteFileW(tempFileName2);
10801090
REQUIRE(spMoveHandle);
@@ -2931,7 +2941,7 @@ TEST_CASE("WindowsInternalTests::TestUniqueArrayCases", "[resource]")
29312941
}
29322942
#endif
29332943

2934-
#ifndef __cplusplus_winrt
2944+
#if !defined(__cplusplus_winrt) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
29352945
TEST_CASE("WindowsInternalTests::VerifyMakeAgileCallback", "[wrl]")
29362946
{
29372947
using namespace ABI::Windows::Foundation;

tests/win7/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
project(witest.win7)
3+
add_executable(witest.win7)
4+
5+
add_definitions("-D_WIN32_WINNT=0x0601")
6+
7+
target_sources(witest.win7 PUBLIC
8+
${CMAKE_CURRENT_SOURCE_DIR}/../main.cpp
9+
${CMAKE_CURRENT_SOURCE_DIR}/../CommonTests.cpp
10+
${CMAKE_CURRENT_SOURCE_DIR}/../ComTests.cpp
11+
${CMAKE_CURRENT_SOURCE_DIR}/../FileSystemTests.cpp
12+
${CMAKE_CURRENT_SOURCE_DIR}/../ResourceTests.cpp
13+
${CMAKE_CURRENT_SOURCE_DIR}/../ResultTests.cpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/../Rpc.cpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/../SafeCastTests.cpp
16+
${CMAKE_CURRENT_SOURCE_DIR}/../StlTests.cpp
17+
${CMAKE_CURRENT_SOURCE_DIR}/../TokenHelpersTests.cpp
18+
${CMAKE_CURRENT_SOURCE_DIR}/../WatcherTests.cpp
19+
${CMAKE_CURRENT_SOURCE_DIR}/../WistdTests.cpp
20+
${CMAKE_CURRENT_SOURCE_DIR}/../wiTest.cpp
21+
)

0 commit comments

Comments
 (0)