diff options
author | rsesek <rsesek@chromium.org> | 2015-07-17 16:10:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-17 23:11:06 +0000 |
commit | 167581a136f768e1761777d8948eb53800902cd8 (patch) | |
tree | 339d7ab4e07a81b4d47c2c8396125b358e8dd5a2 /base | |
parent | ef17e0ebeb6ffbf4e293e95bf694106d81ef8d2b (diff) | |
download | chromium_src-167581a136f768e1761777d8948eb53800902cd8.zip chromium_src-167581a136f768e1761777d8948eb53800902cd8.tar.gz chromium_src-167581a136f768e1761777d8948eb53800902cd8.tar.bz2 |
Delete old, unused code.
BUG=
Review URL: https://codereview.chromium.org/1244433004
Cr-Commit-Position: refs/heads/master@{#339350}
Diffstat (limited to 'base')
-rw-r--r-- | base/BUILD.gn | 2 | ||||
-rw-r--r-- | base/base.gyp | 6 | ||||
-rw-r--r-- | base/test/BUILD.gn | 4 | ||||
-rw-r--r-- | base/test/expectations/OWNERS | 1 | ||||
-rw-r--r-- | base/test/expectations/expectation.cc | 161 | ||||
-rw-r--r-- | base/test/expectations/expectation.h | 94 | ||||
-rw-r--r-- | base/test/expectations/expectation_unittest.cc | 120 | ||||
-rw-r--r-- | base/test/expectations/parser.cc | 201 | ||||
-rw-r--r-- | base/test/expectations/parser.h | 143 | ||||
-rw-r--r-- | base/test/expectations/parser_unittest.cc | 209 |
10 files changed, 0 insertions, 941 deletions
diff --git a/base/BUILD.gn b/base/BUILD.gn index 238a89a..fd25887 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -1356,8 +1356,6 @@ test("base_unittests") { "task/cancelable_task_tracker_unittest.cc", "task_runner_util_unittest.cc", "template_util_unittest.cc", - "test/expectations/expectation_unittest.cc", - "test/expectations/parser_unittest.cc", "test/histogram_tester_unittest.cc", "test/test_reg_util_win_unittest.cc", "test/trace_event_analyzer_unittest.cc", diff --git a/base/base.gyp b/base/base.gyp index 8536727..e9b0995 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -607,8 +607,6 @@ 'task/cancelable_task_tracker_unittest.cc', 'task_runner_util_unittest.cc', 'template_util_unittest.cc', - 'test/expectations/expectation_unittest.cc', - 'test/expectations/parser_unittest.cc', 'test/histogram_tester_unittest.cc', 'test/test_pending_task_unittest.cc', 'test/test_reg_util_win_unittest.cc', @@ -891,10 +889,6 @@ }], ], 'sources': [ - 'test/expectations/expectation.cc', - 'test/expectations/expectation.h', - 'test/expectations/parser.cc', - 'test/expectations/parser.h', 'test/gtest_util.cc', 'test/gtest_util.h', 'test/gtest_xml_unittest_result_printer.cc', diff --git a/base/test/BUILD.gn b/base/test/BUILD.gn index 0d86f4e..127ec82 100644 --- a/base/test/BUILD.gn +++ b/base/test/BUILD.gn @@ -27,10 +27,6 @@ source_set("test_support") { # TODO http://crbug.com/412064 enable this flag all the time. testonly = !is_component_build sources = [ - "expectations/expectation.cc", - "expectations/expectation.h", - "expectations/parser.cc", - "expectations/parser.h", "gtest_util.cc", "gtest_util.h", "gtest_xml_unittest_result_printer.cc", diff --git a/base/test/expectations/OWNERS b/base/test/expectations/OWNERS deleted file mode 100644 index 14fce2a..0000000 --- a/base/test/expectations/OWNERS +++ /dev/null @@ -1 +0,0 @@ -rsesek@chromium.org diff --git a/base/test/expectations/expectation.cc b/base/test/expectations/expectation.cc deleted file mode 100644 index 3081779..0000000 --- a/base/test/expectations/expectation.cc +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/test/expectations/expectation.h" - -#include "base/logging.h" - -#if defined(OS_WIN) -#include "base/win/windows_version.h" -#elif defined(OS_MACOSX) && !defined(OS_IOS) -#include "base/mac/mac_util.h" -#elif defined(OS_LINUX) -#include "base/sys_info.h" -#endif - -namespace test_expectations { - -bool ResultFromString(const base::StringPiece& result, Result* out_result) { - if (result == "Failure") - *out_result = RESULT_FAILURE; - else if (result == "Timeout") - *out_result = RESULT_TIMEOUT; - else if (result == "Crash") - *out_result = RESULT_CRASH; - else if (result == "Skip") - *out_result = RESULT_SKIP; - else if (result == "Pass") - *out_result = RESULT_PASS; - else - return false; - - return true; -} - -static bool IsValidPlatform(const Platform* platform) { - const std::string& name = platform->name; - const std::string& variant = platform->variant; - - if (name == "Win") { - if (!variant.empty() && - variant != "XP" && - variant != "Vista" && - variant != "7" && - variant != "8") { - return false; - } - } else if (name == "Mac") { - if (!variant.empty() && - variant != "10.6" && - variant != "10.7" && - variant != "10.8" && - variant != "10.9" && - variant != "10.10") { - return false; - } - } else if (name == "Linux") { - if (!variant.empty() && - variant != "32" && - variant != "64") { - return false; - } - } else if (name == "ChromeOS") { - // TODO(rsesek): Figure out what ChromeOS needs. - } else if (name == "iOS") { - // TODO(rsesek): Figure out what iOS needs. Probably Device and Simulator. - } else if (name == "Android") { - // TODO(rsesek): Figure out what Android needs. - } else { - return false; - } - - return true; -} - -bool PlatformFromString(const base::StringPiece& modifier, - Platform* out_platform) { - size_t sep = modifier.find('-'); - if (sep == std::string::npos) { - out_platform->name = modifier.as_string(); - out_platform->variant.clear(); - } else { - out_platform->name = modifier.substr(0, sep).as_string(); - out_platform->variant = modifier.substr(sep + 1).as_string(); - } - - return IsValidPlatform(out_platform); -} - -Platform GetCurrentPlatform() { - Platform platform; -#if defined(OS_WIN) - platform.name = "Win"; - base::win::Version version = base::win::GetVersion(); - if (version == base::win::VERSION_XP) - platform.variant = "XP"; - else if (version == base::win::VERSION_VISTA) - platform.variant = "Vista"; - else if (version == base::win::VERSION_WIN7) - platform.variant = "7"; - else if (version == base::win::VERSION_WIN8) - platform.variant = "8"; -#elif defined(OS_IOS) - platform.name = "iOS"; -#elif defined(OS_MACOSX) - platform.name = "Mac"; - if (base::mac::IsOSSnowLeopard()) - platform.variant = "10.6"; - else if (base::mac::IsOSLion()) - platform.variant = "10.7"; - else if (base::mac::IsOSMountainLion()) - platform.variant = "10.8"; - else if (base::mac::IsOSMavericks()) - platform.variant = "10.9"; - else if (base::mac::IsOSYosemite()) - platform.variant = "10.10"; -#elif defined(OS_CHROMEOS) - platform.name = "ChromeOS"; -#elif defined(OS_ANDROID) - platform.name = "Android"; -#elif defined(OS_LINUX) - platform.name = "Linux"; - std::string arch = base::SysInfo::OperatingSystemArchitecture(); - if (arch == "x86") - platform.variant = "32"; - else if (arch == "x86_64") - platform.variant = "64"; -#else - NOTREACHED(); -#endif - return platform; -} - -bool ConfigurationFromString(const base::StringPiece& modifier, - Configuration* out_configuration) { - if (modifier == "Debug") - *out_configuration = CONFIGURATION_DEBUG; - else if (modifier == "Release") - *out_configuration = CONFIGURATION_RELEASE; - else - return false; - - return true; -} - -Configuration GetCurrentConfiguration() { -#if NDEBUG - return CONFIGURATION_RELEASE; -#else - return CONFIGURATION_DEBUG; -#endif -} - -Expectation::Expectation() - : configuration(CONFIGURATION_UNSPECIFIED), - result(RESULT_PASS) { -} - -Expectation::~Expectation() {} - -} // namespace test_expectations diff --git a/base/test/expectations/expectation.h b/base/test/expectations/expectation.h deleted file mode 100644 index be5a9d7..0000000 --- a/base/test/expectations/expectation.h +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_TEST_EXPECTATIONS_EXPECTATION_H_ -#define BASE_TEST_EXPECTATIONS_EXPECTATION_H_ - -#include <string> -#include <vector> - -#include "base/base_export.h" -#include "base/compiler_specific.h" -#include "base/strings/string_piece.h" - -namespace test_expectations { - -// A Result is the expectation of a test's behavior. -enum Result { - // The test has a failing assertion. - RESULT_FAILURE, - - // The test does not complete within the test runner's alloted duration. - RESULT_TIMEOUT, - - // The test crashes during the course of its execution. - RESULT_CRASH, - - // The test should not be run ever. - RESULT_SKIP, - - // The test passes, used to override a more general expectation. - RESULT_PASS, -}; - -// Converts a text string form of a |result| to its enum value, written to -// |out_result|. Returns true on success and false on error. -bool ResultFromString(const base::StringPiece& result, - Result* out_result) WARN_UNUSED_RESULT; - -// A Platform stores information about the OS environment. -struct Platform { - // The name of the platform. E.g., "Win", or "Mac". - std::string name; - - // The variant of the platform, either an OS version like "XP" or "10.8", or - // "Device" or "Simulator" in the case of mobile. - std::string variant; -}; - -// Converts a text string |modifier| to a Platform struct, written to -// |out_platform|. Returns true on success and false on failure. -bool PlatformFromString(const base::StringPiece& modifier, - Platform* out_platform) WARN_UNUSED_RESULT; - -// Returns the Platform for the currently running binary. -Platform GetCurrentPlatform(); - -// The build configuration. -enum Configuration { - CONFIGURATION_UNSPECIFIED, - CONFIGURATION_DEBUG, - CONFIGURATION_RELEASE, -}; - -// Converts the |modifier| to a Configuration constant, writing the value to -// |out_configuration|. Returns true on success or false on failure. -bool ConfigurationFromString(const base::StringPiece& modifier, - Configuration* out_configuration) WARN_UNUSED_RESULT; - -// Returns the Configuration for the currently running binary. -Configuration GetCurrentConfiguration(); - -// An Expectation is records what the result for a given test name should be on -// the specified platforms and configuration. -struct Expectation { - Expectation(); - ~Expectation(); - - // The name of the test, like FooBarTest.BarIsBaz. - std::string test_name; - - // The set of platforms for which this expectation is applicable. - std::vector<Platform> platforms; - - // The build configuration. - Configuration configuration; - - // The expected result of this test. - Result result; -}; - -} // namespace test_expectations - -#endif // BASE_TEST_EXPECTATIONS_EXPECTATION_H_ diff --git a/base/test/expectations/expectation_unittest.cc b/base/test/expectations/expectation_unittest.cc deleted file mode 100644 index c0f55a11..0000000 --- a/base/test/expectations/expectation_unittest.cc +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/test/expectations/expectation.h" - -#include "base/basictypes.h" -#include "testing/gtest/include/gtest/gtest.h" - -TEST(TestExpectationsFunctionsTest, ResultFromString) { - test_expectations::Result result = test_expectations::RESULT_PASS; - - EXPECT_TRUE(ResultFromString("Failure", &result)); - EXPECT_EQ(test_expectations::RESULT_FAILURE, result); - - EXPECT_TRUE(ResultFromString("Timeout", &result)); - EXPECT_EQ(test_expectations::RESULT_TIMEOUT, result); - - EXPECT_TRUE(ResultFromString("Crash", &result)); - EXPECT_EQ(test_expectations::RESULT_CRASH, result); - - EXPECT_TRUE(ResultFromString("Skip", &result)); - EXPECT_EQ(test_expectations::RESULT_SKIP, result); - - EXPECT_TRUE(ResultFromString("Pass", &result)); - EXPECT_EQ(test_expectations::RESULT_PASS, result); - - // Case sensitive. - EXPECT_FALSE(ResultFromString("failure", &result)); - EXPECT_EQ(test_expectations::RESULT_PASS, result); -} - -TEST(TestExpectationsFunctionsTest, ConfigurationFromString) { - test_expectations::Configuration config = - test_expectations::CONFIGURATION_UNSPECIFIED; - - EXPECT_TRUE(ConfigurationFromString("Debug", &config)); - EXPECT_EQ(test_expectations::CONFIGURATION_DEBUG, config); - - EXPECT_TRUE(ConfigurationFromString("Release", &config)); - EXPECT_EQ(test_expectations::CONFIGURATION_RELEASE, config); - - EXPECT_FALSE(ConfigurationFromString("NotAConfig", &config)); - EXPECT_EQ(test_expectations::CONFIGURATION_RELEASE, config); - - // Case sensitive. - EXPECT_FALSE(ConfigurationFromString("debug", &config)); - EXPECT_EQ(test_expectations::CONFIGURATION_RELEASE, config); -} - -TEST(TestExpectationsFunctionsTest, PlatformFromString) { - test_expectations::Platform platform; - - EXPECT_TRUE(PlatformFromString("Win", &platform)); - EXPECT_EQ("Win", platform.name); - EXPECT_EQ("", platform.variant); - - EXPECT_TRUE(PlatformFromString("Mac-10.6", &platform)); - EXPECT_EQ("Mac", platform.name); - EXPECT_EQ("10.6", platform.variant); - - EXPECT_TRUE(PlatformFromString("ChromeOS", &platform)); - EXPECT_EQ("ChromeOS", platform.name); - EXPECT_EQ("", platform.variant); - - EXPECT_TRUE(PlatformFromString("Linux-", &platform)); - EXPECT_EQ("Linux", platform.name); - EXPECT_EQ("", platform.variant); - - EXPECT_FALSE(PlatformFromString("", &platform)); -} - -TEST(TestExpectationsFunctionsTest, IsValidPlatform) { - const char* const kValidPlatforms[] = { - "Win", - "Win-XP", - "Win-Vista", - "Win-7", - "Win-8", - "Mac", - "Mac-10.6", - "Mac-10.7", - "Mac-10.8", - "Linux", - "Linux-32", - "Linux-64", - "ChromeOS", - "iOS", - "Android", - }; - - const char* const kInvalidPlatforms[] = { - "Solaris", - "Plan9", - }; - - for (size_t i = 0; i < arraysize(kValidPlatforms); ++i) { - test_expectations::Platform platform; - EXPECT_TRUE(test_expectations::PlatformFromString( - kValidPlatforms[i], &platform)) << kValidPlatforms[i]; - } - - for (size_t i = 0; i < arraysize(kInvalidPlatforms); ++i) { - test_expectations::Platform platform; - EXPECT_FALSE(test_expectations::PlatformFromString( - kInvalidPlatforms[i], &platform)) << kInvalidPlatforms[i]; - } -} - -TEST(TestExpectationsFunctionsTest, CurrentPlatform) { - test_expectations::Platform current = - test_expectations::GetCurrentPlatform(); - EXPECT_FALSE(current.name.empty()); -} - -TEST(TestExpectationsFunctionsTest, CurrentConfiguration) { - test_expectations::Configuration current = - test_expectations::GetCurrentConfiguration(); - EXPECT_NE(test_expectations::CONFIGURATION_UNSPECIFIED, current); -} diff --git a/base/test/expectations/parser.cc b/base/test/expectations/parser.cc deleted file mode 100644 index 83c64c6..0000000 --- a/base/test/expectations/parser.cc +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/test/expectations/parser.h" - -#include "base/strings/string_util.h" - -namespace test_expectations { - -Parser::Parser(Delegate* delegate, const std::string& input) - : delegate_(delegate), - input_(input), - pos_(NULL), - end_(NULL), - line_number_(0), - data_error_(false) { -} - -Parser::~Parser() { -} - -void Parser::Parse() { - pos_ = &input_[0]; - end_ = pos_ + input_.length(); - - line_number_ = 1; - - StateFuncPtr state = &Parser::Start; - while (state) { - state = (this->*state)(); - } -} - -inline bool Parser::HasNext() { - return pos_ < end_; -} - -Parser::StateFunc Parser::Start() { - // If at the start of a line is whitespace, skip it and arrange to come back - // here. - if (base::IsAsciiWhitespace(*pos_)) - return SkipWhitespaceAndNewLines(&Parser::Start); - - // Handle comments at the start of lines. - if (*pos_ == '#') - return &Parser::ParseComment; - - // After arranging to come back here from skipping whitespace and comments, - // the parser may be at the end of the input. - if (pos_ >= end_) - return NULL; - - current_ = Expectation(); - data_error_ = false; - - return &Parser::ParseBugURL; -} - -Parser::StateFunc Parser::ParseComment() { - if (*pos_ != '#') - return SyntaxError("Invalid start of comment"); - - do { - ++pos_; - } while (HasNext() && *pos_ != '\n'); - - return &Parser::Start; -} - -Parser::StateFunc Parser::ParseBugURL() { - return SkipWhitespace(ExtractString( - &Parser::BeginModifiers)); -} - -Parser::StateFunc Parser::BeginModifiers() { - if (*pos_ != '[' || !HasNext()) - return SyntaxError("Expected '[' for start of modifiers"); - - ++pos_; - return SkipWhitespace(&Parser::InModifiers); -} - -Parser::StateFunc Parser::InModifiers() { - if (*pos_ == ']') - return &Parser::EndModifiers; - - return ExtractString(SkipWhitespace( - &Parser::SaveModifier)); -} - -Parser::StateFunc Parser::SaveModifier() { - if (extracted_string_.empty()) - return SyntaxError("Invalid modifier list"); - - Configuration config; - if (ConfigurationFromString(extracted_string_, &config)) { - if (current_.configuration != CONFIGURATION_UNSPECIFIED) - DataError("Cannot use more than one configuration modifier"); - else - current_.configuration = config; - } else { - Platform platform; - if (PlatformFromString(extracted_string_, &platform)) - current_.platforms.push_back(platform); - else - DataError("Invalid modifier string"); - } - - return SkipWhitespace(&Parser::InModifiers); -} - -Parser::StateFunc Parser::EndModifiers() { - if (*pos_ != ']' || !HasNext()) - return SyntaxError("Expected ']' for end of modifiers list"); - - ++pos_; - return SkipWhitespace(&Parser::ParseTestName); -} - -Parser::StateFunc Parser::ParseTestName() { - return ExtractString(&Parser::SaveTestName); -} - -Parser::StateFunc Parser::SaveTestName() { - if (extracted_string_.empty()) - return SyntaxError("Invalid test name"); - - current_.test_name = extracted_string_.as_string(); - return SkipWhitespace(&Parser::ParseExpectation); -} - -Parser::StateFunc Parser::ParseExpectation() { - if (*pos_ != '=' || !HasNext()) - return SyntaxError("Expected '=' for expectation result"); - - ++pos_; - return SkipWhitespace(&Parser::ParseExpectationType); -} - -Parser::StateFunc Parser::ParseExpectationType() { - return ExtractString(&Parser::SaveExpectationType); -} - -Parser::StateFunc Parser::SaveExpectationType() { - if (!ResultFromString(extracted_string_, ¤t_.result)) - DataError("Unknown expectation type"); - - return SkipWhitespace(&Parser::End); -} - -Parser::StateFunc Parser::End() { - if (!data_error_) - delegate_->EmitExpectation(current_); - - if (HasNext()) - return SkipWhitespaceAndNewLines(&Parser::Start); - - return NULL; -} - -Parser::StateFunc Parser::ExtractString(StateFunc success) { - const char* start = pos_; - while (!base::IsAsciiWhitespace(*pos_) && *pos_ != ']' && HasNext()) { - ++pos_; - if (*pos_ == '#') { - return SyntaxError("Unexpected start of comment"); - } - } - extracted_string_ = base::StringPiece(start, pos_ - start); - return success; -} - -Parser::StateFunc Parser::SkipWhitespace(Parser::StateFunc next) { - while ((*pos_ == ' ' || *pos_ == '\t') && HasNext()) { - ++pos_; - } - return next; -} - -Parser::StateFunc Parser::SkipWhitespaceAndNewLines(Parser::StateFunc next) { - while (base::IsAsciiWhitespace(*pos_) && HasNext()) { - if (*pos_ == '\n') { - ++line_number_; - } - ++pos_; - } - return next; -} - -Parser::StateFunc Parser::SyntaxError(const std::string& message) { - delegate_->OnSyntaxError(message); - return NULL; -} - -void Parser::DataError(const std::string& error) { - data_error_ = true; - delegate_->OnDataError(error); -} - -} // namespace test_expectations diff --git a/base/test/expectations/parser.h b/base/test/expectations/parser.h deleted file mode 100644 index 69a741a..0000000 --- a/base/test/expectations/parser.h +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_TEST_EXPECTATIONS_PARSER_H_ -#define BASE_TEST_EXPECTATIONS_PARSER_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/strings/string_piece.h" -#include "base/test/expectations/expectation.h" - -namespace test_expectations { - -// This is the internal parser for test expectations. It parses an input -// string and reports information to its Delegate as it's processing the -// input. -// -// The input format is documented here: -// https://docs.google.com/a/chromium.org/document/d/1edhMJ5doY_dzfbKNCzeJJ-8XxPrexTbNL2Y_jVvLB8Q/view -// -// Basic format: -// "http://bug/1234 [ OS-Version ] Test.Name = Result" -// -// The parser is implemented as a state machine, with each state returning a -// function pointer to the next state. -class Parser { - public: - // The parser will call these methods on its delegate during a Parse() - // operation. - class Delegate { - public: - // When a well-formed and valid Expectation has been parsed from the input, - // it is reported to the delegate via this method. - virtual void EmitExpectation(const Expectation& expectation) = 0; - - // Called when the input string is not well-formed. Parsing will stop after - // this method is called. - virtual void OnSyntaxError(const std::string& message) = 0; - - // Called when an Expectation has been parsed because it is well-formed but - // contains invalid data (i.e. the modifiers or result are not valid - // keywords). This Expectation will not be reported via EmitExpectation. - virtual void OnDataError(const std::string& message) = 0; - }; - - // Creates a new parser for |input| that will send data to |delegate|. - Parser(Delegate* delegate, const std::string& input); - ~Parser(); - - // Runs the parser of the input string. - void Parse(); - - private: - // This bit of hackery is used to implement a function pointer type that - // returns a pointer to a function of the same signature. Since a definition - // like that is inherently recursive, it's impossible to do: - // type StateFunc(*StateFunc)(StateData*); - // However, this approach works without the need to use void*. Inspired by - // <http://www.gotw.ca/gotw/057.htm>. - struct StateFunc; - typedef StateFunc(Parser::*StateFuncPtr)(); - struct StateFunc { - StateFunc(StateFuncPtr pf) : pf_(pf) {} - operator StateFuncPtr() { - return pf_; - } - StateFuncPtr pf_; - }; - - // Tests whether there is at least one more character at pos_ before end_. - bool HasNext(); - - // The parser state functions. On entry, the parser state is at the beginning - // of the token. Each returns a function pointer to the next state function, - // or NULL to end parsing. On return, the parser is at the beginning of the - // next token. - StateFunc Start(); - StateFunc ParseComment(); - StateFunc ParseBugURL(); - StateFunc BeginModifiers(); - StateFunc InModifiers(); - StateFunc SaveModifier(); - StateFunc EndModifiers(); - StateFunc ParseTestName(); - StateFunc SaveTestName(); - StateFunc ParseExpectation(); - StateFunc ParseExpectationType(); - StateFunc SaveExpectationType(); - StateFunc End(); - - // A state function that collects character data from the current position - // to the next whitespace character. Returns the |success| function when at - // the end of the string, with the data stored in |extracted_string_|. - StateFunc ExtractString(StateFunc success); - - // Function that skips over horizontal whitespace characters and then returns - // the |next| state. - StateFunc SkipWhitespace(StateFunc next); - - // Does the same as SkipWhitespace but includes newlines. - StateFunc SkipWhitespaceAndNewLines(StateFunc next); - - // State function that reports the given syntax error |message| to the - // delegate and then returns NULL, ending the parse loop. - StateFunc SyntaxError(const std::string& message); - - // Function that reports the data |error| to the delegate without stopping - // parsing. - void DataError(const std::string& error); - - // Parser delegate. - Delegate* delegate_; - - // The input string. - std::string input_; - - // Current location in the |input_|. - const char* pos_; - - // Pointer to the end of the |input_|. - const char* end_; - - // Current line number, as updated by SkipWhitespace(). - int line_number_; - - // The character data extracted from |input_| as a result of the - // ExtractString() state. - base::StringPiece extracted_string_; - - // The Expectation object that is currently being processed by the parser. - // Reset in Start(). - Expectation current_; - - // If DataError() has been called during the course of parsing |current_|. - // If true, then |current_| will not be emitted to the Delegate. - bool data_error_; -}; - -} // namespace test_expectations - -#endif // BASE_TEST_EXPECTATIONS_PARSER_H_ diff --git a/base/test/expectations/parser_unittest.cc b/base/test/expectations/parser_unittest.cc deleted file mode 100644 index 074d634..0000000 --- a/base/test/expectations/parser_unittest.cc +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/test/expectations/parser.h" - -#include <string> -#include <vector> - -#include "base/compiler_specific.h" -#include "testing/gtest/include/gtest/gtest.h" - -using test_expectations::Parser; - -class TestExpectationParserTest : public testing::Test, - public Parser::Delegate { - public: - void EmitExpectation( - const test_expectations::Expectation& expectation) override { - expectations_.push_back(expectation); - } - - void OnSyntaxError(const std::string& message) override { - syntax_error_ = message; - } - - void OnDataError(const std::string& error) override { - data_errors_.push_back(error); - } - - protected: - std::vector<test_expectations::Expectation> expectations_; - std::string syntax_error_; - std::vector<std::string> data_errors_; -}; - -TEST_F(TestExpectationParserTest, Basic) { - Parser(this, - "http://crbug.com/1234 [ Win-8 ] DouglasTest.PoopsOk = Timeout"). - Parse(); - EXPECT_TRUE(syntax_error_.empty()); - EXPECT_EQ(0u, data_errors_.size()); - - ASSERT_EQ(1u, expectations_.size()); - EXPECT_EQ("DouglasTest.PoopsOk", expectations_[0].test_name); - EXPECT_EQ(test_expectations::RESULT_TIMEOUT, expectations_[0].result); - EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED, - expectations_[0].configuration); - - ASSERT_EQ(1u, expectations_[0].platforms.size()); - EXPECT_EQ("Win", expectations_[0].platforms[0].name); - EXPECT_EQ("8", expectations_[0].platforms[0].variant); -} - -TEST_F(TestExpectationParserTest, MultiModifier) { - Parser(this, "BUG [ Win-XP Mac ] OhMy.MeOhMy = Failure").Parse(); - EXPECT_TRUE(syntax_error_.empty()); - EXPECT_EQ(0u, data_errors_.size()); - - ASSERT_EQ(1u, expectations_.size()); - EXPECT_EQ("OhMy.MeOhMy", expectations_[0].test_name); - EXPECT_EQ(test_expectations::RESULT_FAILURE, - expectations_[0].result); - EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED, - expectations_[0].configuration); - - ASSERT_EQ(2u, expectations_[0].platforms.size()); - - EXPECT_EQ("Win", expectations_[0].platforms[0].name); - EXPECT_EQ("XP", expectations_[0].platforms[0].variant); - - EXPECT_EQ("Mac", expectations_[0].platforms[1].name); - EXPECT_EQ("", expectations_[0].platforms[1].variant); -} - -TEST_F(TestExpectationParserTest, EmptyModifier) { - Parser(this, - "BUG [] First.Test = Failure\n" - "BUG2 [ ] Second.Test = Crash").Parse(); - EXPECT_EQ(0u, data_errors_.size()); - - ASSERT_EQ(2u, expectations_.size()); - - EXPECT_EQ("First.Test", expectations_[0].test_name); - EXPECT_EQ(test_expectations::RESULT_FAILURE, - expectations_[0].result); - EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED, - expectations_[0].configuration); - EXPECT_EQ(0u, expectations_[0].platforms.size()); - - EXPECT_EQ("Second.Test", expectations_[1].test_name); - EXPECT_EQ(test_expectations::RESULT_CRASH, - expectations_[1].result); - EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED, - expectations_[1].configuration); - EXPECT_EQ(0u, expectations_[1].platforms.size()); -} - -TEST_F(TestExpectationParserTest, MultiLine) { - Parser(this, - "BUG [ Linux ] Line.First = Failure\n" - "\n" - "# A test comment.\n" - "BUG2 [ Release ] Line.Second = Skip").Parse(); - EXPECT_TRUE(syntax_error_.empty()); - EXPECT_EQ(0u, data_errors_.size()); - - ASSERT_EQ(2u, expectations_.size()); - EXPECT_EQ("Line.First", expectations_[0].test_name); - EXPECT_EQ(test_expectations::RESULT_FAILURE, expectations_[0].result); - EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED, - expectations_[0].configuration); - - ASSERT_EQ(1u, expectations_[0].platforms.size()); - EXPECT_EQ("Linux", expectations_[0].platforms[0].name); - EXPECT_EQ("", expectations_[0].platforms[0].variant); - - EXPECT_EQ("Line.Second", expectations_[1].test_name); - EXPECT_EQ(test_expectations::RESULT_SKIP, expectations_[1].result); - EXPECT_EQ(test_expectations::CONFIGURATION_RELEASE, - expectations_[1].configuration); - EXPECT_EQ(0u, expectations_[1].platforms.size()); -} - -TEST_F(TestExpectationParserTest, MultiLineWithComments) { - Parser(this, - " # Comment for your thoughts\n" - " \t \n" - "BUG [ Mac-10.8 Debug] Foo=Bar =Skip # Why not another comment?\n" - "BUG2 [Win-XP\tWin-Vista ] Cow.GoesMoo =\tTimeout\n\n").Parse(); - EXPECT_TRUE(syntax_error_.empty()) << syntax_error_; - EXPECT_EQ(0u, data_errors_.size()); - - ASSERT_EQ(2u, expectations_.size()); - EXPECT_EQ("Foo=Bar", expectations_[0].test_name); - EXPECT_EQ(test_expectations::RESULT_SKIP, expectations_[0].result); - EXPECT_EQ(test_expectations::CONFIGURATION_DEBUG, - expectations_[0].configuration); - - ASSERT_EQ(1u, expectations_[0].platforms.size()); - EXPECT_EQ("Mac", expectations_[0].platforms[0].name); - EXPECT_EQ("10.8", expectations_[0].platforms[0].variant); - - EXPECT_EQ("Cow.GoesMoo", expectations_[1].test_name); - EXPECT_EQ(test_expectations::RESULT_TIMEOUT, expectations_[1].result); - EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED, - expectations_[1].configuration); - - ASSERT_EQ(2u, expectations_[1].platforms.size()); - EXPECT_EQ("Win", expectations_[1].platforms[0].name); - EXPECT_EQ("XP", expectations_[1].platforms[0].variant); - EXPECT_EQ("Win", expectations_[1].platforms[0].name); - EXPECT_EQ("Vista", expectations_[1].platforms[1].variant); -} - -TEST_F(TestExpectationParserTest, WeirdSpaces) { - Parser(this, " BUG [Linux] Weird = Skip ").Parse(); - EXPECT_EQ(1u, expectations_.size()); - EXPECT_TRUE(syntax_error_.empty()); - EXPECT_EQ(0u, data_errors_.size()); -} - -TEST_F(TestExpectationParserTest, SyntaxErrors) { - const char* const kErrors[] = { - "Foo [ dfasd", - "Foo [Linux] # This is an illegal comment", - "Foo [Linux] Bar # Another illegal comment.", - "Foo [Linux] Bar = # Another illegal comment.", - "Foo[Linux]Bar=Failure", - "Foo\n[Linux] Bar = Failure", - "Foo [\nLinux] Bar = Failure", - "Foo [Linux\n] Bar = Failure", - "Foo [ Linux ] \n Bar = Failure", - "Foo [ Linux ] Bar =\nFailure", - "Foo [ Linux \n ] Bar =\nFailure", - }; - - for (size_t i = 0; i < arraysize(kErrors); ++i) { - Parser(this, kErrors[i]).Parse(); - EXPECT_FALSE(syntax_error_.empty()) - << "Should have error for #" << i << ": " << kErrors[i]; - syntax_error_.clear(); - } -} - -TEST_F(TestExpectationParserTest, DataErrors) { - const char* const kOneError[] = { - "http://crbug.com/1234 [MagicBrowzR] BadModifier = Timeout", - "________ [Linux] BadResult = WhatNow", - "http://wkb.ug/1234 [Debug Release Win-7] MultipleConfigs = Skip", - }; - - for (size_t i = 0; i < arraysize(kOneError); ++i) { - Parser(this, kOneError[i]).Parse(); - EXPECT_EQ(1u, data_errors_.size()) << kOneError[i]; - data_errors_.clear(); - } - - const char* const kTwoErrors[] = { - ". [Mac-TurningIntoiOS] BadModifierVariant.BadResult = Foobar", - "1234 [ Debug Release OS/2 ] MultipleConfigs.BadModifier = Pass", - }; - - for (size_t i = 0; i < arraysize(kTwoErrors); ++i) { - Parser(this, kTwoErrors[i]).Parse(); - EXPECT_EQ(2u, data_errors_.size()) << kTwoErrors[i]; - data_errors_.clear(); - } -} |