blob: 40caf726b6c4779a250567828f505db5c907d809 [file] [log] [blame]
deanm@chromium.org42a34eb2008-09-17 19:09:39 +09001// Copyright (c) 2008 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
deanm@chromium.orgee45e8f2008-09-18 21:34:24 +09005#include "base/file_util.h"
deanm@chromium.org42a34eb2008-09-17 19:09:39 +09006#include "base/sys_info.h"
7#include "testing/gtest/include/gtest/gtest.h"
jeremy@chromium.org0d8eba72008-12-03 04:20:15 +09008#include "testing/platform_test.h"
deanm@chromium.org42a34eb2008-09-17 19:09:39 +09009
mark@chromium.org3b2ec6f2008-09-26 05:33:42 +090010typedef PlatformTest SysInfoTest;
11
12TEST_F(SysInfoTest, NumProcs) {
deanm@chromium.org42a34eb2008-09-17 19:09:39 +090013 // We aren't actually testing that it's correct, just that it's sane.
14 EXPECT_GE(base::SysInfo::NumberOfProcessors(), 1);
15}
deanm@chromium.org319f0442008-09-17 22:10:45 +090016
mark@chromium.org3b2ec6f2008-09-26 05:33:42 +090017TEST_F(SysInfoTest, AmountOfMem) {
deanm@chromium.org319f0442008-09-17 22:10:45 +090018 // We aren't actually testing that it's correct, just that it's sane.
19 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemory(), 0);
deanm@chromium.orgee45e8f2008-09-18 21:34:24 +090020 EXPECT_GT(base::SysInfo::AmountOfPhysicalMemoryMB(), 0);
21}
22
mark@chromium.org3b2ec6f2008-09-26 05:33:42 +090023TEST_F(SysInfoTest, AmountOfFreeDiskSpace) {
deanm@chromium.orgee45e8f2008-09-18 21:34:24 +090024 // We aren't actually testing that it's correct, just that it's sane.
phajdan.jr@chromium.orgc8008582009-09-15 04:36:31 +090025 FilePath tmp_path;
deanm@chromium.orgee45e8f2008-09-18 21:34:24 +090026 ASSERT_TRUE(file_util::GetTempDir(&tmp_path));
tony@chromium.org1e25e002009-10-14 09:41:56 +090027 EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0)
phajdan.jr@chromium.orgc8008582009-09-15 04:36:31 +090028 << tmp_path.value();
deanm@chromium.org319f0442008-09-17 22:10:45 +090029}
mark@chromium.orgb93c0542008-09-30 07:18:01 +090030
31TEST_F(SysInfoTest, GetEnvVar) {
32 // Every setup should have non-empty PATH...
33 EXPECT_NE(base::SysInfo::GetEnvVar(L"PATH"), L"");
34}
35
36TEST_F(SysInfoTest, HasEnvVar) {
37 // Every setup should have PATH...
38 EXPECT_TRUE(base::SysInfo::HasEnvVar(L"PATH"));
39}
jeremy@chromium.org7730edb2009-02-25 01:37:13 +090040
evan@chromium.org54b72102009-07-22 09:35:18 +090041#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
jeremy@chromium.org7730edb2009-02-25 01:37:13 +090042TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
43 int32 os_major_version = -1;
44 int32 os_minor_version = -1;
45 int32 os_bugfix_version = -1;
46 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
47 &os_minor_version,
48 &os_bugfix_version);
49 EXPECT_GT(os_major_version, -1);
50 EXPECT_GT(os_minor_version, -1);
51 EXPECT_GT(os_bugfix_version, -1);
52}
evan@chromium.org54b72102009-07-22 09:35:18 +090053#endif
54
evan@chromium.org33410102009-11-12 12:09:15 +090055TEST_F(SysInfoTest, GetPrimaryDisplayDimensions) {
56 // We aren't actually testing that it's correct, just that it's sane.
57 int width, height;
58 base::SysInfo::GetPrimaryDisplayDimensions(&width, &height);
59 EXPECT_GE(width, 10);
60 EXPECT_GE(height, 10);
61}
62
63TEST_F(SysInfoTest, DisplayCount) {
64 // We aren't actually testing that it's correct, just that it's sane.
65 EXPECT_GE(base::SysInfo::DisplayCount(), 1);
66}
67
evan@chromium.org54b72102009-07-22 09:35:18 +090068#if defined(OS_CHROMEOS)
69TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) {
70 int32 os_major_version = -1;
71 int32 os_minor_version = -1;
72 int32 os_bugfix_version = -1;
73 std::string lsb_release("FOO=1234123.34.5\n");
74 lsb_release.append(base::SysInfo::GetLinuxStandardBaseVersionKey());
75 lsb_release.append("=1.2.3.4\n");
76 base::SysInfo::ParseLsbRelease(lsb_release,
77 &os_major_version,
78 &os_minor_version,
79 &os_bugfix_version);
80 EXPECT_EQ(os_major_version, 1);
81 EXPECT_EQ(os_minor_version, 2);
82 EXPECT_EQ(os_bugfix_version, 3);
83}
84
85TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) {
86 int32 os_major_version = -1;
87 int32 os_minor_version = -1;
88 int32 os_bugfix_version = -1;
89 std::string lsb_release(base::SysInfo::GetLinuxStandardBaseVersionKey());
90 lsb_release.append("=1.2.3.4\n");
91 lsb_release.append("FOO=1234123.34.5\n");
92 base::SysInfo::ParseLsbRelease(lsb_release,
93 &os_major_version,
94 &os_minor_version,
95 &os_bugfix_version);
96 EXPECT_EQ(os_major_version, 1);
97 EXPECT_EQ(os_minor_version, 2);
98 EXPECT_EQ(os_bugfix_version, 3);
99}
100
101TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) {
102 int32 os_major_version = -1;
103 int32 os_minor_version = -1;
104 int32 os_bugfix_version = -1;
105 std::string lsb_release("FOO=1234123.34.5\n");
106 base::SysInfo::ParseLsbRelease(lsb_release,
107 &os_major_version,
108 &os_minor_version,
109 &os_bugfix_version);
110 EXPECT_EQ(os_major_version, -1);
111 EXPECT_EQ(os_minor_version, -1);
112 EXPECT_EQ(os_bugfix_version, -1);
113}
114
115#endif // OS_CHROMEOS