hunspell: Cleanup to fix the header include guards under google/ directory.
[chromium-blink-merge.git] / base / sys_info_unittest.cc
blob15ae0989b1d7d4590c1cf5570a980fa901d1e1df
1 // Copyright (c) 2012 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.
5 #include "base/environment.h"
6 #include "base/files/file_util.h"
7 #include "base/sys_info.h"
8 #include "base/threading/platform_thread.h"
9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
13 typedef PlatformTest SysInfoTest;
14 using base::FilePath;
16 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
17 TEST_F(SysInfoTest, MaxSharedMemorySize) {
18 // We aren't actually testing that it's correct, just that it's sane.
19 EXPECT_GT(base::SysInfo::MaxSharedMemorySize(), 0u);
21 #endif
23 TEST_F(SysInfoTest, NumProcs) {
24 // We aren't actually testing that it's correct, just that it's sane.
25 EXPECT_GE(base::SysInfo::NumberOfProcessors(), 1);
28 TEST_F(SysInfoTest, AmountOfMem) {
29 // We aren't actually testing that it's correct, just that it's sane.
30 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemory(), 0);
31 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemoryMB(), 0);
32 // The maxmimal amount of virtual memory can be zero which means unlimited.
33 EXPECT_GE(base::SysInfo::AmountOfVirtualMemory(), 0);
36 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) {
37 // We aren't actually testing that it's correct, just that it's sane.
38 FilePath tmp_path;
39 ASSERT_TRUE(base::GetTempDir(&tmp_path));
40 EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0)
41 << tmp_path.value();
44 #if defined(OS_WIN) || defined(OS_MACOSX)
45 TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
46 int32 os_major_version = -1;
47 int32 os_minor_version = -1;
48 int32 os_bugfix_version = -1;
49 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
50 &os_minor_version,
51 &os_bugfix_version);
52 EXPECT_GT(os_major_version, -1);
53 EXPECT_GT(os_minor_version, -1);
54 EXPECT_GT(os_bugfix_version, -1);
56 #endif
58 TEST_F(SysInfoTest, Uptime) {
59 int64 up_time_1 = base::SysInfo::Uptime();
60 // UpTime() is implemented internally using TimeTicks::Now(), which documents
61 // system resolution as being 1-15ms. Sleep a little longer than that.
62 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
63 int64 up_time_2 = base::SysInfo::Uptime();
64 EXPECT_GT(up_time_1, 0);
65 EXPECT_GT(up_time_2, up_time_1);
68 #if defined(OS_MACOSX) && !defined(OS_IOS)
69 TEST_F(SysInfoTest, HardwareModelName) {
70 std::string hardware_model = base::SysInfo::HardwareModelName();
71 EXPECT_FALSE(hardware_model.empty());
73 #endif
75 #if defined(OS_CHROMEOS)
77 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) {
78 int32 os_major_version = -1;
79 int32 os_minor_version = -1;
80 int32 os_bugfix_version = -1;
81 const char kLsbRelease[] =
82 "FOO=1234123.34.5\n"
83 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
84 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
85 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
86 &os_minor_version,
87 &os_bugfix_version);
88 EXPECT_EQ(1, os_major_version);
89 EXPECT_EQ(2, os_minor_version);
90 EXPECT_EQ(3, os_bugfix_version);
93 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) {
94 int32 os_major_version = -1;
95 int32 os_minor_version = -1;
96 int32 os_bugfix_version = -1;
97 const char kLsbRelease[] =
98 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
99 "FOO=1234123.34.5\n";
100 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
101 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
102 &os_minor_version,
103 &os_bugfix_version);
104 EXPECT_EQ(1, os_major_version);
105 EXPECT_EQ(2, os_minor_version);
106 EXPECT_EQ(3, os_bugfix_version);
109 TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) {
110 int32 os_major_version = -1;
111 int32 os_minor_version = -1;
112 int32 os_bugfix_version = -1;
113 const char kLsbRelease[] = "FOO=1234123.34.5\n";
114 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
115 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
116 &os_minor_version,
117 &os_bugfix_version);
118 EXPECT_EQ(0, os_major_version);
119 EXPECT_EQ(0, os_minor_version);
120 EXPECT_EQ(0, os_bugfix_version);
123 TEST_F(SysInfoTest, GoogleChromeOSLsbReleaseTime) {
124 const char kLsbRelease[] = "CHROMEOS_RELEASE_VERSION=1.2.3.4";
125 // Use a fake time that can be safely displayed as a string.
126 const base::Time lsb_release_time(base::Time::FromDoubleT(12345.6));
127 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, lsb_release_time);
128 base::Time parsed_lsb_release_time = base::SysInfo::GetLsbReleaseTime();
129 EXPECT_DOUBLE_EQ(lsb_release_time.ToDoubleT(),
130 parsed_lsb_release_time.ToDoubleT());
133 TEST_F(SysInfoTest, IsRunningOnChromeOS) {
134 base::SysInfo::SetChromeOSVersionInfoForTest("", base::Time());
135 EXPECT_FALSE(base::SysInfo::IsRunningOnChromeOS());
137 const char kLsbRelease1[] =
138 "CHROMEOS_RELEASE_NAME=Non Chrome OS\n"
139 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
140 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease1, base::Time());
141 EXPECT_FALSE(base::SysInfo::IsRunningOnChromeOS());
143 const char kLsbRelease2[] =
144 "CHROMEOS_RELEASE_NAME=Chrome OS\n"
145 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
146 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease2, base::Time());
147 EXPECT_TRUE(base::SysInfo::IsRunningOnChromeOS());
149 const char kLsbRelease3[] =
150 "CHROMEOS_RELEASE_NAME=Chromium OS\n";
151 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease3, base::Time());
152 EXPECT_TRUE(base::SysInfo::IsRunningOnChromeOS());
155 #endif // OS_CHROMEOS