Home | History | Annotate | Download | only in expectations
      1 // Copyright (c) 2013 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/test/expectations/expectation.h"
      6 
      7 #include "base/basictypes.h"
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 
     10 TEST(TestExpectationsFunctionsTest, ResultFromString) {
     11   test_expectations::Result result = test_expectations::RESULT_PASS;
     12 
     13   EXPECT_TRUE(ResultFromString("Failure", &result));
     14   EXPECT_EQ(test_expectations::RESULT_FAILURE, result);
     15 
     16   EXPECT_TRUE(ResultFromString("Timeout", &result));
     17   EXPECT_EQ(test_expectations::RESULT_TIMEOUT, result);
     18 
     19   EXPECT_TRUE(ResultFromString("Crash", &result));
     20   EXPECT_EQ(test_expectations::RESULT_CRASH, result);
     21 
     22   EXPECT_TRUE(ResultFromString("Skip", &result));
     23   EXPECT_EQ(test_expectations::RESULT_SKIP, result);
     24 
     25   EXPECT_TRUE(ResultFromString("Pass", &result));
     26   EXPECT_EQ(test_expectations::RESULT_PASS, result);
     27 
     28   // Case sensitive.
     29   EXPECT_FALSE(ResultFromString("failure", &result));
     30   EXPECT_EQ(test_expectations::RESULT_PASS, result);
     31 }
     32 
     33 TEST(TestExpectationsFunctionsTest, ConfigurationFromString) {
     34   test_expectations::Configuration config =
     35       test_expectations::CONFIGURATION_UNSPECIFIED;
     36 
     37   EXPECT_TRUE(ConfigurationFromString("Debug", &config));
     38   EXPECT_EQ(test_expectations::CONFIGURATION_DEBUG, config);
     39 
     40   EXPECT_TRUE(ConfigurationFromString("Release", &config));
     41   EXPECT_EQ(test_expectations::CONFIGURATION_RELEASE, config);
     42 
     43   EXPECT_FALSE(ConfigurationFromString("NotAConfig", &config));
     44   EXPECT_EQ(test_expectations::CONFIGURATION_RELEASE, config);
     45 
     46   // Case sensitive.
     47   EXPECT_FALSE(ConfigurationFromString("debug", &config));
     48   EXPECT_EQ(test_expectations::CONFIGURATION_RELEASE, config);
     49 }
     50 
     51 TEST(TestExpectationsFunctionsTest, PlatformFromString) {
     52   test_expectations::Platform platform;
     53 
     54   EXPECT_TRUE(PlatformFromString("Win", &platform));
     55   EXPECT_EQ("Win", platform.name);
     56   EXPECT_EQ("", platform.variant);
     57 
     58   EXPECT_TRUE(PlatformFromString("Mac-10.6", &platform));
     59   EXPECT_EQ("Mac", platform.name);
     60   EXPECT_EQ("10.6", platform.variant);
     61 
     62   EXPECT_TRUE(PlatformFromString("ChromeOS", &platform));
     63   EXPECT_EQ("ChromeOS", platform.name);
     64   EXPECT_EQ("", platform.variant);
     65 
     66   EXPECT_TRUE(PlatformFromString("Linux-", &platform));
     67   EXPECT_EQ("Linux", platform.name);
     68   EXPECT_EQ("", platform.variant);
     69 
     70   EXPECT_FALSE(PlatformFromString("", &platform));
     71 }
     72 
     73 TEST(TestExpectationsFunctionsTest, IsValidPlatform) {
     74   const char* kValidPlatforms[] = {
     75     "Win",
     76     "Win-XP",
     77     "Win-Vista",
     78     "Win-7",
     79     "Win-8",
     80     "Mac",
     81     "Mac-10.6",
     82     "Mac-10.7",
     83     "Mac-10.8",
     84     "Linux",
     85     "Linux-32",
     86     "Linux-64",
     87     "ChromeOS",
     88     "iOS",
     89     "Android",
     90   };
     91 
     92   const char* kInvalidPlatforms[] = {
     93     "Solaris",
     94     "Plan9",
     95   };
     96 
     97   for (size_t i = 0; i < arraysize(kValidPlatforms); ++i) {
     98     test_expectations::Platform platform;
     99     EXPECT_TRUE(test_expectations::PlatformFromString(
    100         kValidPlatforms[i], &platform)) << kValidPlatforms[i];
    101   }
    102 
    103   for (size_t i = 0; i < arraysize(kInvalidPlatforms); ++i) {
    104     test_expectations::Platform platform;
    105     EXPECT_FALSE(test_expectations::PlatformFromString(
    106         kInvalidPlatforms[i], &platform)) << kInvalidPlatforms[i];
    107   }
    108 }
    109 
    110 TEST(TestExpectationsFunctionsTest, CurrentPlatform) {
    111   test_expectations::Platform current =
    112       test_expectations::GetCurrentPlatform();
    113   EXPECT_FALSE(current.name.empty());
    114 }
    115 
    116 TEST(TestExpectationsFunctionsTest, CurrentConfiguration) {
    117   test_expectations::Configuration current =
    118       test_expectations::GetCurrentConfiguration();
    119   EXPECT_NE(test_expectations::CONFIGURATION_UNSPECIFIED, current);
    120 }
    121