Home | History | Annotate | Download | only in base
      1 // 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 
      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 TEST_F(SysInfoTest, GetEnvVar) {
     32   // Every setup should have non-empty PATH...
     33   EXPECT_NE(base::SysInfo::GetEnvVar(L"PATH"), L"");
     34 }
     35 
     36 TEST_F(SysInfoTest, HasEnvVar) {
     37   // Every setup should have PATH...
     38   EXPECT_TRUE(base::SysInfo::HasEnvVar(L"PATH"));
     39 }
     40 
     41 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
     42 TEST_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 }
     53 #endif
     54 
     55 TEST_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 
     63 TEST_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 
     68 #if defined(OS_CHROMEOS)
     69 TEST_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(1, os_major_version);
     81   EXPECT_EQ(2, os_minor_version);
     82   EXPECT_EQ(3, os_bugfix_version);
     83 }
     84 
     85 TEST_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(1, os_major_version);
     97   EXPECT_EQ(2, os_minor_version);
     98   EXPECT_EQ(3, os_bugfix_version);
     99 }
    100 
    101 TEST_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(-1, os_major_version);
    111   EXPECT_EQ(-1, os_minor_version);
    112   EXPECT_EQ(-1, os_bugfix_version);
    113 }
    114 
    115 #endif  // OS_CHROMEOS
    116