1 // Copyright 2018 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/test/scoped_os_info_override_win.h" 6 7 #include <windows.h> 8 9 #include "base/win/windows_version.h" 10 11 namespace base { 12 namespace test { 13 ScopedOSInfoOverride(Type type)14ScopedOSInfoOverride::ScopedOSInfoOverride(Type type) 15 : original_info_(base::win::OSInfo::GetInstance()), 16 overriding_info_(CreateInfoOfType(type)) { 17 *base::win::OSInfo::GetInstanceStorage() = overriding_info_.get(); 18 } 19 ~ScopedOSInfoOverride()20ScopedOSInfoOverride::~ScopedOSInfoOverride() { 21 *base::win::OSInfo::GetInstanceStorage() = original_info_; 22 } 23 24 // static CreateInfoOfType(Type type)25ScopedOSInfoOverride::UniqueOsInfo ScopedOSInfoOverride::CreateInfoOfType( 26 Type type) { 27 _OSVERSIONINFOEXW version_info = {sizeof(version_info)}; 28 _SYSTEM_INFO system_info = {}; 29 int os_type = 0; 30 31 switch (type) { 32 case Type::kWin11Pro: 33 case Type::kWin11Home: 34 version_info.dwMajorVersion = 10; 35 version_info.dwMinorVersion = 0; 36 version_info.dwBuildNumber = 22000; 37 version_info.wServicePackMajor = 0; 38 version_info.wServicePackMinor = 0; 39 version_info.szCSDVersion[0] = 0; 40 version_info.wProductType = VER_NT_WORKSTATION; 41 version_info.wSuiteMask = VER_SUITE_PERSONAL; 42 43 system_info.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64; 44 system_info.dwNumberOfProcessors = 1; 45 system_info.dwAllocationGranularity = 8; 46 47 os_type = 48 type == Type::kWin11Home ? PRODUCT_HOME_BASIC : PRODUCT_PROFESSIONAL; 49 break; 50 case Type::kWinServer2022: 51 version_info.dwMajorVersion = 10; 52 version_info.dwMinorVersion = 0; 53 version_info.dwBuildNumber = 20348; 54 version_info.wServicePackMajor = 0; 55 version_info.wServicePackMinor = 0; 56 version_info.szCSDVersion[0] = 0; 57 version_info.wProductType = VER_NT_SERVER; 58 version_info.wSuiteMask = VER_SUITE_ENTERPRISE; 59 60 system_info.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64; 61 system_info.dwNumberOfProcessors = 4; 62 system_info.dwAllocationGranularity = 64 * 1024; 63 64 os_type = PRODUCT_STANDARD_SERVER; 65 break; 66 case Type::kWin10Pro21H1: 67 case Type::kWin10Pro: 68 case Type::kWin10Home: 69 version_info.dwMajorVersion = 10; 70 version_info.dwMinorVersion = 0; 71 version_info.dwBuildNumber = type == Type::kWin10Pro21H1 ? 19043 : 15063; 72 version_info.wServicePackMajor = 0; 73 version_info.wServicePackMinor = 0; 74 version_info.szCSDVersion[0] = 0; 75 version_info.wProductType = VER_NT_WORKSTATION; 76 version_info.wSuiteMask = VER_SUITE_PERSONAL; 77 78 system_info.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64; 79 system_info.dwNumberOfProcessors = 1; 80 system_info.dwAllocationGranularity = 8; 81 82 os_type = 83 type == Type::kWin10Home ? PRODUCT_HOME_BASIC : PRODUCT_PROFESSIONAL; 84 break; 85 case Type::kWinServer2016: 86 version_info.dwMajorVersion = 10; 87 version_info.dwMinorVersion = 0; 88 version_info.dwBuildNumber = 17134; 89 version_info.wServicePackMajor = 0; 90 version_info.wServicePackMinor = 0; 91 version_info.szCSDVersion[0] = 0; 92 version_info.wProductType = VER_NT_SERVER; 93 version_info.wSuiteMask = VER_SUITE_ENTERPRISE; 94 95 system_info.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64; 96 system_info.dwNumberOfProcessors = 4; 97 system_info.dwAllocationGranularity = 64 * 1024; 98 99 os_type = PRODUCT_STANDARD_SERVER; 100 break; 101 } 102 103 return UniqueOsInfo(new base::win::OSInfo(version_info, system_info, os_type), 104 &ScopedOSInfoOverride::deleter); 105 } 106 107 // static deleter(base::win::OSInfo * info)108void ScopedOSInfoOverride::deleter(base::win::OSInfo* info) { 109 delete info; 110 } 111 112 } // namespace test 113 } // namespace base 114