3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Test Windows SDK functions for Microsoft Visual C/C++.
30 from SCons
.Tool
.MSCommon
.MSVC
import Config
31 from SCons
.Tool
.MSCommon
.MSVC
import WinSDK
32 from SCons
.Tool
.MSCommon
.MSVC
import Registry
33 from SCons
.Tool
.MSCommon
.MSVC
.Exceptions
import MSVCInternalError
39 class MSVC_SDK_VERSIONS
:
41 MSVC_SDK_VERSIONS
= Config
.MSVC_SDK_VERSIONS
45 hook
= set(cls
.MSVC_SDK_VERSIONS
)
46 Config
.MSVC_SDK_VERSIONS
= hook
50 def restore(cls
) -> None:
51 Config
.MSVC_SDK_VERSIONS
= cls
.MSVC_SDK_VERSIONS
55 class sdk_query_paths
:
57 sdk_query_paths
= Registry
.sdk_query_paths
60 def sdk_query_paths_duplicate(cls
, version
):
61 sdk_roots
= cls
.sdk_query_paths(version
)
62 sdk_roots
= sdk_roots
+ sdk_roots
if sdk_roots
else sdk_roots
66 def enable_duplicate(cls
):
67 hook
= cls
.sdk_query_paths_duplicate
68 Registry
.sdk_query_paths
= hook
72 def restore(cls
) -> None:
73 Registry
.sdk_query_paths
= cls
.sdk_query_paths
75 class WinSDKTests(unittest
.TestCase
):
78 def setUpClass(cls
) -> None:
79 Patch
.Registry
.sdk_query_paths
.enable_duplicate()
82 def tearDownClass(cls
) -> None:
83 Patch
.Registry
.sdk_query_paths
.restore()
85 def test_verify(self
) -> None:
86 MSVC_SDK_VERSIONS
= Patch
.Config
.MSVC_SDK_VERSIONS
.enable_copy()
87 MSVC_SDK_VERSIONS
.add('99.0')
88 with self
.assertRaises(MSVCInternalError
):
90 Patch
.Config
.MSVC_SDK_VERSIONS
.restore()
92 def _run_reset(self
) -> None:
94 self
.assertFalse(WinSDK
._sdk
_map
_cache
, "WinSDK._sdk_map_cache was not reset")
95 self
.assertFalse(WinSDK
._sdk
_cache
, "WinSDK._sdk_cache was not reset")
97 def _run_get_msvc_sdk_version_list(self
) -> None:
98 for vcver
in Config
.MSVC_VERSION_SUFFIX
.keys():
99 for msvc_uwp_app
in (True, False):
100 _
= WinSDK
.get_msvc_sdk_version_list(vcver
, msvc_uwp_app
=msvc_uwp_app
)
102 def _run_version_list_sdk_map(self
) -> None:
103 for vcver
in Config
.MSVC_VERSION_SUFFIX
.keys():
104 vs_def
= Config
.MSVC_VERSION_SUFFIX
.get(vcver
)
105 if not vs_def
.vc_sdk_versions
:
107 _
= WinSDK
._version
_list
_sdk
_map
(vs_def
.vc_sdk_versions
)
109 def test_version_list_sdk_map(self
) -> None:
110 self
._run
_version
_list
_sdk
_map
()
111 self
._run
_version
_list
_sdk
_map
()
112 self
.assertTrue(WinSDK
._sdk
_map
_cache
, "WinSDK._sdk_map_cache is empty")
114 def test_get_msvc_sdk_version_list(self
) -> None:
115 self
._run
_get
_msvc
_sdk
_version
_list
()
116 self
._run
_get
_msvc
_sdk
_version
_list
()
117 self
.assertTrue(WinSDK
._sdk
_cache
, "WinSDK._sdk_cache is empty")
119 def test_get_msvc_sdk_version_list_empty(self
) -> None:
120 func
= WinSDK
.get_msvc_sdk_version_list
121 for vcver
in [None, '', '99', '99.9']:
122 sdk_versions
= func(vcver
)
123 self
.assertFalse(sdk_versions
, "{}: sdk versions list was not empty for msvc version {}".format(
124 func
.__name
__, repr(vcver
)
127 def test_reset(self
) -> None:
130 if __name__
== "__main__":