1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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/file_util.h" 6 #include "base/sys_info.h" 7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/platform_test.h" 9 10 typedef PlatformTest SysInfoTest; 11 12 TEST_F(SysInfoTest, NumProcs) { 13 // We aren't actually testing that it's correct, just that it's sane. 14 EXPECT_GE(base::SysInfo::NumberOfProcessors(), 1); 15 } 16 17 TEST_F(SysInfoTest, AmountOfMem) { 18 // We aren't actually testing that it's correct, just that it's sane. 19 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemory(), 0); 20 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemoryMB(), 0); 21 } 22 23 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { 24 // We aren't actually testing that it's correct, just that it's sane. 25 FilePath tmp_path; 26 ASSERT_TRUE(file_util::GetTempDir(&tmp_path)); 27 EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) 28 << tmp_path.value(); 29 } 30 31 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 32 TEST_F(SysInfoTest, OperatingSystemVersionNumbers) { 33 int32 os_major_version = -1; 34 int32 os_minor_version = -1; 35 int32 os_bugfix_version = -1; 36 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, 37 &os_minor_version, 38 &os_bugfix_version); 39 EXPECT_GT(os_major_version, -1); 40 EXPECT_GT(os_minor_version, -1); 41 EXPECT_GT(os_bugfix_version, -1); 42 } 43 #endif 44 45 TEST_F(SysInfoTest, GetPrimaryDisplayDimensions) { 46 // We aren't actually testing that it's correct, just that it's sane. 47 int width, height; 48 base::SysInfo::GetPrimaryDisplayDimensions(&width, &height); 49 EXPECT_GE(width, 10); 50 EXPECT_GE(height, 10); 51 } 52 53 TEST_F(SysInfoTest, DisplayCount) { 54 // We aren't actually testing that it's correct, just that it's sane. 55 EXPECT_GE(base::SysInfo::DisplayCount(), 1); 56 } 57 58 #if defined(OS_CHROMEOS) 59 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) { 60 int32 os_major_version = -1; 61 int32 os_minor_version = -1; 62 int32 os_bugfix_version = -1; 63 std::string lsb_release("FOO=1234123.34.5\n"); 64 lsb_release.append(base::SysInfo::GetLinuxStandardBaseVersionKey()); 65 lsb_release.append("=1.2.3.4\n"); 66 base::SysInfo::ParseLsbRelease(lsb_release, 67 &os_major_version, 68 &os_minor_version, 69 &os_bugfix_version); 70 EXPECT_EQ(2, os_major_version); 71 EXPECT_EQ(3, os_minor_version); 72 EXPECT_EQ(4, os_bugfix_version); 73 } 74 75 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) { 76 int32 os_major_version = -1; 77 int32 os_minor_version = -1; 78 int32 os_bugfix_version = -1; 79 std::string lsb_release(base::SysInfo::GetLinuxStandardBaseVersionKey()); 80 lsb_release.append("=1.2.3.4\n"); 81 lsb_release.append("FOO=1234123.34.5\n"); 82 base::SysInfo::ParseLsbRelease(lsb_release, 83 &os_major_version, 84 &os_minor_version, 85 &os_bugfix_version); 86 EXPECT_EQ(2, os_major_version); 87 EXPECT_EQ(3, os_minor_version); 88 EXPECT_EQ(4, os_bugfix_version); 89 } 90 91 TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) { 92 int32 os_major_version = -1; 93 int32 os_minor_version = -1; 94 int32 os_bugfix_version = -1; 95 std::string lsb_release("FOO=1234123.34.5\n"); 96 base::SysInfo::ParseLsbRelease(lsb_release, 97 &os_major_version, 98 &os_minor_version, 99 &os_bugfix_version); 100 EXPECT_EQ(-1, os_major_version); 101 EXPECT_EQ(-1, os_minor_version); 102 EXPECT_EQ(-1, os_bugfix_version); 103 } 104 105 #endif // OS_CHROMEOS 106