summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/command_line.cc8
-rw-r--r--base/command_line.h8
-rw-r--r--base/command_line_unittest.cc4
-rw-r--r--base/test/test_suite.cc12
-rw-r--r--base/test/test_suite.h4
5 files changed, 22 insertions, 14 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index 0237ffe..983181f 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -167,12 +167,12 @@ CommandLine::~CommandLine() {
}
// static
-void CommandLine::Init(int argc, const char* const* argv) {
+bool CommandLine::Init(int argc, const char* const* argv) {
if (current_process_commandline_) {
// If this is intentional, Reset() must be called first. If we are using
// the shared build mode, we have to share a single object across multiple
// shared libraries.
- return;
+ return false;
}
current_process_commandline_ = new CommandLine(NO_PROGRAM);
@@ -181,6 +181,8 @@ void CommandLine::Init(int argc, const char* const* argv) {
#elif defined(OS_POSIX)
current_process_commandline_->InitFromArgv(argc, argv);
#endif
+
+ return true;
}
// static
diff --git a/base/command_line.h b/base/command_line.h
index a932a05..2ae2189 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -55,8 +55,10 @@ class BASE_EXPORT CommandLine {
// Initialize the current process CommandLine singleton. On Windows, ignores
// its arguments (we instead parse GetCommandLineW() directly) because we
// don't trust the CRT's parsing of the command line, but it still must be
- // called to set up the command line.
- static void Init(int argc, const char* const* argv);
+ // called to set up the command line. Returns false if initialization has
+ // already occurred, and true otherwise. Only the caller receiving a 'true'
+ // return value should take responsibility for calling Reset.
+ static bool Init(int argc, const char* const* argv);
// Destroys the current process CommandLine singleton. This is necessary if
// you want to reset the base library to its initial state (for example, in an
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index 656236e..310632d 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -291,7 +291,7 @@ TEST(CommandLineTest, ProgramQuotes) {
// Calling Init multiple times should not modify the previous CommandLine.
TEST(CommandLineTest, Init) {
CommandLine* initial = CommandLine::ForCurrentProcess();
- CommandLine::Init(0, NULL);
+ EXPECT_FALSE(CommandLine::Init(0, NULL));
CommandLine* current = CommandLine::ForCurrentProcess();
EXPECT_EQ(initial, current);
}
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc
index cf04caf..3416cd1 100644
--- a/base/test/test_suite.cc
+++ b/base/test/test_suite.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -71,16 +71,18 @@ class TestClientInitializer : public testing::EmptyTestEventListener {
const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling";
-TestSuite::TestSuite(int argc, char** argv) {
+TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) {
PreInitialize(argc, argv, true);
}
-TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) {
+TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager)
+ : initialized_command_line_(false) {
PreInitialize(argc, argv, create_at_exit_manager);
}
TestSuite::~TestSuite() {
- CommandLine::Reset();
+ if (initialized_command_line_)
+ CommandLine::Reset();
}
void TestSuite::PreInitialize(int argc, char** argv,
@@ -89,7 +91,7 @@ void TestSuite::PreInitialize(int argc, char** argv,
testing::GTEST_FLAG(catch_exceptions) = false;
#endif
base::EnableTerminationOnHeapCorruption();
- CommandLine::Init(argc, argv);
+ initialized_command_line_ = CommandLine::Init(argc, argv);
testing::InitGoogleTest(&argc, argv);
#if defined(OS_LINUX) && defined(USE_AURA)
// When calling native char conversion functions (e.g wrctomb) we need to
diff --git a/base/test/test_suite.h b/base/test/test_suite.h
index 4cf6857c..2b0e9ce 100644
--- a/base/test/test_suite.h
+++ b/base/test/test_suite.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -87,6 +87,8 @@ class TestSuite {
// Basic initialization for the test suite happens here.
void PreInitialize(int argc, char** argv, bool create_at_exit_manager);
+ bool initialized_command_line_;
+
DISALLOW_COPY_AND_ASSIGN(TestSuite);
};