OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "base/environment.h" |
5 #include "base/file_util.h" | 6 #include "base/file_util.h" |
6 #include "base/sys_info.h" | 7 #include "base/sys_info.h" |
7 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
| 9 #include "base/time/time.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
10 | 12 |
11 typedef PlatformTest SysInfoTest; | 13 typedef PlatformTest SysInfoTest; |
12 using base::FilePath; | 14 using base::FilePath; |
13 | 15 |
14 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 16 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
15 TEST_F(SysInfoTest, MaxSharedMemorySize) { | 17 TEST_F(SysInfoTest, MaxSharedMemorySize) { |
16 // We aren't actually testing that it's correct, just that it's sane. | 18 // We aren't actually testing that it's correct, just that it's sane. |
17 EXPECT_GT(base::SysInfo::MaxSharedMemorySize(), 0u); | 19 EXPECT_GT(base::SysInfo::MaxSharedMemorySize(), 0u); |
(...skipping 12 matching lines...) Expand all Loading... |
30 } | 32 } |
31 | 33 |
32 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { | 34 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { |
33 // We aren't actually testing that it's correct, just that it's sane. | 35 // We aren't actually testing that it's correct, just that it's sane. |
34 FilePath tmp_path; | 36 FilePath tmp_path; |
35 ASSERT_TRUE(file_util::GetTempDir(&tmp_path)); | 37 ASSERT_TRUE(file_util::GetTempDir(&tmp_path)); |
36 EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) | 38 EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) |
37 << tmp_path.value(); | 39 << tmp_path.value(); |
38 } | 40 } |
39 | 41 |
40 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 42 #if defined(OS_WIN) || defined(OS_MACOSX) |
41 TEST_F(SysInfoTest, OperatingSystemVersionNumbers) { | 43 TEST_F(SysInfoTest, OperatingSystemVersionNumbers) { |
42 int32 os_major_version = -1; | 44 int32 os_major_version = -1; |
43 int32 os_minor_version = -1; | 45 int32 os_minor_version = -1; |
44 int32 os_bugfix_version = -1; | 46 int32 os_bugfix_version = -1; |
45 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 47 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
46 &os_minor_version, | 48 &os_minor_version, |
47 &os_bugfix_version); | 49 &os_bugfix_version); |
48 EXPECT_GT(os_major_version, -1); | 50 EXPECT_GT(os_major_version, -1); |
49 EXPECT_GT(os_minor_version, -1); | 51 EXPECT_GT(os_minor_version, -1); |
50 EXPECT_GT(os_bugfix_version, -1); | 52 EXPECT_GT(os_bugfix_version, -1); |
51 } | 53 } |
52 #endif | 54 #endif |
53 | 55 |
54 TEST_F(SysInfoTest, Uptime) { | 56 TEST_F(SysInfoTest, Uptime) { |
55 int64 up_time_1 = base::SysInfo::Uptime(); | 57 int64 up_time_1 = base::SysInfo::Uptime(); |
56 // UpTime() is implemented internally using TimeTicks::Now(), which documents | 58 // UpTime() is implemented internally using TimeTicks::Now(), which documents |
57 // system resolution as being 1-15ms. Sleep a little longer than that. | 59 // system resolution as being 1-15ms. Sleep a little longer than that. |
58 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); | 60 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
59 int64 up_time_2 = base::SysInfo::Uptime(); | 61 int64 up_time_2 = base::SysInfo::Uptime(); |
60 EXPECT_GT(up_time_1, 0); | 62 EXPECT_GT(up_time_1, 0); |
61 EXPECT_GT(up_time_2, up_time_1); | 63 EXPECT_GT(up_time_2, up_time_1); |
62 } | 64 } |
63 | 65 |
64 #if defined(OS_CHROMEOS) | 66 #if defined(OS_CHROMEOS) |
| 67 |
65 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) { | 68 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) { |
66 int32 os_major_version = -1; | 69 int32 os_major_version = -1; |
67 int32 os_minor_version = -1; | 70 int32 os_minor_version = -1; |
68 int32 os_bugfix_version = -1; | 71 int32 os_bugfix_version = -1; |
69 std::string lsb_release("FOO=1234123.34.5\n"); | 72 const char* kLsbRelease = |
70 lsb_release.append(base::SysInfo::GetLinuxStandardBaseVersionKey()); | 73 "FOO=1234123.34.5\n" |
71 lsb_release.append("=1.2.3.4\n"); | 74 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"; |
72 base::SysInfo::ParseLsbRelease(lsb_release, | 75 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); |
73 &os_major_version, | 76 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
74 &os_minor_version, | 77 &os_minor_version, |
75 &os_bugfix_version); | 78 &os_bugfix_version); |
76 EXPECT_EQ(1, os_major_version); | 79 EXPECT_EQ(1, os_major_version); |
77 EXPECT_EQ(2, os_minor_version); | 80 EXPECT_EQ(2, os_minor_version); |
78 EXPECT_EQ(3, os_bugfix_version); | 81 EXPECT_EQ(3, os_bugfix_version); |
79 } | 82 } |
80 | 83 |
81 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) { | 84 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) { |
82 int32 os_major_version = -1; | 85 int32 os_major_version = -1; |
83 int32 os_minor_version = -1; | 86 int32 os_minor_version = -1; |
84 int32 os_bugfix_version = -1; | 87 int32 os_bugfix_version = -1; |
85 std::string lsb_release(base::SysInfo::GetLinuxStandardBaseVersionKey()); | 88 const char* kLsbRelease = |
86 lsb_release.append("=1.2.3.4\n"); | 89 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
87 lsb_release.append("FOO=1234123.34.5\n"); | 90 "FOO=1234123.34.5\n"; |
88 base::SysInfo::ParseLsbRelease(lsb_release, | 91 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); |
89 &os_major_version, | 92 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
90 &os_minor_version, | 93 &os_minor_version, |
91 &os_bugfix_version); | 94 &os_bugfix_version); |
92 EXPECT_EQ(1, os_major_version); | 95 EXPECT_EQ(1, os_major_version); |
93 EXPECT_EQ(2, os_minor_version); | 96 EXPECT_EQ(2, os_minor_version); |
94 EXPECT_EQ(3, os_bugfix_version); | 97 EXPECT_EQ(3, os_bugfix_version); |
95 } | 98 } |
96 | 99 |
97 TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) { | 100 TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) { |
98 int32 os_major_version = -1; | 101 int32 os_major_version = -1; |
99 int32 os_minor_version = -1; | 102 int32 os_minor_version = -1; |
100 int32 os_bugfix_version = -1; | 103 int32 os_bugfix_version = -1; |
101 std::string lsb_release("FOO=1234123.34.5\n"); | 104 const char* kLsbRelease = "FOO=1234123.34.5\n"; |
102 base::SysInfo::ParseLsbRelease(lsb_release, | 105 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); |
103 &os_major_version, | 106 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
104 &os_minor_version, | 107 &os_minor_version, |
105 &os_bugfix_version); | 108 &os_bugfix_version); |
106 EXPECT_EQ(-1, os_major_version); | 109 EXPECT_EQ(0, os_major_version); |
107 EXPECT_EQ(-1, os_minor_version); | 110 EXPECT_EQ(0, os_minor_version); |
108 EXPECT_EQ(-1, os_bugfix_version); | 111 EXPECT_EQ(0, os_bugfix_version); |
| 112 } |
| 113 |
| 114 TEST_F(SysInfoTest, GoogleChromeOSLsbReleaseTime) { |
| 115 const char* kLsbRelease = "CHROMEOS_RELEASE_VERSION=1.2.3.4"; |
| 116 base::Time lsb_release_time = base::Time::Now(); |
| 117 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, lsb_release_time); |
| 118 base::Time parsed_lsb_release_time = base::SysInfo::GetLsbReleaseTime(); |
| 119 EXPECT_EQ(lsb_release_time.ToDoubleT(), |
| 120 parsed_lsb_release_time.ToDoubleT()); |
109 } | 121 } |
110 | 122 |
111 #endif // OS_CHROMEOS | 123 #endif // OS_CHROMEOS |
OLD | NEW |