Merge pull request #4655 from bdbaddog/fix_new_ninja_package
[scons.git] / SCons / Tool / MSCommon / MSVC / WinSDKTests.py
blob10e68f3d6e7b6a52285d39066cd9661b7a3b367e
1 # MIT License
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.
24 """
25 Test Windows SDK functions for Microsoft Visual C/C++.
26 """
28 import unittest
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
35 class Patch:
37 class Config:
39 class MSVC_SDK_VERSIONS:
41 MSVC_SDK_VERSIONS = Config.MSVC_SDK_VERSIONS
43 @classmethod
44 def enable_copy(cls):
45 hook = set(cls.MSVC_SDK_VERSIONS)
46 Config.MSVC_SDK_VERSIONS = hook
47 return hook
49 @classmethod
50 def restore(cls) -> None:
51 Config.MSVC_SDK_VERSIONS = cls.MSVC_SDK_VERSIONS
53 class Registry:
55 class sdk_query_paths:
57 sdk_query_paths = Registry.sdk_query_paths
59 @classmethod
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
63 return sdk_roots
65 @classmethod
66 def enable_duplicate(cls):
67 hook = cls.sdk_query_paths_duplicate
68 Registry.sdk_query_paths = hook
69 return hook
71 @classmethod
72 def restore(cls) -> None:
73 Registry.sdk_query_paths = cls.sdk_query_paths
75 class WinSDKTests(unittest.TestCase):
77 @classmethod
78 def setUpClass(cls) -> None:
79 Patch.Registry.sdk_query_paths.enable_duplicate()
81 @classmethod
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):
89 WinSDK.verify()
90 Patch.Config.MSVC_SDK_VERSIONS.restore()
92 def _run_reset(self) -> None:
93 WinSDK.reset()
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:
106 continue
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:
128 self._run_reset()
130 if __name__ == "__main__":
131 unittest.main()