diff options
Diffstat (limited to 'xbmc/utils/test/TestSystemInfo.cpp')
| -rw-r--r-- | xbmc/utils/test/TestSystemInfo.cpp | 326 |
1 files changed, 326 insertions, 0 deletions
diff --git a/xbmc/utils/test/TestSystemInfo.cpp b/xbmc/utils/test/TestSystemInfo.cpp new file mode 100644 index 0000000..1f2b0a1 --- /dev/null +++ b/xbmc/utils/test/TestSystemInfo.cpp | |||
| @@ -0,0 +1,326 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "GUIInfoManager.h" | ||
| 10 | #include "ServiceBroker.h" | ||
| 11 | #include "settings/Settings.h" | ||
| 12 | #include "utils/CPUInfo.h" | ||
| 13 | #include "utils/SystemInfo.h" | ||
| 14 | #if defined(TARGET_WINDOWS) | ||
| 15 | #include "platform/win32/CharsetConverter.h" | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #include <gtest/gtest.h> | ||
| 19 | |||
| 20 | class TestSystemInfo : public testing::Test | ||
| 21 | { | ||
| 22 | protected: | ||
| 23 | TestSystemInfo() { CServiceBroker::RegisterCPUInfo(CCPUInfo::GetCPUInfo()); } | ||
| 24 | ~TestSystemInfo() { CServiceBroker::UnregisterCPUInfo(); } | ||
| 25 | }; | ||
| 26 | |||
| 27 | TEST_F(TestSystemInfo, Print_System_Info) | ||
| 28 | { | ||
| 29 | std::cout << "'GetKernelName(false)': \"" << g_sysinfo.GetKernelName(true) << "\"\n"; | ||
| 30 | std::cout << "'GetKernelVersion()': \"" << g_sysinfo.GetKernelVersion() << "\"\n"; | ||
| 31 | std::cout << "'GetKernelVersionFull()': \"" << g_sysinfo.GetKernelVersionFull() << "\"\n"; | ||
| 32 | std::cout << "'GetOsPrettyNameWithVersion()': \"" << g_sysinfo.GetOsPrettyNameWithVersion() << "\"\n"; | ||
| 33 | std::cout << "'GetOsName(false)': \"" << g_sysinfo.GetOsName(false) << "\"\n"; | ||
| 34 | std::cout << "'GetOsVersion()': \"" << g_sysinfo.GetOsVersion() << "\"\n"; | ||
| 35 | std::cout << "'GetKernelCpuFamily()': \"" << g_sysinfo.GetKernelCpuFamily() << "\"\n"; | ||
| 36 | std::cout << "'GetKernelBitness()': \"" << g_sysinfo.GetKernelBitness() << "\"\n"; | ||
| 37 | std::cout << "'GetBuildTargetPlatformName()': \"" << g_sysinfo.GetBuildTargetPlatformName() << "\"\n"; | ||
| 38 | std::cout << "'GetBuildTargetPlatformVersionDecoded()': \"" << g_sysinfo.GetBuildTargetPlatformVersionDecoded() << "\"\n"; | ||
| 39 | std::cout << "'GetBuildTargetPlatformVersion()': \"" << g_sysinfo.GetBuildTargetPlatformVersion() << "\"\n"; | ||
| 40 | std::cout << "'GetBuildTargetCpuFamily()': \"" << g_sysinfo.GetBuildTargetCpuFamily() << "\"\n"; | ||
| 41 | std::cout << "'GetXbmcBitness()': \"" << g_sysinfo.GetXbmcBitness() << "\"\n"; | ||
| 42 | std::cout << "'GetUsedCompilerNameAndVer()': \"" << g_sysinfo.GetUsedCompilerNameAndVer() << "\"\n"; | ||
| 43 | std::cout << "'GetManufacturerName()': \"" << g_sysinfo.GetManufacturerName() << "\"\n"; | ||
| 44 | std::cout << "'GetModelName()': \"" << g_sysinfo.GetModelName() << "\"\n"; | ||
| 45 | std::cout << "'GetUserAgent()': \"" << g_sysinfo.GetUserAgent() << "\"\n"; | ||
| 46 | } | ||
| 47 | |||
| 48 | TEST_F(TestSystemInfo, GetKernelName) | ||
| 49 | { | ||
| 50 | EXPECT_FALSE(g_sysinfo.GetKernelName(true).empty()) << "'GetKernelName(true)' must not return empty kernel name"; | ||
| 51 | EXPECT_FALSE(g_sysinfo.GetKernelName(false).empty()) << "'GetKernelName(false)' must not return empty kernel name"; | ||
| 52 | EXPECT_STRCASENE("Unknown kernel", g_sysinfo.GetKernelName(true).c_str()) << "'GetKernelName(true)' must not return 'Unknown kernel'"; | ||
| 53 | EXPECT_STRCASENE("Unknown kernel", g_sysinfo.GetKernelName(false).c_str()) << "'GetKernelName(false)' must not return 'Unknown kernel'"; | ||
| 54 | #ifndef TARGET_DARWIN | ||
| 55 | EXPECT_EQ(g_sysinfo.GetBuildTargetPlatformName(), g_sysinfo.GetKernelName(true)) << "'GetKernelName(true)' must match GetBuildTargetPlatformName()"; | ||
| 56 | EXPECT_EQ(g_sysinfo.GetBuildTargetPlatformName(), g_sysinfo.GetKernelName(false)) << "'GetKernelName(false)' must match GetBuildTargetPlatformName()"; | ||
| 57 | #endif // !TARGET_DARWIN | ||
| 58 | #if defined(TARGET_WINDOWS) | ||
| 59 | EXPECT_NE(std::string::npos, g_sysinfo.GetKernelName(true).find("Windows")) << "'GetKernelName(true)' must contain 'Windows'"; | ||
| 60 | EXPECT_NE(std::string::npos, g_sysinfo.GetKernelName(false).find("Windows")) << "'GetKernelName(false)' must contain 'Windows'"; | ||
| 61 | #elif defined(TARGET_FREEBSD) | ||
| 62 | EXPECT_STREQ("FreeBSD", g_sysinfo.GetKernelName(true).c_str()) << "'GetKernelName(true)' must return 'FreeBSD'"; | ||
| 63 | EXPECT_STREQ("FreeBSD", g_sysinfo.GetKernelName(false).c_str()) << "'GetKernelName(false)' must return 'FreeBSD'"; | ||
| 64 | #elif defined(TARGET_DARWIN) | ||
| 65 | EXPECT_STREQ("Darwin", g_sysinfo.GetKernelName(true).c_str()) << "'GetKernelName(true)' must return 'Darwin'"; | ||
| 66 | EXPECT_STREQ("Darwin", g_sysinfo.GetKernelName(false).c_str()) << "'GetKernelName(false)' must return 'Darwin'"; | ||
| 67 | #elif defined(TARGET_LINUX) | ||
| 68 | EXPECT_STREQ("Linux", g_sysinfo.GetKernelName(true).c_str()) << "'GetKernelName(true)' must return 'Linux'"; | ||
| 69 | EXPECT_STREQ("Linux", g_sysinfo.GetKernelName(false).c_str()) << "'GetKernelName(false)' must return 'Linux'"; | ||
| 70 | #endif | ||
| 71 | } | ||
| 72 | |||
| 73 | TEST_F(TestSystemInfo, GetKernelVersionFull) | ||
| 74 | { | ||
| 75 | EXPECT_FALSE(g_sysinfo.GetKernelVersionFull().empty()) << "'GetKernelVersionFull()' must not return empty string"; | ||
| 76 | EXPECT_STRNE("0.0.0", g_sysinfo.GetKernelVersionFull().c_str()) << "'GetKernelVersionFull()' must not return '0.0.0'"; | ||
| 77 | EXPECT_STRNE("0.0", g_sysinfo.GetKernelVersionFull().c_str()) << "'GetKernelVersionFull()' must not return '0.0'"; | ||
| 78 | EXPECT_EQ(0U, g_sysinfo.GetKernelVersionFull().find_first_of("0123456789")) << "'GetKernelVersionFull()' must not return version not starting from digit"; | ||
| 79 | } | ||
| 80 | |||
| 81 | TEST_F(TestSystemInfo, GetKernelVersion) | ||
| 82 | { | ||
| 83 | EXPECT_FALSE(g_sysinfo.GetKernelVersion().empty()) << "'GetKernelVersion()' must not return empty string"; | ||
| 84 | EXPECT_STRNE("0.0.0", g_sysinfo.GetKernelVersion().c_str()) << "'GetKernelVersion()' must not return '0.0.0'"; | ||
| 85 | EXPECT_STRNE("0.0", g_sysinfo.GetKernelVersion().c_str()) << "'GetKernelVersion()' must not return '0.0'"; | ||
| 86 | EXPECT_EQ(0U, g_sysinfo.GetKernelVersion().find_first_of("0123456789")) << "'GetKernelVersion()' must not return version not starting from digit"; | ||
| 87 | EXPECT_EQ(std::string::npos, g_sysinfo.GetKernelVersion().find_first_not_of("0123456789.")) << "'GetKernelVersion()' must not return version with not only digits and dots"; | ||
| 88 | } | ||
| 89 | |||
| 90 | TEST_F(TestSystemInfo, GetOsName) | ||
| 91 | { | ||
| 92 | EXPECT_FALSE(g_sysinfo.GetOsName(true).empty()) << "'GetOsName(true)' must not return empty OS name"; | ||
| 93 | EXPECT_FALSE(g_sysinfo.GetOsName(false).empty()) << "'GetOsName(false)' must not return empty OS name"; | ||
| 94 | EXPECT_STRCASENE("Unknown OS", g_sysinfo.GetOsName(true).c_str()) << "'GetOsName(true)' must not return 'Unknown OS'"; | ||
| 95 | EXPECT_STRCASENE("Unknown OS", g_sysinfo.GetOsName(false).c_str()) << "'GetOsName(false)' must not return 'Unknown OS'"; | ||
| 96 | #if defined(TARGET_WINDOWS) | ||
| 97 | EXPECT_NE(std::string::npos, g_sysinfo.GetOsName(true).find("Windows")) << "'GetOsName(true)' must contain 'Windows'"; | ||
| 98 | EXPECT_NE(std::string::npos, g_sysinfo.GetOsName(false).find("Windows")) << "'GetOsName(false)' must contain 'Windows'"; | ||
| 99 | #elif defined(TARGET_FREEBSD) | ||
| 100 | EXPECT_STREQ("FreeBSD", g_sysinfo.GetOsName(true).c_str()) << "'GetOsName(true)' must return 'FreeBSD'"; | ||
| 101 | EXPECT_STREQ("FreeBSD", g_sysinfo.GetOsName(false).c_str()) << "'GetOsName(false)' must return 'FreeBSD'"; | ||
| 102 | #elif defined(TARGET_DARWIN_IOS) | ||
| 103 | EXPECT_STREQ("iOS", g_sysinfo.GetOsName(true).c_str()) << "'GetOsName(true)' must return 'iOS'"; | ||
| 104 | EXPECT_STREQ("iOS", g_sysinfo.GetOsName(false).c_str()) << "'GetOsName(false)' must return 'iOS'"; | ||
| 105 | #elif defined(TARGET_DARWIN_TVOS) | ||
| 106 | EXPECT_STREQ("tvOS", g_sysinfo.GetOsName(true).c_str()) << "'GetOsName(true)' must return 'tvOS'"; | ||
| 107 | EXPECT_STREQ("tvOS", g_sysinfo.GetOsName(false).c_str()) | ||
| 108 | << "'GetOsName(false)' must return 'tvOS'"; | ||
| 109 | #elif defined(TARGET_DARWIN_OSX) | ||
| 110 | EXPECT_STREQ("OS X", g_sysinfo.GetOsName(true).c_str()) << "'GetOsName(true)' must return 'OS X'"; | ||
| 111 | EXPECT_STREQ("OS X", g_sysinfo.GetOsName(false).c_str()) << "'GetOsName(false)' must return 'OS X'"; | ||
| 112 | #elif defined(TARGET_ANDROID) | ||
| 113 | EXPECT_STREQ("Android", g_sysinfo.GetOsName(true).c_str()) << "'GetOsName(true)' must return 'Android'"; | ||
| 114 | EXPECT_STREQ("Android", g_sysinfo.GetOsName(false).c_str()) << "'GetOsName(false)' must return 'Android'"; | ||
| 115 | #endif | ||
| 116 | #ifdef TARGET_DARWIN | ||
| 117 | EXPECT_EQ(g_sysinfo.GetBuildTargetPlatformName(), g_sysinfo.GetOsName(true)) << "'GetOsName(true)' must match GetBuildTargetPlatformName()"; | ||
| 118 | EXPECT_EQ(g_sysinfo.GetBuildTargetPlatformName(), g_sysinfo.GetOsName(false)) << "'GetOsName(false)' must match GetBuildTargetPlatformName()"; | ||
| 119 | #endif // TARGET_DARWIN | ||
| 120 | } | ||
| 121 | |||
| 122 | TEST_F(TestSystemInfo, DISABLED_GetOsVersion) | ||
| 123 | { | ||
| 124 | EXPECT_FALSE(g_sysinfo.GetOsVersion().empty()) << "'GetOsVersion()' must not return empty string"; | ||
| 125 | EXPECT_STRNE("0.0.0", g_sysinfo.GetOsVersion().c_str()) << "'GetOsVersion()' must not return '0.0.0'"; | ||
| 126 | EXPECT_STRNE("0.0", g_sysinfo.GetOsVersion().c_str()) << "'GetOsVersion()' must not return '0.0'"; | ||
| 127 | EXPECT_EQ(0U, g_sysinfo.GetOsVersion().find_first_of("0123456789")) << "'GetOsVersion()' must not return version not starting from digit"; | ||
| 128 | EXPECT_EQ(std::string::npos, g_sysinfo.GetOsVersion().find_first_not_of("0123456789.")) << "'GetOsVersion()' must not return version with not only digits and dots"; | ||
| 129 | } | ||
| 130 | |||
| 131 | TEST_F(TestSystemInfo, GetOsPrettyNameWithVersion) | ||
| 132 | { | ||
| 133 | EXPECT_FALSE(g_sysinfo.GetOsPrettyNameWithVersion().empty()) << "'GetOsPrettyNameWithVersion()' must not return empty string"; | ||
| 134 | EXPECT_EQ(std::string::npos, g_sysinfo.GetOsPrettyNameWithVersion().find("Unknown")) << "'GetOsPrettyNameWithVersion()' must not contain 'Unknown'"; | ||
| 135 | EXPECT_EQ(std::string::npos, g_sysinfo.GetOsPrettyNameWithVersion().find("unknown")) << "'GetOsPrettyNameWithVersion()' must not contain 'unknown'"; | ||
| 136 | #ifdef TARGET_WINDOWS | ||
| 137 | EXPECT_NE(std::string::npos, g_sysinfo.GetOsPrettyNameWithVersion().find("Windows")) << "'GetOsPrettyNameWithVersion()' must contain 'Windows'"; | ||
| 138 | #else // ! TARGET_WINDOWS | ||
| 139 | EXPECT_NE(std::string::npos, g_sysinfo.GetOsPrettyNameWithVersion().find(g_sysinfo.GetOsVersion())) << "'GetOsPrettyNameWithVersion()' must contain OS version"; | ||
| 140 | #endif // ! TARGET_WINDOWS | ||
| 141 | } | ||
| 142 | |||
| 143 | TEST_F(TestSystemInfo, GetManufacturerName) | ||
| 144 | { | ||
| 145 | EXPECT_STRCASENE("unknown", g_sysinfo.GetManufacturerName().c_str()) << "'GetManufacturerName()' must return empty string instead of 'Unknown'"; | ||
| 146 | } | ||
| 147 | |||
| 148 | TEST_F(TestSystemInfo, GetModelName) | ||
| 149 | { | ||
| 150 | EXPECT_STRCASENE("unknown", g_sysinfo.GetModelName().c_str()) << "'GetModelName()' must return empty string instead of 'Unknown'"; | ||
| 151 | } | ||
| 152 | |||
| 153 | #ifndef TARGET_WINDOWS | ||
| 154 | TEST_F(TestSystemInfo, IsAeroDisabled) | ||
| 155 | { | ||
| 156 | EXPECT_FALSE(g_sysinfo.IsAeroDisabled()) << "'IsAeroDisabled()' must return 'false'"; | ||
| 157 | } | ||
| 158 | #endif // ! TARGET_WINDOWS | ||
| 159 | |||
| 160 | TEST_F(TestSystemInfo, IsWindowsVersion) | ||
| 161 | { | ||
| 162 | EXPECT_FALSE(g_sysinfo.IsWindowsVersion(CSysInfo::WindowsVersionUnknown)) << "'IsWindowsVersion()' must return 'false' for 'WindowsVersionUnknown'"; | ||
| 163 | #ifndef TARGET_WINDOWS | ||
| 164 | EXPECT_FALSE(g_sysinfo.IsWindowsVersion(CSysInfo::WindowsVersionWin7)) << "'IsWindowsVersion()' must return 'false'"; | ||
| 165 | #endif // ! TARGET_WINDOWS | ||
| 166 | } | ||
| 167 | |||
| 168 | TEST_F(TestSystemInfo, IsWindowsVersionAtLeast) | ||
| 169 | { | ||
| 170 | EXPECT_FALSE(g_sysinfo.IsWindowsVersionAtLeast(CSysInfo::WindowsVersionUnknown)) << "'IsWindowsVersionAtLeast()' must return 'false' for 'WindowsVersionUnknown'"; | ||
| 171 | EXPECT_FALSE(g_sysinfo.IsWindowsVersionAtLeast(CSysInfo::WindowsVersionFuture)) << "'IsWindowsVersionAtLeast()' must return 'false' for 'WindowsVersionFuture'"; | ||
| 172 | #ifndef TARGET_WINDOWS | ||
| 173 | EXPECT_FALSE(g_sysinfo.IsWindowsVersion(CSysInfo::WindowsVersionWin7)) << "'IsWindowsVersionAtLeast()' must return 'false'"; | ||
| 174 | #endif // ! TARGET_WINDOWS | ||
| 175 | } | ||
| 176 | |||
| 177 | TEST_F(TestSystemInfo, GetWindowsVersion) | ||
| 178 | { | ||
| 179 | #ifdef TARGET_WINDOWS | ||
| 180 | EXPECT_NE(CSysInfo::WindowsVersionUnknown, g_sysinfo.GetWindowsVersion()) << "'GetWindowsVersion()' must not return 'WindowsVersionUnknown'"; | ||
| 181 | EXPECT_NE(CSysInfo::WindowsVersionFuture, g_sysinfo.GetWindowsVersion()) << "'GetWindowsVersion()' must not return 'WindowsVersionFuture'"; | ||
| 182 | #else // ! TARGET_WINDOWS | ||
| 183 | EXPECT_EQ(CSysInfo::WindowsVersionUnknown, g_sysinfo.GetWindowsVersion()) << "'GetWindowsVersion()' must return 'WindowsVersionUnknown'"; | ||
| 184 | #endif // ! TARGET_WINDOWS | ||
| 185 | } | ||
| 186 | |||
| 187 | TEST_F(TestSystemInfo, GetKernelBitness) | ||
| 188 | { | ||
| 189 | EXPECT_TRUE(g_sysinfo.GetKernelBitness() == 32 || g_sysinfo.GetKernelBitness() == 64) << "'GetKernelBitness()' must return '32' or '64', but not '" << g_sysinfo.GetKernelBitness() << "'"; | ||
| 190 | EXPECT_LE(g_sysinfo.GetXbmcBitness(), g_sysinfo.GetKernelBitness()) << "'GetKernelBitness()' must be greater or equal to 'GetXbmcBitness()'"; | ||
| 191 | } | ||
| 192 | |||
| 193 | TEST_F(TestSystemInfo, GetKernelCpuFamily) | ||
| 194 | { | ||
| 195 | EXPECT_STRNE("unknown CPU family", g_sysinfo.GetKernelCpuFamily().c_str()) << "'GetKernelCpuFamily()' must not return 'unknown CPU family'"; | ||
| 196 | #if defined(__thumb__) || defined(_M_ARMT) || defined(__arm__) || defined(_M_ARM) || defined (__aarch64__) | ||
| 197 | EXPECT_STREQ("ARM", g_sysinfo.GetKernelCpuFamily().c_str()) << "'GetKernelCpuFamily()' must return 'ARM'"; | ||
| 198 | #else // ! ARM | ||
| 199 | EXPECT_EQ(g_sysinfo.GetBuildTargetCpuFamily(), g_sysinfo.GetKernelCpuFamily()) << "'GetKernelCpuFamily()' must match 'GetBuildTargetCpuFamily()'"; | ||
| 200 | #endif // ! ARM | ||
| 201 | } | ||
| 202 | |||
| 203 | TEST_F(TestSystemInfo, GetXbmcBitness) | ||
| 204 | { | ||
| 205 | EXPECT_TRUE(g_sysinfo.GetXbmcBitness() == 32 || g_sysinfo.GetXbmcBitness() == 64) << "'GetXbmcBitness()' must return '32' or '64', but not '" << g_sysinfo.GetXbmcBitness() << "'"; | ||
| 206 | EXPECT_GE(g_sysinfo.GetKernelBitness(), g_sysinfo.GetXbmcBitness()) << "'GetXbmcBitness()' must be not greater than 'GetKernelBitness()'"; | ||
| 207 | } | ||
| 208 | |||
| 209 | TEST_F(TestSystemInfo, GetUserAgent) | ||
| 210 | { | ||
| 211 | EXPECT_STREQ(g_sysinfo.GetAppName().c_str(), g_sysinfo.GetUserAgent().substr(0, g_sysinfo.GetAppName().size()).c_str()) << "'GetUserAgent()' string must start with app name'"; | ||
| 212 | EXPECT_NE(std::string::npos, g_sysinfo.GetUserAgent().find('(')) << "'GetUserAgent()' must contain brackets around second parameter"; | ||
| 213 | EXPECT_NE(std::string::npos, g_sysinfo.GetUserAgent().find(')')) << "'GetUserAgent()' must contain brackets around second parameter"; | ||
| 214 | EXPECT_EQ(g_sysinfo.GetUserAgent().find(' '), g_sysinfo.GetUserAgent().find(" (")) << "Second parameter in 'GetUserAgent()' string must be in brackets"; | ||
| 215 | EXPECT_EQ(g_sysinfo.GetUserAgent().find(" (") + 1, g_sysinfo.GetUserAgent().find('(')) << "'GetUserAgent()' string must not contain any opening brackets before second parameter"; | ||
| 216 | EXPECT_GT(g_sysinfo.GetUserAgent().find(')'), g_sysinfo.GetUserAgent().find('(')) << "'GetUserAgent()' string must not contain any closing brackets before second parameter"; | ||
| 217 | EXPECT_EQ(g_sysinfo.GetUserAgent().find(") "), g_sysinfo.GetUserAgent().find(')')) << "'GetUserAgent()' string must not contain any closing brackets before end of second parameter"; | ||
| 218 | #if defined(TARGET_WINDOWS) | ||
| 219 | EXPECT_EQ(g_sysinfo.GetUserAgent().find('('), g_sysinfo.GetUserAgent().find("(Windows")) << "Second parameter in 'GetUserAgent()' string must start from `Windows`"; | ||
| 220 | EXPECT_NE(std::string::npos, g_sysinfo.GetUserAgent().find("Windows")) << "'GetUserAgent()' must contain 'Windows'"; | ||
| 221 | #elif defined(TARGET_DARWIN_IOS) | ||
| 222 | EXPECT_NE(std::string::npos, g_sysinfo.GetUserAgent().find("like Mac OS X")) << "'GetUserAgent()' must contain ' like Mac OS X'"; | ||
| 223 | EXPECT_TRUE(g_sysinfo.GetUserAgent().find("CPU OS ") != std::string::npos || g_sysinfo.GetUserAgent().find("CPU iPhone OS ") != std::string::npos) << "'GetUserAgent()' must contain 'CPU OS ' or 'CPU iPhone OS '"; | ||
| 224 | #elif defined(TARGET_DARWIN_TVOS) | ||
| 225 | EXPECT_NE(std::string::npos, g_sysinfo.GetUserAgent().find("like Mac OS X")) | ||
| 226 | << "'GetUserAgent()' must contain ' like Mac OS X'"; | ||
| 227 | EXPECT_TRUE(g_sysinfo.GetUserAgent().find("CPU TVOS ") != std::string::npos) | ||
| 228 | << "'GetUserAgent()' must contain 'CPU TVOS '"; | ||
| 229 | #elif defined(TARGET_DARWIN_OSX) | ||
| 230 | EXPECT_EQ(g_sysinfo.GetUserAgent().find('('), g_sysinfo.GetUserAgent().find("(Macintosh; ")) << "Second parameter in 'GetUserAgent()' string must start from 'Macintosh; '"; | ||
| 231 | #elif defined(TARGET_ANDROID) | ||
| 232 | EXPECT_EQ(g_sysinfo.GetUserAgent().find('('), g_sysinfo.GetUserAgent().find("(Linux; Android ")) << "Second parameter in 'GetUserAgent()' string must start from 'Linux; Android '"; | ||
| 233 | #elif defined(TARGET_POSIX) | ||
| 234 | EXPECT_EQ(g_sysinfo.GetUserAgent().find('('), g_sysinfo.GetUserAgent().find("(X11; ")) << "Second parameter in 'GetUserAgent()' string must start from 'X11; '"; | ||
| 235 | #if defined(TARGET_FREEBSD) | ||
| 236 | EXPECT_EQ(g_sysinfo.GetUserAgent().find('('), g_sysinfo.GetUserAgent().find("(X11; FreeBSD ")) << "Second parameter in 'GetUserAgent()' string must start from 'X11; FreeBSD '"; | ||
| 237 | #elif defined(TARGET_LINUX) | ||
| 238 | EXPECT_EQ(g_sysinfo.GetUserAgent().find('('), g_sysinfo.GetUserAgent().find("(X11; Linux ")) << "Second parameter in 'GetUserAgent()' string must start from 'X11; Linux '"; | ||
| 239 | #endif // defined(TARGET_LINUX) | ||
| 240 | #endif // defined(TARGET_POSIX) | ||
| 241 | |||
| 242 | #ifdef TARGET_RASPBERRY_PI | ||
| 243 | EXPECT_NE(std::string::npos, g_sysinfo.GetUserAgent().find(" XBMC_HW_RaspberryPi/")) << "'GetUserAgent()' must contain ' XBMC_HW_RaspberryPi/'"; | ||
| 244 | #endif // TARGET_RASPBERRY_PI | ||
| 245 | |||
| 246 | EXPECT_NE(std::string::npos, g_sysinfo.GetUserAgent().find(" App_Bitness/")) << "'GetUserAgent()' must contain ' App_Bitness/'"; | ||
| 247 | EXPECT_NE(std::string::npos, g_sysinfo.GetUserAgent().find(" Version/")) << "'GetUserAgent()' must contain ' Version/'"; | ||
| 248 | } | ||
| 249 | |||
| 250 | TEST_F(TestSystemInfo, GetBuildTargetPlatformName) | ||
| 251 | { | ||
| 252 | EXPECT_EQ(std::string::npos, g_sysinfo.GetBuildTargetPlatformName().find("Unknown")) << "'GetBuildTargetPlatformName()' must not contain 'Unknown', actual value: '" << g_sysinfo.GetBuildTargetPlatformName() << "'"; | ||
| 253 | EXPECT_EQ(std::string::npos, g_sysinfo.GetBuildTargetPlatformName().find("unknown")) << "'GetBuildTargetPlatformName()' must not contain 'unknown', actual value: '" << g_sysinfo.GetBuildTargetPlatformName() << "'"; | ||
| 254 | } | ||
| 255 | |||
| 256 | TEST_F(TestSystemInfo, GetBuildTargetPlatformVersion) | ||
| 257 | { | ||
| 258 | EXPECT_EQ(std::string::npos, g_sysinfo.GetBuildTargetPlatformVersion().find("Unknown")) << "'GetBuildTargetPlatformVersion()' must not contain 'Unknown', actual value: '" << g_sysinfo.GetBuildTargetPlatformVersion() << "'"; | ||
| 259 | EXPECT_EQ(std::string::npos, g_sysinfo.GetBuildTargetPlatformVersion().find("unknown")) << "'GetBuildTargetPlatformVersion()' must not contain 'unknown', actual value: '" << g_sysinfo.GetBuildTargetPlatformVersion() << "'"; | ||
| 260 | } | ||
| 261 | |||
| 262 | TEST_F(TestSystemInfo, GetBuildTargetPlatformVersionDecoded) | ||
| 263 | { | ||
| 264 | EXPECT_EQ(std::string::npos, g_sysinfo.GetBuildTargetPlatformVersionDecoded().find("Unknown")) << "'GetBuildTargetPlatformVersionDecoded()' must not contain 'Unknown', actual value: '" << g_sysinfo.GetBuildTargetPlatformVersion() << "'"; | ||
| 265 | EXPECT_EQ(std::string::npos, g_sysinfo.GetBuildTargetPlatformVersionDecoded().find("unknown")) << "'GetBuildTargetPlatformVersionDecoded()' must not contain 'unknown', actual value: '" << g_sysinfo.GetBuildTargetPlatformVersion() << "'"; | ||
| 266 | #ifdef TARGET_ANDROID | ||
| 267 | EXPECT_STREQ("API level ", g_sysinfo.GetBuildTargetPlatformVersionDecoded().substr(0, 10).c_str()) << "'GetBuildTargetPlatformVersionDecoded()' must start from 'API level '"; | ||
| 268 | #else | ||
| 269 | EXPECT_STREQ("version ", g_sysinfo.GetBuildTargetPlatformVersionDecoded().substr(0, 8).c_str()) << "'GetBuildTargetPlatformVersionDecoded()' must start from 'version'"; | ||
| 270 | #endif | ||
| 271 | } | ||
| 272 | |||
| 273 | TEST_F(TestSystemInfo, GetBuildTargetCpuFamily) | ||
| 274 | { | ||
| 275 | EXPECT_STRNE("unknown CPU family", g_sysinfo.GetBuildTargetCpuFamily().c_str()) << "'GetBuildTargetCpuFamily()' must not return 'unknown CPU family'"; | ||
| 276 | #if defined(__thumb__) || defined(_M_ARMT) || defined(__arm__) || defined(_M_ARM) || defined (__aarch64__) | ||
| 277 | EXPECT_STREQ("ARM", g_sysinfo.GetBuildTargetCpuFamily().substr(0, 3).c_str()) << "'GetKernelCpuFamily()' string must start from 'ARM'"; | ||
| 278 | #else // ! ARM | ||
| 279 | EXPECT_EQ(g_sysinfo.GetKernelCpuFamily(), g_sysinfo.GetBuildTargetCpuFamily()) << "'GetBuildTargetCpuFamily()' must match 'GetKernelCpuFamily()'"; | ||
| 280 | #endif // ! ARM | ||
| 281 | } | ||
| 282 | |||
| 283 | TEST_F(TestSystemInfo, GetUsedCompilerNameAndVer) | ||
| 284 | { | ||
| 285 | EXPECT_STRNE("unknown compiler", g_sysinfo.GetUsedCompilerNameAndVer().c_str()) << "'GetUsedCompilerNameAndVer()' must not return 'unknown compiler'"; | ||
| 286 | } | ||
| 287 | |||
| 288 | TEST_F(TestSystemInfo, GetDiskSpace) | ||
| 289 | { | ||
| 290 | int iTotal, iTotalFree, iTotalUsed, iPercentFree, iPercentUsed; | ||
| 291 | |||
| 292 | iTotal = iTotalFree = iTotalUsed = iPercentFree = iPercentUsed = 0; | ||
| 293 | EXPECT_TRUE(g_sysinfo.GetDiskSpace("*", iTotal, iTotalFree, iTotalUsed, iPercentFree, iPercentUsed)) << "'GetDiskSpace()' return 'false' for disk '*'"; | ||
| 294 | EXPECT_NE(0, iTotal) << "'GetDiskSpace()' return zero total space for disk '*'"; | ||
| 295 | EXPECT_EQ(iTotal, iTotalFree + iTotalUsed) << "'GetDiskSpace()' return 'TotalFree + TotalUsed' not equal to 'Total' for disk '*'"; | ||
| 296 | EXPECT_EQ(100, iPercentFree + iPercentUsed) << "'GetDiskSpace()' return 'PercentFree + PercentUsed' not equal to '100' for disk '*'"; | ||
| 297 | |||
| 298 | iTotal = iTotalFree = iTotalUsed = iPercentFree = iPercentUsed = 0; | ||
| 299 | EXPECT_TRUE(g_sysinfo.GetDiskSpace("", iTotal, iTotalFree, iTotalUsed, iPercentFree, iPercentUsed)) << "'GetDiskSpace()' return 'false' for disk ''"; | ||
| 300 | EXPECT_NE(0, iTotal) << "'GetDiskSpace()' return zero total space for disk ''"; | ||
| 301 | EXPECT_EQ(iTotal, iTotalFree + iTotalUsed) << "'GetDiskSpace()' return 'TotalFree + TotalUsed' not equal to 'Total' for disk ''"; | ||
| 302 | EXPECT_EQ(100, iPercentFree + iPercentUsed) << "'GetDiskSpace()' return 'PercentFree + PercentUsed' not equal to '100' for disk ''"; | ||
| 303 | |||
| 304 | #ifdef TARGET_WINDOWS | ||
| 305 | using KODI::PLATFORM::WINDOWS::FromW; | ||
| 306 | wchar_t sysDrive[300]; | ||
| 307 | DWORD res = GetEnvironmentVariableW(L"SystemDrive", sysDrive, sizeof(sysDrive) / sizeof(wchar_t)); | ||
| 308 | std::string sysDriveLtr; | ||
| 309 | if (res != 0 && res <= sizeof(sysDrive) / sizeof(wchar_t)) | ||
| 310 | sysDriveLtr.assign(FromW(sysDrive), 0, 1); | ||
| 311 | else | ||
| 312 | sysDriveLtr = "C"; // fallback | ||
| 313 | |||
| 314 | iTotal = iTotalFree = iTotalUsed = iPercentFree = iPercentUsed = 0; | ||
| 315 | EXPECT_TRUE(g_sysinfo.GetDiskSpace(sysDriveLtr, iTotal, iTotalFree, iTotalUsed, iPercentFree, iPercentUsed)) << "'GetDiskSpace()' return 'false' for disk '" << sysDriveLtr << ":'"; | ||
| 316 | EXPECT_NE(0, iTotal) << "'GetDiskSpace()' return zero total space for disk '" << sysDriveLtr << ":'"; | ||
| 317 | EXPECT_EQ(iTotal, iTotalFree + iTotalUsed) << "'GetDiskSpace()' return 'TotalFree + TotalUsed' not equal to 'Total' for disk '" << sysDriveLtr << ":'"; | ||
| 318 | EXPECT_EQ(100, iPercentFree + iPercentUsed) << "'GetDiskSpace()' return 'PercentFree + PercentUsed' not equal to '100' for disk '" << sysDriveLtr << ":'"; | ||
| 319 | #elif defined(TARGET_POSIX) | ||
| 320 | iTotal = iTotalFree = iTotalUsed = iPercentFree = iPercentUsed = 0; | ||
| 321 | EXPECT_TRUE(g_sysinfo.GetDiskSpace("/", iTotal, iTotalFree, iTotalUsed, iPercentFree, iPercentUsed)) << "'GetDiskSpace()' return 'false' for directory '/'"; | ||
| 322 | EXPECT_NE(0, iTotal) << "'GetDiskSpace()' return zero total space for directory '/'"; | ||
| 323 | EXPECT_EQ(iTotal, iTotalFree + iTotalUsed) << "'GetDiskSpace()' return 'TotalFree + TotalUsed' not equal to 'Total' for directory '/'"; | ||
| 324 | EXPECT_EQ(100, iPercentFree + iPercentUsed) << "'GetDiskSpace()' return 'PercentFree + PercentUsed' not equal to '100' for directory '/'"; | ||
| 325 | #endif | ||
| 326 | } | ||
